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