@@ -5,19 +5,19 @@ 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( |
| 10 | 10 | 'name' => '', |
| 11 | 11 | 'description' => '', |
| 12 | 12 | 'item_key' => '', |
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | - $values['fields'] = array(); |
|
| 16 | - if ( empty($fields) ) { |
|
| 17 | - return apply_filters('frm_setup_new_entry', $values); |
|
| 18 | - } |
|
| 15 | + $values['fields'] = array(); |
|
| 16 | + if ( empty($fields) ) { |
|
| 17 | + return apply_filters('frm_setup_new_entry', $values); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - foreach ( (array) $fields as $field ) { |
|
| 20 | + foreach ( (array) $fields as $field ) { |
|
| 21 | 21 | $original_default = $field->default_value; |
| 22 | 22 | self::prepare_field_default_value( $field ); |
| 23 | 23 | $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args ); |
| 34 | 34 | |
| 35 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
| 35 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
| 36 | 36 | |
| 37 | - $values['fields'][] = $field_array; |
|
| 37 | + $values['fields'][] = $field_array; |
|
| 38 | 38 | |
| 39 | - if ( ! $form || ! isset($form->id) ) { |
|
| 40 | - $form = FrmForm::getOne($field->form_id); |
|
| 41 | - } |
|
| 42 | - } |
|
| 39 | + if ( ! $form || ! isset($form->id) ) { |
|
| 40 | + $form = FrmForm::getOne($field->form_id); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | $form->options = maybe_unserialize( $form->options ); |
| 45 | 45 | if ( is_array( $form->options ) ) { |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $values = array_merge( $form_defaults, $values ); |
| 55 | 55 | |
| 56 | 56 | return apply_filters( 'frm_setup_new_entry', $values ); |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * @since 2.05 |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | - * Set the value for each field |
|
| 75 | - * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
| 76 | - * |
|
| 77 | - * @since 2.0.13 |
|
| 78 | - * |
|
| 79 | - * @param object $field - this is passed by reference since it is an object |
|
| 80 | - * @param boolean $reset |
|
| 81 | - * @param array $args |
|
| 82 | - * @return string|array $new_value |
|
| 83 | - */ |
|
| 74 | + * Set the value for each field |
|
| 75 | + * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
| 76 | + * |
|
| 77 | + * @since 2.0.13 |
|
| 78 | + * |
|
| 79 | + * @param object $field - this is passed by reference since it is an object |
|
| 80 | + * @param boolean $reset |
|
| 81 | + * @param array $args |
|
| 82 | + * @return string|array $new_value |
|
| 83 | + */ |
|
| 84 | 84 | private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
| 85 | 85 | $new_value = $field->default_value; |
| 86 | 86 | |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * Check if a field has a posted value |
|
| 109 | - * |
|
| 110 | - * @since 2.01.0 |
|
| 111 | - * @param object $field |
|
| 112 | - * @param array $args |
|
| 113 | - * @return boolean $value_is_posted |
|
| 114 | - */ |
|
| 108 | + * Check if a field has a posted value |
|
| 109 | + * |
|
| 110 | + * @since 2.01.0 |
|
| 111 | + * @param object $field |
|
| 112 | + * @param array $args |
|
| 113 | + * @return boolean $value_is_posted |
|
| 114 | + */ |
|
| 115 | 115 | public static function value_is_posted( $field, $args ) { |
| 116 | 116 | $value_is_posted = false; |
| 117 | 117 | if ( $_POST ) { |
@@ -129,93 +129,93 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | public static function setup_edit_vars( $values, $record ) { |
| 131 | 131 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
| 132 | - $values['form_id'] = $record->form_id; |
|
| 133 | - $values['is_draft'] = $record->is_draft; |
|
| 134 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 135 | - } |
|
| 132 | + $values['form_id'] = $record->form_id; |
|
| 133 | + $values['is_draft'] = $record->is_draft; |
|
| 134 | + return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | public static function replace_default_message( $message, $atts ) { |
| 138 | - if ( strpos($message, '[default-message') === false && |
|
| 139 | - strpos($message, '[default_message') === false && |
|
| 140 | - ! empty( $message ) ) { |
|
| 141 | - return $message; |
|
| 142 | - } |
|
| 138 | + if ( strpos($message, '[default-message') === false && |
|
| 139 | + strpos($message, '[default_message') === false && |
|
| 140 | + ! empty( $message ) ) { |
|
| 141 | + return $message; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if ( empty($message) ) { |
|
| 145 | - $message = '[default-message]'; |
|
| 146 | - } |
|
| 144 | + if ( empty($message) ) { |
|
| 145 | + $message = '[default-message]'; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 148 | + preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 149 | 149 | |
| 150 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
| 150 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
| 151 | 151 | $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
| 152 | 152 | if ( ! empty( $add_atts ) ) { |
| 153 | - $this_atts = array_merge($atts, $add_atts); |
|
| 154 | - } else { |
|
| 155 | - $this_atts = $atts; |
|
| 156 | - } |
|
| 153 | + $this_atts = array_merge($atts, $add_atts); |
|
| 154 | + } else { |
|
| 155 | + $this_atts = $atts; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | $default = FrmEntriesController::show_entry_shortcode( $this_atts ); |
| 159 | 159 | |
| 160 | - // Add the default message |
|
| 161 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 162 | - } |
|
| 160 | + // Add the default message |
|
| 161 | + $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - return $message; |
|
| 165 | - } |
|
| 164 | + return $message; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | public static function prepare_display_value( $entry, $field, $atts ) { |
| 168 | 168 | $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
| 169 | 169 | |
| 170 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
| 170 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
| 171 | 171 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
| 172 | - } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 175 | - return self::display_value($field_value, $field, $atts); |
|
| 176 | - } |
|
| 174 | + if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 175 | + return self::display_value($field_value, $field, $atts); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - // this is an embeded form |
|
| 179 | - $val = ''; |
|
| 178 | + // this is an embeded form |
|
| 179 | + $val = ''; |
|
| 180 | 180 | |
| 181 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 182 | - //this is a repeating section |
|
| 181 | + if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 182 | + //this is a repeating section |
|
| 183 | 183 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
| 184 | - } else { |
|
| 185 | - // get all values for this field |
|
| 186 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 184 | + } else { |
|
| 185 | + // get all values for this field |
|
| 186 | + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 187 | 187 | |
| 188 | - if ( $child_values ) { |
|
| 189 | - $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
| 190 | - } |
|
| 191 | - } |
|
| 188 | + if ( $child_values ) { |
|
| 189 | + $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - $field_value = array(); |
|
| 193 | + $field_value = array(); |
|
| 194 | 194 | |
| 195 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 196 | - return $val; |
|
| 197 | - } |
|
| 195 | + if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 196 | + return $val; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - foreach ( $child_entries as $child_entry ) { |
|
| 200 | - $atts['item_id'] = $child_entry->id; |
|
| 201 | - $atts['post_id'] = $child_entry->post_id; |
|
| 199 | + foreach ( $child_entries as $child_entry ) { |
|
| 200 | + $atts['item_id'] = $child_entry->id; |
|
| 201 | + $atts['post_id'] = $child_entry->post_id; |
|
| 202 | 202 | |
| 203 | - // get the value for this field -- check for post values as well |
|
| 204 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 203 | + // get the value for this field -- check for post values as well |
|
| 204 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 205 | 205 | |
| 206 | - if ( $entry_val ) { |
|
| 207 | - // foreach entry get display_value |
|
| 208 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 209 | - } |
|
| 206 | + if ( $entry_val ) { |
|
| 207 | + // foreach entry get display_value |
|
| 208 | + $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - unset($child_entry); |
|
| 212 | - } |
|
| 211 | + unset($child_entry); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - $val = implode(', ', (array) $field_value ); |
|
| 214 | + $val = implode(', ', (array) $field_value ); |
|
| 215 | 215 | return FrmAppHelper::kses( $val, 'all' ); |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 218 | + /** |
|
| 219 | 219 | * Prepare the saved value for display |
| 220 | 220 | * |
| 221 | 221 | * @param array|string $value |
@@ -239,35 +239,35 @@ discard block |
||
| 239 | 239 | 'return_array' => false, |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | - $atts = wp_parse_args( $atts, $defaults ); |
|
| 242 | + $atts = wp_parse_args( $atts, $defaults ); |
|
| 243 | 243 | |
| 244 | 244 | if ( FrmField::is_image( $field ) || $field->type == 'star' ) { |
| 245 | 245 | $atts['truncate'] = false; |
| 246 | 246 | $atts['html'] = true; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
| 249 | + $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
| 250 | 250 | |
| 251 | - if ( ! isset($field->field_options['post_field']) ) { |
|
| 252 | - $field->field_options['post_field'] = ''; |
|
| 253 | - } |
|
| 251 | + if ( ! isset($field->field_options['post_field']) ) { |
|
| 252 | + $field->field_options['post_field'] = ''; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
| 256 | - $field->field_options['custom_field'] = ''; |
|
| 257 | - } |
|
| 255 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
| 256 | + $field->field_options['custom_field'] = ''; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
| 260 | - $atts['pre_truncate'] = $atts['truncate']; |
|
| 261 | - $atts['truncate'] = true; |
|
| 262 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
| 259 | + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
| 260 | + $atts['pre_truncate'] = $atts['truncate']; |
|
| 261 | + $atts['truncate'] = true; |
|
| 262 | + $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
| 263 | 263 | |
| 264 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
| 265 | - $atts['truncate'] = $atts['pre_truncate']; |
|
| 266 | - } |
|
| 264 | + $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
| 265 | + $atts['truncate'] = $atts['pre_truncate']; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - if ( $value == '' ) { |
|
| 269 | - return $value; |
|
| 270 | - } |
|
| 268 | + if ( $value == '' ) { |
|
| 269 | + return $value; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | 272 | $unfiltered_value = maybe_unserialize( $value ); |
| 273 | 273 | $value = apply_filters('frm_display_value_custom', $unfiltered_value, $field, $atts); |
@@ -277,130 +277,130 @@ discard block |
||
| 277 | 277 | $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) ); |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( $atts['truncate'] && $atts['type'] != 'url' ) { |
|
| 281 | - $value = FrmAppHelper::truncate($value, 50); |
|
| 282 | - } |
|
| 280 | + if ( $atts['truncate'] && $atts['type'] != 'url' ) { |
|
| 281 | + $value = FrmAppHelper::truncate($value, 50); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
| 285 | 285 | $value = FrmAppHelper::kses( $value, 'all' ); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | return apply_filters( 'frm_display_value', $value, $field, $atts ); |
| 289 | - } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | public static function set_posted_value( $field, $value, $args ) { |
| 292 | - // If validating a field with "other" opt, set back to prev value now |
|
| 293 | - if ( isset( $args['other'] ) && $args['other'] ) { |
|
| 294 | - $value = $args['temp_value']; |
|
| 295 | - } |
|
| 296 | - if ( empty($args['parent_field_id']) ) { |
|
| 297 | - $_POST['item_meta'][ $field->id ] = $value; |
|
| 298 | - } else { |
|
| 299 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
| 300 | - } |
|
| 301 | - } |
|
| 292 | + // If validating a field with "other" opt, set back to prev value now |
|
| 293 | + if ( isset( $args['other'] ) && $args['other'] ) { |
|
| 294 | + $value = $args['temp_value']; |
|
| 295 | + } |
|
| 296 | + if ( empty($args['parent_field_id']) ) { |
|
| 297 | + $_POST['item_meta'][ $field->id ] = $value; |
|
| 298 | + } else { |
|
| 299 | + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | public static function get_posted_value( $field, &$value, $args ) { |
| 304 | 304 | $field_id = is_object( $field ) ? $field->id : $field; |
| 305 | 305 | |
| 306 | - if ( empty($args['parent_field_id']) ) { |
|
| 307 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
| 308 | - } else { |
|
| 309 | - $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 ] : ''; |
|
| 310 | - } |
|
| 306 | + if ( empty($args['parent_field_id']) ) { |
|
| 307 | + $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
| 308 | + } else { |
|
| 309 | + $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 ] : ''; |
|
| 310 | + } |
|
| 311 | 311 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
| 312 | 312 | $value = stripslashes_deep( $value ); |
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Check if field has an "Other" option and if any other values are posted |
|
| 317 | - * |
|
| 318 | - * @since 2.0 |
|
| 319 | - * |
|
| 320 | - * @param object $field |
|
| 321 | - * @param string|array $value |
|
| 322 | - * @param array $args |
|
| 323 | - */ |
|
| 324 | - public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
| 325 | - $args['other'] = false; |
|
| 326 | - if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
| 327 | - return; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // Get other value for fields in repeating section |
|
| 331 | - self::set_other_repeating_vals( $field, $value, $args ); |
|
| 332 | - |
|
| 333 | - // Check if there are any posted "Other" values |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Check if field has an "Other" option and if any other values are posted |
|
| 317 | + * |
|
| 318 | + * @since 2.0 |
|
| 319 | + * |
|
| 320 | + * @param object $field |
|
| 321 | + * @param string|array $value |
|
| 322 | + * @param array $args |
|
| 323 | + */ |
|
| 324 | + public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
| 325 | + $args['other'] = false; |
|
| 326 | + if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
| 327 | + return; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // Get other value for fields in repeating section |
|
| 331 | + self::set_other_repeating_vals( $field, $value, $args ); |
|
| 332 | + |
|
| 333 | + // Check if there are any posted "Other" values |
|
| 334 | 334 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
| 335 | 335 | |
| 336 | - // Save original value |
|
| 337 | - $args['temp_value'] = $value; |
|
| 338 | - $args['other'] = true; |
|
| 339 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
| 340 | - |
|
| 341 | - // Set the validation value now |
|
| 342 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
| 348 | - * |
|
| 349 | - * @since 2.0 |
|
| 350 | - * |
|
| 351 | - * @param object $field |
|
| 352 | - * @param string|array $value |
|
| 353 | - * @param array $args |
|
| 354 | - */ |
|
| 355 | - public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
| 356 | - if ( ! $args['parent_field_id'] ) { |
|
| 357 | - return; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // Check if there are any other posted "other" values for this field |
|
| 336 | + // Save original value |
|
| 337 | + $args['temp_value'] = $value; |
|
| 338 | + $args['other'] = true; |
|
| 339 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
| 340 | + |
|
| 341 | + // Set the validation value now |
|
| 342 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
| 348 | + * |
|
| 349 | + * @since 2.0 |
|
| 350 | + * |
|
| 351 | + * @param object $field |
|
| 352 | + * @param string|array $value |
|
| 353 | + * @param array $args |
|
| 354 | + */ |
|
| 355 | + public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
| 356 | + if ( ! $args['parent_field_id'] ) { |
|
| 357 | + return; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // Check if there are any other posted "other" values for this field |
|
| 361 | 361 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
| 362 | - // Save original value |
|
| 363 | - $args['temp_value'] = $value; |
|
| 364 | - $args['other'] = true; |
|
| 365 | - |
|
| 366 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
| 367 | - |
|
| 368 | - // Set the validation value now |
|
| 369 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Modify value used for validation |
|
| 375 | - * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
| 376 | - * It also adds any text from the free text fields to the value |
|
| 377 | - * |
|
| 378 | - * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
| 379 | - * |
|
| 380 | - * @since 2.0 |
|
| 381 | - * |
|
| 382 | - * @param string|array $value |
|
| 383 | - * @param string|array $other_vals (usually of posted values) |
|
| 384 | - * @param object $field |
|
| 385 | - * @param array $args |
|
| 386 | - */ |
|
| 387 | - public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
| 388 | - // Checkboxes and multi-select dropdowns |
|
| 389 | - if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
| 390 | - // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
| 391 | - $value = array_merge( $value, $other_vals ); |
|
| 392 | - $value = array_filter( $value ); |
|
| 393 | - if ( count( $value ) == 0 ) { |
|
| 394 | - $value = ''; |
|
| 395 | - } |
|
| 396 | - } else { |
|
| 362 | + // Save original value |
|
| 363 | + $args['temp_value'] = $value; |
|
| 364 | + $args['other'] = true; |
|
| 365 | + |
|
| 366 | + $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
| 367 | + |
|
| 368 | + // Set the validation value now |
|
| 369 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Modify value used for validation |
|
| 375 | + * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
| 376 | + * It also adds any text from the free text fields to the value |
|
| 377 | + * |
|
| 378 | + * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
| 379 | + * |
|
| 380 | + * @since 2.0 |
|
| 381 | + * |
|
| 382 | + * @param string|array $value |
|
| 383 | + * @param string|array $other_vals (usually of posted values) |
|
| 384 | + * @param object $field |
|
| 385 | + * @param array $args |
|
| 386 | + */ |
|
| 387 | + public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
| 388 | + // Checkboxes and multi-select dropdowns |
|
| 389 | + if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
| 390 | + // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
| 391 | + $value = array_merge( $value, $other_vals ); |
|
| 392 | + $value = array_filter( $value ); |
|
| 393 | + if ( count( $value ) == 0 ) { |
|
| 394 | + $value = ''; |
|
| 395 | + } |
|
| 396 | + } else { |
|
| 397 | 397 | // Radio and dropdowns |
| 398 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
| 399 | - $other_key = reset( $other_key ); |
|
| 398 | + $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
| 399 | + $other_key = reset( $other_key ); |
|
| 400 | 400 | |
| 401 | - // Multi-select dropdown |
|
| 402 | - if ( is_array( $value ) ) { |
|
| 403 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
| 401 | + // Multi-select dropdown |
|
| 402 | + if ( is_array( $value ) ) { |
|
| 403 | + $o_key = array_search( $field->options[ $other_key ], $value ); |
|
| 404 | 404 | |
| 405 | 405 | if ( $o_key !== false ) { |
| 406 | 406 | // Modify the original value so other key will be preserved |
@@ -418,15 +418,15 @@ discard block |
||
| 418 | 418 | unset( $value[ $other_key ] ); |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
| 422 | - $value = $other_vals; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 421 | + } else if ( $field->options[ $other_key ] == $value ) { |
|
| 422 | + $value = $other_vals; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | - // Add submitted values to a string for spam checking |
|
| 427 | + // Add submitted values to a string for spam checking |
|
| 428 | 428 | public static function entry_array_to_string( $values ) { |
| 429 | - $content = ''; |
|
| 429 | + $content = ''; |
|
| 430 | 430 | foreach ( $values['item_meta'] as $val ) { |
| 431 | 431 | if ( $content != '' ) { |
| 432 | 432 | $content .= "\n\n"; |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | return $content; |
| 444 | - } |
|
| 444 | + } |
|
| 445 | 445 | |
| 446 | 446 | /** |
| 447 | 447 | * 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 | |
@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | 15 | $values['fields'] = array(); |
| 16 | - if ( empty($fields) ) { |
|
| 17 | - return apply_filters('frm_setup_new_entry', $values); |
|
| 16 | + if ( empty( $fields ) ) { |
|
| 17 | + return apply_filters( 'frm_setup_new_entry', $values ); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | foreach ( (array) $fields as $field ) { |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $values['fields'][] = $field_array; |
| 38 | 38 | |
| 39 | - if ( ! $form || ! isset($form->id) ) { |
|
| 40 | - $form = FrmForm::getOne($field->form_id); |
|
| 39 | + if ( ! $form || ! isset( $form->id ) ) { |
|
| 40 | + $form = FrmForm::getOne( $field->form_id ); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $form_defaults = FrmFormsHelper::get_default_opts(); |
| 50 | 50 | |
| 51 | 51 | $frm_settings = FrmAppHelper::get_settings(); |
| 52 | - $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
| 52 | + $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
| 53 | 53 | |
| 54 | 54 | $values = array_merge( $form_defaults, $values ); |
| 55 | 55 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | if ( ! is_array( $new_value ) ) { |
| 101 | - $new_value = str_replace('"', '"', $new_value); |
|
| 101 | + $new_value = str_replace( '"', '"', $new_value ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $new_value; |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | if ( $_POST ) { |
| 118 | 118 | $repeating = isset( $args['repeating'] ) && $args['repeating']; |
| 119 | 119 | if ( $repeating ) { |
| 120 | - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { |
|
| 120 | + if ( isset( $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] ) ) { |
|
| 121 | 121 | $value_is_posted = true; |
| 122 | 122 | } |
| 123 | - } else if ( isset( $_POST['item_meta'][ $field->id ] ) ) { |
|
| 123 | + } else if ( isset( $_POST['item_meta'][$field->id] ) ) { |
|
| 124 | 124 | $value_is_posted = true; |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -131,26 +131,26 @@ discard block |
||
| 131 | 131 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
| 132 | 132 | $values['form_id'] = $record->form_id; |
| 133 | 133 | $values['is_draft'] = $record->is_draft; |
| 134 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 134 | + return apply_filters( 'frm_setup_edit_entry_vars', $values, $record ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | public static function replace_default_message( $message, $atts ) { |
| 138 | - if ( strpos($message, '[default-message') === false && |
|
| 139 | - strpos($message, '[default_message') === false && |
|
| 138 | + if ( strpos( $message, '[default-message' ) === false && |
|
| 139 | + strpos( $message, '[default_message' ) === false && |
|
| 140 | 140 | ! empty( $message ) ) { |
| 141 | 141 | return $message; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( empty($message) ) { |
|
| 144 | + if ( empty( $message ) ) { |
|
| 145 | 145 | $message = '[default-message]'; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 148 | + preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER ); |
|
| 149 | 149 | |
| 150 | 150 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 151 | - $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
|
| 151 | + $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][$short_key] ); |
|
| 152 | 152 | if ( ! empty( $add_atts ) ) { |
| 153 | - $this_atts = array_merge($atts, $add_atts); |
|
| 153 | + $this_atts = array_merge( $atts, $add_atts ); |
|
| 154 | 154 | } else { |
| 155 | 155 | $this_atts = $atts; |
| 156 | 156 | } |
@@ -158,32 +158,32 @@ discard block |
||
| 158 | 158 | $default = FrmEntriesController::show_entry_shortcode( $this_atts ); |
| 159 | 159 | |
| 160 | 160 | // Add the default message |
| 161 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 161 | + $message = str_replace( $shortcodes[0][$short_key], $default, $message ); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | return $message; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | public static function prepare_display_value( $entry, $field, $atts ) { |
| 168 | - $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
|
| 168 | + $field_value = isset( $entry->metas[$field->id] ) ? $entry->metas[$field->id] : false; |
|
| 169 | 169 | |
| 170 | 170 | if ( FrmAppHelper::pro_is_installed() ) { |
| 171 | 171 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 175 | - return self::display_value($field_value, $field, $atts); |
|
| 174 | + if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) { |
|
| 175 | + return self::display_value( $field_value, $field, $atts ); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // this is an embeded form |
| 179 | 179 | $val = ''; |
| 180 | 180 | |
| 181 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 181 | + if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) { |
|
| 182 | 182 | //this is a repeating section |
| 183 | 183 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
| 184 | 184 | } else { |
| 185 | 185 | // get all values for this field |
| 186 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 186 | + $child_values = isset( $entry->metas[$atts['embedded_field_id']] ) ? $entry->metas[$atts['embedded_field_id']] : false; |
|
| 187 | 187 | |
| 188 | 188 | if ( $child_values ) { |
| 189 | 189 | $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | $field_value = array(); |
| 194 | 194 | |
| 195 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 195 | + if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 196 | 196 | return $val; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -201,17 +201,17 @@ discard block |
||
| 201 | 201 | $atts['post_id'] = $child_entry->post_id; |
| 202 | 202 | |
| 203 | 203 | // get the value for this field -- check for post values as well |
| 204 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 204 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field ); |
|
| 205 | 205 | |
| 206 | 206 | if ( $entry_val ) { |
| 207 | 207 | // foreach entry get display_value |
| 208 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 208 | + $field_value[] = self::display_value( $entry_val, $field, $atts ); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - unset($child_entry); |
|
| 211 | + unset( $child_entry ); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $val = implode(', ', (array) $field_value ); |
|
| 214 | + $val = implode( ', ', (array) $field_value ); |
|
| 215 | 215 | return FrmAppHelper::kses( $val, 'all' ); |
| 216 | 216 | } |
| 217 | 217 | |
@@ -246,22 +246,22 @@ discard block |
||
| 246 | 246 | $atts['html'] = true; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
| 249 | + $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value ); |
|
| 250 | 250 | |
| 251 | - if ( ! isset($field->field_options['post_field']) ) { |
|
| 251 | + if ( ! isset( $field->field_options['post_field'] ) ) { |
|
| 252 | 252 | $field->field_options['post_field'] = ''; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
| 255 | + if ( ! isset( $field->field_options['custom_field'] ) ) { |
|
| 256 | 256 | $field->field_options['custom_field'] = ''; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
| 260 | 260 | $atts['pre_truncate'] = $atts['truncate']; |
| 261 | 261 | $atts['truncate'] = true; |
| 262 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
| 262 | + $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0; |
|
| 263 | 263 | |
| 264 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
| 264 | + $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts ); |
|
| 265 | 265 | $atts['truncate'] = $atts['pre_truncate']; |
| 266 | 266 | } |
| 267 | 267 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | $unfiltered_value = maybe_unserialize( $value ); |
| 273 | - $value = apply_filters('frm_display_value_custom', $unfiltered_value, $field, $atts); |
|
| 273 | + $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts ); |
|
| 274 | 274 | $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) ); |
| 275 | 275 | |
| 276 | 276 | if ( $value == $unfiltered_value ) { |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | if ( $atts['truncate'] && $atts['type'] != 'url' ) { |
| 281 | - $value = FrmAppHelper::truncate($value, 50); |
|
| 281 | + $value = FrmAppHelper::truncate( $value, 50 ); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
@@ -293,20 +293,20 @@ discard block |
||
| 293 | 293 | if ( isset( $args['other'] ) && $args['other'] ) { |
| 294 | 294 | $value = $args['temp_value']; |
| 295 | 295 | } |
| 296 | - if ( empty($args['parent_field_id']) ) { |
|
| 297 | - $_POST['item_meta'][ $field->id ] = $value; |
|
| 296 | + if ( empty( $args['parent_field_id'] ) ) { |
|
| 297 | + $_POST['item_meta'][$field->id] = $value; |
|
| 298 | 298 | } else { |
| 299 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
| 299 | + $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] = $value; |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | public static function get_posted_value( $field, &$value, $args ) { |
| 304 | 304 | $field_id = is_object( $field ) ? $field->id : $field; |
| 305 | 305 | |
| 306 | - if ( empty($args['parent_field_id']) ) { |
|
| 307 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
| 306 | + if ( empty( $args['parent_field_id'] ) ) { |
|
| 307 | + $value = isset( $_POST['item_meta'][$field_id] ) ? $_POST['item_meta'][$field_id] : ''; |
|
| 308 | 308 | } else { |
| 309 | - $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 ] : ''; |
|
| 309 | + $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] : ''; |
|
| 310 | 310 | } |
| 311 | 311 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
| 312 | 312 | $value = stripslashes_deep( $value ); |
@@ -331,12 +331,12 @@ discard block |
||
| 331 | 331 | self::set_other_repeating_vals( $field, $value, $args ); |
| 332 | 332 | |
| 333 | 333 | // Check if there are any posted "Other" values |
| 334 | - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
|
| 334 | + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][$field->id] ) ) { |
|
| 335 | 335 | |
| 336 | 336 | // Save original value |
| 337 | 337 | $args['temp_value'] = $value; |
| 338 | 338 | $args['other'] = true; |
| 339 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
| 339 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][$field->id] ); |
|
| 340 | 340 | |
| 341 | 341 | // Set the validation value now |
| 342 | 342 | self::set_other_validation_val( $value, $other_vals, $field, $args ); |
@@ -358,12 +358,12 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // Check if there are any other posted "other" values for this field |
| 361 | - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
|
| 361 | + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']]['other'][$field->id] ) ) { |
|
| 362 | 362 | // Save original value |
| 363 | 363 | $args['temp_value'] = $value; |
| 364 | 364 | $args['other'] = true; |
| 365 | 365 | |
| 366 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
| 366 | + $other_vals = $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']]['other'][$field->id]; |
|
| 367 | 367 | |
| 368 | 368 | // Set the validation value now |
| 369 | 369 | self::set_other_validation_val( $value, $other_vals, $field, $args ); |
@@ -395,30 +395,30 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | } else { |
| 397 | 397 | // Radio and dropdowns |
| 398 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
| 398 | + $other_key = array_filter( array_keys( $field->options ), 'is_string' ); |
|
| 399 | 399 | $other_key = reset( $other_key ); |
| 400 | 400 | |
| 401 | 401 | // Multi-select dropdown |
| 402 | 402 | if ( is_array( $value ) ) { |
| 403 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
| 403 | + $o_key = array_search( $field->options[$other_key], $value ); |
|
| 404 | 404 | |
| 405 | 405 | if ( $o_key !== false ) { |
| 406 | 406 | // Modify the original value so other key will be preserved |
| 407 | - $value[ $other_key ] = $value[ $o_key ]; |
|
| 407 | + $value[$other_key] = $value[$o_key]; |
|
| 408 | 408 | |
| 409 | 409 | // By default, the array keys will be numeric for multi-select dropdowns |
| 410 | 410 | // If going backwards and forwards between pages, the array key will match the other key |
| 411 | 411 | if ( $o_key !== $other_key ) { |
| 412 | - unset( $value[ $o_key ] ); |
|
| 412 | + unset( $value[$o_key] ); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $args['temp_value'] = $value; |
| 416 | - $value[ $other_key ] = reset( $other_vals ); |
|
| 417 | - if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) { |
|
| 418 | - unset( $value[ $other_key ] ); |
|
| 416 | + $value[$other_key] = reset( $other_vals ); |
|
| 417 | + if ( FrmAppHelper::is_empty_value( $value[$other_key] ) ) { |
|
| 418 | + unset( $value[$other_key] ); |
|
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
| 421 | + } else if ( $field->options[$other_key] == $value ) { |
|
| 422 | 422 | $value = $other_vals; |
| 423 | 423 | } |
| 424 | 424 | } |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | $content .= "\n\n"; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if ( is_array($val) ) { |
|
| 435 | + if ( is_array( $val ) ) { |
|
| 436 | 436 | $val = FrmAppHelper::array_flatten( $val ); |
| 437 | 437 | $val = implode( ', ', $val ); |
| 438 | 438 | } |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers |
| 497 | 497 | |
| 498 | 498 | // see how many we have |
| 499 | - $i = count($matches['browser']); |
|
| 499 | + $i = count( $matches['browser'] ); |
|
| 500 | 500 | |
| 501 | 501 | if ( $i > 1 ) { |
| 502 | 502 | //we will have two since we are not using 'other' argument yet |
@@ -1,18 +1,18 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmEntryValidate { |
| 4 | - public static function validate( $values, $exclude = false ) { |
|
| 5 | - FrmEntry::sanitize_entry_post( $values ); |
|
| 6 | - $errors = array(); |
|
| 4 | + public static function validate( $values, $exclude = false ) { |
|
| 5 | + FrmEntry::sanitize_entry_post( $values ); |
|
| 6 | + $errors = array(); |
|
| 7 | 7 | |
| 8 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 9 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 10 | - return $errors; |
|
| 11 | - } |
|
| 8 | + if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 9 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 10 | + return $errors; |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | 13 | if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
| 14 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 15 | - } |
|
| 14 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | self::set_item_key( $values ); |
| 18 | 18 | |
@@ -57,24 +57,24 @@ discard block |
||
| 57 | 57 | return FrmField::getAll( $where, 'field_order' ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 61 | - $defaults = array( |
|
| 62 | - 'id' => $posted_field->id, |
|
| 63 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 64 | - 'key_pointer' => '', // the pointer in the posted array |
|
| 65 | - 'exclude' => array(), // exclude these field types from validation |
|
| 66 | - ); |
|
| 67 | - $args = wp_parse_args( $args, $defaults ); |
|
| 60 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 61 | + $defaults = array( |
|
| 62 | + 'id' => $posted_field->id, |
|
| 63 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 64 | + 'key_pointer' => '', // the pointer in the posted array |
|
| 65 | + 'exclude' => array(), // exclude these field types from validation |
|
| 66 | + ); |
|
| 67 | + $args = wp_parse_args( $args, $defaults ); |
|
| 68 | 68 | |
| 69 | - if ( empty($args['parent_field_id']) ) { |
|
| 69 | + if ( empty($args['parent_field_id']) ) { |
|
| 70 | 70 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
| 71 | - } else { |
|
| 72 | - // value is from a nested form |
|
| 73 | - $value = $values; |
|
| 74 | - } |
|
| 71 | + } else { |
|
| 72 | + // value is from a nested form |
|
| 73 | + $value = $values; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Check for values in "Other" fields |
|
| 77 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 76 | + // Check for values in "Other" fields |
|
| 77 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 78 | 78 | |
| 79 | 79 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
| 80 | 80 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | $value = trim( $value ); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) { |
|
| 90 | + if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) { |
|
| 91 | 91 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
| 92 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
| 93 | - $_POST['item_name'] = $value; |
|
| 94 | - } |
|
| 92 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
| 93 | + $_POST['item_name'] = $value; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
| 97 | 97 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 105 | 105 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
| 109 | 109 | $is_default = ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ); |
@@ -239,34 +239,34 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | self::validate_field_types( $errors, $field, '', $args ); |
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * check for spam |
|
| 246 | - * @param boolean $exclude |
|
| 247 | - * @param array $values |
|
| 248 | - * @param array $errors by reference |
|
| 249 | - */ |
|
| 250 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
| 251 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 252 | - // only check spam if there are no other errors |
|
| 253 | - return; |
|
| 254 | - } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * check for spam |
|
| 246 | + * @param boolean $exclude |
|
| 247 | + * @param array $values |
|
| 248 | + * @param array $errors by reference |
|
| 249 | + */ |
|
| 250 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
| 251 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 252 | + // only check spam if there are no other errors |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | 256 | if ( self::is_honeypot_spam() || self::is_spam_bot() ) { |
| 257 | 257 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( self::blacklist_check( $values ) ) { |
|
| 261 | - $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
| 262 | - } |
|
| 260 | + if ( self::blacklist_check( $values ) ) { |
|
| 261 | + $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - if ( self::is_akismet_spam( $values ) ) { |
|
| 264 | + if ( self::is_akismet_spam( $values ) ) { |
|
| 265 | 265 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
| 266 | 266 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 267 | 267 | } |
| 268 | - } |
|
| 269 | - } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | private static function is_honeypot_spam() { |
| 272 | 272 | $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' ); |
@@ -288,15 +288,15 @@ discard block |
||
| 288 | 288 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - public static function blacklist_check( $values ) { |
|
| 292 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 293 | - return false; |
|
| 294 | - } |
|
| 291 | + public static function blacklist_check( $values ) { |
|
| 292 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 293 | + return false; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 297 | - if ( empty( $mod_keys ) ) { |
|
| 298 | - return false; |
|
| 299 | - } |
|
| 296 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 297 | + if ( empty( $mod_keys ) ) { |
|
| 298 | + return false; |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | 301 | $content = FrmEntriesHelper::entry_array_to_string( $values ); |
| 302 | 302 | if ( empty( $content ) ) { |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $user_info = self::get_spam_check_user_info( $values ); |
| 309 | 309 | |
| 310 | 310 | return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent ); |
| 311 | - } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | 314 | * Check entries for Akismet spam |
@@ -5,12 +5,12 @@ discard block |
||
| 5 | 5 | FrmEntry::sanitize_entry_post( $values ); |
| 6 | 6 | $errors = array(); |
| 7 | 7 | |
| 8 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 8 | + if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) { |
|
| 9 | 9 | $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
| 10 | 10 | return $errors; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) { |
|
| 13 | + if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_' . $values['form_id']] ) || ! wp_verify_nonce( $values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce' ) ) ) { |
|
| 14 | 14 | $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
| 15 | 15 | } |
| 16 | 16 | |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | ); |
| 67 | 67 | $args = wp_parse_args( $args, $defaults ); |
| 68 | 68 | |
| 69 | - if ( empty($args['parent_field_id']) ) { |
|
| 70 | - $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
|
| 69 | + if ( empty( $args['parent_field_id'] ) ) { |
|
| 70 | + $value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : ''; |
|
| 71 | 71 | } else { |
| 72 | 72 | // value is from a nested form |
| 73 | 73 | $value = $values; |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
| 80 | 80 | |
| 81 | 81 | // Reset arrays with only one value if it's not a field where array keys need to be preserved |
| 82 | - if ( is_array($value) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
| 83 | - $value = reset($value); |
|
| 82 | + if ( is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) ) { |
|
| 83 | + $value = reset( $value ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | if ( ! is_array( $value ) ) { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) { |
| 91 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
| 91 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
|
| 92 | 92 | } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
| 93 | 93 | $_POST['item_name'] = $value; |
| 94 | 94 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $pattern = self::phone_format( $field ); |
| 172 | 172 | |
| 173 | 173 | if ( ! preg_match( $pattern, $value ) ) { |
| 174 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 174 | + $errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | |
| 281 | 281 | private static function is_akismet_spam( $values ) { |
| 282 | 282 | global $wpcom_api_key; |
| 283 | - return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) ); |
|
| 283 | + return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | private static function is_akismet_enabled_for_user( $form_id ) { |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | public static function blacklist_check( $values ) { |
| 292 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 292 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { |
|
| 293 | 293 | return false; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
| 349 | 349 | $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false; |
| 350 | 350 | $datas['blog_lang'] = get_locale(); |
| 351 | - $datas['blog_charset'] = get_option('blog_charset'); |
|
| 351 | + $datas['blog_charset'] = get_option( 'blog_charset' ); |
|
| 352 | 352 | |
| 353 | 353 | if ( akismet_test_mode() ) { |
| 354 | 354 | $datas['is_test'] = 'true'; |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | // Send any potentially useful $_SERVER vars, but avoid sending junk we don't need. |
| 404 | 404 | if ( $include_value ) { |
| 405 | - $datas[ $key ] = $value; |
|
| 405 | + $datas[$key] = $value; |
|
| 406 | 406 | } |
| 407 | 407 | unset( $key, $value ); |
| 408 | 408 | } |