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 _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 _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 _e( 'Custom CSS', 'formidable' ) ?></a> |
|
|
|
|
95
|
|
|
</h2> |
96
|
|
|
<?php |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function minus_icons() { |
100
|
|
|
return array( |
101
|
|
|
0 => array( '-' => '62e', '+' => '62f' ), |
102
|
|
|
1 => array( '-' => '600', '+' => '602' ), |
103
|
|
|
2 => array( '-' => '604', '+' => '603' ), |
104
|
|
|
3 => array( '-' => '633', '+' => '632' ), |
105
|
|
|
4 => array( '-' => '613', '+' => '60f' ), |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public static function arrow_icons() { |
110
|
|
|
$minus_icons = self::minus_icons(); |
111
|
|
|
|
112
|
|
|
return array( |
113
|
|
|
6 => array( '-' => '62d', '+' => '62a' ), |
114
|
|
|
0 => array( '-' => '60d', '+' => '609' ), |
115
|
|
|
1 => array( '-' => '60e', '+' => '60c' ), |
116
|
|
|
2 => array( '-' => '630', '+' => '631' ), |
117
|
|
|
3 => array( '-' => '62b', '+' => '628' ), |
118
|
|
|
4 => array( '-' => '62c', '+' => '629' ), |
119
|
|
|
5 => array( '-' => '635', '+' => '634' ), |
120
|
|
|
'p0' => $minus_icons[0], |
121
|
|
|
'p1' => $minus_icons[1], |
122
|
|
|
'p2' => $minus_icons[2], |
123
|
|
|
'p3' => $minus_icons[3], |
124
|
|
|
'p4' => $minus_icons[4], |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @since 2.0 |
130
|
|
|
* @return The class for this icon |
131
|
|
|
*/ |
132
|
|
|
public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) { |
133
|
|
|
if ( 'arrow' == $type && is_numeric($key) ) { |
134
|
|
|
//frm_arrowup6_icon |
135
|
|
|
$arrow = array( '-' => 'down', '+' => 'up' ); |
136
|
|
|
$class = 'frm_arrow' . $arrow[ $icon ]; |
137
|
|
|
} else { |
138
|
|
|
//frm_minus1_icon |
139
|
|
|
$key = str_replace('p', '', $key); |
140
|
|
|
$plus = array( '-' => 'minus', '+' => 'plus' ); |
141
|
|
|
$class = 'frm_' . $plus[ $icon ]; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if ( $key ) { |
145
|
|
|
$class .= $key; |
146
|
|
|
} |
147
|
|
|
$class .= '_icon'; |
148
|
|
|
|
149
|
|
|
return $class; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) { |
153
|
|
|
$function_name = $type . '_icons'; |
154
|
|
|
$icons = self::$function_name(); |
155
|
|
|
unset( $function_name ); |
156
|
|
|
|
157
|
|
|
$name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon'; |
158
|
|
|
?> |
159
|
|
|
<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"> |
160
|
|
|
<?php foreach ( $icons as $key => $icon ) { ?> |
161
|
|
|
<option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[ $name ], $key ) ?>> |
162
|
|
|
<?php echo '' . $icon['+'] . '; ' . $icon['-'] . ';'; ?> |
|
|
|
|
163
|
|
|
</option> |
164
|
|
|
<?php } ?> |
165
|
|
|
</select> |
166
|
|
|
|
167
|
|
|
<div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ) ?>_select"> |
168
|
|
|
<button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button"> |
169
|
|
|
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ) ?>"></i> |
170
|
|
|
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ) ?>"></i> |
171
|
|
|
<b class="caret"></b> |
172
|
|
|
</button> |
173
|
|
|
<ul class="multiselect-container frm-dropdown-menu"> |
174
|
|
|
<?php foreach ( $icons as $key => $icon ) { ?> |
175
|
|
|
<li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : '' ?>> |
|
|
|
|
176
|
|
|
<a href="javascript:void(0);"> |
177
|
|
|
<label> |
178
|
|
|
<input type="radio" value="<?php echo esc_attr( $key ) ?>"/> |
179
|
|
|
<span> |
180
|
|
|
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '+', $type ) ) ?>"></i> |
181
|
|
|
<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '-', $type ) ) ?>"></i> |
182
|
|
|
</span> |
183
|
|
|
</label> |
184
|
|
|
</a> |
185
|
|
|
</li> |
186
|
|
|
<?php } ?> |
187
|
|
|
</ul> |
188
|
|
|
</div> |
189
|
|
|
<?php |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public static function hex2rgb( $hex ) { |
193
|
|
|
$hex = str_replace('#', '', $hex); |
194
|
|
|
|
195
|
|
|
if ( strlen($hex) == 3 ) { |
196
|
|
|
$r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); |
197
|
|
|
$g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); |
198
|
|
|
$b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); |
199
|
|
|
} else { |
200
|
|
|
$r = hexdec( substr( $hex, 0, 2 ) ); |
201
|
|
|
$g = hexdec( substr( $hex, 2, 2 ) ); |
202
|
|
|
$b = hexdec( substr( $hex, 4, 2 ) ); |
203
|
|
|
} |
204
|
|
|
$rgb = array( $r, $g, $b ); |
205
|
|
|
return implode(',', $rgb); // returns the rgb values separated by commas |
206
|
|
|
//return $rgb; // returns an array with the rgb values |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @since 2.3 |
211
|
|
|
*/ |
212
|
|
|
public static function get_settings_for_output( $style ) { |
213
|
|
|
if ( self::previewing_style() ) { |
214
|
|
|
if ( isset( $_GET['frm_style_setting'] ) ) { |
215
|
|
|
$settings = $_GET['frm_style_setting']['post_content']; |
|
|
|
|
216
|
|
|
} else { |
217
|
|
|
$settings = $_GET; |
|
|
|
|
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$style_name = FrmAppHelper::simple_get( 'style_name', 'sanitize_title' ); |
221
|
|
|
$settings['style_class'] = ''; |
222
|
|
|
if ( ! empty( $style_name ) ) { |
223
|
|
|
$settings['style_class'] = $style_name . '.'; |
224
|
|
|
} |
225
|
|
|
} else { |
226
|
|
|
$settings = $style->post_content; |
227
|
|
|
$settings['style_class'] = 'frm_style_' . $style->post_name . '.'; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$settings['style_class'] .= 'with_frm_style'; |
231
|
|
|
$settings['font'] = stripslashes( $settings['font'] ); |
232
|
|
|
$settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] ); |
233
|
|
|
|
234
|
|
|
$checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' ); |
235
|
|
|
foreach ( $checkbox_opts as $opt ) { |
236
|
|
|
if ( ! isset( $settings[ $opt ] ) ) { |
237
|
|
|
$settings[ $opt ] = 0; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
self::prepare_color_output( $settings ); |
242
|
|
|
|
243
|
|
|
return $settings; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @since 2.3 |
248
|
|
|
*/ |
249
|
|
|
private static function prepare_color_output( &$settings ) { |
250
|
|
|
$colors = self::allow_color_override(); |
251
|
|
|
foreach ( $colors as $css => $opts ) { |
252
|
|
|
foreach ( $opts as $opt ) { |
253
|
|
|
self::get_color_output( $css, $settings[ $opt ] ); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @since 2.3 |
260
|
|
|
*/ |
261
|
|
|
private static function allow_color_override() { |
262
|
|
|
return array( |
263
|
|
|
'transparent' => array( |
264
|
|
|
'fieldset_color', 'fieldset_bg_color', 'bg_color', |
265
|
|
|
'bg_color_disabled', 'bg_color_active', 'bg_color_error', |
266
|
|
|
'section_bg_color', 'error_bg', 'success_bg_color', |
267
|
|
|
), |
268
|
|
|
'' => array( |
269
|
|
|
'title_color', 'section_color', 'submit_text_color', |
270
|
|
|
'label_color', 'check_label_color', 'form_desc_color', |
271
|
|
|
'description_color', 'text_color', 'text_color_disabled', |
272
|
|
|
'border_color', 'submit_bg_color', 'submit_border_color', |
273
|
|
|
'error_text', |
274
|
|
|
'submit_hover_bg_color', 'submit_hover_border_color', 'submit_hover_color', |
275
|
|
|
'submit_active_color', 'submit_active_border_color', 'submit_active_bg_color', |
276
|
|
|
), |
277
|
|
|
); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @since 2.3 |
282
|
|
|
*/ |
283
|
|
|
private static function get_color_output( $default, &$color ) { |
284
|
|
|
$color = ( trim( $color ) == '' ) ? $default : '#' . $color; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* If left/right label is over a certain size, |
289
|
|
|
* adjust the field description margin at a different screen size |
290
|
|
|
* @since 2.3 |
291
|
|
|
*/ |
292
|
|
|
private static function description_margin_for_screensize( $width ) { |
293
|
|
|
$temp_label_width = str_replace( 'px', '', $width ); |
294
|
|
|
$change_margin = false; |
295
|
|
|
if ( $temp_label_width >= 230 ) { |
296
|
|
|
$change_margin = '800px'; |
297
|
|
|
} else if ( $width >= 215 ) { |
298
|
|
|
$change_margin = '700px'; |
299
|
|
|
} else if ( $width >= 180 ) { |
300
|
|
|
$change_margin = '650px'; |
301
|
|
|
} |
302
|
|
|
return $change_margin; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @since 2.3 |
307
|
|
|
*/ |
308
|
|
|
public static function previewing_style() { |
309
|
|
|
return isset( $_GET['frm_style_setting'] ) || isset( $_GET['flat'] ); |
|
|
|
|
310
|
|
|
} |
311
|
|
|
} |
312
|
|
|
|