Version Description
- Added: new CF7 count shortcode is now supported
- Enhanced: form properties can now be modified without any code (i.e. without a filter); the properties can be defined in the new "Additional Settings" tab of Contact Form 7
- Enhanced: textual inputs now support Bootstrap's input group feature
- Enhanced: checkbox and radio types can now show an actual label; it is only used as the checkbox label if no option is provided
- Tweaked: plugin now adheres to WordPress Coding Standards
- Fixed: improved display method for captcha images
- Fixed: textarea row attribute now honored
- Fixed: free_text attribute on checkbox and radio types now honored
- Fixed: form attribute 'group_type' now honored
- Fixed: additional CF7 styles are now outputted in the head
- Fixed: check if CF7 functions are available before calling them
Download this release
Release Info
Developer | flixos90 |
Plugin | Bootstrap for Contact Form 7 |
Version | 1.2.0 |
Comparing to | |
See all releases |
Code changes from version 1.1.1 to 1.2.0
- .editorconfig +36 -0
- assets/.jshintrc +1 -1
- assets/scripts.js +56 -56
- assets/scripts.min.js +1 -1
- bootstrap-for-contact-form-7.php +104 -113
- changelog.txt +13 -0
- classes/CF7BS_Alert.php +77 -92
- classes/CF7BS_Button.php +144 -166
- classes/CF7BS_Button_Group.php +90 -108
- classes/CF7BS_Component.php +38 -54
- classes/CF7BS_Form_Field.php +474 -575
- composer.json +1 -1
- modifications.php +195 -235
- modules/acceptance.php +48 -53
- modules/captcha.php +84 -98
- modules/checkbox.php +164 -179
- modules/count.php +36 -0
- modules/date.php +59 -68
- modules/file.php +53 -62
- modules/number.php +61 -70
- modules/quiz.php +49 -53
- modules/select.php +121 -152
- modules/submit.php +31 -34
- modules/text.php +94 -89
- modules/textarea.php +63 -66
- package.json +2 -2
- readme.txt +32 -11
.editorconfig
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# WordPress Coding Standards
|
2 |
+
# http://make.wordpress.org/core/handbook/coding-standards/
|
3 |
+
|
4 |
+
root = true
|
5 |
+
|
6 |
+
[*]
|
7 |
+
charset = utf-8
|
8 |
+
end_of_line = lf
|
9 |
+
indent_size = 4
|
10 |
+
tab_width = 4
|
11 |
+
indent_style = tab
|
12 |
+
insert_final_newline = true
|
13 |
+
trim_trailing_whitespace = true
|
14 |
+
|
15 |
+
[*.md]
|
16 |
+
trim_trailing_whitespace = false
|
17 |
+
indent_style = space
|
18 |
+
indent_size = 2
|
19 |
+
|
20 |
+
[*.txt]
|
21 |
+
trim_trailing_whitespace = false
|
22 |
+
|
23 |
+
[*.json]
|
24 |
+
insert_final_newline = false
|
25 |
+
indent_style = space
|
26 |
+
indent_size = 2
|
27 |
+
|
28 |
+
[.*rc]
|
29 |
+
insert_final_newline = false
|
30 |
+
indent_style = space
|
31 |
+
indent_size = 2
|
32 |
+
|
33 |
+
[*.yml]
|
34 |
+
insert_final_newline = false
|
35 |
+
indent_style = space
|
36 |
+
indent_size = 2
|
assets/.jshintrc
CHANGED
@@ -12,4 +12,4 @@
|
|
12 |
"strict" : true,
|
13 |
"undef" : true,
|
14 |
"unused" : true
|
15 |
-
}
|
12 |
"strict" : true,
|
13 |
"undef" : true,
|
14 |
"unused" : true
|
15 |
+
}
|
assets/scripts.js
CHANGED
@@ -1,64 +1,64 @@
|
|
1 |
-
+function ($) {
|
2 |
-
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
// WPCF7 Function Override: Adjusted for Bootstrap Help Block Output and Status Class
|
21 |
-
$.fn.wpcf7NotValidTip = function(message) {
|
22 |
-
return this.each(function() {
|
23 |
-
var $into = $(this);
|
24 |
-
$into.addClass('has-error');
|
25 |
-
$into.find('span.wpcf7-not-valid-tip').remove();
|
26 |
-
$into.append('<span class="help-block wpcf7-not-valid-tip">' + message + '</span>');
|
27 |
-
$into.slideDown('fast');
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
});
|
39 |
-
};
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
});
|
51 |
-
});
|
52 |
-
};
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
}(jQuery);
|
1 |
+
+function ( $ ) {
|
2 |
+
'use strict';
|
3 |
|
4 |
+
// add Bootstrap Alert classes to response output
|
5 |
+
$( function() {
|
6 |
+
$( 'div.wpcf7' ).on( 'invalid.wpcf7', function() {
|
7 |
+
$( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-warning' );
|
8 |
+
});
|
9 |
+
$( 'div.wpcf7' ).on( 'spam.wpcf7', function() {
|
10 |
+
$( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-warning' );
|
11 |
+
});
|
12 |
+
$( 'div.wpcf7' ).on( 'mailsent.wpcf7', function() {
|
13 |
+
$( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-success' );
|
14 |
+
});
|
15 |
+
$( 'div.wpcf7' ).on( 'mailfailed.wpcf7', function() {
|
16 |
+
$( this ).find( 'div.wpcf7-response-output' ).addClass( 'alert-danger' );
|
17 |
+
});
|
18 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
// WPCF7 Function Override: Adjusted for Bootstrap Help Block Output and Status Class
|
21 |
+
$.fn.wpcf7NotValidTip = function( message ) {
|
22 |
+
return this.each( function() {
|
23 |
+
var $into = $( this );
|
24 |
+
$into.addClass( 'has-error' );
|
25 |
+
$into.find( 'span.wpcf7-not-valid-tip' ).remove();
|
26 |
+
$into.append( '<span class="help-block wpcf7-not-valid-tip">' + message + '</span>' );
|
27 |
+
$into.slideDown( 'fast' );
|
28 |
|
29 |
+
if ( $into.is( '.use-floating-validation-tip *' ) ) {
|
30 |
+
$( '.wpcf7-not-valid-tip', $into ).mouseover( function() {
|
31 |
+
$( this ).wpcf7FadeOut();
|
32 |
+
});
|
|
|
|
|
33 |
|
34 |
+
$( ':input', $into ).focus( function() {
|
35 |
+
$( '.wpcf7-not-valid-tip', $into ).not( ':hidden' ).wpcf7FadeOut();
|
36 |
+
});
|
37 |
+
}
|
38 |
+
});
|
39 |
+
};
|
40 |
|
41 |
+
// WPCF7 Function Override: Different DOM Element is required
|
42 |
+
$.fn.wpcf7RefillQuiz = function( quiz ) {
|
43 |
+
return this.each( function() {
|
44 |
+
var form = $( this );
|
|
|
|
|
|
|
45 |
|
46 |
+
$.each( quiz, function( i, n ) {
|
47 |
+
form.find( ':input[name="' + i + '"]' ).clearFields();
|
48 |
+
form.find( ':input[name="' + i + '"]' ).siblings( 'p.wpcf7-quiz-label' ).text( n[0] );
|
49 |
+
form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[1] );
|
50 |
+
});
|
51 |
+
});
|
52 |
+
};
|
53 |
+
|
54 |
+
// WPCF7 Function Override: Adjusted for Bootstrap Alert classes and Status Class
|
55 |
+
$.fn.wpcf7ClearResponseOutput = function() {
|
56 |
+
return this.each(function() {
|
57 |
+
$( this ).find( 'div.wpcf7-response-output' ).hide().empty().removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked alert-warning alert-success alert-danger' ).removeAttr( 'role' );
|
58 |
+
$( this ).find( 'div.form-group' ).removeClass( 'has-error' );
|
59 |
+
$( this ).find( 'span.wpcf7-not-valid-tip' ).remove();
|
60 |
+
$( this ).find( 'img.ajax-loader' ).css({ visibility: 'hidden' });
|
61 |
+
});
|
62 |
+
};
|
63 |
|
64 |
}(jQuery);
|
assets/scripts.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
/*!
|
2 |
-
* Bootstrap for Contact Form 7 Scripts - Version 1.
|
3 |
*
|
4 |
* Modifications and Additions to WPCF7 Scripts to work with CF7BS
|
5 |
* Felix Arntz <felix-arntz@leaves-and-love.net>
|
1 |
/*!
|
2 |
+
* Bootstrap for Contact Form 7 Scripts - Version 1.2.0
|
3 |
*
|
4 |
* Modifications and Additions to WPCF7 Scripts to work with CF7BS
|
5 |
* Felix Arntz <felix-arntz@leaves-and-love.net>
|
bootstrap-for-contact-form-7.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Bootstrap for Contact Form 7
|
4 |
Plugin URI: http://wordpress.org/plugins/bootstrap-for-contact-form-7/
|
5 |
Description: This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.
|
6 |
-
Version: 1.
|
7 |
Author: Felix Arntz
|
8 |
Author URI: http://leaves-and-love.net
|
9 |
License: GNU General Public License v2
|
@@ -11,140 +11,131 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
11 |
*/
|
12 |
/**
|
13 |
* @package CF7BS
|
14 |
-
* @version 1.
|
15 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
16 |
*/
|
17 |
|
18 |
-
define( 'CF7BS_VERSION', '1.
|
19 |
define( 'CF7BS_MAINFILE', __FILE__ );
|
20 |
define( 'CF7BS_PATH', untrailingslashit( plugin_dir_path( CF7BS_MAINFILE ) ) );
|
21 |
define( 'CF7BS_URL', untrailingslashit( plugin_dir_url( CF7BS_MAINFILE ) ) );
|
22 |
define( 'CF7BS_BASENAME', plugin_basename( CF7BS_MAINFILE ) );
|
23 |
|
24 |
-
if( !defined( 'WPCF7_AUTOP' ) )
|
25 |
-
|
26 |
-
define( 'WPCF7_AUTOP', false );
|
27 |
}
|
28 |
|
29 |
-
function cf7bs_maybe_init()
|
30 |
-
{
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
include_once CF7BS_PATH . '/classes/CF7BS_Alert.php';
|
38 |
-
include_once CF7BS_PATH . '/classes/CF7BS_Form_Field.php';
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
}
|
62 |
}
|
63 |
add_action( 'plugins_loaded', 'cf7bs_maybe_init', 50 );
|
64 |
|
65 |
$current_form_id = 0;
|
66 |
$current_form_properties = array();
|
67 |
|
68 |
-
function cf7bs_get_form_property( $property, $form_id = 0 )
|
69 |
-
|
70 |
-
global $current_form_id, $current_form_properties;
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
if( $current_form_id != $form_id )
|
85 |
-
{
|
86 |
-
$current_form_id = $form_id;
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
}
|
98 |
|
99 |
-
function cf7bs_get_default_form_properties()
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
return apply_filters( 'cf7bs_default_form_properties', $properties );
|
112 |
}
|
113 |
|
114 |
-
function cf7bs_add_get_parameter()
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
}
|
139 |
-
else
|
140 |
-
{
|
141 |
-
$uri = $args[2];
|
142 |
-
}
|
143 |
-
if( count( $args ) < 2 )
|
144 |
-
{
|
145 |
-
return $uri;
|
146 |
-
}
|
147 |
-
return add_query_arg( $args[0], cf7bs_parameter_encode( $args[1] ), $uri );
|
148 |
-
}
|
149 |
-
return '';
|
150 |
}
|
3 |
Plugin Name: Bootstrap for Contact Form 7
|
4 |
Plugin URI: http://wordpress.org/plugins/bootstrap-for-contact-form-7/
|
5 |
Description: This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.
|
6 |
+
Version: 1.2.0
|
7 |
Author: Felix Arntz
|
8 |
Author URI: http://leaves-and-love.net
|
9 |
License: GNU General Public License v2
|
11 |
*/
|
12 |
/**
|
13 |
* @package CF7BS
|
14 |
+
* @version 1.2.0
|
15 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
16 |
*/
|
17 |
|
18 |
+
define( 'CF7BS_VERSION', '1.2.0' );
|
19 |
define( 'CF7BS_MAINFILE', __FILE__ );
|
20 |
define( 'CF7BS_PATH', untrailingslashit( plugin_dir_path( CF7BS_MAINFILE ) ) );
|
21 |
define( 'CF7BS_URL', untrailingslashit( plugin_dir_url( CF7BS_MAINFILE ) ) );
|
22 |
define( 'CF7BS_BASENAME', plugin_basename( CF7BS_MAINFILE ) );
|
23 |
|
24 |
+
if ( ! defined( 'WPCF7_AUTOP' ) ) {
|
25 |
+
define( 'WPCF7_AUTOP', false );
|
|
|
26 |
}
|
27 |
|
28 |
+
function cf7bs_maybe_init() {
|
29 |
+
if ( defined( 'WPCF7_VERSION' ) && apply_filters( 'cf7bs_using_bootstrap', true ) ) {
|
30 |
+
include_once CF7BS_PATH . '/modifications.php';
|
31 |
+
include_once CF7BS_PATH . '/classes/CF7BS_Component.php';
|
32 |
+
include_once CF7BS_PATH . '/classes/CF7BS_Button.php';
|
33 |
+
include_once CF7BS_PATH . '/classes/CF7BS_Button_Group.php';
|
34 |
+
include_once CF7BS_PATH . '/classes/CF7BS_Alert.php';
|
35 |
+
include_once CF7BS_PATH . '/classes/CF7BS_Form_Field.php';
|
|
|
|
|
36 |
|
37 |
+
$modules = array(
|
38 |
+
'acceptance',
|
39 |
+
'submit',
|
40 |
+
'captcha',
|
41 |
+
'count',
|
42 |
+
'number',
|
43 |
+
'text',
|
44 |
+
'checkbox',
|
45 |
+
'quiz',
|
46 |
+
'textarea',
|
47 |
+
'date',
|
48 |
+
'file',
|
49 |
+
'select',
|
50 |
+
);
|
51 |
+
foreach ( $modules as $module ) {
|
52 |
+
$file = CF7BS_PATH . '/modules/' . $module . '.php';
|
53 |
+
if ( file_exists( $file ) ) {
|
54 |
+
include_once $file;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
|
|
58 |
}
|
59 |
add_action( 'plugins_loaded', 'cf7bs_maybe_init', 50 );
|
60 |
|
61 |
$current_form_id = 0;
|
62 |
$current_form_properties = array();
|
63 |
|
64 |
+
function cf7bs_get_form_property( $property, $form_id = 0 ) {
|
65 |
+
global $current_form_id, $current_form_properties;
|
|
|
66 |
|
67 |
+
if ( $form_id == 0 ) {
|
68 |
+
if ( is_callable( array( 'WPCF7_ContactForm', 'get_current' ) ) ) {
|
69 |
+
$current_form = WPCF7_ContactForm::get_current();
|
70 |
+
if ( is_a( $current_form, 'WPCF7_ContactForm' ) && is_callable( array( $current_form, 'id' ) ) ) {
|
71 |
+
$form_id = $current_form->id();
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
|
76 |
+
if ( $form_id == 0 ) {
|
77 |
+
return false;
|
78 |
+
}
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
if ( $current_form_id != $form_id ) {
|
81 |
+
$current_form_id = $form_id;
|
82 |
+
|
83 |
+
$properties = cf7bs_get_default_form_properties();
|
84 |
+
if ( is_a( $current_form, 'WPCF7_ContactForm' ) && is_callable( array( $current_form, 'additional_setting' ) ) ) {
|
85 |
+
foreach ( $properties as $key => &$value ) {
|
86 |
+
$setting = $current_form->additional_setting( $key );
|
87 |
+
if ( isset( $setting[0] ) ) {
|
88 |
+
$value = $setting[0];
|
89 |
+
}
|
90 |
+
}
|
91 |
+
unset( $key );
|
92 |
+
unset( $value );
|
93 |
+
}
|
94 |
+
$current_form_properties = apply_filters( 'cf7bs_form_' . $form_id . '_properties', $properties );
|
95 |
+
}
|
96 |
+
|
97 |
+
if ( isset( $current_form_properties[ $property ] ) ) {
|
98 |
+
return $current_form_properties[ $property ];
|
99 |
+
}
|
100 |
+
return false;
|
101 |
}
|
102 |
|
103 |
+
function cf7bs_get_default_form_properties() {
|
104 |
+
$properties = array(
|
105 |
+
'layout' => 'default', // default, inline, horizontal
|
106 |
+
'label_width' => 3, // integer between 1 and 11
|
107 |
+
'breakpoint' => 'sm', // xs, sm, md, lg
|
108 |
+
'size' => 'default', // default, small, large
|
109 |
+
'required_html' => '<span class="required">*</span>',
|
110 |
+
'group_layout' => 'default', // default, inline, buttons
|
111 |
+
'group_type' => 'default', // default, primary, success, info, warning, danger (only if group_layout=buttons)
|
112 |
+
'submit_type' => 'primary', // default, primary, success, info, warning, danger
|
113 |
+
);
|
114 |
+
return apply_filters( 'cf7bs_default_form_properties', $properties );
|
|
|
115 |
}
|
116 |
|
117 |
+
function cf7bs_add_get_parameter() {
|
118 |
+
$args = func_get_args();
|
119 |
+
if ( is_array( $args[0] ) ) {
|
120 |
+
if ( count( $args ) < 2 || $args[1] === false ) {
|
121 |
+
$uri = $_SERVER['REQUEST_URI'];
|
122 |
+
} else {
|
123 |
+
$uri = $args[1];
|
124 |
+
}
|
125 |
+
foreach ( $args[0] as $key => &$value ) {
|
126 |
+
$value = cf7bs_parameter_encode( $value );
|
127 |
+
}
|
128 |
+
return add_query_arg( $args[0], $uri );
|
129 |
+
} else {
|
130 |
+
if ( count( $args ) < 3 || $args[2] === false ) {
|
131 |
+
$uri = $_SERVER['REQUEST_URI'];
|
132 |
+
} else {
|
133 |
+
$uri = $args[2];
|
134 |
+
}
|
135 |
+
if ( count( $args ) < 2 ) {
|
136 |
+
return $uri;
|
137 |
+
}
|
138 |
+
return add_query_arg( $args[0], cf7bs_parameter_encode( $args[1] ), $uri );
|
139 |
+
}
|
140 |
+
return '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
changelog.txt
CHANGED
@@ -1,5 +1,18 @@
|
|
1 |
== Changelog ==
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
= 1.1.1 =
|
4 |
* Fixed: exclusive option for checkbox now working
|
5 |
* Fixed: default option for radio/checkbox now working
|
1 |
== Changelog ==
|
2 |
|
3 |
+
= 1.2.0 =
|
4 |
+
* Added: new CF7 count shortcode is now supported
|
5 |
+
* Enhanced: form properties can now be modified without any code (i.e. without a filter); the properties can be defined in the new "Additional Settings" tab of Contact Form 7
|
6 |
+
* Enhanced: textual inputs now support Bootstrap's input group feature
|
7 |
+
* Enhanced: checkbox and radio types can now show an actual label; it is only used as the checkbox label if no option is provided
|
8 |
+
* Tweaked: plugin now adheres to WordPress Coding Standards
|
9 |
+
* Fixed: improved display method for captcha images
|
10 |
+
* Fixed: textarea row attribute now honored
|
11 |
+
* Fixed: free_text attribute on checkbox and radio types now honored
|
12 |
+
* Fixed: form attribute 'group_type' now honored
|
13 |
+
* Fixed: additional CF7 styles are now outputted in the head
|
14 |
+
* Fixed: check if CF7 functions are available before calling them
|
15 |
+
|
16 |
= 1.1.1 =
|
17 |
* Fixed: exclusive option for checkbox now working
|
18 |
* Fixed: default option for radio/checkbox now working
|
classes/CF7BS_Alert.php
CHANGED
@@ -1,99 +1,84 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
-
* @version 1.
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
-
class CF7BS_Alert extends CF7BS_Component
|
9 |
-
{
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
private function validate_type( $type )
|
85 |
-
{
|
86 |
-
$whitelist = array(
|
87 |
-
'success',
|
88 |
-
'info',
|
89 |
-
'warning',
|
90 |
-
'danger'
|
91 |
-
);
|
92 |
-
|
93 |
-
if( !in_array( $type, $whitelist ) )
|
94 |
-
{
|
95 |
-
$type = '';
|
96 |
-
}
|
97 |
-
return $type;
|
98 |
-
}
|
99 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
+
* @version 1.2.0
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
+
class CF7BS_Alert extends CF7BS_Component {
|
9 |
+
public function open( $echo = true ) {
|
10 |
+
$output = apply_filters( 'cf7bs_bootstrap_alert_open', '', $this->args );
|
11 |
+
|
12 |
+
if ( empty( $output ) ) {
|
13 |
+
$output = '';
|
14 |
+
|
15 |
+
extract( $this->args );
|
16 |
+
|
17 |
+
$type = $this->validate_type( $type );
|
18 |
+
|
19 |
+
if ( ! empty( $class ) ) {
|
20 |
+
$class .= ' ';
|
21 |
+
}
|
22 |
+
$class .= 'alert';
|
23 |
+
if ( ! empty( $type ) ) {
|
24 |
+
$class .= ' alert-' . $type;
|
25 |
+
}
|
26 |
+
if ( $dismissable ) {
|
27 |
+
$class .= ' alert-dismissable';
|
28 |
+
}
|
29 |
+
|
30 |
+
$output .= '<div class="' . esc_attr( $class ) . '"' . ( $hide ? ' style="display:none;"' : '' ) . '>';
|
31 |
+
if ( $dismissable ) {
|
32 |
+
$output .= '<button class="close" data-dismiss="alert" type="button">×</button>';
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
if ( $echo ) {
|
37 |
+
echo $output;
|
38 |
+
}
|
39 |
+
return $output;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function close( $echo = true ) {
|
43 |
+
$output = apply_filters( 'cf7bs_bootstrap_alert_close', '', $this->args );
|
44 |
+
|
45 |
+
if ( empty( $output ) ) {
|
46 |
+
$output .= '</div>';
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( $echo ) {
|
50 |
+
echo $output;
|
51 |
+
}
|
52 |
+
return $output;
|
53 |
+
}
|
54 |
+
|
55 |
+
protected function validate_args( $args, $exclude = array() ) {
|
56 |
+
$args = parent::validate_args( $args, $exclude );
|
57 |
+
|
58 |
+
return $args;
|
59 |
+
}
|
60 |
+
|
61 |
+
protected function get_defaults() {
|
62 |
+
$defaults = array(
|
63 |
+
'type' => 'default',
|
64 |
+
'class' => '',
|
65 |
+
'dismissable' => false,
|
66 |
+
'hide' => false,
|
67 |
+
);
|
68 |
+
return apply_filters( 'cf7bs_bootstrap_alert_defaults', $defaults );
|
69 |
+
}
|
70 |
+
|
71 |
+
private function validate_type( $type ) {
|
72 |
+
$whitelist = array(
|
73 |
+
'success',
|
74 |
+
'info',
|
75 |
+
'warning',
|
76 |
+
'danger'
|
77 |
+
);
|
78 |
+
|
79 |
+
if ( ! in_array( $type, $whitelist ) ) {
|
80 |
+
$type = '';
|
81 |
+
}
|
82 |
+
return $type;
|
83 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
classes/CF7BS_Button.php
CHANGED
@@ -1,173 +1,151 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
-
* @version 1.
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
-
class CF7BS_Button extends CF7BS_Component
|
9 |
-
{
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
);
|
152 |
-
|
153 |
-
$type = strtolower( $type );
|
154 |
-
if( !in_array( $type, $whitelist ) )
|
155 |
-
{
|
156 |
-
$type = 'default';
|
157 |
-
}
|
158 |
-
return $type;
|
159 |
-
}
|
160 |
-
|
161 |
-
private function get_column_class( $label_column_width = 2, $breakpoint = 'sm' )
|
162 |
-
{
|
163 |
-
if( $label_column_width > 11 || $label_column_width < 1 )
|
164 |
-
{
|
165 |
-
$label_column_width = 2;
|
166 |
-
}
|
167 |
-
if( !in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) )
|
168 |
-
{
|
169 |
-
$breakpoint = 'sm';
|
170 |
-
}
|
171 |
-
return 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ) . ' col-' . $breakpoint . '-offset-' . $label_column_width;
|
172 |
-
}
|
173 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
+
* @version 1.2.0
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
+
class CF7BS_Button extends CF7BS_Component {
|
9 |
+
public function display( $echo = true ) {
|
10 |
+
$output = apply_filters( 'cf7bs_bootstrap_button_display', '', $this->args );
|
11 |
+
|
12 |
+
if ( empty( $output ) ) {
|
13 |
+
$output = '';
|
14 |
+
|
15 |
+
extract( $this->args );
|
16 |
+
|
17 |
+
$type = $this->validate_type( $type );
|
18 |
+
|
19 |
+
if ( ! empty( $class ) ) {
|
20 |
+
$class .= ' ';
|
21 |
+
}
|
22 |
+
|
23 |
+
$class .= 'btn btn-' . $type;
|
24 |
+
|
25 |
+
$sizes = array(
|
26 |
+
'mini' => 'xs',
|
27 |
+
'small' => 'sm',
|
28 |
+
'large' => 'lg',
|
29 |
+
);
|
30 |
+
if ( isset( $sizes[ $size ] ) ) {
|
31 |
+
$class .= ' btn-' . $sizes[ $size ];
|
32 |
+
}
|
33 |
+
|
34 |
+
if ( ! empty( $id ) ) {
|
35 |
+
$id = ' id="' . esc_attr( $id ) . '"';
|
36 |
+
}
|
37 |
+
|
38 |
+
if ( ! empty( $name ) ) {
|
39 |
+
$name = ' name="' . esc_attr( $name ) . '"';
|
40 |
+
}
|
41 |
+
|
42 |
+
if ( 'checkbox' == $mode ) {
|
43 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
44 |
+
$title = esc_html( $title );
|
45 |
+
}
|
46 |
+
$output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="checkbox" value="' . esc_attr( $value ) . '"' . $append . '>' . $title . '</label>';
|
47 |
+
} elseif ( 'radio' == $mode ) {
|
48 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
49 |
+
$title = esc_html( $title );
|
50 |
+
}
|
51 |
+
$output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="radio" value="' . esc_attr( $value ) . '"' . $append . '>' . $title . '</label>';
|
52 |
+
} else {
|
53 |
+
$wrapper_class = array();
|
54 |
+
|
55 |
+
if ( $align && 'inline' != $form_layout ) {
|
56 |
+
$wrapper_class[] = 'text-' . $align;
|
57 |
+
}
|
58 |
+
|
59 |
+
if ( 'horizontal' == $form_layout ) {
|
60 |
+
$wrapper_class[] = $this->get_column_class( $form_label_width, $form_breakpoint );
|
61 |
+
}
|
62 |
+
|
63 |
+
$wrapper_class = implode( ' ', $wrapper_class );
|
64 |
+
|
65 |
+
if ( ! empty( $wrapper_class ) ) {
|
66 |
+
$wrapper_class = ' class="' . $wrapper_class . '"';
|
67 |
+
}
|
68 |
+
|
69 |
+
if ( is_int( $tabindex ) ) {
|
70 |
+
$tabindex = ' tabindex="' . $tabindex . '"';
|
71 |
+
} else {
|
72 |
+
$tabindex = '';
|
73 |
+
}
|
74 |
+
$output .= '<div class="form-group"><div' . $wrapper_class . '>';
|
75 |
+
$output .= '<input class="' . esc_attr( $class ) . '"' . $id . $name . ' type="submit" value="' . esc_attr( $title ) . '"' . $tabindex . '>';
|
76 |
+
$output .= '</div></div>';
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
if ( $echo ) {
|
81 |
+
echo $output;
|
82 |
+
}
|
83 |
+
return $output;
|
84 |
+
}
|
85 |
+
|
86 |
+
protected function validate_args( $args, $exclude = array() ) {
|
87 |
+
$exclude[] = 'tabindex';
|
88 |
+
$exclude[] = 'align';
|
89 |
+
$args = parent::validate_args( $args, $exclude );
|
90 |
+
|
91 |
+
if ( is_string( $args['align'] ) ) {
|
92 |
+
$args['align'] = strtolower( $args['align'] );
|
93 |
+
}
|
94 |
+
|
95 |
+
if ( ! in_array( $args['align'], array( 'left', 'center', 'right' ) ) ) {
|
96 |
+
$args['align'] = false;
|
97 |
+
}
|
98 |
+
|
99 |
+
// type whitelist check is made later in the display() function to allow different types to use in a filter
|
100 |
+
|
101 |
+
return $args;
|
102 |
+
}
|
103 |
+
|
104 |
+
protected function get_defaults() {
|
105 |
+
$defaults = array(
|
106 |
+
'type' => 'default',
|
107 |
+
'size' => 'default', // default, large, small, mini
|
108 |
+
'mode' => 'submit', // checkbox, radio, submit
|
109 |
+
'id' => '',
|
110 |
+
'class' => '',
|
111 |
+
'title' => 'Button Title',
|
112 |
+
'name' => '',
|
113 |
+
'append' => '', // for checkbox/radio only
|
114 |
+
'value' => '', // for checkbox/radio only
|
115 |
+
'tabindex' => false,
|
116 |
+
'align' => false,
|
117 |
+
'form_layout' => 'default', // default, inline, horizontal
|
118 |
+
'form_label_width' => 2,
|
119 |
+
'form_breakpoint' => 'sm',
|
120 |
+
);
|
121 |
+
return apply_filters( 'cf7bs_bootstrap_button_defaults', $defaults );
|
122 |
+
}
|
123 |
+
|
124 |
+
private function validate_type( $type ) {
|
125 |
+
$whitelist = array(
|
126 |
+
'default',
|
127 |
+
'primary',
|
128 |
+
'info',
|
129 |
+
'success',
|
130 |
+
'warning',
|
131 |
+
'danger',
|
132 |
+
'link',
|
133 |
+
);
|
134 |
+
|
135 |
+
$type = strtolower( $type );
|
136 |
+
if ( ! in_array( $type, $whitelist ) ) {
|
137 |
+
$type = 'default';
|
138 |
+
}
|
139 |
+
return $type;
|
140 |
+
}
|
141 |
+
|
142 |
+
private function get_column_class( $label_column_width = 2, $breakpoint = 'sm' ) {
|
143 |
+
if ( $label_column_width > 11 || $label_column_width < 1 ) {
|
144 |
+
$label_column_width = 2;
|
145 |
+
}
|
146 |
+
if ( ! in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) ) {
|
147 |
+
$breakpoint = 'sm';
|
148 |
+
}
|
149 |
+
return 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ) . ' col-' . $breakpoint . '-offset-' . $label_column_width;
|
150 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
}
|
classes/CF7BS_Button_Group.php
CHANGED
@@ -1,115 +1,97 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
-
* @version 1.
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
-
class CF7BS_Button_Group extends CF7BS_Component
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
return $args;
|
98 |
-
}
|
99 |
-
|
100 |
-
protected function get_defaults()
|
101 |
-
{
|
102 |
-
$defaults = array(
|
103 |
-
'mode' => 'default', // default, checkbox, radio
|
104 |
-
'size' => 'default', // default, large, small, mini
|
105 |
-
'layout' => 'default', // default, vertical, justified
|
106 |
-
'id' => '',
|
107 |
-
);
|
108 |
-
return apply_filters( 'cf7bs_bootstrap_button_group_defaults', $defaults );
|
109 |
-
}
|
110 |
-
|
111 |
-
public function get_contents()
|
112 |
-
{
|
113 |
-
return $this->buttons;
|
114 |
-
}
|
115 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
+
* @version 1.2.0
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
+
class CF7BS_Button_Group extends CF7BS_Component {
|
9 |
+
private $buttons = array();
|
10 |
+
|
11 |
+
public function open( $echo = true ) {
|
12 |
+
$output = apply_filters( 'cf7bs_bootstrap_button_group_open', '', $this->args );
|
13 |
+
|
14 |
+
if ( empty( $output ) ) {
|
15 |
+
$output = '';
|
16 |
+
|
17 |
+
extract( $this->args );
|
18 |
+
|
19 |
+
$class = 'btn-group';
|
20 |
+
|
21 |
+
if ( 'vertical' == $layout ) {
|
22 |
+
$class .= '-vertical';
|
23 |
+
} elseif( 'justified' == $layout ) {
|
24 |
+
$class .= ' btn-group-justified';
|
25 |
+
}
|
26 |
+
|
27 |
+
$sizes = array(
|
28 |
+
'mini' => 'xs',
|
29 |
+
'small' => 'sm',
|
30 |
+
'large' => 'lg',
|
31 |
+
);
|
32 |
+
if ( isset( $sizes[ $size ] ) ) {
|
33 |
+
$class .= ' btn-group-' . $sizes[ $size ];
|
34 |
+
}
|
35 |
+
|
36 |
+
if ( ! empty( $id ) ) {
|
37 |
+
$id = ' id="' . $id . '"';
|
38 |
+
}
|
39 |
+
|
40 |
+
$toggle = '';
|
41 |
+
if ( in_array( $mode, array( 'checkbox', 'radio' ) ) ) {
|
42 |
+
$toggle = ' data-toggle="buttons"';
|
43 |
+
}
|
44 |
+
|
45 |
+
$output .= '<div class="' . $class . '"' . $id . $toggle . '>';
|
46 |
+
}
|
47 |
+
|
48 |
+
if ( $echo ) {
|
49 |
+
echo $output;
|
50 |
+
}
|
51 |
+
return $output;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function close( $echo = true ) {
|
55 |
+
$output = apply_filters( 'cf7bs_bootstrap_button_group_close', '', $this->args );
|
56 |
+
|
57 |
+
if ( empty( $output ) ) {
|
58 |
+
$output = '</div>';
|
59 |
+
}
|
60 |
+
|
61 |
+
if ( $echo ) {
|
62 |
+
echo $output;
|
63 |
+
}
|
64 |
+
return $output;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function insert_button( $args = array(), $echo = true, $shortcode_tag = '' ) {
|
68 |
+
$args = (array) $args;
|
69 |
+
$args['size'] = 'default'; // size is defined in button group, so set it to 'default' on button
|
70 |
+
if ( in_array( $this->args['mode'], array( 'checkbox', 'radio' ) ) ) {
|
71 |
+
$args['mode'] = $this->args['mode'];
|
72 |
+
}
|
73 |
+
$temp = new CF7BS_Button( $args, $shortcode_tag );
|
74 |
+
$this->buttons[] = $temp;
|
75 |
+
return $temp->display( $echo );
|
76 |
+
}
|
77 |
+
|
78 |
+
protected function validate_args( $args, $exclude = array() ) {
|
79 |
+
$args = parent::validate_args( $args, $exclude );
|
80 |
+
|
81 |
+
return $args;
|
82 |
+
}
|
83 |
+
|
84 |
+
protected function get_defaults() {
|
85 |
+
$defaults = array(
|
86 |
+
'mode' => 'default', // default, checkbox, radio
|
87 |
+
'size' => 'default', // default, large, small, mini
|
88 |
+
'layout' => 'default', // default, vertical, justified
|
89 |
+
'id' => '',
|
90 |
+
);
|
91 |
+
return apply_filters( 'cf7bs_bootstrap_button_group_defaults', $defaults );
|
92 |
+
}
|
93 |
+
|
94 |
+
public function get_contents() {
|
95 |
+
return $this->buttons;
|
96 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
}
|
classes/CF7BS_Component.php
CHANGED
@@ -1,61 +1,45 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
-
* @version 1.
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
-
abstract class CF7BS_Component
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
elseif( is_object( $value ) )
|
46 |
-
{
|
47 |
-
$args[ $key ] = (object) $args[ $key ];
|
48 |
-
}
|
49 |
-
}
|
50 |
-
}
|
51 |
-
|
52 |
-
return $args;
|
53 |
-
}
|
54 |
-
|
55 |
-
protected abstract function get_defaults();
|
56 |
-
|
57 |
-
public function get_args()
|
58 |
-
{
|
59 |
-
return $this->args;
|
60 |
-
}
|
61 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
+
* @version 1.2.0
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
+
abstract class CF7BS_Component {
|
9 |
+
protected $args = array();
|
10 |
+
|
11 |
+
public function __construct( $args = array() ) {
|
12 |
+
$this->args = $this->validate_args( $args );
|
13 |
+
}
|
14 |
+
|
15 |
+
protected function validate_args( $args, $exclude = array() ) {
|
16 |
+
$defaults = $this->get_defaults();
|
17 |
+
$args = wp_parse_args( $args, $defaults );
|
18 |
+
foreach ( $defaults as $key => $value ) {
|
19 |
+
if ( ! in_array( $key, $exclude ) ) {
|
20 |
+
if ( is_string( $value ) ) {
|
21 |
+
$args[ $key ] = (string) $args[ $key ];
|
22 |
+
} elseif ( is_int( $value ) ) {
|
23 |
+
$args[ $key ] = intval( $args[ $key ] );
|
24 |
+
} elseif ( is_float( $value ) ) {
|
25 |
+
$args[ $key ] = floatval( $args[ $key ] );
|
26 |
+
} elseif ( is_bool( $value ) ) {
|
27 |
+
$args[ $key ] = (bool) $args[ $key ];
|
28 |
+
} elseif ( is_array( $value ) ) {
|
29 |
+
$args[ $key ] = (array) $args[ $key ];
|
30 |
+
} elseif ( is_object( $value ) ) {
|
31 |
+
$args[ $key ] = (object) $args[ $key ];
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
return $args;
|
37 |
+
}
|
38 |
+
|
39 |
+
protected abstract function get_defaults();
|
40 |
+
|
41 |
+
public function get_args()
|
42 |
+
{
|
43 |
+
return $this->args;
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
classes/CF7BS_Form_Field.php
CHANGED
@@ -1,582 +1,481 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
-
* @version 1.
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
-
class CF7BS_Form_Field extends CF7BS_Component
|
9 |
-
{
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
'mode' => 'default', // default, required, static, disabled
|
482 |
-
'status' => 'default', // default, success, warning, error
|
483 |
-
'readonly' => false,
|
484 |
-
'maxlength' => false,
|
485 |
-
'tabindex' => false,
|
486 |
-
'group_layout' => 'default', // default, inline, buttons
|
487 |
-
'group_type' => 'default', // only if group_layout==buttons
|
488 |
-
'wrapper_class' => '',
|
489 |
-
'input_before' => '',
|
490 |
-
'input_after' => '',
|
491 |
-
'input_before_class' => 'input-group-addon',
|
492 |
-
'input_after_class' => 'input-group-addon',
|
493 |
-
);
|
494 |
-
return apply_filters( 'cf7bs_bootstrap_form_field_defaults', $defaults );
|
495 |
-
}
|
496 |
-
|
497 |
-
private function validate_type( $type )
|
498 |
-
{
|
499 |
-
$whitelist = array(
|
500 |
-
'text',
|
501 |
-
'password',
|
502 |
-
'datetime',
|
503 |
-
'datetime-local',
|
504 |
-
'date',
|
505 |
-
'month',
|
506 |
-
'time',
|
507 |
-
'week',
|
508 |
-
'number',
|
509 |
-
'range',
|
510 |
-
'email',
|
511 |
-
'url',
|
512 |
-
'search',
|
513 |
-
'tel',
|
514 |
-
'color',
|
515 |
-
'textarea',
|
516 |
-
'file',
|
517 |
-
'hidden',
|
518 |
-
'select',
|
519 |
-
'multiselect',
|
520 |
-
'checkbox',
|
521 |
-
'radio',
|
522 |
-
);
|
523 |
-
|
524 |
-
$type = strtolower( $type );
|
525 |
-
if( !in_array( $type, $whitelist ) )
|
526 |
-
{
|
527 |
-
$type = 'text';
|
528 |
-
}
|
529 |
-
return $type;
|
530 |
-
}
|
531 |
-
|
532 |
-
private function validate_value( $value, $type, $options = array() )
|
533 |
-
{
|
534 |
-
if( $type == 'multiselect' || $type == 'checkbox' && is_array( $options ) && count( $options ) > 1 )
|
535 |
-
{
|
536 |
-
$value = (array) $value;
|
537 |
-
}
|
538 |
-
else
|
539 |
-
{
|
540 |
-
if( is_array( $value ) )
|
541 |
-
{
|
542 |
-
if ( count( $value ) > 0 ) {
|
543 |
-
reset( $value );
|
544 |
-
$value = $value[ key( $value ) ];
|
545 |
-
} else {
|
546 |
-
$value = '';
|
547 |
-
}
|
548 |
-
}
|
549 |
-
$value = (string) $value;
|
550 |
-
}
|
551 |
-
return $value;
|
552 |
-
}
|
553 |
-
|
554 |
-
private function get_column_width_classes( $label_column_width = 2, $breakpoint = 'sm' )
|
555 |
-
{
|
556 |
-
if( $label_column_width > 11 || $label_column_width < 1 )
|
557 |
-
{
|
558 |
-
$label_column_width = 2;
|
559 |
-
}
|
560 |
-
if( !in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) )
|
561 |
-
{
|
562 |
-
$breakpoint = 'sm';
|
563 |
-
}
|
564 |
-
return array(
|
565 |
-
'label' => 'col-' . $breakpoint . '-' . $label_column_width,
|
566 |
-
'input' => 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ),
|
567 |
-
);
|
568 |
-
}
|
569 |
-
|
570 |
-
private function get_column_offset_class( $label_column_width = 2, $breakpoint = 'sm' )
|
571 |
-
{
|
572 |
-
if( $label_column_width > 11 || $label_column_width < 1 )
|
573 |
-
{
|
574 |
-
$label_column_width = 2;
|
575 |
-
}
|
576 |
-
if( !in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) )
|
577 |
-
{
|
578 |
-
$breakpoint = 'sm';
|
579 |
-
}
|
580 |
-
return 'col-' . $breakpoint . '-offset-' . $label_column_width;
|
581 |
-
}
|
582 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
+
* @version 1.2.0
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
+
class CF7BS_Form_Field extends CF7BS_Component {
|
9 |
+
public function display( $echo = true ) {
|
10 |
+
$output = apply_filters( 'cf7bs_bootstrap_form_field_display', '', $this->args );
|
11 |
+
|
12 |
+
if ( empty( $output ) ) {
|
13 |
+
$output = '';
|
14 |
+
|
15 |
+
extract( $this->args );
|
16 |
+
|
17 |
+
$type = $this->validate_type( $type );
|
18 |
+
|
19 |
+
$value = $this->validate_value( $value, $type, $options );
|
20 |
+
|
21 |
+
if ( 'hidden' != $type ) {
|
22 |
+
$label_class = 'control-label';
|
23 |
+
$input_div_class = '';
|
24 |
+
$input_class = $class;
|
25 |
+
if ( 'horizontal' == $form_layout ) {
|
26 |
+
$classes = $this->get_column_width_classes( $form_label_width, $form_breakpoint );
|
27 |
+
$label_class .= ' ' . $classes['label'];
|
28 |
+
$input_div_class = $classes['input'];
|
29 |
+
if ( empty( $label ) ) {
|
30 |
+
$input_div_class .= ' ' . $this->get_column_offset_class( $form_label_width, $form_breakpoint );
|
31 |
+
}
|
32 |
+
} elseif( 'inline' == $form_layout ) {
|
33 |
+
if ( empty( $placeholder ) ) {
|
34 |
+
$placeholder = $label;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
if ( ! empty( $wrapper_class ) ) {
|
39 |
+
$wrapper_class = ' ' . esc_attr( $wrapper_class );
|
40 |
+
}
|
41 |
+
|
42 |
+
if ( ! in_array( $type, array( 'radio', 'checkbox' ) ) ) {
|
43 |
+
if ( ! empty( $input_class ) ) {
|
44 |
+
$input_class .= ' ';
|
45 |
+
}
|
46 |
+
if ( ! in_array( $type, array( 'file', 'range' ) ) ) {
|
47 |
+
$input_class .= 'form-control';
|
48 |
+
}
|
49 |
+
|
50 |
+
if ( 'textarea' != $type ) {
|
51 |
+
if ( 'large' == $size ) {
|
52 |
+
$input_class .= ' input-lg';
|
53 |
+
} elseif ( in_array( $size, array( 'small', 'mini' ) ) ) {
|
54 |
+
$input_class .= ' input-sm';
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
if ( is_int( $tabindex ) ) {
|
59 |
+
$tabindex = ' tabindex="' . $tabindex . '"';
|
60 |
+
} else {
|
61 |
+
$tabindex = '';
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
if ( ! empty( $input_class ) ) {
|
66 |
+
$input_class = ' class="' . esc_attr( $input_class ) . '"';
|
67 |
+
}
|
68 |
+
if ( ! empty( $placeholder ) ) {
|
69 |
+
$placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"';
|
70 |
+
}
|
71 |
+
|
72 |
+
if ( $readonly ) {
|
73 |
+
$readonly = ' readonly';
|
74 |
+
} else {
|
75 |
+
$readonly = '';
|
76 |
+
}
|
77 |
+
|
78 |
+
if ( $maxlength > -1 && !empty( $maxlength ) ) {
|
79 |
+
$maxlength = ' maxlength="' . absint( $maxlength ) . '"';
|
80 |
+
} else {
|
81 |
+
$maxlength = '';
|
82 |
+
}
|
83 |
+
|
84 |
+
$append = '';
|
85 |
+
|
86 |
+
if ( in_array( $status, array( 'success', 'warning', 'error' ) ) ) {
|
87 |
+
$status = ' has-' . $status;
|
88 |
+
} else {
|
89 |
+
$status = '';
|
90 |
+
}
|
91 |
+
|
92 |
+
if ( 'has-error' == $status ) {
|
93 |
+
$append .= ' aria-invalid="true"';
|
94 |
+
} else {
|
95 |
+
$append .= ' aria-invalid="false"';
|
96 |
+
}
|
97 |
+
|
98 |
+
$label_required = '';
|
99 |
+
if ( 'required' == $mode ) {
|
100 |
+
$append .= ' aria-required="true" required';
|
101 |
+
$label_required = ' ' . cf7bs_get_form_property( 'required_html' );
|
102 |
+
} elseif( 'disabled' == $mode ) {
|
103 |
+
$append .= ' disabled';
|
104 |
+
}
|
105 |
+
|
106 |
+
if ( 'horizontal' == $form_layout ) {
|
107 |
+
$output .= '<div class="form-group' . $wrapper_class . $status . '">';
|
108 |
+
if ( ! empty( $label ) ) {
|
109 |
+
$output .= '<label class="' . esc_attr( $label_class ) . '" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
|
110 |
+
}
|
111 |
+
$output .= '<div class="' . esc_attr( $input_div_class ) . '">';
|
112 |
+
} elseif( 'inline' == $form_layout ) {
|
113 |
+
$output .= '<div class="form-group' . $wrapper_class . $status . '">';
|
114 |
+
if ( ! empty( $label ) ) {
|
115 |
+
$output .= '<label class="sr-only" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
|
116 |
+
}
|
117 |
+
} else {
|
118 |
+
$output .= '<div class="form-group' . $wrapper_class . $status . '">';
|
119 |
+
if ( ! empty( $label ) ) {
|
120 |
+
$rc_group_style = '';
|
121 |
+
if ( in_array( $type, array( 'radio', 'checkbox' ) ) ) {
|
122 |
+
$rc_group_style = ' style="display:block;"';
|
123 |
+
}
|
124 |
+
$output .= '<label for="' . esc_attr( $id ) . '"' . $rc_group_style . '>' . esc_html( $label ) . $label_required . '</label>';
|
125 |
+
}
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
switch ( $type ) {
|
130 |
+
case 'checkbox':
|
131 |
+
if ( count( $options ) <= 1 ) {
|
132 |
+
$curval = key( $options );
|
133 |
+
$title = $options[ $curval ];
|
134 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
135 |
+
$title = esc_html( $title );
|
136 |
+
}
|
137 |
+
$output .= '<div class="checkbox' . $wrapper_class . '">';
|
138 |
+
$output .= '<label>';
|
139 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . $tabindex . '"' : '' ) . $append . '>';
|
140 |
+
$output .= $title;
|
141 |
+
$output .= '</label>';
|
142 |
+
$output .= '</div>';
|
143 |
+
} else {
|
144 |
+
if ( 'buttons' == $group_layout ) {
|
145 |
+
$button_group = new CF7BS_Button_Group( array(
|
146 |
+
'mode' => 'checkbox',
|
147 |
+
'size' => $size,
|
148 |
+
) );
|
149 |
+
$output .= $button_group->open( false );
|
150 |
+
$counter = 0;
|
151 |
+
foreach ( $options as $curval => $title ) {
|
152 |
+
$is_checked = cf7bs_multiple_checked( $value, $curval, false );
|
153 |
+
$output .= $button_group->insert_button( array(
|
154 |
+
'type' => $group_type,
|
155 |
+
'id' => $id . ( $counter + 1 ),
|
156 |
+
'name' => $name . '[]',
|
157 |
+
'class' => $class,
|
158 |
+
'value' => $curval,
|
159 |
+
'title' => $title,
|
160 |
+
'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
|
161 |
+
), false );
|
162 |
+
$counter++;
|
163 |
+
}
|
164 |
+
$output .= $button_group->close( false );
|
165 |
+
} elseif ( 'inline' == $group_layout && 'inline' != $form_layout ) {
|
166 |
+
$counter = 0;
|
167 |
+
foreach ( $options as $curval => $title ) {
|
168 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
169 |
+
$title = esc_html( $title );
|
170 |
+
}
|
171 |
+
$output .= '<label class="checkbox-inline">';
|
172 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_checked( $value, $curval, false ) . ( $tabindex >= 0 ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
|
173 |
+
$output .= $title;
|
174 |
+
$output .= '</label>';
|
175 |
+
$counter++;
|
176 |
+
}
|
177 |
+
} else {
|
178 |
+
$counter = 0;
|
179 |
+
foreach ( $options as $curval => $title ) {
|
180 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
181 |
+
$title = esc_html( $title );
|
182 |
+
}
|
183 |
+
$output .= '<div class="checkbox">';
|
184 |
+
$output .= '<label>';
|
185 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" type="checkbox" value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
|
186 |
+
$output .= $title;
|
187 |
+
$output .= '</label>';
|
188 |
+
$output .= '</div>';
|
189 |
+
$counter++;
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
break;
|
194 |
+
case 'select':
|
195 |
+
$output .= '<select' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '"' . $tabindex . $append . '>';
|
196 |
+
foreach ( $options as $curval => $title ) {
|
197 |
+
$output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
|
198 |
+
}
|
199 |
+
$output .= '</select>';
|
200 |
+
break;
|
201 |
+
case 'multiselect':
|
202 |
+
$output .= '<select' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" multiple' . $tabindex . $append . '>';
|
203 |
+
foreach ( $options as $curval => $title ) {
|
204 |
+
$output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
|
205 |
+
}
|
206 |
+
$output .= '</select>';
|
207 |
+
break;
|
208 |
+
case 'radio':
|
209 |
+
if ( count( $options ) <= 1 ) {
|
210 |
+
$curval = key( $options );
|
211 |
+
$title = $options[ $curval ];
|
212 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
213 |
+
$title = esc_html( $title );
|
214 |
+
}
|
215 |
+
$output .= '<div class="radio' . $wrapper_class . '">';
|
216 |
+
$output .= '<label>';
|
217 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . $tabindex . '"' : '' ) . $append . '>';
|
218 |
+
$output .= $title;
|
219 |
+
$output .= '</label>';
|
220 |
+
$output .= '</div>';
|
221 |
+
} else {
|
222 |
+
if ( 'buttons' == $group_layout ) {
|
223 |
+
$button_group = new CF7BS_Button_Group( array(
|
224 |
+
'mode' => 'radio',
|
225 |
+
'size' => $size,
|
226 |
+
) );
|
227 |
+
$output .= $button_group->open( false );
|
228 |
+
$counter = 0;
|
229 |
+
foreach ( $options as $curval => $title ) {
|
230 |
+
$is_checked = cf7bs_checked( $value, $curval, false );
|
231 |
+
$output .= $button_group->insert_button( array(
|
232 |
+
'type' => $group_type,
|
233 |
+
'id' => $id . ( $counter + 1 ),
|
234 |
+
'name' => $name,
|
235 |
+
'class' => $class,
|
236 |
+
'value' => $curval,
|
237 |
+
'title' => $title,
|
238 |
+
'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
|
239 |
+
), false );
|
240 |
+
$counter++;
|
241 |
+
}
|
242 |
+
$output .= $button_group->close( false );
|
243 |
+
} elseif( 'inline' == $group_layout && 'inline' != $form_layout ) {
|
244 |
+
$counter = 0;
|
245 |
+
foreach ( $options as $curval => $title ) {
|
246 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
247 |
+
$title = esc_html( $title );
|
248 |
+
}
|
249 |
+
$output .= '<label class="radio-inline">';
|
250 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( $tabindex >= 0 ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
|
251 |
+
$output .= $title;
|
252 |
+
$output .= '</label>';
|
253 |
+
$counter++;
|
254 |
+
}
|
255 |
+
} else {
|
256 |
+
$counter = 0;
|
257 |
+
foreach ( $options as $curval => $title ) {
|
258 |
+
if ( false === strpos( $title, 'wpcf7-free-text' ) ) {
|
259 |
+
$title = esc_html( $title );
|
260 |
+
}
|
261 |
+
$output .= '<div class="radio">';
|
262 |
+
$output .= '<label>';
|
263 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id . ( $counter + 1 ) ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="radio" value="' . esc_attr( $curval ) . '"' . cf7bs_checked( $value, $curval, false ) . ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $append . '>';
|
264 |
+
$output .= $title;
|
265 |
+
$output .= '</label>';
|
266 |
+
$output .= '</div>';
|
267 |
+
$counter++;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
break;
|
272 |
+
case 'textarea':
|
273 |
+
$output .= '<textarea' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" rows="' . absint( $rows ) . '"' . $placeholder . $readonly . $tabindex . $append . '>';
|
274 |
+
$output .= esc_textarea( $value );
|
275 |
+
$output .= '</textarea>';
|
276 |
+
break;
|
277 |
+
case 'file':
|
278 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="file"' . $tabindex . $append . '>';
|
279 |
+
break;
|
280 |
+
case 'hidden':
|
281 |
+
$output .= '<input' . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="hidden" value="' . esc_attr( $value ) . '">';
|
282 |
+
break;
|
283 |
+
case 'number':
|
284 |
+
case 'range':
|
285 |
+
case 'date':
|
286 |
+
case 'datetime':
|
287 |
+
case 'datetime-local':
|
288 |
+
case 'month':
|
289 |
+
case 'time':
|
290 |
+
case 'week':
|
291 |
+
$min = '';
|
292 |
+
if ( isset( $options['min'] ) ) {
|
293 |
+
$min = ' min="' . esc_attr( $options['min'] ) . '"';
|
294 |
+
}
|
295 |
+
$max = '';
|
296 |
+
if ( isset( $options['max'] ) ) {
|
297 |
+
$max = ' max="' . esc_attr( $options['max'] ) . '"';
|
298 |
+
}
|
299 |
+
$step = '';
|
300 |
+
if ( isset( $options['step'] ) ) {
|
301 |
+
$step = ' step="' . esc_attr( $options['step'] ) . '"';
|
302 |
+
}
|
303 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="' . esc_attr( $type ) . '" value="' . esc_attr( $value ) . '"' . $placeholder . $min . $max . $step . $readonly . $tabindex . $append . '>';
|
304 |
+
break;
|
305 |
+
case 'custom':
|
306 |
+
if ( ! empty( $name ) ) {
|
307 |
+
$output .= $name;
|
308 |
+
}
|
309 |
+
break;
|
310 |
+
default:
|
311 |
+
if ( 'static' == $mode ) {
|
312 |
+
$output .= '<p class="form-control-static">' . esc_html( $value ) . '</p>';
|
313 |
+
} else {
|
314 |
+
if ( ! empty( $input_before ) || ! empty( $input_after ) ) {
|
315 |
+
$input_group_class = 'input-group';
|
316 |
+
if ( false !== strpos( $input_class, ' input-lg') ) {
|
317 |
+
$input_class = str_replace( ' input-lg', '', $input_class );
|
318 |
+
$input_group_class .= ' input-group-lg';
|
319 |
+
} elseif ( false !== strpos( $input_class, ' input-sm') ) {
|
320 |
+
$input_class = str_replace( ' input-sm', '', $input_class );
|
321 |
+
$input_group_class .= ' input-group-sm';
|
322 |
+
}
|
323 |
+
$output .= '<div class="' . $input_group_class . '">';
|
324 |
+
if ( ! empty( $input_before ) ) {
|
325 |
+
$output .= '<span class="' . esc_attr( $input_before_class ) . '">';
|
326 |
+
$output .= $input_before;
|
327 |
+
$output .= '</span>';
|
328 |
+
}
|
329 |
+
}
|
330 |
+
|
331 |
+
$output .= '<input' . $input_class . ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="' . esc_attr( $type ) . '" value="' . esc_attr( $value ) . '"' . $placeholder . $readonly . $maxlength . $tabindex . $append . '>';
|
332 |
+
|
333 |
+
if ( ! empty( $input_before ) || ! empty( $input_after ) ) {
|
334 |
+
if ( ! empty( $input_after ) ) {
|
335 |
+
$output .= '<span class="' . esc_attr( $input_after_class ) . '">';
|
336 |
+
$output .= $input_after;
|
337 |
+
$output .= '</span>';
|
338 |
+
}
|
339 |
+
$output .= '</div>';
|
340 |
+
}
|
341 |
+
}
|
342 |
+
break;
|
343 |
+
}
|
344 |
+
|
345 |
+
if ( 'hidden' != $type ) {
|
346 |
+
if ( ! empty( $help_text ) && 'inline' != $form_layout ) {
|
347 |
+
$output .= '<span class="help-block">' . $help_text . '</span>';
|
348 |
+
}
|
349 |
+
|
350 |
+
if ( 'horizontal' == $form_layout ) {
|
351 |
+
$output .= '</div>';
|
352 |
+
$output .= '</div>';
|
353 |
+
} else {
|
354 |
+
$output .= '</div>';
|
355 |
+
}
|
356 |
+
}
|
357 |
+
}
|
358 |
+
|
359 |
+
if ( $echo ) {
|
360 |
+
echo $output;
|
361 |
+
}
|
362 |
+
return $output;
|
363 |
+
}
|
364 |
+
|
365 |
+
protected function validate_args( $args, $exclude = array() ) {
|
366 |
+
$exclude[] = 'value';
|
367 |
+
$exclude[] = 'maxlength';
|
368 |
+
$exclude[] = 'tabindex';
|
369 |
+
$args = parent::validate_args( $args, $exclude );
|
370 |
+
|
371 |
+
// type whitelist check is made later in the display() function to allow different types to use in a filter
|
372 |
+
|
373 |
+
return $args;
|
374 |
+
}
|
375 |
+
|
376 |
+
protected function get_defaults() {
|
377 |
+
$defaults = array(
|
378 |
+
'name' => '',
|
379 |
+
'id' => '',
|
380 |
+
'class' => '',
|
381 |
+
'type' => 'text',
|
382 |
+
'value' => '', // for multiselect and multiple checkbox an array, for singular checkboxes and all others a string
|
383 |
+
'placeholder' => '',
|
384 |
+
'label' => '',
|
385 |
+
'options' => array(), // for select, multiselect, checkbox and radio: value => title; for number, range and all datetime-related fields: min, max, step
|
386 |
+
'rows' => 4,
|
387 |
+
'help_text' => '',
|
388 |
+
'size' => 'default', // default, large, small, mini
|
389 |
+
'form_layout' => 'default', // default, inline, horizontal
|
390 |
+
'form_label_width' => 2,
|
391 |
+
'form_breakpoint' => 'sm',
|
392 |
+
'mode' => 'default', // default, required, static, disabled
|
393 |
+
'status' => 'default', // default, success, warning, error
|
394 |
+
'readonly' => false,
|
395 |
+
'maxlength' => false,
|
396 |
+
'tabindex' => false,
|
397 |
+
'group_layout' => 'default', // default, inline, buttons
|
398 |
+
'group_type' => 'default', // only if group_layout==buttons
|
399 |
+
'wrapper_class' => '',
|
400 |
+
'input_before' => '',
|
401 |
+
'input_after' => '',
|
402 |
+
'input_before_class' => 'input-group-addon',
|
403 |
+
'input_after_class' => 'input-group-addon',
|
404 |
+
);
|
405 |
+
return apply_filters( 'cf7bs_bootstrap_form_field_defaults', $defaults );
|
406 |
+
}
|
407 |
+
|
408 |
+
private function validate_type( $type ) {
|
409 |
+
$whitelist = array(
|
410 |
+
'text',
|
411 |
+
'password',
|
412 |
+
'datetime',
|
413 |
+
'datetime-local',
|
414 |
+
'date',
|
415 |
+
'month',
|
416 |
+
'time',
|
417 |
+
'week',
|
418 |
+
'number',
|
419 |
+
'range',
|
420 |
+
'email',
|
421 |
+
'url',
|
422 |
+
'search',
|
423 |
+
'tel',
|
424 |
+
'color',
|
425 |
+
'textarea',
|
426 |
+
'file',
|
427 |
+
'hidden',
|
428 |
+
'select',
|
429 |
+
'multiselect',
|
430 |
+
'checkbox',
|
431 |
+
'radio',
|
432 |
+
'custom',
|
433 |
+
);
|
434 |
+
|
435 |
+
$type = strtolower( $type );
|
436 |
+
if ( ! in_array( $type, $whitelist ) ) {
|
437 |
+
$type = 'text';
|
438 |
+
}
|
439 |
+
return $type;
|
440 |
+
}
|
441 |
+
|
442 |
+
private function validate_value( $value, $type, $options = array() ) {
|
443 |
+
if ( 'multiselect' == $type || 'checkbox' == $type && is_array( $options ) && count( $options ) > 1 ) {
|
444 |
+
$value = (array) $value;
|
445 |
+
} else {
|
446 |
+
if ( is_array( $value ) ) {
|
447 |
+
if ( count( $value ) > 0 ) {
|
448 |
+
reset( $value );
|
449 |
+
$value = $value[ key( $value ) ];
|
450 |
+
} else {
|
451 |
+
$value = '';
|
452 |
+
}
|
453 |
+
}
|
454 |
+
$value = (string) $value;
|
455 |
+
}
|
456 |
+
return $value;
|
457 |
+
}
|
458 |
+
|
459 |
+
private function get_column_width_classes( $label_column_width = 2, $breakpoint = 'sm' ) {
|
460 |
+
if ( $label_column_width > 11 || $label_column_width < 1 ) {
|
461 |
+
$label_column_width = 2;
|
462 |
+
}
|
463 |
+
if ( ! in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) ) {
|
464 |
+
$breakpoint = 'sm';
|
465 |
+
}
|
466 |
+
return array(
|
467 |
+
'label' => 'col-' . $breakpoint . '-' . $label_column_width,
|
468 |
+
'input' => 'col-' . $breakpoint . '-' . ( 12 - $label_column_width ),
|
469 |
+
);
|
470 |
+
}
|
471 |
+
|
472 |
+
private function get_column_offset_class( $label_column_width = 2, $breakpoint = 'sm' ) {
|
473 |
+
if ( $label_column_width > 11 || $label_column_width < 1 ) {
|
474 |
+
$label_column_width = 2;
|
475 |
+
}
|
476 |
+
if ( ! in_array( $breakpoint, array( 'xs', 'sm', 'md', 'lg' ) ) ) {
|
477 |
+
$breakpoint = 'sm';
|
478 |
+
}
|
479 |
+
return 'col-' . $breakpoint . '-offset-' . $label_column_width;
|
480 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
481 |
}
|
composer.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
{
|
2 |
"name": "felixarntz/bootstrap-for-contact-form-7",
|
3 |
"description": "This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.",
|
4 |
-
"version": "1.
|
5 |
"license": "GPL-2.0",
|
6 |
"type": "wordpress-plugin",
|
7 |
"keywords": [
|
1 |
{
|
2 |
"name": "felixarntz/bootstrap-for-contact-form-7",
|
3 |
"description": "This plugin modifies the output of the popular Contact Form 7 plugin to be styled in compliance with themes using the Bootstrap CSS framework.",
|
4 |
+
"version": "1.2.0",
|
5 |
"license": "GPL-2.0",
|
6 |
"type": "wordpress-plugin",
|
7 |
"keywords": [
|
modifications.php
CHANGED
@@ -1,277 +1,237 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* @package CF7BS
|
4 |
-
* @version 1.
|
5 |
* @author Felix Arntz <felix-arntz@leaves-and-love.net>
|
6 |
*/
|
7 |
|
8 |
-
function cf7bs_selected( $selected, $current = true, $echo = true )
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|