| 1 |
<?php |
| 2 |
class FrmStylesHelper { |
| 3 |
|
| 4 |
public static function jquery_themes() { |
| 5 |
$themes = array( |
| 6 |
'ui-lightness' => 'UI Lightness', |
| 7 |
'ui-darkness' => 'UI Darkness', |
| 8 |
'smoothness' => 'Smoothness', |
| 9 |
'start' => 'Start', |
| 10 |
'redmond' => 'Redmond', |
| 11 |
'sunny' => 'Sunny', |
| 12 |
'overcast' => 'Overcast', |
| 13 |
'le-frog' => 'Le Frog', |
| 14 |
'flick' => 'Flick', |
| 15 |
'pepper-grinder' => 'Pepper Grinder', |
| 16 |
'eggplant' => 'Eggplant', |
| 17 |
'dark-hive' => 'Dark Hive', |
| 18 |
'cupertino' => 'Cupertino', |
| 19 |
'south-street' => 'South Street', |
| 20 |
'blitzer' => 'Blitzer', |
| 21 |
'humanity' => 'Humanity', |
| 22 |
'hot-sneaks' => 'Hot Sneaks', |
| 23 |
'excite-bike' => 'Excite Bike', |
| 24 |
'vader' => 'Vader', |
| 25 |
'dot-luv' => 'Dot Luv', |
| 26 |
'mint-choc' => 'Mint Choc', |
| 27 |
'black-tie' => 'Black Tie', |
| 28 |
'trontastic' => 'Trontastic', |
| 29 |
'swanky-purse' => 'Swanky Purse', |
| 30 |
); |
| 31 |
|
| 32 |
$themes = apply_filters('frm_jquery_themes', $themes); |
| 33 |
return $themes; |
| 34 |
} |
| 35 |
|
| 36 |
public static function jquery_css_url( $theme_css ) { |
| 37 |
if ( $theme_css == -1 ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) { |
| 42 |
$css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css'; |
| 43 |
} else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) { |
| 44 |
$css_file = $theme_css; |
| 45 |
} else { |
| 46 |
$uploads = self::get_upload_base(); |
| 47 |
$file_path = '/formidable/css/' . $theme_css . '/jquery-ui.css'; |
| 48 |
if ( file_exists($uploads['basedir'] . $file_path) ) { |
| 49 |
$css_file = $uploads['baseurl'] . $file_path; |
| 50 |
} else { |
| 51 |
$css_file = FrmAppHelper::jquery_ui_base_url() . '/themes/' . $theme_css . '/jquery-ui.min.css'; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
return $css_file; |
| 56 |
} |
| 57 |
|
| 58 |
public static function enqueue_jquery_css() { |
| 59 |
$form = self::get_form_for_page(); |
| 60 |
$theme_css = FrmStylesController::get_style_val( 'theme_css', $form ); |
| 61 |
if ( $theme_css != -1 ) { |
| 62 |
wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version()); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
public static function get_form_for_page() { |
| 67 |
global $frm_vars; |
| 68 |
$form_id = 'default'; |
| 69 |
if ( ! empty( $frm_vars['forms_loaded'] ) ) { |
| 70 |
foreach ( $frm_vars['forms_loaded'] as $form ) { |
| 71 |
if ( is_object( $form ) ) { |
| 72 |
$form_id = $form->id; |
| 73 |
break; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
return $form_id; |
| 78 |
} |
| 79 |
|
| 80 |
public static function get_upload_base() { |
| 81 |
$uploads = wp_upload_dir(); |
| 82 |
if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) { |
| 83 |
$uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']); |
| 84 |
} |
| 85 |
|
| 86 |
return $uploads; |
| 87 |
} |
| 88 |
|
| 89 |
public static function style_menu( $active = '' ) { |
| 90 |
?> |
| 91 |
<h2 class="nav-tab-wrapper"> |
| 92 |
<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles' ) ) ?>" class="nav-tab <?php echo ( '' == $active ) ? 'nav-tab-active' : '' ?>"><?php esc_html_e( 'Edit Styles', 'formidable' ) ?></a> |
| 93 |
<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=manage' ) ) ?>" class="nav-tab <?php echo ( 'manage' == $active ) ? 'nav-tab-active' : '' ?>"><?php esc_html_e( 'Manage Form Styles', 'formidable' ) ?></a> |
| 94 |
<a href="<?php echo esc_url( admin_url('admin.php?page=formidable-styles&frm_action=custom_css' ) ) ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php esc_html_e( 'Custom CSS', 'formidable' ) ?></a> |
| 95 |
</h2> |
| 96 |
<?php |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* @since 2.05 |
| 101 |
*/ |
| 102 |
public static function get_css_label_positions() { |
| 103 |
return array( |
| 104 |
'none' => __( 'top', 'formidable' ), |
| 105 |
'left' => __( 'left', 'formidable' ), |
| 106 |
'right' => __( 'right', 'formidable' ), |
| 107 |
'no_label' => __( 'none', 'formidable' ), |
| 108 |
'inside' => __( 'inside', 'formidable' ), |
| 109 |
); |
| 110 |
} |
| 111 |
|
| 112 |
public static function get_sigle_label_postitions() { |
| 113 |
return array( |
| 114 |
'top' => __( 'Top', 'formidable' ), |
| 115 |
'left' => __( 'Left', 'formidable' ), |
| 116 |
'right' => __( 'Right', 'formidable' ), |
| 117 |
'inline' => __( 'Inline (left without a set width)', 'formidable' ), |
| 118 |
'none' => __( 'None', 'formidable' ), |
| 119 |
'hidden' => __( 'Hidden (but leave the space)', 'formidable' ), |
| 120 |
'inside' => __( 'Placeholder inside the field', 'formidable' ), |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
public static function minus_icons() { |
| 125 |
return array( |
| 126 |
0 => array( |
| 127 |
'-' => '62e', |
| 128 |
'+' => '62f', |
| 129 |
), |
| 130 |
1 => array( |
| 131 |
'-' => '600', |
| 132 |
'+' => '602', |
| 133 |
), |
| 134 |
2 => array( |
| 135 |
'-' => '604', |
| 136 |
'+' => '603', |
| 137 |
), |
| 138 |
3 => array( |
| 139 |
'-' => '633', |
| 140 |
'+' => '632', |
| 141 |
), |
| 142 |
4 => array( |
| 143 |
'-' => '613', |
| 144 |
'+' => '60f', |
| 145 |
), |
| 146 |
); |
| 147 |
} |
| 148 |
|
| 149 |
public static function arrow_icons() { |
| 150 |
$minus_icons = self::minus_icons(); |
| 151 |
|
| 152 |
return array( |
| 153 |
6 => array( |
| 154 |
'-' => '62d', |
| 155 |
'+' => '62a', |
| 156 |
), |
| 157 |
0 => array( |
| 158 |
'-' => '60d', |
| 159 |
'+' => '609', |
| 160 |
), |
| 161 |
1 => array( |
| 162 |
'-' => '60e', |
| 163 |
'+' => '60c', |
| 164 |
), |
| 165 |
2 => array( |
| 166 |
'-' => '630', |
| 167 |
'+' => '631', |
| 168 |
), |
| 169 |
3 => array( |
| 170 |
'-' => '62b', |
| 171 |
'+' => '628', |
| 172 |
), |
| 173 |
4 => array( |
| 174 |
'-' => '62c', |
| 175 |
'+' => '629', |
| 176 |
), |
| 177 |
5 => array( |
| 178 |
'-' => '635', |
| 179 |
'+' => '634', |
| 180 |
), |
| 181 |
'p0' => $minus_icons[0], |
| 182 |
'p1' => $minus_icons[1], |
| 183 |
'p2' => $minus_icons[2], |
| 184 |
'p3' => $minus_icons[3], |
| 185 |
'p4' => $minus_icons[4], |
| 186 |
); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* @since 2.0 |
| 191 |
* @return The class for this icon |
| 192 |
*/ |
| 193 |
public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) { |
| 194 |
if ( 'arrow' == $type && is_numeric( $key ) ) { |
| 195 |
//frm_arrowup6_icon |
| 196 |
$arrow = array( |
| 197 |
'-' => 'down', |
| 198 |
'+' => 'up', |
| 199 |
); |
| 200 |
$class = 'frm_arrow' . $arrow[ $icon ]; |
| 201 |
} else { |
| 202 |
//frm_minus1_icon |
| 203 |
$key = str_replace( 'p', '', $key ); |
| 204 |
$plus = array( |
| 205 |
'-' => 'minus', |
| 206 |
'+' => 'plus', |
| 207 |
); |
| 208 |
$class = 'frm_' . $plus[ $icon ]; |
| 209 |
} |
| 210 |
|
| 211 |
if ( $key ) { |
| 212 |
$class .= $key; |
| 213 |
} |
| 214 |
$class .= '_icon'; |
| 215 |
|
| 216 |
return $class; |
| 217 |
} |
| 218 |
|
| 219 |
public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) { |
| 220 |
$function_name = $type . '_icons'; |
| 221 |
$icons = self::$function_name(); |
| 222 |
unset( $function_name ); |
| 223 |
|
| 224 |
$name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon'; |
| 225 |
?> |
| 226 |
<select name="<?php echo esc_attr( $frm_style->get_field_name($name) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js"> |
| 227 |
<?php foreach ( $icons as $key => $icon ) { ?> |
| 228 |
<option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[ $name ], $key ) ?>> |
| 229 |
<?php echo '' . $icon['+'] . '; ' . $icon['-'] . ';'; ?> |
| 230 |
</option> |
| 231 |
<?php } ?> |
| 232 |
</select> |
| 233 |
|
| 234 |
<div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ) ?>_select"> |
| 235 |
<button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button"> |
| 236 |
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ) ?>"></i> |
| 237 |
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ) ?>"></i> |
| 238 |
<b class="caret"></b> |
| 239 |
</button> |
| 240 |
<ul class="multiselect-container frm-dropdown-menu"> |
| 241 |
<?php foreach ( $icons as $key => $icon ) { ?> |
| 242 |
<li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : '' ?>> |
| 243 |
<a href="javascript:void(0);"> |
| 244 |
<label> |
| 245 |
<input type="radio" value="<?php echo esc_attr( $key ) ?>"/> |
| 246 |
<span> |
| 247 |
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '+', $type ) ) ?>"></i> |
| 248 |
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '-', $type ) ) ?>"></i> |
| 249 |
</span> |
| 250 |
</label> |
| 251 |
</a> |
| 252 |
</li> |
| 253 |
<?php } ?> |
| 254 |
</ul> |
| 255 |
</div> |
| 256 |
<?php |
| 257 |
} |
| 258 |
|
| 259 |
public static function hex2rgb( $hex ) { |
| 260 |
$hex = str_replace('#', '', $hex); |
| 261 |
|
| 262 |
if ( strlen($hex) == 3 ) { |
| 263 |
$r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); |
| 264 |
$g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); |
| 265 |
$b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); |
| 266 |
} else { |
| 267 |
$r = hexdec( substr( $hex, 0, 2 ) ); |
| 268 |
$g = hexdec( substr( $hex, 2, 2 ) ); |
| 269 |
$b = hexdec( substr( $hex, 4, 2 ) ); |
| 270 |
} |
| 271 |
$rgb = array( $r, $g, $b ); |
| 272 |
return implode(',', $rgb); // returns the rgb values separated by commas |
| 273 |
//return $rgb; // returns an array with the rgb values |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* @param $hex string - The original color in hex format #ffffff |
| 278 |
* @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter |
| 279 |
* @since 2.3 |
| 280 |
*/ |
| 281 |
public static function adjust_brightness( $hex, $steps ) { |
| 282 |
$steps = max( -255, min( 255, $steps ) ); |
| 283 |
|
| 284 |
// Normalize into a six character long hex string |
| 285 |
$hex = str_replace( '#', '', $hex ); |
| 286 |
if ( strlen( $hex ) == 3 ) { |
| 287 |
$hex = str_repeat( substr( $hex, 0, 1 ), 2 ); |
| 288 |
$hex .= str_repeat( substr( $hex, 1, 1 ), 2 ); |
| 289 |
$hex .= str_repeat( substr( $hex, 2, 1 ), 2 ); |
| 290 |
} |
| 291 |
|
| 292 |
// Split into three parts: R, G and B |
| 293 |
$color_parts = str_split( $hex, 2 ); |
| 294 |
$return = '#'; |
| 295 |
|
| 296 |
foreach ( $color_parts as $color ) { |
| 297 |
$color = hexdec( $color ); // Convert to decimal |
| 298 |
$color = max( 0, min( 255, $color + $steps ) ); // Adjust color |
| 299 |
$return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code |
| 300 |
} |
| 301 |
|
| 302 |
return $return; |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* @since 2.3 |
| 307 |
*/ |
| 308 |
public static function get_settings_for_output( $style ) { |
| 309 |
if ( self::previewing_style() ) { |
| 310 |
if ( isset( $_GET['frm_style_setting'] ) ) { |
| 311 |
$settings = $_GET['frm_style_setting']['post_content']; |
| 312 |
} else { |
| 313 |
$settings = $_GET; |
| 314 |
} |
| 315 |
FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings ); |
| 316 |
|
| 317 |
$style_name = FrmAppHelper::simple_get( 'style_name', 'sanitize_title' ); |
| 318 |
$settings['style_class'] = ''; |
| 319 |
if ( ! empty( $style_name ) ) { |
| 320 |
$settings['style_class'] = $style_name . '.'; |
| 321 |
} |
| 322 |
} else { |
| 323 |
$settings = $style->post_content; |
| 324 |
$settings['style_class'] = 'frm_style_' . $style->post_name . '.'; |
| 325 |
} |
| 326 |
|
| 327 |
$settings['style_class'] .= 'with_frm_style'; |
| 328 |
$settings['font'] = stripslashes( $settings['font'] ); |
| 329 |
$settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] ); |
| 330 |
|
| 331 |
$checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' ); |
| 332 |
foreach ( $checkbox_opts as $opt ) { |
| 333 |
if ( ! isset( $settings[ $opt ] ) ) { |
| 334 |
$settings[ $opt ] = 0; |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
self::prepare_color_output( $settings ); |
| 339 |
|
| 340 |
return $settings; |
| 341 |
} |
| 342 |
|
| 343 |
/** |
| 344 |
* @since 2.3 |
| 345 |
*/ |
| 346 |
private static function prepare_color_output( &$settings ) { |
| 347 |
$colors = self::allow_color_override(); |
| 348 |
foreach ( $colors as $css => $opts ) { |
| 349 |
foreach ( $opts as $opt ) { |
| 350 |
self::get_color_output( $css, $settings[ $opt ] ); |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* @since 2.3 |
| 357 |
*/ |
| 358 |
private static function allow_color_override() { |
| 359 |
return array( |
| 360 |
'transparent' => array( 'fieldset_color', 'fieldset_bg_color', 'bg_color', 'section_bg_color', 'error_bg', 'success_bg_color', 'progress_bg_color', 'progress_active_bg_color' ), |
| 361 |
'' => array( 'title_color', 'section_color', 'submit_text_color', 'label_color', 'check_label_color', 'form_desc_color', 'description_color', 'text_color', 'text_color_disabled', 'border_color', 'submit_bg_color', 'submit_border_color', 'error_text', 'progress_border_color', 'progress_color', 'progress_active_color', 'submit_hover_bg_color', 'submit_hover_border_color', 'submit_hover_color', 'submit_active_color', 'submit_active_border_color', 'submit_active_bg_color' ), |
| 362 |
); |
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* @since 2.3 |
| 367 |
*/ |
| 368 |
private static function get_color_output( $default, &$color ) { |
| 369 |
$color = ( trim( $color ) == '' ) ? $default : '#' . $color; |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* If left/right label is over a certain size, |
| 374 |
* adjust the field description margin at a different screen size |
| 375 |
* @since 2.3 |
| 376 |
*/ |
| 377 |
private static function description_margin_for_screensize( $width ) { |
| 378 |
$temp_label_width = str_replace( 'px', '', $width ); |
| 379 |
$change_margin = false; |
| 380 |
if ( $temp_label_width >= 230 ) { |
| 381 |
$change_margin = '800px'; |
| 382 |
} else if ( $width >= 215 ) { |
| 383 |
$change_margin = '700px'; |
| 384 |
} else if ( $width >= 180 ) { |
| 385 |
$change_margin = '650px'; |
| 386 |
} |
| 387 |
return $change_margin; |
| 388 |
} |
| 389 |
|
| 390 |
/** |
| 391 |
* @since 2.3 |
| 392 |
*/ |
| 393 |
public static function previewing_style() { |
| 394 |
return isset( $_GET['frm_style_setting'] ) || isset( $_GET['flat'] ); |
| 395 |
} |
| 396 |
} |
| 397 |
|