@@ -5,55 +5,55 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class FrmEntriesHelper { |
| 7 | 7 | |
| 8 | - public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
| 9 | - $values = array(); |
|
| 8 | + public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
| 9 | + $values = array(); |
|
| 10 | 10 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
| 11 | 11 | $values[ $var ] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
| 12 | - } |
|
| 13 | - |
|
| 14 | - $values['fields'] = array(); |
|
| 15 | - if ( empty($fields) ) { |
|
| 16 | - return apply_filters('frm_setup_new_entry', $values); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - foreach ( (array) $fields as $field ) { |
|
| 20 | - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
| 21 | - |
|
| 22 | - $field_array = array( |
|
| 23 | - 'id' => $field->id, |
|
| 24 | - 'value' => $new_value, |
|
| 25 | - 'default_value' => $field->default_value, |
|
| 26 | - 'name' => $field->name, |
|
| 27 | - 'description' => $field->description, |
|
| 28 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
| 29 | - 'options' => $field->options, |
|
| 30 | - 'required' => $field->required, |
|
| 31 | - 'field_key' => $field->field_key, |
|
| 32 | - 'field_order' => $field->field_order, |
|
| 33 | - 'form_id' => $field->form_id, |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + $values['fields'] = array(); |
|
| 15 | + if ( empty($fields) ) { |
|
| 16 | + return apply_filters('frm_setup_new_entry', $values); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + foreach ( (array) $fields as $field ) { |
|
| 20 | + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
| 21 | + |
|
| 22 | + $field_array = array( |
|
| 23 | + 'id' => $field->id, |
|
| 24 | + 'value' => $new_value, |
|
| 25 | + 'default_value' => $field->default_value, |
|
| 26 | + 'name' => $field->name, |
|
| 27 | + 'description' => $field->description, |
|
| 28 | + 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
| 29 | + 'options' => $field->options, |
|
| 30 | + 'required' => $field->required, |
|
| 31 | + 'field_key' => $field->field_key, |
|
| 32 | + 'field_order' => $field->field_order, |
|
| 33 | + 'form_id' => $field->form_id, |
|
| 34 | 34 | 'parent_form_id' => isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id, |
| 35 | - 'reset_value' => $reset, |
|
| 35 | + 'reset_value' => $reset, |
|
| 36 | 36 | 'in_embed_form' => isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0', |
| 37 | - ); |
|
| 37 | + ); |
|
| 38 | 38 | |
| 39 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 40 | - $opt_defaults['required_indicator'] = ''; |
|
| 39 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 40 | + $opt_defaults['required_indicator'] = ''; |
|
| 41 | 41 | $opt_defaults['original_type'] = $field->type; |
| 42 | 42 | |
| 43 | 43 | foreach ( $opt_defaults as $opt => $default_opt ) { |
| 44 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
| 45 | - unset($opt, $default_opt); |
|
| 46 | - } |
|
| 44 | + $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
| 45 | + unset($opt, $default_opt); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - unset($opt_defaults); |
|
| 48 | + unset($opt_defaults); |
|
| 49 | 49 | |
| 50 | - if ( $field_array['custom_html'] == '' ) { |
|
| 51 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
| 52 | - } |
|
| 50 | + if ( $field_array['custom_html'] == '' ) { |
|
| 51 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
| 54 | + $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
| 55 | 55 | |
| 56 | - /*if ( $field_array['type'] == 'user_id' && current_user_can('administrator') ){ |
|
| 56 | + /*if ( $field_array['type'] == 'user_id' && current_user_can('administrator') ){ |
|
| 57 | 57 | $field_array['type'] = 'select'; |
| 58 | 58 | $field_array['options'] = FrmProFieldsHelper::get_user_options(); |
| 59 | 59 | $field_array['use_key'] = true; |
@@ -61,22 +61,22 @@ discard block |
||
| 61 | 61 | }*/ |
| 62 | 62 | |
| 63 | 63 | |
| 64 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
| 64 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
| 65 | 65 | |
| 66 | - $values['fields'][] = $field_array; |
|
| 66 | + $values['fields'][] = $field_array; |
|
| 67 | 67 | |
| 68 | - if ( ! $form || ! isset($form->id) ) { |
|
| 69 | - $form = FrmForm::getOne($field->form_id); |
|
| 70 | - } |
|
| 71 | - } |
|
| 68 | + if ( ! $form || ! isset($form->id) ) { |
|
| 69 | + $form = FrmForm::getOne($field->form_id); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $form->options = maybe_unserialize($form->options); |
|
| 74 | - if ( is_array($form->options) ) { |
|
| 75 | - foreach ( $form->options as $opt => $value ) { |
|
| 76 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
| 77 | - unset($opt, $value); |
|
| 78 | - } |
|
| 79 | - } |
|
| 73 | + $form->options = maybe_unserialize($form->options); |
|
| 74 | + if ( is_array($form->options) ) { |
|
| 75 | + foreach ( $form->options as $opt => $value ) { |
|
| 76 | + $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
| 77 | + unset($opt, $value); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | $form_defaults = FrmFormsHelper::get_default_opts(); |
| 82 | 82 | |
@@ -86,19 +86,19 @@ discard block |
||
| 86 | 86 | $values = array_merge( $form_defaults, $values ); |
| 87 | 87 | |
| 88 | 88 | return apply_filters( 'frm_setup_new_entry', $values ); |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Set the value for each field |
|
| 93 | - * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
| 94 | - * |
|
| 95 | - * @since 2.0.13 |
|
| 96 | - * |
|
| 97 | - * @param object $field - this is passed by reference since it is an object |
|
| 98 | - * @param boolean $reset |
|
| 99 | - * @param array $args |
|
| 100 | - * @return string|array $new_value |
|
| 101 | - */ |
|
| 92 | + * Set the value for each field |
|
| 93 | + * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
| 94 | + * |
|
| 95 | + * @since 2.0.13 |
|
| 96 | + * |
|
| 97 | + * @param object $field - this is passed by reference since it is an object |
|
| 98 | + * @param boolean $reset |
|
| 99 | + * @param array $args |
|
| 100 | + * @return string|array $new_value |
|
| 101 | + */ |
|
| 102 | 102 | private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
| 103 | 103 | //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array |
| 104 | 104 | $return_array = FrmField::is_field_with_multiple_values( $field ); |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | - * Check if a field has a posted value |
|
| 134 | - * |
|
| 135 | - * @since 2.01.0 |
|
| 136 | - * @param object $field |
|
| 137 | - * @param array $args |
|
| 138 | - * @return boolean $value_is_posted |
|
| 139 | - */ |
|
| 133 | + * Check if a field has a posted value |
|
| 134 | + * |
|
| 135 | + * @since 2.01.0 |
|
| 136 | + * @param object $field |
|
| 137 | + * @param array $args |
|
| 138 | + * @return boolean $value_is_posted |
|
| 139 | + */ |
|
| 140 | 140 | public static function value_is_posted( $field, $args ) { |
| 141 | 141 | $value_is_posted = false; |
| 142 | 142 | if ( $_POST ) { |
@@ -154,15 +154,15 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | public static function setup_edit_vars( $values, $record ) { |
| 156 | 156 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
| 157 | - $values['form_id'] = $record->form_id; |
|
| 158 | - $values['is_draft'] = $record->is_draft; |
|
| 159 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 160 | - } |
|
| 157 | + $values['form_id'] = $record->form_id; |
|
| 158 | + $values['is_draft'] = $record->is_draft; |
|
| 159 | + return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - public static function get_admin_params( $form = null ) { |
|
| 162 | + public static function get_admin_params( $form = null ) { |
|
| 163 | 163 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_admin_params' ); |
| 164 | 164 | return FrmForm::set_current_form( $form ); |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | public static function set_current_form( $form_id ) { |
| 168 | 168 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::set_current_form' ); |
@@ -174,284 +174,284 @@ discard block |
||
| 174 | 174 | return FrmForm::get_current_form( $form_id ); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - public static function get_current_form_id() { |
|
| 177 | + public static function get_current_form_id() { |
|
| 178 | 178 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_current_form_id' ); |
| 179 | 179 | return FrmForm::get_current_form_id(); |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public static function maybe_get_entry( &$entry ) { |
|
| 182 | + public static function maybe_get_entry( &$entry ) { |
|
| 183 | 183 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntry::maybe_get_entry' ); |
| 184 | 184 | FrmEntry::maybe_get_entry( $entry ); |
| 185 | - } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | public static function replace_default_message( $message, $atts ) { |
| 188 | - if ( strpos($message, '[default-message') === false && |
|
| 189 | - strpos($message, '[default_message') === false && |
|
| 190 | - ! empty( $message ) ) { |
|
| 191 | - return $message; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ( empty($message) ) { |
|
| 195 | - $message = '[default-message]'; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 199 | - |
|
| 200 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
| 201 | - $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
| 202 | - if ( $add_atts ) { |
|
| 203 | - $this_atts = array_merge($atts, $add_atts); |
|
| 204 | - } else { |
|
| 205 | - $this_atts = $atts; |
|
| 206 | - } |
|
| 188 | + if ( strpos($message, '[default-message') === false && |
|
| 189 | + strpos($message, '[default_message') === false && |
|
| 190 | + ! empty( $message ) ) { |
|
| 191 | + return $message; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ( empty($message) ) { |
|
| 195 | + $message = '[default-message]'; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 199 | + |
|
| 200 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
| 201 | + $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
| 202 | + if ( $add_atts ) { |
|
| 203 | + $this_atts = array_merge($atts, $add_atts); |
|
| 204 | + } else { |
|
| 205 | + $this_atts = $atts; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | $default = FrmEntryFormat::show_entry( $this_atts ); |
| 209 | 209 | |
| 210 | - // Add the default message |
|
| 211 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 212 | - } |
|
| 210 | + // Add the default message |
|
| 211 | + $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return $message; |
|
| 215 | - } |
|
| 214 | + return $message; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | 217 | public static function prepare_display_value( $entry, $field, $atts ) { |
| 218 | 218 | $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
| 219 | 219 | |
| 220 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
| 220 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
| 221 | 221 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 225 | - return self::display_value($field_value, $field, $atts); |
|
| 226 | - } |
|
| 224 | + if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 225 | + return self::display_value($field_value, $field, $atts); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - // this is an embeded form |
|
| 229 | - $val = ''; |
|
| 228 | + // this is an embeded form |
|
| 229 | + $val = ''; |
|
| 230 | 230 | |
| 231 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 232 | - //this is a repeating section |
|
| 231 | + if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 232 | + //this is a repeating section |
|
| 233 | 233 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
| 234 | - } else { |
|
| 235 | - // get all values for this field |
|
| 236 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 234 | + } else { |
|
| 235 | + // get all values for this field |
|
| 236 | + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 237 | 237 | |
| 238 | - if ( $child_values ) { |
|
| 239 | - $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
| 240 | - } |
|
| 241 | - } |
|
| 238 | + if ( $child_values ) { |
|
| 239 | + $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - $field_value = array(); |
|
| 243 | + $field_value = array(); |
|
| 244 | 244 | |
| 245 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 246 | - return $val; |
|
| 247 | - } |
|
| 245 | + if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 246 | + return $val; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - foreach ( $child_entries as $child_entry ) { |
|
| 250 | - $atts['item_id'] = $child_entry->id; |
|
| 251 | - $atts['post_id'] = $child_entry->post_id; |
|
| 249 | + foreach ( $child_entries as $child_entry ) { |
|
| 250 | + $atts['item_id'] = $child_entry->id; |
|
| 251 | + $atts['post_id'] = $child_entry->post_id; |
|
| 252 | 252 | |
| 253 | - // get the value for this field -- check for post values as well |
|
| 254 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 253 | + // get the value for this field -- check for post values as well |
|
| 254 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 255 | 255 | |
| 256 | - if ( $entry_val ) { |
|
| 257 | - // foreach entry get display_value |
|
| 258 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 259 | - } |
|
| 256 | + if ( $entry_val ) { |
|
| 257 | + // foreach entry get display_value |
|
| 258 | + $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - unset($child_entry); |
|
| 262 | - } |
|
| 261 | + unset($child_entry); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - $val = implode(', ', (array) $field_value ); |
|
| 264 | + $val = implode(', ', (array) $field_value ); |
|
| 265 | 265 | $val = wp_kses_post( $val ); |
| 266 | 266 | |
| 267 | - return $val; |
|
| 268 | - } |
|
| 267 | + return $val; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Prepare the saved value for display |
|
| 272 | - * @return string |
|
| 273 | - */ |
|
| 270 | + /** |
|
| 271 | + * Prepare the saved value for display |
|
| 272 | + * @return string |
|
| 273 | + */ |
|
| 274 | 274 | public static function display_value( $value, $field, $atts = array() ) { |
| 275 | 275 | |
| 276 | - $defaults = array( |
|
| 277 | - 'type' => '', 'html' => false, 'show_filename' => true, |
|
| 278 | - 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
| 279 | - 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
| 276 | + $defaults = array( |
|
| 277 | + 'type' => '', 'html' => false, 'show_filename' => true, |
|
| 278 | + 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
| 279 | + 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
| 280 | 280 | 'return_array' => false, |
| 281 | - ); |
|
| 281 | + ); |
|
| 282 | 282 | |
| 283 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 284 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
| 283 | + $atts = wp_parse_args( $atts, $defaults ); |
|
| 284 | + $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
| 285 | 285 | |
| 286 | - if ( ! isset($field->field_options['post_field']) ) { |
|
| 287 | - $field->field_options['post_field'] = ''; |
|
| 288 | - } |
|
| 286 | + if ( ! isset($field->field_options['post_field']) ) { |
|
| 287 | + $field->field_options['post_field'] = ''; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
| 291 | - $field->field_options['custom_field'] = ''; |
|
| 292 | - } |
|
| 290 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
| 291 | + $field->field_options['custom_field'] = ''; |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
| 295 | - $atts['pre_truncate'] = $atts['truncate']; |
|
| 296 | - $atts['truncate'] = true; |
|
| 297 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
| 294 | + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
| 295 | + $atts['pre_truncate'] = $atts['truncate']; |
|
| 296 | + $atts['truncate'] = true; |
|
| 297 | + $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
| 298 | 298 | |
| 299 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
| 300 | - $atts['truncate'] = $atts['pre_truncate']; |
|
| 301 | - } |
|
| 299 | + $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
| 300 | + $atts['truncate'] = $atts['pre_truncate']; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - if ( $value == '' ) { |
|
| 304 | - return $value; |
|
| 305 | - } |
|
| 303 | + if ( $value == '' ) { |
|
| 304 | + return $value; |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
| 307 | + $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
| 308 | 308 | $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) ); |
| 309 | 309 | |
| 310 | - $new_value = ''; |
|
| 310 | + $new_value = ''; |
|
| 311 | 311 | |
| 312 | - if ( is_array($value) && $atts['type'] != 'file' ) { |
|
| 313 | - foreach ( $value as $val ) { |
|
| 314 | - if ( is_array($val) ) { |
|
| 312 | + if ( is_array($value) && $atts['type'] != 'file' ) { |
|
| 313 | + foreach ( $value as $val ) { |
|
| 314 | + if ( is_array($val) ) { |
|
| 315 | 315 | //TODO: add options for display (li or ,) |
| 316 | - $new_value .= implode($atts['sep'], $val); |
|
| 317 | - if ( $atts['type'] != 'data' ) { |
|
| 318 | - $new_value .= '<br/>'; |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - unset($val); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if ( ! empty($new_value) ) { |
|
| 326 | - $value = $new_value; |
|
| 327 | - } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
| 328 | - $value = implode($atts['sep'], $value); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
| 332 | - $value = FrmAppHelper::truncate($value, 50); |
|
| 333 | - } |
|
| 316 | + $new_value .= implode($atts['sep'], $val); |
|
| 317 | + if ( $atts['type'] != 'data' ) { |
|
| 318 | + $new_value .= '<br/>'; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + unset($val); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if ( ! empty($new_value) ) { |
|
| 326 | + $value = $new_value; |
|
| 327 | + } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
| 328 | + $value = implode($atts['sep'], $value); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
| 332 | + $value = FrmAppHelper::truncate($value, 50); |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | 335 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
| 336 | 336 | $value = wp_kses_post( $value ); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - return apply_filters('frm_display_value', $value, $field, $atts); |
|
| 340 | - } |
|
| 339 | + return apply_filters('frm_display_value', $value, $field, $atts); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | public static function set_posted_value( $field, $value, $args ) { |
| 343 | - // If validating a field with "other" opt, set back to prev value now |
|
| 344 | - if ( isset( $args['other'] ) && $args['other'] ) { |
|
| 345 | - $value = $args['temp_value']; |
|
| 346 | - } |
|
| 347 | - if ( empty($args['parent_field_id']) ) { |
|
| 348 | - $_POST['item_meta'][ $field->id ] = $value; |
|
| 349 | - } else { |
|
| 350 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
| 351 | - } |
|
| 352 | - } |
|
| 343 | + // If validating a field with "other" opt, set back to prev value now |
|
| 344 | + if ( isset( $args['other'] ) && $args['other'] ) { |
|
| 345 | + $value = $args['temp_value']; |
|
| 346 | + } |
|
| 347 | + if ( empty($args['parent_field_id']) ) { |
|
| 348 | + $_POST['item_meta'][ $field->id ] = $value; |
|
| 349 | + } else { |
|
| 350 | + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | 354 | public static function get_posted_value( $field, &$value, $args ) { |
| 355 | 355 | $field_id = is_object( $field ) ? $field->id : $field; |
| 356 | 356 | |
| 357 | - if ( empty($args['parent_field_id']) ) { |
|
| 358 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
| 359 | - } else { |
|
| 360 | - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
| 361 | - } |
|
| 357 | + if ( empty($args['parent_field_id']) ) { |
|
| 358 | + $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
| 359 | + } else { |
|
| 360 | + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
| 361 | + } |
|
| 362 | 362 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
| 363 | 363 | $value = stripslashes_deep( $value ); |
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Check if field has an "Other" option and if any other values are posted |
|
| 368 | - * |
|
| 369 | - * @since 2.0 |
|
| 370 | - * |
|
| 371 | - * @param object $field |
|
| 372 | - * @param string|array $value |
|
| 373 | - * @param array $args |
|
| 374 | - */ |
|
| 375 | - public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
| 376 | - $args['other'] = false; |
|
| 377 | - if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
| 378 | - return; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - // Get other value for fields in repeating section |
|
| 382 | - self::set_other_repeating_vals( $field, $value, $args ); |
|
| 383 | - |
|
| 384 | - // Check if there are any posted "Other" values |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Check if field has an "Other" option and if any other values are posted |
|
| 368 | + * |
|
| 369 | + * @since 2.0 |
|
| 370 | + * |
|
| 371 | + * @param object $field |
|
| 372 | + * @param string|array $value |
|
| 373 | + * @param array $args |
|
| 374 | + */ |
|
| 375 | + public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
| 376 | + $args['other'] = false; |
|
| 377 | + if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
| 378 | + return; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + // Get other value for fields in repeating section |
|
| 382 | + self::set_other_repeating_vals( $field, $value, $args ); |
|
| 383 | + |
|
| 384 | + // Check if there are any posted "Other" values |
|
| 385 | 385 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
| 386 | 386 | |
| 387 | - // Save original value |
|
| 388 | - $args['temp_value'] = $value; |
|
| 389 | - $args['other'] = true; |
|
| 390 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
| 391 | - |
|
| 392 | - // Set the validation value now |
|
| 393 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
| 399 | - * |
|
| 400 | - * @since 2.0 |
|
| 401 | - * |
|
| 402 | - * @param object $field |
|
| 403 | - * @param string|array $value |
|
| 404 | - * @param array $args |
|
| 405 | - */ |
|
| 406 | - public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
| 407 | - if ( ! $args['parent_field_id'] ) { |
|
| 408 | - return; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // Check if there are any other posted "other" values for this field |
|
| 387 | + // Save original value |
|
| 388 | + $args['temp_value'] = $value; |
|
| 389 | + $args['other'] = true; |
|
| 390 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
| 391 | + |
|
| 392 | + // Set the validation value now |
|
| 393 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
| 399 | + * |
|
| 400 | + * @since 2.0 |
|
| 401 | + * |
|
| 402 | + * @param object $field |
|
| 403 | + * @param string|array $value |
|
| 404 | + * @param array $args |
|
| 405 | + */ |
|
| 406 | + public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
| 407 | + if ( ! $args['parent_field_id'] ) { |
|
| 408 | + return; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // Check if there are any other posted "other" values for this field |
|
| 412 | 412 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
| 413 | - // Save original value |
|
| 414 | - $args['temp_value'] = $value; |
|
| 415 | - $args['other'] = true; |
|
| 416 | - |
|
| 417 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
| 418 | - |
|
| 419 | - // Set the validation value now |
|
| 420 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Modify value used for validation |
|
| 426 | - * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
| 427 | - * It also adds any text from the free text fields to the value |
|
| 428 | - * |
|
| 429 | - * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
| 430 | - * |
|
| 431 | - * @since 2.0 |
|
| 432 | - * |
|
| 433 | - * @param string|array $value |
|
| 434 | - * @param string|array $other_vals (usually of posted values) |
|
| 435 | - * @param object $field |
|
| 436 | - * @param array $args |
|
| 437 | - */ |
|
| 438 | - public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
| 439 | - // Checkboxes and multi-select dropdowns |
|
| 440 | - if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
| 441 | - // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
| 442 | - $value = array_merge( $value, $other_vals ); |
|
| 443 | - $value = array_filter( $value ); |
|
| 444 | - if ( count( $value ) == 0 ) { |
|
| 445 | - $value = ''; |
|
| 446 | - } |
|
| 447 | - } else { |
|
| 413 | + // Save original value |
|
| 414 | + $args['temp_value'] = $value; |
|
| 415 | + $args['other'] = true; |
|
| 416 | + |
|
| 417 | + $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
| 418 | + |
|
| 419 | + // Set the validation value now |
|
| 420 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Modify value used for validation |
|
| 426 | + * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
| 427 | + * It also adds any text from the free text fields to the value |
|
| 428 | + * |
|
| 429 | + * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
| 430 | + * |
|
| 431 | + * @since 2.0 |
|
| 432 | + * |
|
| 433 | + * @param string|array $value |
|
| 434 | + * @param string|array $other_vals (usually of posted values) |
|
| 435 | + * @param object $field |
|
| 436 | + * @param array $args |
|
| 437 | + */ |
|
| 438 | + public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
| 439 | + // Checkboxes and multi-select dropdowns |
|
| 440 | + if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
| 441 | + // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
| 442 | + $value = array_merge( $value, $other_vals ); |
|
| 443 | + $value = array_filter( $value ); |
|
| 444 | + if ( count( $value ) == 0 ) { |
|
| 445 | + $value = ''; |
|
| 446 | + } |
|
| 447 | + } else { |
|
| 448 | 448 | // Radio and dropdowns |
| 449 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
| 450 | - $other_key = reset( $other_key ); |
|
| 449 | + $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
| 450 | + $other_key = reset( $other_key ); |
|
| 451 | 451 | |
| 452 | - // Multi-select dropdown |
|
| 453 | - if ( is_array( $value ) ) { |
|
| 454 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
| 452 | + // Multi-select dropdown |
|
| 453 | + if ( is_array( $value ) ) { |
|
| 454 | + $o_key = array_search( $field->options[ $other_key ], $value ); |
|
| 455 | 455 | |
| 456 | 456 | if ( $o_key !== false ) { |
| 457 | 457 | // Modify the original value so other key will be preserved |
@@ -466,20 +466,20 @@ discard block |
||
| 466 | 466 | $args['temp_value'] = $value; |
| 467 | 467 | $value[ $other_key ] = reset( $other_vals ); |
| 468 | 468 | } |
| 469 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
| 470 | - $value = $other_vals; |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 469 | + } else if ( $field->options[ $other_key ] == $value ) { |
|
| 470 | + $value = $other_vals; |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | 475 | public static function enqueue_scripts( $params ) { |
| 476 | 476 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmFormsController::enqueue_scripts' ); |
| 477 | 477 | FrmFormsController::enqueue_scripts( $params ); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - // Add submitted values to a string for spam checking |
|
| 480 | + // Add submitted values to a string for spam checking |
|
| 481 | 481 | public static function entry_array_to_string( $values ) { |
| 482 | - $content = ''; |
|
| 482 | + $content = ''; |
|
| 483 | 483 | foreach ( $values['item_meta'] as $val ) { |
| 484 | 484 | if ( $content != '' ) { |
| 485 | 485 | $content .= "\n\n"; |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | return $content; |
| 497 | - } |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | 499 | public static function fill_entry_values( $atts, $f, array &$values ) { |
| 500 | 500 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryFormat::fill_entry_values' ); |