Bootstrap for Contact Form 7 - Version 1.2.0

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 Icon 128x128 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 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
- '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);
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.1.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.1.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.1.1
15
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
16
  */
17
 
18
- define( 'CF7BS_VERSION', '1.1.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
- if( defined( 'WPCF7_VERSION' ) && apply_filters( 'cf7bs_using_bootstrap', true ) )
32
- {
33
- include_once CF7BS_PATH . '/modifications.php';
34
- include_once CF7BS_PATH . '/classes/CF7BS_Component.php';
35
- include_once CF7BS_PATH . '/classes/CF7BS_Button.php';
36
- include_once CF7BS_PATH . '/classes/CF7BS_Button_Group.php';
37
- include_once CF7BS_PATH . '/classes/CF7BS_Alert.php';
38
- include_once CF7BS_PATH . '/classes/CF7BS_Form_Field.php';
39
 
40
- $modules = array(
41
- 'acceptance',
42
- 'submit',
43
- 'captcha',
44
- 'number',
45
- 'text',
46
- 'checkbox',
47
- 'quiz',
48
- 'textarea',
49
- 'date',
50
- 'file',
51
- 'select',
52
- );
53
- foreach( $modules as $module )
54
- {
55
- $file = CF7BS_PATH . '/modules/' . $module . '.php';
56
- if( file_exists( $file ) )
57
- {
58
- include_once $file;
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
- if( $form_id == 0 )
73
- {
74
- $current_form = WPCF7_ContactForm::get_current();
75
- if ( $current_form !== null ) {
76
- $form_id = $current_form->id();
77
- }
78
- }
 
79
 
80
- if ( $form_id == 0 ) {
81
- return false;
82
- }
83
-
84
- if( $current_form_id != $form_id )
85
- {
86
- $current_form_id = $form_id;
87
 
88
- $properties = cf7bs_get_default_form_properties();
89
- $current_form_properties = apply_filters( 'cf7bs_form_' . $form_id . '_properties', $properties );
90
- }
91
-
92
- if( isset( $current_form_properties[ $property ] ) )
93
- {
94
- return $current_form_properties[ $property ];
95
- }
96
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
- function cf7bs_get_default_form_properties()
100
- {
101
- $properties = array(
102
- 'layout' => 'default', // default, inline, horizontal
103
- 'label_width' => 3, // integer between 1 and 11
104
- 'breakpoint' => 'sm', // xs, sm, md, lg
105
- 'size' => 'default', // default, small, large
106
- 'required_html' => '<span class="required">*</span>',
107
- 'group_layout' => 'default', // default, inline, buttons
108
- 'group_type' => 'default', // default, primary, success, info, warning, danger (only if group_layout=buttons)
109
- 'submit_type' => 'primary', // default, primary, success, info, warning, danger
110
- );
111
- return apply_filters( 'cf7bs_default_form_properties', $properties );
112
  }
113
 
114
- function cf7bs_add_get_parameter()
115
- {
116
- $args = func_get_args();
117
- if( is_array( $args[0] ) )
118
- {
119
- if( count( $args ) < 2 || $args[1] === false )
120
- {
121
- $uri = $_SERVER['REQUEST_URI'];
122
- }
123
- else
124
- {
125
- $uri = $args[1];
126
- }
127
- foreach( $args[0] as $key => &$value )
128
- {
129
- $value = cf7bs_parameter_encode( $value );
130
- }
131
- return add_query_arg( $args[0], $uri );
132
- }
133
- else
134
- {
135
- if( count( $args ) < 3 || $args[2] === false )
136
- {
137
- $uri = $_SERVER['REQUEST_URI'];
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.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Alert extends CF7BS_Component
9
- {
10
- public function open( $echo = true )
11
- {
12
- $output = apply_filters( 'cf7bs_bootstrap_alert_open', '', $this->args );
13
-
14
- if( empty( $output ) )
15
- {
16
- $output = '';
17
-
18
- extract( $this->args );
19
-
20
- $type = $this->validate_type( $type );
21
-
22
- if( !empty( $class ) )
23
- {
24
- $class .= ' ';
25
- }
26
- $class .= 'alert';
27
- if( !empty( $type ) )
28
- {
29
- $class .= ' alert-' . $type;
30
- }
31
- if( $dismissable )
32
- {
33
- $class .= ' alert-dismissable';
34
- }
35
-
36
- $output .= '<div class="' . esc_attr( $class ) . '"' . ( $hide ? ' style="display:none;"' : '' ) . '>';
37
- if( $dismissable )
38
- {
39
- $output .= '<button class="close" data-dismiss="alert" type="button">&times;</button>';
40
- }
41
- }
42
-
43
- if( $echo )
44
- {
45
- echo $output;
46
- }
47
- return $output;
48
- }
49
-
50
- public function close( $echo = true )
51
- {
52
- $output = apply_filters( 'cf7bs_bootstrap_alert_close', '', $this->args );
53
-
54
- if( empty( $output ) )
55
- {
56
- $output .= '</div>';
57
- }
58
-
59
- if( $echo )
60
- {
61
- echo $output;
62
- }
63
- return $output;
64
- }
65
-
66
- protected function validate_args( $args, $exclude = array() )
67
- {
68
- $args = parent::validate_args( $args, $exclude );
69
-
70
- return $args;
71
- }
72
-
73
- protected function get_defaults()
74
- {
75
- $defaults = array(
76
- 'type' => 'default',
77
- 'class' => '',
78
- 'dismissable' => false,
79
- 'hide' => false,
80
- );
81
- return apply_filters( 'cf7bs_bootstrap_alert_defaults', $defaults );
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">&times;</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.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Button extends CF7BS_Component
9
- {
10
- public function display( $echo = true )
11
- {
12
- $output = apply_filters( 'cf7bs_bootstrap_button_display', '', $this->args );
13
-
14
- if( empty( $output ) )
15
- {
16
- $output = '';
17
-
18
- extract( $this->args );
19
-
20
- $type = $this->validate_type( $type );
21
-
22
- if( !empty( $class ) )
23
- {
24
- $class .= ' ';
25
- }
26
-
27
- $class .= 'btn btn-' . $type;
28
-
29
- $sizes = array(
30
- 'mini' => 'xs',
31
- 'small' => 'sm',
32
- 'large' => 'lg',
33
- );
34
- if( isset( $sizes[ $size ] ) )
35
- {
36
- $class .= ' btn-' . $sizes[ $size ];
37
- }
38
-
39
- if( !empty( $id ) )
40
- {
41
- $id = ' id="' . esc_attr( $id ) . '"';
42
- }
43
-
44
- if( !empty( $name ) )
45
- {
46
- $name = ' name="' . esc_attr( $name ) . '"';
47
- }
48
-
49
- if( $mode == 'checkbox' )
50
- {
51
- $output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="checkbox" value="' . esc_attr( $value ) . '"' . $append . '>' . esc_html( $title ) . '</label>';
52
- }
53
- elseif( $mode == 'radio' )
54
- {
55
- $output .= '<label class="' . esc_attr( $class ) . '"><input' . $id . $name . ' type="radio" value="' . esc_attr( $value ) . '"' . $append . '>' . esc_html( $title ) . '</label>';
56
- }
57
- else
58
- {
59
- $wrapper_class = array();
60
-
61
- if( $align && $form_layout != 'inline' )
62
- {
63
- $wrapper_class[] = 'text-' . $align;
64
- }
65
-
66
- if( $form_layout == 'horizontal' )
67
- {
68
- $wrapper_class[] = $this->get_column_class( $form_label_width, $form_breakpoint );
69
- }
70
-
71
- $wrapper_class = implode( ' ', $wrapper_class );
72
-
73
- if( !empty( $wrapper_class ) )
74
- {
75
- $wrapper_class = ' class="' . $wrapper_class . '"';
76
- }
77
-
78
- if( is_int( $tabindex ) )
79
- {
80
- $tabindex = ' tabindex="' . $tabindex . '"';
81
- }
82
- else
83
- {
84
- $tabindex = '';
85
- }
86
- $output .= '<div class="form-group"><div' . $wrapper_class . '>';
87
- $output .= '<input class="' . esc_attr( $class ) . '"' . $id . $name . ' type="submit" value="' . esc_attr( $title ) . '"' . $tabindex . '>';
88
- $output .= '</div></div>';
89
- }
90
- }
91
-
92
- if( $echo )
93
- {
94
- echo $output;
95
- }
96
- return $output;
97
- }
98
-
99
- protected function validate_args( $args, $exclude = array() )
100
- {
101
- $exclude[] = 'tabindex';
102
- $exclude[] = 'align';
103
- $args = parent::validate_args( $args, $exclude );
104
-
105
- if( is_string( $args['align'] ) )
106
- {
107
- $args['align'] = strtolower( $args['align'] );
108
- }
109
-
110
- if( !in_array( $args['align'], array( 'left', 'center', 'right' ) ) )
111
- {
112
- $args['align'] = false;
113
- }
114
-
115
- // type whitelist check is made later in the display() function to allow different types to use in a filter
116
-
117
- return $args;
118
- }
119
-
120
- protected function get_defaults()
121
- {
122
- $defaults = array(
123
- 'type' => 'default',
124
- 'size' => 'default', // default, large, small, mini
125
- 'mode' => 'submit', // checkbox, radio, submit
126
- 'id' => '',
127
- 'class' => '',
128
- 'title' => 'Button Title',
129
- 'name' => '',
130
- 'append' => '', // for checkbox/radio only
131
- 'value' => '', // for checkbox/radio only
132
- 'tabindex' => false,
133
- 'align' => false,
134
- 'form_layout' => 'default', // default, inline, horizontal
135
- 'form_label_width' => 2,
136
- 'form_breakpoint' => 'sm',
137
- );
138
- return apply_filters( 'cf7bs_bootstrap_button_defaults', $defaults );
139
- }
140
-
141
- private function validate_type( $type )
142
- {
143
- $whitelist = array(
144
- 'default',
145
- 'primary',
146
- 'info',
147
- 'success',
148
- 'warning',
149
- 'danger',
150
- 'link'
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.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Button_Group extends CF7BS_Component
9
- {
10
- private $buttons = array();
11
-
12
- public function open( $echo = true )
13
- {
14
- $output = apply_filters( 'cf7bs_bootstrap_button_group_open', '', $this->args );
15
-
16
- if( empty( $output ) )
17
- {
18
- $output = '';
19
-
20
- extract( $this->args );
21
-
22
- $class = 'btn-group';
23
-
24
- if( $layout == 'vertical' )
25
- {
26
- $class .= '-vertical';
27
- }
28
- elseif( $layout == 'justified' )
29
- {
30
- $class .= ' btn-group-justified';
31
- }
32
-
33
- $sizes = array(
34
- 'mini' => 'xs',
35
- 'small' => 'sm',
36
- 'large' => 'lg',
37
- );
38
- if( isset( $sizes[ $size ] ) )
39
- {
40
- $class .= ' btn-group-' . $sizes[ $size ];
41
- }
42
-
43
- if( !empty( $id ) )
44
- {
45
- $id = ' id="' . $id . '"';
46
- }
47
-
48
- $toggle = '';
49
- if( in_array( $mode, array( 'checkbox', 'radio' ) ) )
50
- {
51
- $toggle = ' data-toggle="buttons"';
52
- }
53
-
54
- $output .= '<div class="' . $class . '"' . $id . $toggle . '>';
55
- }
56
-
57
- if( $echo )
58
- {
59
- echo $output;
60
- }
61
- return $output;
62
- }
63
-
64
- public function close( $echo = true )
65
- {
66
- $output = apply_filters( 'cf7bs_bootstrap_button_group_close', '', $this->args );
67
-
68
- if( empty( $output ) )
69
- {
70
- $output = '</div>';
71
- }
72
-
73
- if( $echo )
74
- {
75
- echo $output;
76
- }
77
- return $output;
78
- }
79
-
80
- public function insert_button( $args = array(), $echo = true, $shortcode_tag = '' )
81
- {
82
- $args = (array) $args;
83
- $args['size'] = 'default'; // size is defined in button group, so set it to 'default' on button
84
- if( in_array( $this->args['mode'], array( 'checkbox', 'radio' ) ) )
85
- {
86
- $args['mode'] = $this->args['mode'];
87
- }
88
- $temp = new CF7BS_Button( $args, $shortcode_tag );
89
- $this->buttons[] = $temp;
90
- return $temp->display( $echo );
91
- }
92
-
93
- protected function validate_args( $args, $exclude = array() )
94
- {
95
- $args = parent::validate_args( $args, $exclude );
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.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- abstract class CF7BS_Component
9
- {
10
- protected $args = array();
11
-
12
- public function __construct( $args = array() )
13
- {
14
- $this->args = $this->validate_args( $args );
15
- }
16
-
17
- protected function validate_args( $args, $exclude = array() )
18
- {
19
- $defaults = $this->get_defaults();
20
- $args = wp_parse_args( $args, $defaults );
21
- foreach( $defaults as $key => $value )
22
- {
23
- if( !in_array( $key, $exclude ) )
24
- {
25
- if( is_string( $value ) )
26
- {
27
- $args[ $key ] = (string) $args[ $key ];
28
- }
29
- elseif( is_int( $value ) )
30
- {
31
- $args[ $key ] = intval( $args[ $key ] );
32
- }
33
- elseif( is_float( $value ) )
34
- {
35
- $args[ $key ] = floatval( $args[ $key ] );
36
- }
37
- elseif( is_bool( $value ) )
38
- {
39
- $args[ $key ] = (bool) $args[ $key ];
40
- }
41
- elseif( is_array( $value ) )
42
- {
43
- $args[ $key ] = (array) $args[ $key ];
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.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- class CF7BS_Form_Field extends CF7BS_Component
9
- {
10
- public function display( $echo = true )
11
- {
12
- $output = apply_filters( 'cf7bs_bootstrap_form_field_display', '', $this->args );
13
-
14
- if( empty( $output ) )
15
- {
16
- $output = '';
17
-
18
- extract( $this->args );
19
-
20
- $type = $this->validate_type( $type );
21
-
22
- $value = $this->validate_value( $value, $type, $options );
23
-
24
- if( $type != 'hidden' )
25
- {
26
- $label_class = 'control-label';
27
- $input_div_class = '';
28
- $input_class = $class;
29
- if( $form_layout == 'horizontal' )
30
- {
31
- $classes = $this->get_column_width_classes( $form_label_width, $form_breakpoint );
32
- $label_class .= ' ' . $classes['label'];
33
- $input_div_class = $classes['input'];
34
- if( empty( $label ) || in_array( $type, array( 'radio', 'checkbox' ) ) && count( $options ) <= 1 )
35
- {
36
- $input_div_class .= ' ' . $this->get_column_offset_class( $form_label_width, $form_breakpoint );
37
- }
38
- }
39
- elseif( $form_layout == 'inline' )
40
- {
41
- if( empty( $placeholder ) )
42
- {
43
- $placeholder = $label;
44
- }
45
- }
46
-
47
- if( !empty( $wrapper_class ) )
48
- {
49
- $wrapper_class = ' ' . esc_attr( $wrapper_class );
50
- }
51
-
52
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) )
53
- {
54
- if( !empty( $input_class ) )
55
- {
56
- $input_class .= ' ';
57
- }
58
- if( !in_array( $type, array( 'file', 'range' ) ) )
59
- {
60
- $input_class .= 'form-control';
61
- }
62
-
63
- if( $type != 'textarea' )
64
- {
65
- if( $size == 'large' )
66
- {
67
- $input_class .= ' input-lg';
68
- }
69
- elseif( $size == 'small' || $size == 'mini' )
70
- {
71
- $input_class .= ' input-sm';
72
- }
73
- }
74
-
75
- if( is_int( $tabindex ) )
76
- {
77
- $tabindex = ' tabindex="' . $tabindex . '"';
78
- }
79
- else
80
- {
81
- $tabindex = '';
82
- }
83
- }
84
-
85
- if( !empty( $input_class ) )
86
- {
87
- $input_class = ' class="' . esc_attr( $input_class ) . '"';
88
- }
89
- if( !empty( $placeholder ) )
90
- {
91
- $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"';
92
- }
93
-
94
- if( $readonly )
95
- {
96
- $readonly = ' readonly';
97
- }
98
- else
99
- {
100
- $readonly = '';
101
- }
102
- if( $maxlength > -1 && !empty( $maxlength ) )
103
- {
104
- $maxlength = ' maxlength="' . absint( $maxlength ) . '"';
105
- }
106
- else
107
- {
108
- $maxlength = '';
109
- }
110
-
111
- $append = '';
112
- if( $mode == 'required' )
113
- {
114
- $append = ' required';
115
- }
116
- elseif( $mode == 'disabled' )
117
- {
118
- $append = ' disabled';
119
- }
120
-
121
- $label_required = '';
122
- if( $mode == 'required' )
123
- {
124
- $label_required = ' ' . cf7bs_get_form_property( 'required_html' );
125
- }
126
-
127
- if( in_array( $status, array( 'success', 'warning', 'error' ) ) )
128
- {
129
- $status = ' has-' . $status;
130
- }
131
- else
132
- {
133
- $status = '';
134
- }
135
-
136
- if( $form_layout == 'horizontal' )
137
- {
138
- $output .= '<div class="form-group' . $wrapper_class . $status . '">';
139
- if( !empty( $label ) && ( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 ) )
140
- {
141
- $output .= '<label class="' . esc_attr( $label_class ) . '" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
142
- }
143
- $output .= '<div class="' . esc_attr( $input_div_class ) . '">';
144
- }
145
- elseif( $form_layout == 'inline' )
146
- {
147
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 )
148
- {
149
- $output .= '<div class="form-group' . $wrapper_class . $status . '">';
150
- if( !empty( $label ) )
151
- {
152
- $output .= '<label class="sr-only" for="' . esc_attr( $id ) . '">' . esc_html( $label ) . $label_required . '</label>';
153
- }
154
- }
155
- }
156
- else
157
- {
158
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 )
159
- {
160
- $output .= '<div class="form-group' . $wrapper_class . $status . '">';
161
- if( !empty( $label ) )
162
- {
163
- $rc_group_style = '';
164
- if( in_array( $type, array( 'radio', 'checkbox' ) ) )
165
- {
166
- $rc_group_style = ' style="display:block;"';
167
- }
168
- $output .= '<label for="' . esc_attr( $id ) . '"' . $rc_group_style . '>' . esc_html( $label ) . $label_required . '</label>';
169
- }
170
- }
171
- }
172
- }
173
-
174
- switch( $type )
175
- {
176
- case 'checkbox':
177
- if( count( $options ) <= 1 )
178
- {
179
- if( count( $options ) < 1 )
180
- {
181
- $curval = 'true';
182
- $title = $label;
183
- }
184
- else
185
- {
186
- reset( $options );
187
- $curval = key( $options );
188
- $title = $options[ $curval ];
189
- }
190
- $output .= '<div class="checkbox' . $wrapper_class . '">';
191
- $output .= '<label>';
192
- $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 . '>';
193
- $output .= esc_html( $title );
194
- $output .= '</label>';
195
- $output .= '</div>';
196
- }
197
- else
198
- {
199
- if( $group_layout == 'buttons' )
200
- {
201
- $button_group = new CF7BS_Button_Group( array(
202
- 'mode' => 'checkbox',
203
- 'size' => $size,
204
- ) );
205
- $output .= $button_group->open( false );
206
- $counter = 0;
207
- foreach( $options as $curval => $title )
208
- {
209
- $is_checked = cf7bs_multiple_checked( $value, $curval, false );
210
- $output .= $button_group->insert_button( array(
211
- 'type' => $group_type,
212
- 'id' => $id . ( $counter + 1 ),
213
- 'name' => $name . '[]',
214
- 'class' => $class,
215
- 'value' => $curval,
216
- 'title' => $title,
217
- 'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
218
- ), false );
219
- $counter++;
220
- }
221
- $output .= $button_group->close( false );
222
- }
223
- elseif( $group_layout == 'inline' && $form_layout != 'inline' )
224
- {
225
- $counter = 0;
226
- foreach( $options as $curval => $title )
227
- {
228
- $output .= '<label class="checkbox-inline">';
229
- $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 . '>';
230
- $output .= esc_html( $title );
231
- $output .= '</label>';
232
- $counter++;
233
- }
234
- }
235
- else
236
- {
237
- $counter = 0;
238
- foreach( $options as $curval => $title )
239
- {
240
- $output .= '<div class="checkbox">';
241
- $output .= '<label>';
242
- $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 . '>';
243
- $output .= esc_html( $title );
244
- $output .= '</label>';
245
- $output .= '</div>';
246
- $counter++;
247
- }
248
- }
249
- }
250
- break;
251
- case 'select':
252
- $output .= '<select' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '"' . $tabindex . $append . '>';
253
- foreach( $options as $curval => $title )
254
- {
255
- $output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
256
- }
257
- $output .= '</select>';
258
- break;
259
- case 'multiselect':
260
- $output .= '<select' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name . '[]' ) . '" multiple' . $tabindex . $append . '>';
261
- foreach( $options as $curval => $title )
262
- {
263
- $output .= '<option value="' . esc_attr( $curval ) . '"' . cf7bs_multiple_selected( $value, $curval, false ) . '>' . esc_html( $title ) . '</option>';
264
- }
265
- $output .= '</select>';
266
- break;
267
- case 'radio':
268
- if( count( $options ) <= 1 )
269
- {
270
- if( count( $options ) < 1 )
271
- {
272
- $curval = 'true';
273
- $title = $label;
274
- }
275
- else
276
- {
277
- reset( $options );
278
- $curval = key( $options );
279
- $title = $options[ $curval ];
280
- }
281
- $output .= '<div class="radio' . $wrapper_class . '">';
282
- $output .= '<label>';
283
- $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 . '>';
284
- $output .= esc_html( $title );
285
- $output .= '</label>';
286
- $output .= '</div>';
287
- }
288
- else
289
- {
290
- if( $group_layout == 'buttons' )
291
- {
292
- $button_group = new CF7BS_Button_Group( array(
293
- 'mode' => 'radio',
294
- 'size' => $size,
295
- ) );
296
- $output .= $button_group->open( false );
297
- $counter = 0;
298
- foreach( $options as $curval => $title )
299
- {
300
- $is_checked = cf7bs_checked( $value, $curval, false );
301
- $output .= $button_group->insert_button( array(
302
- 'type' => $group_type,
303
- 'id' => $id . ( $counter + 1 ),
304
- 'name' => $name,
305
- 'class' => $class,
306
- 'value' => $curval,
307
- 'title' => $title,
308
- 'append' => ( is_int( $tabindex ) ? ' tabindex="' . ( $tabindex + $counter ) . '"' : '' ) . $is_checked . $append,
309
- ), false );
310
- $counter++;
311
- }
312
- $output .= $button_group->close( false );
313
- }
314
- elseif( $group_layout == 'inline' && $form_layout != 'inline' )
315
- {
316
- $counter = 0;
317
- foreach( $options as $curval => $title )
318
- {
319
- $output .= '<label class="radio-inline">';
320
- $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 . '>';
321
- $output .= esc_html( $title );
322
- $output .= '</label>';
323
- $counter++;
324
- }
325
- }
326
- else
327
- {
328
- $counter = 0;
329
- foreach( $options as $curval => $title )
330
- {
331
- $output .= '<div class="radio">';
332
- $output .= '<label>';
333
- $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 . '>';
334
- $output .= esc_html( $title );
335
- $output .= '</label>';
336
- $output .= '</div>';
337
- $counter++;
338
- }
339
- }
340
- }
341
- break;
342
- case 'textarea':
343
- $output .= '<textarea' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" rows="' . absint( $rows ) . '"' . $placeholder . $readonly . $tabindex . $append . '>';
344
- $output .= esc_textarea( $value );
345
- $output .= '</textarea>';
346
- break;
347
- case 'file':
348
- $output .= '<input' . $input_class . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="file"' . $tabindex . $append . '>';
349
- break;
350
- case 'hidden':
351
- $output .= '<input' . ( !empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ) . ' name="' . esc_attr( $name ) . '" type="hidden" value="' . esc_attr( $value ) . '">';
352
- break;
353
- case 'number':
354
- case 'range':
355
- case 'date':
356
- case 'datetime':
357
- case 'datetime-local':
358
- case 'month':
359
- case 'time':
360
- case 'week':
361
- $min = '';
362
- if( isset( $options['min'] ) )
363
- {
364
- $min = ' min="' . esc_attr( $options['min'] ) . '"';
365
- }
366
- $max = '';
367
- if( isset( $options['max'] ) )
368
- {
369
- $max = ' max="' . esc_attr( $options['max'] ) . '"';
370
- }
371
- $step = '';
372
- if( isset( $options['step'] ) )
373
- {
374
- $step = ' step="' . esc_attr( $options['step'] ) . '"';
375
- }
376
- $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 . '>';
377
- break;
378
- default:
379
- if( $mode == 'static' )
380
- {
381
- $output .= '<p class="form-control-static">' . esc_html( $value ) . '</p>';
382
- }
383
- else
384
- {
385
- if( !empty( $input_before ) || !empty( $input_after ) )
386
- {
387
- $input_group_class = 'input-group';
388
- if( strpos( $input_class, ' input-lg') !== false )
389
- {
390
- $input_class = str_replace( ' input-lg', '', $input_class );
391
- $input_group_class .= ' input-group-lg';
392
- }
393
- elseif( strpos( $input_class, ' input-sm') !== false )
394
- {
395
- $input_class = str_replace( ' input-sm', '', $input_class );
396
- $input_group_class .= ' input-group-sm';
397
- }
398
- $output .= '<div class="' . $input_group_class . '">';
399
- if( !empty( $input_before ) )
400
- {
401
- $output .= '<span class="' . esc_attr( $input_before_class ) . '">';
402
- $output .= $input_before;
403
- $output .= '</span>';
404
- }
405
- }
406
-
407
- $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 . '>';
408
-
409
- if( !empty( $input_before ) || !empty( $input_after ) )
410
- {
411
- if( !empty( $input_after ) )
412
- {
413
- $output .= '<span class="' . esc_attr( $input_after_class ) . '">';
414
- $output .= $input_after;
415
- $output .= '</span>';
416
- }
417
- $output .= '</div>';
418
- }
419
- }
420
- break;
421
- }
422
-
423
- if( $type != 'hidden' )
424
- {
425
- if( !empty( $help_text ) && $form_layout != 'inline' )
426
- {
427
- $output .= '<span class="help-block">' . $help_text . '</span>';
428
- }
429
-
430
- if( $form_layout == 'horizontal' )
431
- {
432
- $output .= '</div>';
433
- $output .= '</div>';
434
- }
435
- else
436
- {
437
- if( !in_array( $type, array( 'radio', 'checkbox' ) ) || count( $options ) > 1 )
438
- {
439
- $output .= '</div>';
440
- }
441
- }
442
- }
443
- }
444
-
445
- if( $echo )
446
- {
447
- echo $output;
448
- }
449
- return $output;
450
- }
451
-
452
- protected function validate_args( $args, $exclude = array() )
453
- {
454
- $exclude[] = 'value';
455
- $exclude[] = 'maxlength';
456
- $exclude[] = 'tabindex';
457
- $args = parent::validate_args( $args, $exclude );
458
-
459
- // type whitelist check is made later in the display() function to allow different types to use in a filter
460
-
461
- return $args;
462
- }
463
-
464
- protected function get_defaults()
465
- {
466
- $defaults = array(
467
- 'name' => '',
468
- 'id' => '',
469
- 'class' => '',
470
- 'type' => 'text',
471
- 'value' => '', // for multiselect and multiple checkbox an array, for singular checkboxes and all others a string
472
- 'placeholder' => '',
473
- 'label' => '',
474
- 'options' => array(), // for select, multiselect, checkbox and radio: value => title; for number, range and all datetime-related fields: min, max, step
475
- 'rows' => 4,
476
- 'help_text' => '',
477
- 'size' => 'default', // default, large, small, mini
478
- 'form_layout' => 'default', // default, inline, horizontal
479
- 'form_label_width' => 2,
480
- 'form_breakpoint' => 'sm',
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.1.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.1.1
5
  * @author Felix Arntz <felix-arntz@leaves-and-love.net>
6
  */
7
 
8
- function cf7bs_selected( $selected, $current = true, $echo = true )
9
- {
10
- $result = '';
11
-
12
- if( $selected == $current )
13
- {
14
- $result = ' selected';
15
- if( !wpcf7_support_html5()