@@ -10,107 +10,107 @@ discard block |
||
| 10 | 10 | * |
| 11 | 11 | * @var string |
| 12 | 12 | */ |
| 13 | - protected $name; |
|
| 13 | + protected $name; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Field settings |
| 17 | 17 | * |
| 18 | 18 | * @var array |
| 19 | 19 | */ |
| 20 | - protected $field; |
|
| 20 | + protected $field; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Field current value |
| 24 | 24 | * |
| 25 | 25 | * @var mixed |
| 26 | 26 | */ |
| 27 | - protected $value; |
|
| 28 | - |
|
| 29 | - function __construct( $name = '', $field = array(), $curr_value = NULL ) { |
|
| 30 | - |
|
| 31 | - $this->name = $name; |
|
| 32 | - |
|
| 33 | - $defaults = self::get_field_defaults(); |
|
| 34 | - |
|
| 35 | - // Backward compatibility |
|
| 36 | - if( !empty( $field['choices'] ) ) { |
|
| 37 | - $field['options'] = $field['choices']; |
|
| 38 | - unset( $field['choices'] ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $this->field = wp_parse_args( $field, $defaults ); |
|
| 42 | - |
|
| 43 | - $this->value = is_null( $curr_value ) ? $this->field['value'] : $curr_value; |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Returns the default details for a field option |
|
| 49 | - * |
|
| 50 | - * - default // default option value, in case nothing is defined (@deprecated) |
|
| 51 | - * - desc // option description |
|
| 52 | - * - value // the option default value |
|
| 53 | - * - label // the option label |
|
| 54 | - * - left_label // In case of checkboxes, left label will appear on the left of the checkbox |
|
| 55 | - * - id // the field id |
|
| 56 | - * - type // the option type ( text, checkbox, select, ... ) |
|
| 57 | - * - options // when type is select, define the select options ('choices' is @deprecated) |
|
| 58 | - * - merge_tags // if the option supports merge tags feature |
|
| 59 | - * - class // (new) define extra classes for the field |
|
| 60 | - * - tooltip // |
|
| 61 | - * |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public static function get_field_defaults() { |
|
| 65 | - return array( |
|
| 66 | - 'desc' => '', |
|
| 67 | - 'value' => null, |
|
| 68 | - 'label' => '', |
|
| 69 | - 'left_label' => null, |
|
| 70 | - 'id' => null, |
|
| 71 | - 'type' => 'text', |
|
| 72 | - 'options' => null, |
|
| 73 | - 'merge_tags' => true, |
|
| 74 | - 'class' => '', |
|
| 75 | - 'tooltip' => null, |
|
| 76 | - 'requires' => null |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - function get_tooltip() { |
|
| 82 | - if( ! function_exists('gform_tooltip') ) { |
|
| 83 | - return null; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $article = wp_parse_args( \GV\Utils::get( $this->field, 'article', array() ), array( |
|
| 87 | - 'id' => '', |
|
| 88 | - 'type' => 'inline', |
|
| 89 | - 'url' => '#', |
|
| 90 | - ) ); |
|
| 91 | - |
|
| 92 | - return !empty( $this->field['tooltip'] ) ? ' '. $this->tooltip( $this->field['tooltip'], false, true, $article ) : null; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Displays the tooltip |
|
| 97 | - * |
|
| 98 | - * @since 2.8.1 |
|
| 99 | - * |
|
| 100 | - * @global $__gf_tooltips |
|
| 101 | - * |
|
| 102 | - * @param string $name The name of the tooltip to be displayed |
|
| 103 | - * @param string $css_class Optional. The CSS class to apply toi the element. Defaults to empty string. |
|
| 104 | - * @param bool $return Optional. If the tooltip should be returned instead of output. Defaults to false (output) |
|
| 105 | - * @param array $article Optional. Details about support doc article connected to the tooltip. { |
|
| 106 | - * @type string $id Unique ID of article for Beacon API |
|
| 107 | - * @type string $url URL of support doc article |
|
| 108 | - * @type string $type Type of Beacon element to open. {@see https://developer.helpscout.com/beacon-2/web/javascript-api/#beaconarticle} |
|
| 109 | - * } |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - function tooltip( $name, $css_class = '', $return = false, $article = array() ) { |
|
| 27 | + protected $value; |
|
| 28 | + |
|
| 29 | + function __construct( $name = '', $field = array(), $curr_value = NULL ) { |
|
| 30 | + |
|
| 31 | + $this->name = $name; |
|
| 32 | + |
|
| 33 | + $defaults = self::get_field_defaults(); |
|
| 34 | + |
|
| 35 | + // Backward compatibility |
|
| 36 | + if( !empty( $field['choices'] ) ) { |
|
| 37 | + $field['options'] = $field['choices']; |
|
| 38 | + unset( $field['choices'] ); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $this->field = wp_parse_args( $field, $defaults ); |
|
| 42 | + |
|
| 43 | + $this->value = is_null( $curr_value ) ? $this->field['value'] : $curr_value; |
|
| 44 | + |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Returns the default details for a field option |
|
| 49 | + * |
|
| 50 | + * - default // default option value, in case nothing is defined (@deprecated) |
|
| 51 | + * - desc // option description |
|
| 52 | + * - value // the option default value |
|
| 53 | + * - label // the option label |
|
| 54 | + * - left_label // In case of checkboxes, left label will appear on the left of the checkbox |
|
| 55 | + * - id // the field id |
|
| 56 | + * - type // the option type ( text, checkbox, select, ... ) |
|
| 57 | + * - options // when type is select, define the select options ('choices' is @deprecated) |
|
| 58 | + * - merge_tags // if the option supports merge tags feature |
|
| 59 | + * - class // (new) define extra classes for the field |
|
| 60 | + * - tooltip // |
|
| 61 | + * |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public static function get_field_defaults() { |
|
| 65 | + return array( |
|
| 66 | + 'desc' => '', |
|
| 67 | + 'value' => null, |
|
| 68 | + 'label' => '', |
|
| 69 | + 'left_label' => null, |
|
| 70 | + 'id' => null, |
|
| 71 | + 'type' => 'text', |
|
| 72 | + 'options' => null, |
|
| 73 | + 'merge_tags' => true, |
|
| 74 | + 'class' => '', |
|
| 75 | + 'tooltip' => null, |
|
| 76 | + 'requires' => null |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + function get_tooltip() { |
|
| 82 | + if( ! function_exists('gform_tooltip') ) { |
|
| 83 | + return null; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $article = wp_parse_args( \GV\Utils::get( $this->field, 'article', array() ), array( |
|
| 87 | + 'id' => '', |
|
| 88 | + 'type' => 'inline', |
|
| 89 | + 'url' => '#', |
|
| 90 | + ) ); |
|
| 91 | + |
|
| 92 | + return !empty( $this->field['tooltip'] ) ? ' '. $this->tooltip( $this->field['tooltip'], false, true, $article ) : null; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Displays the tooltip |
|
| 97 | + * |
|
| 98 | + * @since 2.8.1 |
|
| 99 | + * |
|
| 100 | + * @global $__gf_tooltips |
|
| 101 | + * |
|
| 102 | + * @param string $name The name of the tooltip to be displayed |
|
| 103 | + * @param string $css_class Optional. The CSS class to apply toi the element. Defaults to empty string. |
|
| 104 | + * @param bool $return Optional. If the tooltip should be returned instead of output. Defaults to false (output) |
|
| 105 | + * @param array $article Optional. Details about support doc article connected to the tooltip. { |
|
| 106 | + * @type string $id Unique ID of article for Beacon API |
|
| 107 | + * @type string $url URL of support doc article |
|
| 108 | + * @type string $type Type of Beacon element to open. {@see https://developer.helpscout.com/beacon-2/web/javascript-api/#beaconarticle} |
|
| 109 | + * } |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + function tooltip( $name, $css_class = '', $return = false, $article = array() ) { |
|
| 114 | 114 | global $__gf_tooltips; //declared as global to improve WPML performance |
| 115 | 115 | |
| 116 | 116 | $css_class = empty( $css_class ) ? 'tooltip' : $css_class; |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | $tooltip_class = isset( $__gf_tooltips[ $name ] ) ? "tooltip_{$name}" : ''; |
| 129 | 129 | $tooltip_class = esc_attr( $tooltip_class ); |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Below this line has been modified by GravityView. |
|
| 133 | - */ |
|
| 131 | + /** |
|
| 132 | + * Below this line has been modified by GravityView. |
|
| 133 | + */ |
|
| 134 | 134 | |
| 135 | 135 | if ( empty( $tooltip_text ) && empty( $article['id'] ) ) { |
| 136 | 136 | return ''; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $url = '#'; |
| 140 | - $atts = 'onclick="return false;" onkeypress="return false;"'; |
|
| 141 | - $anchor_text = '<i class=\'fa fa-question-circle\'></i>'; |
|
| 140 | + $atts = 'onclick="return false;" onkeypress="return false;"'; |
|
| 141 | + $anchor_text = '<i class=\'fa fa-question-circle\'></i>'; |
|
| 142 | 142 | $css_class = gravityview_sanitize_html_class( 'gf_tooltip ' . $css_class . ' ' . $tooltip_class ); |
| 143 | 143 | |
| 144 | 144 | $tooltip = sprintf( '<a href="%s" %s class="%s" title="%s" role="button">%s</a>', |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | $anchor_text |
| 150 | 150 | ); |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Modify the tooltip HTML before outputting |
|
| 154 | - * @internal |
|
| 155 | - * @see GravityView_Support_Port::maybe_add_article_to_tooltip() |
|
| 156 | - */ |
|
| 152 | + /** |
|
| 153 | + * Modify the tooltip HTML before outputting |
|
| 154 | + * @internal |
|
| 155 | + * @see GravityView_Support_Port::maybe_add_article_to_tooltip() |
|
| 156 | + */ |
|
| 157 | 157 | $tooltip = apply_filters( 'gravityview/tooltips/tooltip', $tooltip, $article, $url, $atts, $css_class, $tooltip_text, $anchor_text ); |
| 158 | 158 | |
| 159 | 159 | if ( ! $return ) { |
@@ -163,84 +163,84 @@ discard block |
||
| 163 | 163 | return $tooltip; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Build input id based on the name |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - function get_field_id() { |
|
| 171 | - if( isset( $this->field['id'] ) ) { |
|
| 172 | - return esc_attr( $this->field['id'] ); |
|
| 173 | - } |
|
| 174 | - return esc_attr( sanitize_html_class( $this->name ) ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Retrieve field label |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - function get_field_label() { |
|
| 182 | - return esc_html( trim( $this->field['label'] ) ); |
|
| 183 | - } |
|
| 166 | + /** |
|
| 167 | + * Build input id based on the name |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + function get_field_id() { |
|
| 171 | + if( isset( $this->field['id'] ) ) { |
|
| 172 | + return esc_attr( $this->field['id'] ); |
|
| 173 | + } |
|
| 174 | + return esc_attr( sanitize_html_class( $this->name ) ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Retrieve field label |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + function get_field_label() { |
|
| 182 | + return esc_html( trim( $this->field['label'] ) ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * Retrieve field left label |
| 187 | - * |
|
| 188 | - * @since 1.7 |
|
| 189 | - * |
|
| 187 | + * |
|
| 188 | + * @since 1.7 |
|
| 189 | + * |
|
| 190 | 190 | * @return string |
| 191 | 191 | */ |
| 192 | 192 | function get_field_left_label() { |
| 193 | 193 | return ! empty( $this->field['left_label'] ) ? esc_html( trim( $this->field['left_label'] ) ) : NULL; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Retrieve field label class |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - function get_label_class() { |
|
| 201 | - return 'gv-label-'. sanitize_html_class( $this->field['type'] ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Retrieve field description |
|
| 207 | - * @return string |
|
| 208 | - */ |
|
| 209 | - function get_field_desc() { |
|
| 210 | - return !empty( $this->field['desc'] ) ? '<span class="howto">'. $this->field['desc'] .'</span>' : ''; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Verify if field should have merge tags |
|
| 216 | - * @return boolean |
|
| 217 | - */ |
|
| 218 | - function show_merge_tags() { |
|
| 219 | - // Show the merge tags if the field is a list view |
|
| 220 | - $is_list = preg_match( '/_list-/ism', $this->name ); |
|
| 221 | - // Or is a single entry view |
|
| 222 | - $is_single = preg_match( '/single_/ism', $this->name ); |
|
| 223 | - |
|
| 224 | - return ( $is_single || $is_list ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * important! Override this class |
|
| 231 | - * outputs the field option html |
|
| 232 | - */ |
|
| 233 | - function render_option() { |
|
| 234 | - // to replace on each field |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * important! Override this class if needed |
|
| 239 | - * outputs the field setting html |
|
| 240 | - */ |
|
| 241 | - function render_setting( $override_input = NULL ) { |
|
| 242 | - |
|
| 243 | - if( !empty( $this->field['full_width'] ) ) { ?> |
|
| 196 | + /** |
|
| 197 | + * Retrieve field label class |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + function get_label_class() { |
|
| 201 | + return 'gv-label-'. sanitize_html_class( $this->field['type'] ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Retrieve field description |
|
| 207 | + * @return string |
|
| 208 | + */ |
|
| 209 | + function get_field_desc() { |
|
| 210 | + return !empty( $this->field['desc'] ) ? '<span class="howto">'. $this->field['desc'] .'</span>' : ''; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Verify if field should have merge tags |
|
| 216 | + * @return boolean |
|
| 217 | + */ |
|
| 218 | + function show_merge_tags() { |
|
| 219 | + // Show the merge tags if the field is a list view |
|
| 220 | + $is_list = preg_match( '/_list-/ism', $this->name ); |
|
| 221 | + // Or is a single entry view |
|
| 222 | + $is_single = preg_match( '/single_/ism', $this->name ); |
|
| 223 | + |
|
| 224 | + return ( $is_single || $is_list ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * important! Override this class |
|
| 231 | + * outputs the field option html |
|
| 232 | + */ |
|
| 233 | + function render_option() { |
|
| 234 | + // to replace on each field |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * important! Override this class if needed |
|
| 239 | + * outputs the field setting html |
|
| 240 | + */ |
|
| 241 | + function render_setting( $override_input = NULL ) { |
|
| 242 | + |
|
| 243 | + if( !empty( $this->field['full_width'] ) ) { ?> |
|
| 244 | 244 | <th scope="row" colspan="2"> |
| 245 | 245 | <div> |
| 246 | 246 | <label for="<?php echo $this->get_field_id(); ?>"> |
@@ -260,14 +260,14 @@ discard block |
||
| 260 | 260 | </td> |
| 261 | 261 | <?php } |
| 262 | 262 | |
| 263 | - } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * important! Override this class |
|
| 267 | - * outputs the input html part |
|
| 268 | - */ |
|
| 269 | - function render_input( $override_input ) { |
|
| 270 | - echo ''; |
|
| 271 | - } |
|
| 265 | + /** |
|
| 266 | + * important! Override this class |
|
| 267 | + * outputs the input html part |
|
| 268 | + */ |
|
| 269 | + function render_input( $override_input ) { |
|
| 270 | + echo ''; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | 273 | } |