@@ -5,70 +5,70 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class FrmEntriesHelper { |
| 7 | 7 | |
| 8 | - public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
| 9 | - $values = array(); |
|
| 8 | + public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
| 9 | + $values = array(); |
|
| 10 | 10 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
| 11 | 11 | $values[ $var ] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
| 12 | - } |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - $values['fields'] = array(); |
|
| 15 | - if ( empty($fields) ) { |
|
| 16 | - return apply_filters('frm_setup_new_entry', $values); |
|
| 17 | - } |
|
| 14 | + $values['fields'] = array(); |
|
| 15 | + if ( empty($fields) ) { |
|
| 16 | + return apply_filters('frm_setup_new_entry', $values); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - foreach ( (array) $fields as $field ) { |
|
| 19 | + foreach ( (array) $fields as $field ) { |
|
| 20 | 20 | self::prepare_field_default_value( $field ); |
| 21 | - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
| 22 | - |
|
| 23 | - $field_array = array( |
|
| 24 | - 'id' => $field->id, |
|
| 25 | - 'value' => $new_value, |
|
| 26 | - 'default_value' => $field->default_value, |
|
| 27 | - 'name' => $field->name, |
|
| 28 | - 'description' => $field->description, |
|
| 29 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
| 30 | - 'options' => $field->options, |
|
| 31 | - 'required' => $field->required, |
|
| 32 | - 'field_key' => $field->field_key, |
|
| 33 | - 'field_order' => $field->field_order, |
|
| 34 | - 'form_id' => $field->form_id, |
|
| 21 | + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
| 22 | + |
|
| 23 | + $field_array = array( |
|
| 24 | + 'id' => $field->id, |
|
| 25 | + 'value' => $new_value, |
|
| 26 | + 'default_value' => $field->default_value, |
|
| 27 | + 'name' => $field->name, |
|
| 28 | + 'description' => $field->description, |
|
| 29 | + 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
| 30 | + 'options' => $field->options, |
|
| 31 | + 'required' => $field->required, |
|
| 32 | + 'field_key' => $field->field_key, |
|
| 33 | + 'field_order' => $field->field_order, |
|
| 34 | + 'form_id' => $field->form_id, |
|
| 35 | 35 | 'parent_form_id' => isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id, |
| 36 | - 'reset_value' => $reset, |
|
| 36 | + 'reset_value' => $reset, |
|
| 37 | 37 | 'in_embed_form' => isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0', |
| 38 | - ); |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 41 | - $opt_defaults['required_indicator'] = ''; |
|
| 40 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 41 | + $opt_defaults['required_indicator'] = ''; |
|
| 42 | 42 | $opt_defaults['original_type'] = $field->type; |
| 43 | 43 | |
| 44 | 44 | foreach ( $opt_defaults as $opt => $default_opt ) { |
| 45 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
| 46 | - unset($opt, $default_opt); |
|
| 47 | - } |
|
| 45 | + $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
| 46 | + unset($opt, $default_opt); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - unset($opt_defaults); |
|
| 49 | + unset($opt_defaults); |
|
| 50 | 50 | |
| 51 | - if ( $field_array['custom_html'] == '' ) { |
|
| 52 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
| 53 | - } |
|
| 51 | + if ( $field_array['custom_html'] == '' ) { |
|
| 52 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
| 56 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
| 55 | + $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
| 56 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
| 57 | 57 | |
| 58 | - $values['fields'][] = $field_array; |
|
| 58 | + $values['fields'][] = $field_array; |
|
| 59 | 59 | |
| 60 | - if ( ! $form || ! isset($form->id) ) { |
|
| 61 | - $form = FrmForm::getOne($field->form_id); |
|
| 62 | - } |
|
| 63 | - } |
|
| 60 | + if ( ! $form || ! isset($form->id) ) { |
|
| 61 | + $form = FrmForm::getOne($field->form_id); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $form->options = maybe_unserialize($form->options); |
|
| 66 | - if ( is_array($form->options) ) { |
|
| 67 | - foreach ( $form->options as $opt => $value ) { |
|
| 68 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
| 69 | - unset($opt, $value); |
|
| 70 | - } |
|
| 71 | - } |
|
| 65 | + $form->options = maybe_unserialize($form->options); |
|
| 66 | + if ( is_array($form->options) ) { |
|
| 67 | + foreach ( $form->options as $opt => $value ) { |
|
| 68 | + $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
| 69 | + unset($opt, $value); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | $form_defaults = FrmFormsHelper::get_default_opts(); |
| 74 | 74 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $values = array_merge( $form_defaults, $values ); |
| 79 | 79 | |
| 80 | 80 | return apply_filters( 'frm_setup_new_entry', $values ); |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * @since 2.04.02 |
@@ -93,16 +93,16 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * Set the value for each field |
|
| 97 | - * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
| 98 | - * |
|
| 99 | - * @since 2.0.13 |
|
| 100 | - * |
|
| 101 | - * @param object $field - this is passed by reference since it is an object |
|
| 102 | - * @param boolean $reset |
|
| 103 | - * @param array $args |
|
| 104 | - * @return string|array $new_value |
|
| 105 | - */ |
|
| 96 | + * Set the value for each field |
|
| 97 | + * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
| 98 | + * |
|
| 99 | + * @since 2.0.13 |
|
| 100 | + * |
|
| 101 | + * @param object $field - this is passed by reference since it is an object |
|
| 102 | + * @param boolean $reset |
|
| 103 | + * @param array $args |
|
| 104 | + * @return string|array $new_value |
|
| 105 | + */ |
|
| 106 | 106 | private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
| 107 | 107 | $new_value = $field->default_value; |
| 108 | 108 | |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * Check if a field has a posted value |
|
| 131 | - * |
|
| 132 | - * @since 2.01.0 |
|
| 133 | - * @param object $field |
|
| 134 | - * @param array $args |
|
| 135 | - * @return boolean $value_is_posted |
|
| 136 | - */ |
|
| 130 | + * Check if a field has a posted value |
|
| 131 | + * |
|
| 132 | + * @since 2.01.0 |
|
| 133 | + * @param object $field |
|
| 134 | + * @param array $args |
|
| 135 | + * @return boolean $value_is_posted |
|
| 136 | + */ |
|
| 137 | 137 | public static function value_is_posted( $field, $args ) { |
| 138 | 138 | $value_is_posted = false; |
| 139 | 139 | if ( $_POST ) { |
@@ -151,15 +151,15 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | public static function setup_edit_vars( $values, $record ) { |
| 153 | 153 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
| 154 | - $values['form_id'] = $record->form_id; |
|
| 155 | - $values['is_draft'] = $record->is_draft; |
|
| 156 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 157 | - } |
|
| 154 | + $values['form_id'] = $record->form_id; |
|
| 155 | + $values['is_draft'] = $record->is_draft; |
|
| 156 | + return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public static function get_admin_params( $form = null ) { |
|
| 159 | + public static function get_admin_params( $form = null ) { |
|
| 160 | 160 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_admin_params' ); |
| 161 | 161 | return FrmForm::set_current_form( $form ); |
| 162 | - } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | public static function set_current_form( $form_id ) { |
| 165 | 165 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::set_current_form' ); |
@@ -171,284 +171,284 @@ discard block |
||
| 171 | 171 | return FrmForm::get_current_form( $form_id ); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - public static function get_current_form_id() { |
|
| 174 | + public static function get_current_form_id() { |
|
| 175 | 175 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_current_form_id' ); |
| 176 | 176 | return FrmForm::get_current_form_id(); |
| 177 | - } |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - public static function maybe_get_entry( &$entry ) { |
|
| 179 | + public static function maybe_get_entry( &$entry ) { |
|
| 180 | 180 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntry::maybe_get_entry' ); |
| 181 | 181 | FrmEntry::maybe_get_entry( $entry ); |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | public static function replace_default_message( $message, $atts ) { |
| 185 | - if ( strpos($message, '[default-message') === false && |
|
| 186 | - strpos($message, '[default_message') === false && |
|
| 187 | - ! empty( $message ) ) { |
|
| 188 | - return $message; |
|
| 189 | - } |
|
| 185 | + if ( strpos($message, '[default-message') === false && |
|
| 186 | + strpos($message, '[default_message') === false && |
|
| 187 | + ! empty( $message ) ) { |
|
| 188 | + return $message; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - if ( empty($message) ) { |
|
| 192 | - $message = '[default-message]'; |
|
| 193 | - } |
|
| 191 | + if ( empty($message) ) { |
|
| 192 | + $message = '[default-message]'; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 195 | + preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 196 | 196 | |
| 197 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
| 197 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
| 198 | 198 | $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
| 199 | 199 | if ( ! empty( $add_atts ) ) { |
| 200 | - $this_atts = array_merge($atts, $add_atts); |
|
| 201 | - } else { |
|
| 202 | - $this_atts = $atts; |
|
| 203 | - } |
|
| 200 | + $this_atts = array_merge($atts, $add_atts); |
|
| 201 | + } else { |
|
| 202 | + $this_atts = $atts; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | $default = FrmEntriesController::show_entry_shortcode( $this_atts ); |
| 206 | 206 | |
| 207 | - // Add the default message |
|
| 208 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 209 | - } |
|
| 207 | + // Add the default message |
|
| 208 | + $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - return $message; |
|
| 212 | - } |
|
| 211 | + return $message; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | 214 | public static function prepare_display_value( $entry, $field, $atts ) { |
| 215 | 215 | $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
| 216 | 216 | |
| 217 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
| 217 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
| 218 | 218 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
| 219 | - } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 222 | - return self::display_value($field_value, $field, $atts); |
|
| 223 | - } |
|
| 221 | + if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 222 | + return self::display_value($field_value, $field, $atts); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // this is an embeded form |
|
| 226 | - $val = ''; |
|
| 225 | + // this is an embeded form |
|
| 226 | + $val = ''; |
|
| 227 | 227 | |
| 228 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 229 | - //this is a repeating section |
|
| 228 | + if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 229 | + //this is a repeating section |
|
| 230 | 230 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
| 231 | - } else { |
|
| 232 | - // get all values for this field |
|
| 233 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 231 | + } else { |
|
| 232 | + // get all values for this field |
|
| 233 | + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 234 | 234 | |
| 235 | - if ( $child_values ) { |
|
| 236 | - $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
| 237 | - } |
|
| 238 | - } |
|
| 235 | + if ( $child_values ) { |
|
| 236 | + $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - $field_value = array(); |
|
| 240 | + $field_value = array(); |
|
| 241 | 241 | |
| 242 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 243 | - return $val; |
|
| 244 | - } |
|
| 242 | + if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 243 | + return $val; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - foreach ( $child_entries as $child_entry ) { |
|
| 247 | - $atts['item_id'] = $child_entry->id; |
|
| 248 | - $atts['post_id'] = $child_entry->post_id; |
|
| 246 | + foreach ( $child_entries as $child_entry ) { |
|
| 247 | + $atts['item_id'] = $child_entry->id; |
|
| 248 | + $atts['post_id'] = $child_entry->post_id; |
|
| 249 | 249 | |
| 250 | - // get the value for this field -- check for post values as well |
|
| 251 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 250 | + // get the value for this field -- check for post values as well |
|
| 251 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 252 | 252 | |
| 253 | - if ( $entry_val ) { |
|
| 254 | - // foreach entry get display_value |
|
| 255 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 256 | - } |
|
| 253 | + if ( $entry_val ) { |
|
| 254 | + // foreach entry get display_value |
|
| 255 | + $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - unset($child_entry); |
|
| 259 | - } |
|
| 258 | + unset($child_entry); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $val = implode(', ', (array) $field_value ); |
|
| 261 | + $val = implode(', ', (array) $field_value ); |
|
| 262 | 262 | $val = wp_kses_post( $val ); |
| 263 | 263 | |
| 264 | - return $val; |
|
| 265 | - } |
|
| 264 | + return $val; |
|
| 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 = wp_kses_post( $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 | |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
| 9 | 9 | $values = array(); |
| 10 | 10 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
| 11 | - $values[ $var ] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
|
| 11 | + $values[$var] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | $values['fields'] = array(); |
| 15 | - if ( empty($fields) ) { |
|
| 16 | - return apply_filters('frm_setup_new_entry', $values); |
|
| 15 | + if ( empty( $fields ) ) { |
|
| 16 | + return apply_filters( 'frm_setup_new_entry', $values ); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | foreach ( (array) $fields as $field ) { |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | 'default_value' => $field->default_value, |
| 27 | 27 | 'name' => $field->name, |
| 28 | 28 | 'description' => $field->description, |
| 29 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
| 29 | + 'type' => apply_filters( 'frm_field_type', $field->type, $field, $new_value ), |
|
| 30 | 30 | 'options' => $field->options, |
| 31 | 31 | 'required' => $field->required, |
| 32 | 32 | 'field_key' => $field->field_key, |
@@ -37,43 +37,43 @@ discard block |
||
| 37 | 37 | 'in_embed_form' => isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0', |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
| 40 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts( $field_array['type'], $field, true ); |
|
| 41 | 41 | $opt_defaults['required_indicator'] = ''; |
| 42 | 42 | $opt_defaults['original_type'] = $field->type; |
| 43 | 43 | |
| 44 | 44 | foreach ( $opt_defaults as $opt => $default_opt ) { |
| 45 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
| 46 | - unset($opt, $default_opt); |
|
| 45 | + $field_array[$opt] = ( isset( $field->field_options[$opt] ) && $field->field_options[$opt] != '' ) ? $field->field_options[$opt] : $default_opt; |
|
| 46 | + unset( $opt, $default_opt ); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - unset($opt_defaults); |
|
| 49 | + unset( $opt_defaults ); |
|
| 50 | 50 | |
| 51 | 51 | if ( $field_array['custom_html'] == '' ) { |
| 52 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
| 52 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html( $field->type ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
| 55 | + $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
| 56 | 56 | $field_array = array_merge( $field->field_options, $field_array ); |
| 57 | 57 | |
| 58 | 58 | $values['fields'][] = $field_array; |
| 59 | 59 | |
| 60 | - if ( ! $form || ! isset($form->id) ) { |
|
| 61 | - $form = FrmForm::getOne($field->form_id); |
|
| 60 | + if ( ! $form || ! isset( $form->id ) ) { |
|
| 61 | + $form = FrmForm::getOne( $field->form_id ); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $form->options = maybe_unserialize($form->options); |
|
| 66 | - if ( is_array($form->options) ) { |
|
| 65 | + $form->options = maybe_unserialize( $form->options ); |
|
| 66 | + if ( is_array( $form->options ) ) { |
|
| 67 | 67 | foreach ( $form->options as $opt => $value ) { |
| 68 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
| 69 | - unset($opt, $value); |
|
| 68 | + $values[$opt] = FrmAppHelper::get_post_param( $opt, $value ); |
|
| 69 | + unset( $opt, $value ); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $form_defaults = FrmFormsHelper::get_default_opts(); |
| 74 | 74 | |
| 75 | 75 | $frm_settings = FrmAppHelper::get_settings(); |
| 76 | - $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
| 76 | + $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' ); |
|
| 77 | 77 | |
| 78 | 78 | $values = array_merge( $form_defaults, $values ); |
| 79 | 79 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if ( ! is_array( $new_value ) ) { |
| 123 | - $new_value = str_replace('"', '"', $new_value); |
|
| 123 | + $new_value = str_replace( '"', '"', $new_value ); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $new_value; |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | if ( $_POST ) { |
| 140 | 140 | $repeating = isset( $args['repeating'] ) && $args['repeating']; |
| 141 | 141 | if ( $repeating ) { |
| 142 | - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { |
|
| 142 | + if ( isset( $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] ) ) { |
|
| 143 | 143 | $value_is_posted = true; |
| 144 | 144 | } |
| 145 | - } else if ( isset( $_POST['item_meta'][ $field->id ] ) ) { |
|
| 145 | + } else if ( isset( $_POST['item_meta'][$field->id] ) ) { |
|
| 146 | 146 | $value_is_posted = true; |
| 147 | 147 | } |
| 148 | 148 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
| 154 | 154 | $values['form_id'] = $record->form_id; |
| 155 | 155 | $values['is_draft'] = $record->is_draft; |
| 156 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
| 156 | + return apply_filters( 'frm_setup_edit_entry_vars', $values, $record ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | public static function get_admin_params( $form = null ) { |
@@ -182,22 +182,22 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public static function replace_default_message( $message, $atts ) { |
| 185 | - if ( strpos($message, '[default-message') === false && |
|
| 186 | - strpos($message, '[default_message') === false && |
|
| 185 | + if ( strpos( $message, '[default-message' ) === false && |
|
| 186 | + strpos( $message, '[default_message' ) === false && |
|
| 187 | 187 | ! empty( $message ) ) { |
| 188 | 188 | return $message; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( empty($message) ) { |
|
| 191 | + if ( empty( $message ) ) { |
|
| 192 | 192 | $message = '[default-message]'; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
| 195 | + preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER ); |
|
| 196 | 196 | |
| 197 | 197 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 198 | - $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
|
| 198 | + $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][$short_key] ); |
|
| 199 | 199 | if ( ! empty( $add_atts ) ) { |
| 200 | - $this_atts = array_merge($atts, $add_atts); |
|
| 200 | + $this_atts = array_merge( $atts, $add_atts ); |
|
| 201 | 201 | } else { |
| 202 | 202 | $this_atts = $atts; |
| 203 | 203 | } |
@@ -205,32 +205,32 @@ discard block |
||
| 205 | 205 | $default = FrmEntriesController::show_entry_shortcode( $this_atts ); |
| 206 | 206 | |
| 207 | 207 | // Add the default message |
| 208 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
| 208 | + $message = str_replace( $shortcodes[0][$short_key], $default, $message ); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | return $message; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | public static function prepare_display_value( $entry, $field, $atts ) { |
| 215 | - $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
|
| 215 | + $field_value = isset( $entry->metas[$field->id] ) ? $entry->metas[$field->id] : false; |
|
| 216 | 216 | |
| 217 | 217 | if ( FrmAppHelper::pro_is_installed() ) { |
| 218 | 218 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
| 222 | - return self::display_value($field_value, $field, $atts); |
|
| 221 | + if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) { |
|
| 222 | + return self::display_value( $field_value, $field, $atts ); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // this is an embeded form |
| 226 | 226 | $val = ''; |
| 227 | 227 | |
| 228 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
| 228 | + if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) { |
|
| 229 | 229 | //this is a repeating section |
| 230 | 230 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
| 231 | 231 | } else { |
| 232 | 232 | // get all values for this field |
| 233 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
| 233 | + $child_values = isset( $entry->metas[$atts['embedded_field_id']] ) ? $entry->metas[$atts['embedded_field_id']] : false; |
|
| 234 | 234 | |
| 235 | 235 | if ( $child_values ) { |
| 236 | 236 | $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | $field_value = array(); |
| 241 | 241 | |
| 242 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 242 | + if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
| 243 | 243 | return $val; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -248,17 +248,17 @@ discard block |
||
| 248 | 248 | $atts['post_id'] = $child_entry->post_id; |
| 249 | 249 | |
| 250 | 250 | // get the value for this field -- check for post values as well |
| 251 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
| 251 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field ); |
|
| 252 | 252 | |
| 253 | 253 | if ( $entry_val ) { |
| 254 | 254 | // foreach entry get display_value |
| 255 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
| 255 | + $field_value[] = self::display_value( $entry_val, $field, $atts ); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - unset($child_entry); |
|
| 258 | + unset( $child_entry ); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - $val = implode(', ', (array) $field_value ); |
|
| 261 | + $val = implode( ', ', (array) $field_value ); |
|
| 262 | 262 | $val = wp_kses_post( $val ); |
| 263 | 263 | |
| 264 | 264 | return $val; |
@@ -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 = wp_kses_post( $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 |
@@ -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,7 +9,7 @@ discard block |
||
| 9 | 9 | static $transient_size = 200; |
| 10 | 10 | |
| 11 | 11 | public static function field_selection() { |
| 12 | - $fields = apply_filters('frm_available_fields', array( |
|
| 12 | + $fields = apply_filters( 'frm_available_fields', array( |
|
| 13 | 13 | 'text' => __( 'Single Line Text', 'formidable' ), |
| 14 | 14 | 'textarea' => __( 'Paragraph Text', 'formidable' ), |
| 15 | 15 | 'checkbox' => __( 'Checkboxes', 'formidable' ), |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | 'email' => __( 'Email Address', 'formidable' ), |
| 19 | 19 | 'url' => __( 'Website/URL', 'formidable' ), |
| 20 | 20 | 'captcha' => __( 'reCAPTCHA', 'formidable' ), |
| 21 | - )); |
|
| 21 | + ) ); |
|
| 22 | 22 | |
| 23 | 23 | return $fields; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public static function pro_field_selection() { |
| 27 | - return apply_filters('frm_pro_available_fields', array( |
|
| 27 | + return apply_filters( 'frm_pro_available_fields', array( |
|
| 28 | 28 | 'end_divider' => array( |
| 29 | 29 | 'name' => __( 'End Section', 'formidable' ), |
| 30 | 30 | 'switch_from' => 'divider', |
@@ -49,36 +49,36 @@ discard block |
||
| 49 | 49 | 'tag' => __( 'Tags', 'formidable' ), |
| 50 | 50 | 'credit_card' => __( 'Credit Card', 'formidable' ), |
| 51 | 51 | 'address' => __( 'Address', 'formidable' ), |
| 52 | - )); |
|
| 52 | + ) ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public static function create( $values, $return = true ) { |
| 56 | 56 | global $wpdb, $frm_duplicate_ids; |
| 57 | 57 | |
| 58 | 58 | $new_values = array(); |
| 59 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 59 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
| 60 | 60 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 61 | 61 | |
| 62 | 62 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 63 | - $new_values[ $col ] = $values[ $col ]; |
|
| 63 | + $new_values[$col] = $values[$col]; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $new_values['options'] = $values['options']; |
| 67 | 67 | |
| 68 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 69 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 70 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 68 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
| 69 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
| 70 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
| 71 | 71 | $new_values['field_options'] = $values['field_options']; |
| 72 | - $new_values['created_at'] = current_time('mysql', 1); |
|
| 72 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
| 73 | 73 | |
| 74 | 74 | if ( isset( $values['id'] ) ) { |
| 75 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
| 76 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 75 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
| 76 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | foreach ( $new_values as $k => $v ) { |
| 80 | 80 | if ( is_array( $v ) ) { |
| 81 | - $new_values[ $k ] = serialize( $v ); |
|
| 81 | + $new_values[$k] = serialize( $v ); |
|
| 82 | 82 | } |
| 83 | 83 | unset( $k, $v ); |
| 84 | 84 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | if ( $query_results ) { |
| 101 | 101 | if ( isset( $values['id'] ) ) { |
| 102 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
| 102 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
| 103 | 103 | } |
| 104 | 104 | return $new_id; |
| 105 | 105 | } else { |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 115 | 115 | |
| 116 | 116 | foreach ( (array) $fields as $field ) { |
| 117 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 118 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 119 | - $new_key = rtrim($new_key, 2); |
|
| 117 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
| 118 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
| 119 | + $new_key = rtrim( $new_key, 2 ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $values = array(); |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | $values['form_id'] = $new_repeat_form_id; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $values = apply_filters('frm_duplicated_field', $values); |
|
| 143 | - $new_id = self::create($values); |
|
| 144 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 145 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 146 | - unset($field); |
|
| 142 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
| 143 | + $new_id = self::create( $values ); |
|
| 144 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
| 145 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
| 146 | + unset( $field ); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( isset($values['required']) ) { |
|
| 159 | + if ( isset( $values['required'] ) ) { |
|
| 160 | 160 | $values['required'] = (int) $values['required']; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // serialize array values |
| 170 | 170 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
| 171 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
| 172 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
| 171 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
| 172 | + $values[$opt] = serialize( $values[$opt] ); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | if ( isset( $values['form_id'] ) ) { |
| 180 | 180 | $form_id = absint( $values['form_id'] ); |
| 181 | 181 | } else { |
| 182 | - $field = self::getOne($id); |
|
| 182 | + $field = self::getOne( $id ); |
|
| 183 | 183 | if ( $field ) { |
| 184 | 184 | $form_id = $field->form_id; |
| 185 | 185 | } |
| 186 | - unset($field); |
|
| 186 | + unset( $field ); |
|
| 187 | 187 | } |
| 188 | - unset($values); |
|
| 188 | + unset( $values ); |
|
| 189 | 189 | |
| 190 | 190 | if ( $query_results ) { |
| 191 | 191 | wp_cache_delete( $id, 'frm_field' ); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | FrmAppHelper::cache_delete_group( 'frm_field' ); |
| 240 | 240 | |
| 241 | - $form = FrmForm::getOne($form_id); |
|
| 241 | + $form = FrmForm::getOne( $form_id ); |
|
| 242 | 242 | if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) { |
| 243 | 243 | self::delete_form_transient( $form->parent_form_id ); |
| 244 | 244 | } |
@@ -260,16 +260,16 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | global $wpdb; |
| 262 | 262 | |
| 263 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 263 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
| 264 | 264 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
| 265 | 265 | |
| 266 | 266 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
| 267 | 267 | |
| 268 | - if ( empty($results) ) { |
|
| 268 | + if ( empty( $results ) ) { |
|
| 269 | 269 | return $results; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if ( is_numeric($id) ) { |
|
| 272 | + if ( is_numeric( $id ) ) { |
|
| 273 | 273 | FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' ); |
| 274 | 274 | } else if ( $results ) { |
| 275 | 275 | FrmAppHelper::set_cache( $results->id, $results, 'frm_field' ); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | self::prepare_options( $results ); |
| 279 | 279 | |
| 280 | - return stripslashes_deep($results); |
|
| 280 | + return stripslashes_deep( $results ); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -310,20 +310,20 @@ discard block |
||
| 310 | 310 | continue; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $fields[ $result->id ] = $result; |
|
| 314 | - $count++; |
|
| 313 | + $fields[$result->id] = $result; |
|
| 314 | + $count ++; |
|
| 315 | 315 | if ( $limit == 1 ) { |
| 316 | 316 | $fields = $result; |
| 317 | 317 | break; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 320 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 321 | 321 | break; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - unset($result); |
|
| 324 | + unset( $result ); |
|
| 325 | 325 | } |
| 326 | - return stripslashes_deep($fields); |
|
| 326 | + return stripslashes_deep( $fields ); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | self::$use_cache = false; |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 333 | 333 | $results = self::getAll( $where, 'field_order', $limit ); |
| 334 | 334 | self::$use_cache = true; |
| 335 | - self::include_sub_fields($results, $inc_sub, $type); |
|
| 335 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
| 336 | 336 | |
| 337 | 337 | return $results; |
| 338 | 338 | } |
@@ -344,15 +344,15 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 346 | 346 | if ( ! empty( $results ) ) { |
| 347 | - if ( empty($limit) ) { |
|
| 347 | + if ( empty( $limit ) ) { |
|
| 348 | 348 | return $results; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | $fields = array(); |
| 352 | 352 | $count = 0; |
| 353 | 353 | foreach ( $results as $result ) { |
| 354 | - $fields[ $result->id ] = $result; |
|
| 355 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 354 | + $fields[$result->id] = $result; |
|
| 355 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 356 | 356 | break; |
| 357 | 357 | } |
| 358 | 358 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 372 | 372 | |
| 373 | - if ( empty($limit) ) { |
|
| 373 | + if ( empty( $limit ) ) { |
|
| 374 | 374 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 375 | 375 | } |
| 376 | 376 | |
@@ -399,22 +399,22 @@ discard block |
||
| 399 | 399 | $form_fields = $results; |
| 400 | 400 | $index_offset = 1; |
| 401 | 401 | foreach ( $form_fields as $k => $field ) { |
| 402 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 402 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
| 403 | 403 | continue; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | if ( $type == 'all' ) { |
| 407 | 407 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
| 408 | 408 | } else { |
| 409 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 409 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if ( ! empty($sub_fields) ) { |
|
| 412 | + if ( ! empty( $sub_fields ) ) { |
|
| 413 | 413 | $index = $k + $index_offset; |
| 414 | 414 | $index_offset += count( $sub_fields ); |
| 415 | - array_splice($results, $index, 0, $sub_fields); |
|
| 415 | + array_splice( $results, $index, 0, $sub_fields ); |
|
| 416 | 416 | } |
| 417 | - unset($field, $sub_fields); |
|
| 417 | + unset( $field, $sub_fields ); |
|
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | 420 | |
@@ -422,9 +422,9 @@ discard block |
||
| 422 | 422 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 423 | 423 | if ( self::$use_cache ) { |
| 424 | 424 | // make sure old cache doesn't get saved as a transient |
| 425 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 425 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
| 426 | 426 | if ( false !== $results ) { |
| 427 | - return stripslashes_deep($results); |
|
| 427 | + return stripslashes_deep( $results ); |
|
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | 430 | |
@@ -449,16 +449,16 @@ discard block |
||
| 449 | 449 | $order_by = ' ORDER BY ' . $order_by; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - $limit = FrmAppHelper::esc_limit($limit); |
|
| 452 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
| 453 | 453 | |
| 454 | 454 | $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
| 455 | 455 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
| 456 | 456 | |
| 457 | - if ( is_array($where) ) { |
|
| 457 | + if ( is_array( $where ) ) { |
|
| 458 | 458 | $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
| 459 | 459 | } else { |
| 460 | 460 | // if the query is not an array, then it has already been prepared |
| 461 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 461 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
| 462 | 462 | |
| 463 | 463 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 464 | 464 | $results = $wpdb->$function_name( $query ); |
@@ -481,9 +481,9 @@ discard block |
||
| 481 | 481 | FrmAppHelper::set_cache( $result->id, $result, 'frm_field' ); |
| 482 | 482 | FrmAppHelper::set_cache( $result->field_key, $result, 'frm_field' ); |
| 483 | 483 | |
| 484 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
| 485 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
| 486 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
| 484 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
| 485 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
| 486 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
| 487 | 487 | |
| 488 | 488 | unset( $r_key, $result ); |
| 489 | 489 | } |
@@ -502,8 +502,8 @@ discard block |
||
| 502 | 502 | private static function prepare_options( &$results ) { |
| 503 | 503 | $results->field_options = maybe_unserialize( $results->field_options ); |
| 504 | 504 | |
| 505 | - $results->options = maybe_unserialize($results->options); |
|
| 506 | - $results->default_value = maybe_unserialize($results->default_value); |
|
| 505 | + $results->options = maybe_unserialize( $results->options ); |
|
| 506 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /** |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | |
| 531 | 531 | if ( count( $next_fields ) >= self::$transient_size ) { |
| 532 | 532 | // if this transient is full, check for another |
| 533 | - $next++; |
|
| 533 | + $next ++; |
|
| 534 | 534 | self::get_next_transient( $fields, $base_name, $next ); |
| 535 | 535 | } |
| 536 | 536 | } |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | return; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - $next++; |
|
| 559 | + $next ++; |
|
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | $field_type = is_array( $field ) ? $field['type'] : $field->type; |
| 611 | 611 | $data_type = self::get_option( $field, 'data_type' ); |
| 612 | 612 | |
| 613 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select') ) ); |
|
| 613 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select' ) ) ); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -656,23 +656,23 @@ discard block |
||
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | public static function is_option_true_in_array( $field, $option ) { |
| 659 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
| 659 | + return isset( $field[$option] ) && $field[$option]; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | public static function is_option_true_in_object( $field, $option ) { |
| 663 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
| 663 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | public static function is_option_empty_in_array( $field, $option ) { |
| 667 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
| 667 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | public static function is_option_empty_in_object( $field, $option ) { |
| 671 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
| 671 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | public static function is_option_value_in_object( $field, $option ) { |
| 675 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
| 675 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -688,11 +688,11 @@ discard block |
||
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | public static function get_option_in_array( $field, $option ) { |
| 691 | - return $field[ $option ]; |
|
| 691 | + return $field[$option]; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | public static function get_option_in_object( $field, $option ) { |
| 695 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
| 695 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |