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

452 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FrmStylesHelper {
4
5 public static function get_upload_base() {
6 $uploads = wp_upload_dir();
7 if ( is_ssl() && ! preg_match( '/^https:\/\/.*\..*$/', $uploads['baseurl'] ) ) {
8 $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] );
9 }
10
11 return $uploads;
12 }
13
14 /**
15 * @since 4.0
16 */
17 public static function get_style_menu( $active = '' ) {
18 ob_start();
19 self::style_menu( $active );
20 $menu = ob_get_contents();
21 ob_end_clean();
22
23 return $menu;
24 }
25
26 public static function style_menu( $active = '' ) {
27 ?>
28 <ul class="frm_form_nav">
29 <li>
30 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles' ) ); ?>"
31 class="<?php echo ( '' == $active ) ? 'current_page' : ''; ?>">
32 <?php esc_html_e( 'Edit Styles', 'formidable' ); ?>
33 </a>
34 </li>
35 <li>
36 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=manage' ) ); ?>"
37 class="<?php echo ( 'manage' == $active ) ? 'current_page' : ''; ?>">
38 <?php esc_html_e( 'Manage Styles', 'formidable' ); ?>
39 </a>
40 </li>
41 <li>
42 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=custom_css' ) ); ?>"
43 class="<?php echo ( 'custom_css' == $active ) ? 'current_page' : ''; ?>">
44 <?php esc_html_e( 'Custom CSS', 'formidable' ); ?>
45 </a>
46 </li>
47 </ul>
48 <?php
49 }
50
51 /**
52 * @since 4.0
53 */
54 public static function styler_save_button( $atts ) {
55 $style = $atts['style'];
56 if ( ! empty( $style->ID ) && empty( $style->menu_order ) ) {
57 $delete_link = admin_url( 'admin.php?page=formidable-styles&frm_action=destroy&id=' . $style->ID );
58 }
59
60 include( FrmAppHelper::plugin_path() . '/classes/views/styles/header-buttons.php' );
61 }
62
63 /**
64 * Called from the admin header.
65 *
66 * @since 4.0
67 */
68 public static function save_button() {
69 ?>
70 <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" />
71 <?php
72 }
73
74 /**
75 * Either get the heading or the style switcher.
76 *
77 * @since 4.0
78 */
79 public static function styler_switcher( $atts ) {
80 if ( has_action( 'frm_style_switcher_heading' ) ) {
81 do_action( 'frm_style_switcher_heading', $atts );
82 } else {
83 ?>
84 <div class="frm_top_left">
85 <h1>
86 <?php echo esc_html( $atts['style']->post_title ); ?>
87 </h1>
88 </div>
89 <?php
90 }
91 }
92
93 /**
94 * @since 2.05
95 */
96 public static function get_css_label_positions() {
97 return array(
98 'none' => __( 'top', 'formidable' ),
99 'left' => __( 'left', 'formidable' ),
100 'right' => __( 'right', 'formidable' ),
101 'no_label' => __( 'none', 'formidable' ),
102 'inside' => __( 'inside', 'formidable' ),
103 );
104 }
105
106 public static function get_single_label_positions() {
107 return array(
108 'top' => __( 'Top', 'formidable' ),
109 'left' => __( 'Left', 'formidable' ),
110 'right' => __( 'Right', 'formidable' ),
111 'inline' => __( 'Inline (left without a set width)', 'formidable' ),
112 'none' => __( 'None', 'formidable' ),
113 'hidden' => __( 'Hidden (but leave the space)', 'formidable' ),
114 'inside' => __( 'Placeholder inside the field', 'formidable' ),
115 );
116 }
117
118 public static function minus_icons() {
119 return array(
120 0 => array(
121 '-' => '62e',
122 '+' => '62f',
123 ),
124 1 => array(
125 '-' => '600',
126 '+' => '602',
127 ),
128 2 => array(
129 '-' => '604',
130 '+' => '603',
131 ),
132 3 => array(
133 '-' => '633',
134 '+' => '632',
135 ),
136 4 => array(
137 '-' => '613',
138 '+' => '60f',
139 ),
140 );
141 }
142
143 public static function arrow_icons() {
144 $minus_icons = self::minus_icons();
145
146 return array(
147 6 => array(
148 '-' => '62d',
149 '+' => '62a',
150 ),
151 0 => array(
152 '-' => '60d',
153 '+' => '609',
154 ),
155 1 => array(
156 '-' => '60e',
157 '+' => '60c',
158 ),
159 2 => array(
160 '-' => '630',
161 '+' => '631',
162 ),
163 3 => array(
164 '-' => '62b',
165 '+' => '628',
166 ),
167 4 => array(
168 '-' => '62c',
169 '+' => '629',
170 ),
171 5 => array(
172 '-' => '635',
173 '+' => '634',
174 ),
175 'p0' => $minus_icons[0],
176 'p1' => $minus_icons[1],
177 'p2' => $minus_icons[2],
178 'p3' => $minus_icons[3],
179 'p4' => $minus_icons[4],
180 );
181 }
182
183 /**
184 * @since 2.0
185 * @return The class for this icon
186 */
187 public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
188 if ( 'arrow' == $type && is_numeric( $key ) ) {
189 //frm_arrowup6_icon
190 $arrow = array(
191 '-' => 'down',
192 '+' => 'up',
193 );
194 $class = 'frm_arrow' . $arrow[ $icon ];
195 } else {
196 //frm_minus1_icon
197 $key = str_replace( 'p', '', $key );
198 $plus = array(
199 '-' => 'minus',
200 '+' => 'plus',
201 );
202 $class = 'frm_' . $plus[ $icon ];
203 }
204
205 if ( $key ) {
206 $class .= $key;
207 }
208 $class .= '_icon';
209
210 return $class;
211 }
212
213 public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
214 $function_name = $type . '_icons';
215 $icons = self::$function_name();
216 unset( $function_name );
217
218 $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
219 ?>
220 <div class="btn-group" id="frm_<?php echo esc_attr( $name ); ?>_select">
221 <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
222 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?>
223 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ); ?>
224 <b class="caret"></b>
225 </button>
226 <ul class="multiselect-container frm-dropdown-menu">
227 <?php foreach ( $icons as $key => $icon ) { ?>
228 <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : ''; ?>>
229 <a href="javascript:void(0);">
230 <label>
231 <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 ); ?>/>
232 <span>
233 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '+', $type ) ); ?>
234 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '-', $type ) ); ?>
235 </span>
236 </label>
237 </a>
238 </li>
239 <?php } ?>
240 </ul>
241 </div>
242 <?php
243 }
244
245 public static function hex2rgb( $hex ) {
246 $hex = str_replace( '#', '', $hex );
247
248 list( $r, $g, $b ) = sscanf( $hex, '%02x%02x%02x' );
249
250 $rgb = array( $r, $g, $b );
251
252 return implode( ',', $rgb );
253 }
254
255 /**
256 * @since 4.0
257 */
258 public static function hex2rgba( $hex, $a ) {
259 $rgb = self::hex2rgb( $hex );
260
261 return 'rgba(' . $rgb . ',' . $a . ')';
262 }
263
264 /**
265 * @param $hex string - The original color in hex format #ffffff
266 * @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter
267 *
268 * @since 2.3
269 */
270 public static function adjust_brightness( $hex, $steps ) {
271 $steps = max( - 255, min( 255, $steps ) );
272
273 // Normalize into a six character long hex string
274 $hex = str_replace( '#', '', $hex );
275 if ( strlen( $hex ) == 3 ) {
276 $hex = str_repeat( substr( $hex, 0, 1 ), 2 );
277 $hex .= str_repeat( substr( $hex, 1, 1 ), 2 );
278 $hex .= str_repeat( substr( $hex, 2, 1 ), 2 );
279 }
280
281 // Split into three parts: R, G and B
282 $color_parts = str_split( $hex, 2 );
283 $return = '#';
284
285 foreach ( $color_parts as $color ) {
286 $color = hexdec( $color ); // Convert to decimal
287 $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
288 $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
289 }
290
291 return $return;
292 }
293
294 /**
295 * @since 2.3
296 */
297 public static function get_settings_for_output( $style ) {
298 if ( self::previewing_style() ) {
299 if ( isset( $_POST['frm_style_setting'] ) && isset( $_POST['frm_style_setting']['post_content'] ) ) {
300 $settings = wp_unslash( $_POST['frm_style_setting']['post_content'] );
301 } else {
302 $settings = $_GET;
303 }
304 FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
305
306 $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
307 $settings['style_class'] = '';
308 if ( ! empty( $style_name ) ) {
309 $settings['style_class'] = $style_name . '.';
310 }
311 } else {
312 $settings = $style->post_content;
313 $settings['style_class'] = 'frm_style_' . $style->post_name . '.';
314 }
315
316 $settings['style_class'] .= 'with_frm_style';
317 $settings['font'] = stripslashes( $settings['font'] );
318 $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
319
320 $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
321 foreach ( $checkbox_opts as $opt ) {
322 if ( ! isset( $settings[ $opt ] ) ) {
323 $settings[ $opt ] = 0;
324 }
325 }
326
327 self::prepare_color_output( $settings );
328
329 return $settings;
330 }
331
332 /**
333 * @since 2.3
334 */
335 public static function prepare_color_output( &$settings, $allow_transparent = true ) {
336 $colors = self::allow_color_override();
337 foreach ( $colors as $css => $opts ) {
338 if ( $css === 'transparent' && ! $allow_transparent ) {
339 $css = '';
340 }
341 foreach ( $opts as $opt ) {
342 self::get_color_output( $css, $settings[ $opt ] );
343 }
344 }
345 }
346
347 /**
348 * @since 2.3
349 */
350 private static function allow_color_override() {
351 $frm_style = new FrmStyle();
352 $colors = $frm_style->get_color_settings();
353
354 $transparent = array(
355 'fieldset_color',
356 'fieldset_bg_color',
357 'bg_color',
358 'section_bg_color',
359 'error_bg',
360 'success_bg_color',
361 'progress_bg_color',
362 'progress_active_bg_color',
363 );
364
365 return array(
366 'transparent' => $transparent,
367 '' => array_diff( $colors, $transparent ),
368 );
369 }
370
371 /**
372 * @since 2.3
373 */
374 private static function get_color_output( $default, &$color ) {
375 $color = trim( $color );
376 if ( empty( $color ) ) {
377 $color = $default;
378 } elseif ( strpos( $color, '#' ) === false ) {
379 $color = '#' . $color;
380 }
381 }
382
383 /**
384 * If left/right label is over a certain size,
385 * adjust the field description margin at a different screen size
386 *
387 * @since 2.3
388 */
389 private static function description_margin_for_screensize( $width ) {
390 $temp_label_width = str_replace( 'px', '', $width );
391 $change_margin = false;
392 if ( $temp_label_width >= 230 ) {
393 $change_margin = '800px';
394 } elseif ( $width >= 215 ) {
395 $change_margin = '700px';
396 } elseif ( $width >= 180 ) {
397 $change_margin = '650px';
398 }
399
400 return $change_margin;
401 }
402
403 /**
404 * @since 2.3
405 */
406 public static function previewing_style() {
407 $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] );
408
409 return $ajax_change || isset( $_GET['flat'] );
410 }
411
412 /**
413 * @deprecated 3.01
414 * @codeCoverageIgnore
415 */
416 public static function get_sigle_label_postitions() {
417 return FrmDeprecated::get_sigle_label_postitions();
418 }
419
420 /**
421 * @deprecated 3.02.03
422 * @codeCoverageIgnore
423 */
424 public static function jquery_themes() {
425 return FrmDeprecated::jquery_themes();
426 }
427
428 /**
429 * @deprecated 3.02.03
430 * @codeCoverageIgnore
431 */
432 public static function jquery_css_url( $theme_css ) {
433 return FrmDeprecated::jquery_css_url( $theme_css );
434 }
435
436 /**
437 * @deprecated 3.02.03
438 * @codeCoverageIgnore
439 */
440 public static function enqueue_jquery_css() {
441 FrmDeprecated::enqueue_jquery_css();
442 }
443
444 /**
445 * @deprecated 3.02.03
446 * @codeCoverageIgnore
447 */
448 public static function get_form_for_page() {
449 return FrmDeprecated::get_form_for_page();
450 }
451 }
452