Formidable Forms – Form Builder for WordPress - Version 2.0.08

Version Description

  • Fix security vulnerability allowing shortcodes to be excuted inside a form https://research.g0blin.co.uk/?p=618&d=i4ziyggqao0oz0L0vpUTd8KZwrO2P9Mw
  • Added frm_filter_final_form hook. This will need to be used to cover shortcodes that span multiple blocks of field HTML since we can't do a general shortcode replacement on the rendered form
  • Revert change that prevented scripts from firing in the form success message
  • Fix timestamp timezone on view/edit entry page
  • Added frm_entries_{$col_name}_column hook to allow custom columns on the entries listing page
  • Pro: Allow the last page of a form to be conditional
  • Pro: When a field is conditionally hidden, clear the value and trigger calculations and child logic
  • Pro: Improved accuracy of calculations using the other option, and across page breaks
  • Pro: Added frm_calendar_day_names hook for displaying the full weekday name in calendar view
  • Pro: Allow a comma-separated list of ids when filtering by entry id in the view settings
  • Pro: Include the remove link on multiple file uploads
  • Pro: Display a view row correctly right after a quick-edit
  • Pro: Delete views when their form is permanently deleted
  • Pro: Only show the ID column in google table when specified
  • Pro: Fix boolean values in google entry table
  • Pro: Reduce the memory usage when exporting a CSV by preventing entry caching
  • Pro: Fix dependent taxonomies
  • Pro: Fix the graph tooltips and wrap the text on graphs so it doesn't go beyond the width of the graph
  • Pro: Allow the frm_user_can_edit hook to fire when loading a form with the entry id in the form shortcode
  • Pro: Fix backslash removal in the phone format option when the form is saved
  • Pro: Make sure validation is always performed even if there are only radio fields on the page, before showing a message that the entry failed
  • Pro: Fix Dynamic List fields dependent on Dynamic checkboxes
  • Pro: Keep the user on the last page when a draft is saved and there is only one field on the last page
  • Pro: Export the category name in the CSV instead of the id
  • Pro: Save user ID even if it's in a conditional section/page
Download this release

Release Info

Developer sswells
Plugin Icon 128x128 Formidable Forms – Form Builder for WordPress
Version 2.0.08
Comparing to
See all releases

Code changes from version 2.0.07 to 2.0.08

Files changed (89) hide show
  1. classes/controllers/FrmAppController.php +1 -1
  2. classes/controllers/FrmFieldsController.php +8 -7
  3. classes/controllers/FrmFormActionsController.php +17 -15
  4. classes/controllers/FrmFormsController.php +83 -50
  5. classes/controllers/FrmHooksController.php +1 -1
  6. classes/controllers/FrmSettingsController.php +1 -1
  7. classes/controllers/FrmStylesController.php +4 -4
  8. classes/controllers/FrmXMLController.php +5 -6
  9. classes/helpers/FrmAppHelper.php +73 -43
  10. classes/helpers/FrmEntriesHelper.php +38 -24
  11. classes/helpers/FrmEntriesListHelper.php +43 -32
  12. classes/helpers/FrmFieldsHelper.php +59 -20
  13. classes/helpers/FrmFormsHelper.php +5 -3
  14. classes/helpers/FrmFormsListHelper.php +1 -1
  15. classes/helpers/FrmListHelper.php +1 -1
  16. classes/helpers/FrmStylesHelper.php +16 -16
  17. classes/helpers/FrmXMLHelper.php +45 -24
  18. classes/models/FrmDb.php +7 -7
  19. classes/models/FrmEntry.php +22 -18
  20. classes/models/FrmEntryMeta.php +9 -9
  21. classes/models/FrmField.php +42 -35
  22. classes/models/FrmForm.php +11 -11
  23. classes/models/FrmFormAction.php +6 -7
  24. classes/models/FrmNotification.php +3 -3
  25. classes/models/FrmStyle.php +2 -2
  26. classes/views/frm-entries/_sidebar-shared-pub.php +3 -3
  27. classes/views/frm-entries/direct.php +1 -1
  28. classes/views/frm-entries/errors.php +4 -2
  29. classes/views/frm-entries/form.php +4 -3
  30. classes/views/frm-entries/new.php +1 -1
  31. classes/views/frm-entries/sidebar-shared.php +4 -4
  32. classes/views/frm-fields/import_choices.php +1 -1
  33. classes/views/frm-fields/input.php +8 -5
  34. classes/views/frm-fields/show-build.php +9 -8
  35. classes/views/frm-fields/show.php +0 -4
  36. classes/views/frm-fields/single-option.php +2 -2
  37. classes/views/frm-form-actions/_action_inside.php +1 -1
  38. classes/views/frm-form-actions/_email_settings.php +1 -1
  39. classes/views/frm-form-actions/email_action.php +2 -2
  40. classes/views/frm-form-actions/form_action.php +1 -1
  41. classes/views/frm-forms/_publish_box.php +1 -1
  42. classes/views/frm-forms/add_field.php +8 -6
  43. classes/views/frm-forms/add_field_links.php +7 -7
  44. classes/views/frm-forms/form.php +1 -1
  45. classes/views/frm-forms/insert_form_popup.php +1 -1
  46. classes/views/frm-forms/mb_html_tab.php +7 -7
  47. classes/views/frm-forms/mb_insert_fields.php +1 -1
  48. classes/views/frm-forms/settings.php +2 -2
  49. classes/views/frm-forms/shortcode_opts.php +1 -1
  50. classes/views/frm-forms/sidebar-settings.php +1 -1
  51. classes/views/frm-settings/form.php +2 -2
  52. classes/views/frm-settings/license_box.php +1 -1
  53. classes/views/frm-statistics/list.php +1 -2
  54. classes/views/frm-statistics/list_displays.php +1 -2
  55. classes/views/shared/errors.php +1 -1
  56. classes/views/shared/mb_adv_info.php +2 -2
  57. classes/views/shared/update_message.php +1 -1
  58. classes/views/styles/_check-box-radio-fields.php +1 -1
  59. classes/views/styles/_field-description.php +1 -1
  60. classes/views/styles/_field-labels.php +1 -1
  61. classes/views/styles/_field-sizes.php +1 -1
  62. classes/views/styles/_general.php +1 -1
  63. classes/views/styles/_sample_form.php +1 -1
  64. classes/views/styles/_section-fields.php +1 -1
  65. classes/views/styles/manage.php +1 -1
  66. classes/views/styles/show.php +1 -1
  67. classes/views/xml/forms_xml.php +2 -2
  68. classes/views/xml/import_form.php +1 -1
  69. classes/views/xml/posts_xml.php +2 -2
  70. classes/views/xml/xml.php +2 -2
  71. css/_single_theme.css.php +1 -1
  72. css/frm_admin.css +23 -2
  73. formidable.php +1 -1
  74. images/recaptcha.png +0 -0
  75. js/formidable.min.js +52 -49
  76. js/formidable_admin.js +1 -1
  77. languages/formidable-da_DK.mo +0 -0
  78. languages/formidable-da_DK.po +765 -763
  79. languages/formidable-de_DE.mo +0 -0
  80. languages/formidable-de_DE.po +765 -763
  81. languages/formidable-en_US.po +765 -763
  82. languages/formidable-es_ES.mo +0 -0
  83. languages/formidable-es_ES.po +765 -763
  84. languages/formidable-fr_FR.mo +0 -0
  85. languages/formidable-fr_FR.po +765 -763
  86. languages/formidable-it_IT.mo +0 -0
  87. languages/formidable-it_IT.po +765 -763
  88. languages/formidable-nl_NL.mo +0 -0
  89. languages/formidable-nl_NL.po +149 -149
classes/controllers/FrmAppController.php CHANGED
@@ -414,7 +414,7 @@ class FrmAppController {
414
 
415
  //disable the plugin and redirect after uninstall so the tables don't get added right back
416
  deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false );
417
- echo admin_url( 'plugins.php?deactivate=true' );
418
  } else {
419
  $frm_settings = FrmAppHelper::get_settings();
420
  wp_die( $frm_settings->admin_permission );
414
 
415
  //disable the plugin and redirect after uninstall so the tables don't get added right back
416
  deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false );
417
+ echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
418
  } else {
419
  $frm_settings = FrmAppHelper::get_settings();
420
  wp_die( $frm_settings->admin_permission );
classes/controllers/FrmFieldsController.php CHANGED
@@ -90,10 +90,11 @@ class FrmFieldsController {
90
  $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
91
 
92
  if ( ! $field_id || ! $form_id ) {
93
- return;
94
  }
95
 
96
- FrmField::update( $field_id, compact('form_id') );
 
97
 
98
  wp_die();
99
  }
@@ -118,7 +119,7 @@ class FrmFieldsController {
118
  }
119
 
120
  FrmField::update( $id, array( $field => $value ) );
121
- echo stripslashes($value);
122
  wp_die();
123
  }
124
 
@@ -160,17 +161,17 @@ class FrmFieldsController {
160
  global $wpdb;
161
 
162
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
 
 
163
  $copy_field = FrmField::getOne( $field_id );
164
  if ( ! $copy_field ) {
165
  wp_die();
166
  }
167
 
168
- $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
169
-
170
  do_action('frm_duplicate_field', $copy_field, $form_id);
171
  do_action('frm_duplicate_field_'. $copy_field->type, $copy_field, $form_id);
172
 
173
- $values = array();
174
  FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
175
 
176
  $field_count = FrmDb::get_count( $wpdb->prefix .'frm_fields fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) );
@@ -647,7 +648,7 @@ class FrmFieldsController {
647
  $add_html['placeholder'] = 'placeholder="'. esc_attr($field['default_value']) .'"';
648
  wp_enqueue_script('jquery-placeholder');
649
  } else if ( ! $frm_settings->use_html ) {
650
- $val = str_replace( array("\r\n", "\n"), '\r', addslashes(str_replace(''', "'", esc_attr($field['default_value']))));
651
  $add_html['data-frmval'] = 'data-frmval="'. esc_attr($val) .'"';
652
  $class[] = 'frm_toggle_default';
653
 
90
  $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
91
 
92
  if ( ! $field_id || ! $form_id ) {
93
+ wp_die();
94
  }
95
 
96
+ $updated = FrmField::update( $field_id, compact( 'form_id' ) );
97
+ echo absint( $updated );
98
 
99
  wp_die();
100
  }
119
  }
120
 
121
  FrmField::update( $id, array( $field => $value ) );
122
+ echo stripslashes( wp_kses_post( $value ) );
123
  wp_die();
124
  }
125
 
161
  global $wpdb;
162
 
163
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
164
+ $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
165
+
166
  $copy_field = FrmField::getOne( $field_id );
167
  if ( ! $copy_field ) {
168
  wp_die();
169
  }
170
 
 
 
171
  do_action('frm_duplicate_field', $copy_field, $form_id);
172
  do_action('frm_duplicate_field_'. $copy_field->type, $copy_field, $form_id);
173
 
174
+ $values = array( 'id' => $form_id );
175
  FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
176
 
177
  $field_count = FrmDb::get_count( $wpdb->prefix .'frm_fields fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) );
648
  $add_html['placeholder'] = 'placeholder="'. esc_attr($field['default_value']) .'"';
649
  wp_enqueue_script('jquery-placeholder');
650
  } else if ( ! $frm_settings->use_html ) {
651
+ $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) );
652
  $add_html['data-frmval'] = 'data-frmval="'. esc_attr($val) .'"';
653
  $class[] = 'frm_toggle_default';
654
 
classes/controllers/FrmFormActionsController.php CHANGED
@@ -181,7 +181,7 @@ class FrmFormActionsController {
181
  private static function fields_to_values($form_id, array &$values) {
182
  $form = FrmForm::getOne($form_id);
183
 
184
- $values = array( 'fields' => array(), 'id' => $form->id);
185
 
186
  $fields = FrmField::get_all_for_form($form->id);
187
  foreach ( $fields as $k => $f ) {
@@ -203,7 +203,7 @@ class FrmFormActionsController {
203
 
204
  $registered_actions = self::$registered_actions->actions;
205
 
206
- $old_actions = FrmDb::get_col( $wpdb->posts, array( 'post_type' => self::$action_post_type, 'menu_order' => $form_id), 'ID' );
207
  $new_actions = array();
208
 
209
  foreach ( $registered_actions as $registered_action ) {
@@ -219,15 +219,18 @@ class FrmFormActionsController {
219
  }
220
  $old_actions = array_diff( $old_actions, $new_actions );
221
 
222
- // delete any actions that were not included on the page
223
- if ( ! empty( $old_actions ) ) {
224
- foreach ( $old_actions as $old_id ) {
225
- wp_delete_post( $old_id );
226
- }
227
- FrmAppHelper::cache_delete_group( 'frm_actions' );
228
- }
229
  }
230
 
 
 
 
 
 
 
 
 
 
231
  public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
232
  self::trigger_actions( 'create', $form_id, $entry_id, 'all', $args );
233
  }
@@ -261,6 +264,10 @@ class FrmFormActionsController {
261
  $entry = FrmEntry::getOne( $entry, true );
262
  }
263
 
 
 
 
 
264
  $child_entry = ( ( $form && is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ( isset( $args['is_child'] ) && $args['is_child'] ) );
265
 
266
  if ( $child_entry ) {
@@ -268,11 +275,6 @@ class FrmFormActionsController {
268
  continue;
269
  }
270
 
271
- if ( $entry->is_draft ) {
272
- // TODO: add trigger actions for drafts
273
- continue;
274
- }
275
-
276
  // check conditional logic
277
  $stop = FrmFormActionsHelper::action_conditions_met($action, $entry);
278
  if ( $stop ) {
@@ -360,4 +362,4 @@ class Frm_Form_Action_Factory {
360
  }
361
  }
362
  }
363
- }
181
  private static function fields_to_values($form_id, array &$values) {
182
  $form = FrmForm::getOne($form_id);
183
 
184
+ $values = array( 'fields' => array(), 'id' => $form->id );
185
 
186
  $fields = FrmField::get_all_for_form($form->id);
187
  foreach ( $fields as $k => $f ) {
203
 
204
  $registered_actions = self::$registered_actions->actions;
205
 
206
+ $old_actions = FrmDb::get_col( $wpdb->posts, array( 'post_type' => self::$action_post_type, 'menu_order' => $form_id ), 'ID' );
207
  $new_actions = array();
208
 
209
  foreach ( $registered_actions as $registered_action ) {
219
  }
220
  $old_actions = array_diff( $old_actions, $new_actions );
221
 
222
+ self::delete_missing_actions( $old_actions );
 
 
 
 
 
 
223
  }
224
 
225
+ public static function delete_missing_actions( $old_actions ) {
226
+ if ( ! empty( $old_actions ) ) {
227
+ foreach ( $old_actions as $old_id ) {
228
+ wp_delete_post( $old_id );
229
+ }
230
+ FrmAppHelper::cache_delete_group( 'frm_actions' );
231
+ }
232
+ }
233
+
234
  public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
235
  self::trigger_actions( 'create', $form_id, $entry_id, 'all', $args );
236
  }
264
  $entry = FrmEntry::getOne( $entry, true );
265
  }
266
 
267
+ if ( empty( $entry ) || $entry->is_draft ) {
268
+ continue;
269
+ }
270
+
271
  $child_entry = ( ( $form && is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ( isset( $args['is_child'] ) && $args['is_child'] ) );
272
 
273
  if ( $child_entry ) {
275
  continue;
276
  }
277
 
 
 
 
 
 
278
  // check conditional logic
279
  $stop = FrmFormActionsHelper::action_conditions_met($action, $entry);
280
  if ( $stop ) {
362
  }
363
  }
364
  }
365
+ }
classes/controllers/FrmFormsController.php CHANGED
@@ -35,7 +35,7 @@ class FrmFormsController {
35
  $errors = self::process_bulk_form_actions( array());
36
  $errors = apply_filters('frm_admin_list_form_action', $errors);
37
 
38
- return self::display_forms_list($params, '', false, $errors);
39
  }
40
 
41
  public static function new_form( $values = array() ) {
@@ -220,7 +220,7 @@ class FrmFormsController {
220
  FrmForm::destroy( $current_form );
221
  }
222
 
223
- echo admin_url( 'admin.php?page=formidable&action=duplicate&id=' . $template_id );
224
  wp_die();
225
  }
226
 
@@ -332,7 +332,7 @@ class FrmFormsController {
332
 
333
  $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
334
 
335
- self::display_forms_list($params, $message, 1);
336
  }
337
 
338
  public static function bulk_destroy($ids) {
@@ -355,14 +355,14 @@ class FrmFormsController {
355
  //check nonce url
356
  $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
357
  if ( $permission_error !== false ) {
358
- self::display_forms_list( array(), '', 1, array( $permission_error ) );
359
  return;
360
  }
361
 
362
  $count = self::scheduled_delete(time());
363
  $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
364
 
365
- self::display_forms_list( array(), $message, 1 );
366
  }
367
 
368
  /**
@@ -372,7 +372,7 @@ class FrmFormsController {
372
  public static function scheduled_delete($delete_timestamp = '') {
373
  global $wpdb;
374
 
375
- $trash_forms = FrmDb::get_results($wpdb->prefix .'frm_forms', array( 'status' => 'trash'), 'id, options' );
376
 
377
  if ( ! $trash_forms ) {
378
  return;
@@ -405,14 +405,14 @@ class FrmFormsController {
405
 
406
  public static function insert_form_popup() {
407
  $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
408
- if ( ! in_array($page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php') ) ) {
409
  return;
410
  }
411
 
412
  FrmAppHelper::load_admin_wide_js();
413
 
414
  $shortcodes = array(
415
- 'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' )),
416
  );
417
 
418
  $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
@@ -438,9 +438,9 @@ class FrmFormsController {
438
  $opts = array(
439
  'form_id' => 'id',
440
  //'key' => ',
441
- 'title' => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' )),
442
- 'description' => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' )),
443
- 'minimize' => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' )),
444
  );
445
  break;
446
  }
@@ -459,8 +459,12 @@ class FrmFormsController {
459
  wp_die();
460
  }
461
 
462
- public static function display_forms_list( $params = array(), $message = '', $current_page_ov = false, $errors = array() ) {
463
  FrmAppHelper::permission_check( 'frm_view_forms' );
 
 
 
 
464
 
465
  global $wpdb, $frm_vars;
466
 
@@ -715,14 +719,7 @@ class FrmFormsController {
715
  }
716
 
717
  public static function filter_content( $content, $form, $entry = false ) {
718
- if ( ! $entry || ! is_object( $entry ) ) {
719
- if ( ! $entry || ! is_numeric( $entry ) ) {
720
- $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
721
- }
722
-
723
- FrmEntriesHelper::maybe_get_entry( $entry );
724
- }
725
-
726
  if ( ! $entry ) {
727
  return $content;
728
  }
@@ -737,6 +734,16 @@ class FrmFormsController {
737
  return $content;
738
  }
739
 
 
 
 
 
 
 
 
 
 
 
740
  public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
741
  return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
742
  }
@@ -746,7 +753,7 @@ class FrmFormsController {
746
  return $errors;
747
  }
748
 
749
- $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_title' );
750
  if ( $bulkaction == -1 ) {
751
  $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
752
  }
@@ -803,7 +810,7 @@ class FrmFormsController {
803
 
804
  for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) {
805
  $filename = str_replace( '.php', '', str_replace( $path.'/', '', $templates[ $i ] ) );
806
- $template_query = array( 'form_key' => $filename);
807
  if ( $template ) {
808
  $template_query['is_template'] = 1;
809
  }
@@ -832,7 +839,7 @@ class FrmFormsController {
832
  }
833
 
834
  if ( $form ) {
835
- do_action('frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id));
836
  }
837
  }
838
  }
@@ -890,7 +897,7 @@ class FrmFormsController {
890
  return;
891
  }
892
 
893
- $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_title' );
894
  if ( $action == -1 ) {
895
  $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
896
  }
@@ -963,7 +970,7 @@ class FrmFormsController {
963
  'parent' => 'frm-forms',
964
  'id' => 'edit_form_'. $form_id,
965
  'title' => empty($name) ? __( '(no title)') : $name,
966
- 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
967
  ) );
968
  }
969
  }
@@ -1015,29 +1022,40 @@ class FrmFormsController {
1015
 
1016
  $frm_settings = FrmAppHelper::get_settings();
1017
 
1018
- // don't show a draft form on a page
1019
- global $post;
1020
- if ( $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ( ! $post || $post->ID != $frm_settings->preview_page_id ) && ! FrmAppHelper::is_preview_page() ) {
1021
- return __( 'Please select a valid form', 'formidable' );
1022
- }
1023
-
1024
- // don't show the form if user should be logged in
1025
- if ( $form->logged_in && ! is_user_logged_in() ) {
1026
- return do_shortcode( $frm_settings->login_msg );
1027
- }
 
 
 
 
 
 
 
1028
 
1029
- // don't show the form if user doesn't have permission
1030
- if ( $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] ) ) {
1031
- return do_shortcode( $frm_settings->login_msg );
1032
- }
1033
 
1034
- $form = self::get_form( $form, $title, $description, $atts );
 
 
 
 
1035
 
1036
- // check for external shortcodes
1037
- $form = do_shortcode( $form );
 
1038
 
1039
- return $form;
1040
- }
 
1041
 
1042
  public static function get_form( $form, $title, $description, $atts = array() ) {
1043
  ob_start();
@@ -1048,10 +1066,7 @@ class FrmFormsController {
1048
  $contents = ob_get_contents();
1049
  ob_end_clean();
1050
 
1051
- // check if minimizing is turned on
1052
- if ( isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ) ) {
1053
- $contents = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $contents );
1054
- }
1055
 
1056
  return $contents;
1057
  }
@@ -1101,7 +1116,7 @@ class FrmFormsController {
1101
 
1102
  if ( $created && is_numeric($created) && $conf_method != 'message' ) {
1103
  do_action('frm_success_action', $conf_method, $form, $form->options, $created);
1104
- do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
1105
  return;
1106
  }
1107
 
@@ -1126,6 +1141,24 @@ class FrmFormsController {
1126
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
1127
  }
1128
 
1129
- do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
1130
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1131
  }
35
  $errors = self::process_bulk_form_actions( array());
36
  $errors = apply_filters('frm_admin_list_form_action', $errors);
37
 
38
+ return self::display_forms_list( $params, '', $errors );
39
  }
40
 
41
  public static function new_form( $values = array() ) {
220
  FrmForm::destroy( $current_form );
221
  }
222
 
223
+ echo esc_url_raw( admin_url( 'admin.php?page=formidable&action=duplicate&id=' . $template_id ) );
224
  wp_die();
225
  }
226
 
332
 
333
  $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
334
 
335
+ self::display_forms_list( $params, $message );
336
  }
337
 
338
  public static function bulk_destroy($ids) {
355
  //check nonce url
356
  $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
357
  if ( $permission_error !== false ) {
358
+ self::display_forms_list( array(), '', array( $permission_error ) );
359
  return;
360
  }
361
 
362
  $count = self::scheduled_delete(time());
363
  $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
364
 
365
+ self::display_forms_list( array(), $message );
366
  }
367
 
368
  /**
372
  public static function scheduled_delete($delete_timestamp = '') {
373
  global $wpdb;
374
 
375
+ $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' );
376
 
377
  if ( ! $trash_forms ) {
378
  return;
405
 
406
  public static function insert_form_popup() {
407
  $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
408
+ if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
409
  return;
410
  }
411
 
412
  FrmAppHelper::load_admin_wide_js();
413
 
414
  $shortcodes = array(
415
+ 'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' ) ),
416
  );
417
 
418
  $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
438
  $opts = array(
439
  'form_id' => 'id',
440
  //'key' => ',
441
+ 'title' => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' ) ),
442
+ 'description' => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' ) ),
443
+ 'minimize' => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' ) ),
444
  );
445
  break;
446
  }
459
  wp_die();
460
  }
461
 
462
+ public static function display_forms_list( $params = array(), $message = '', $errors = array(), $deprecated_errors = array() ) {
463
  FrmAppHelper::permission_check( 'frm_view_forms' );
464
+ if ( ! empty( $deprecated_errors ) ) {
465
+ $errors = $deprecated_errors;
466
+ _deprecated_argument( 'errors', '2.0.8' );
467
+ }
468
 
469
  global $wpdb, $frm_vars;
470
 
719
  }
720
 
721
  public static function filter_content( $content, $form, $entry = false ) {
722
+ self::get_entry_by_param( $entry );
 
 
 
 
 
 
 
723
  if ( ! $entry ) {
724
  return $content;
725
  }
734
  return $content;
735
  }
736
 
737
+ private static function get_entry_by_param( &$entry ) {
738
+ if ( ! $entry || ! is_object( $entry ) ) {
739
+ if ( ! $entry || ! is_numeric( $entry ) ) {
740
+ $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
741
+ }
742
+
743
+ FrmEntriesHelper::maybe_get_entry( $entry );
744
+ }
745
+ }
746
+
747
  public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
748
  return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
749
  }
753
  return $errors;
754
  }
755
 
756
+ $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
757
  if ( $bulkaction == -1 ) {
758
  $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
759
  }
810
 
811
  for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) {
812
  $filename = str_replace( '.php', '', str_replace( $path.'/', '', $templates[ $i ] ) );
813
+ $template_query = array( 'form_key' => $filename );
814
  if ( $template ) {
815
  $template_query['is_template'] = 1;
816
  }
839
  }
840
 
841
  if ( $form ) {
842
+ do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) );
843
  }
844
  }
845
  }
897
  return;
898
  }
899
 
900
+ $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
901
  if ( $action == -1 ) {
902
  $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
903
  }
970
  'parent' => 'frm-forms',
971
  'id' => 'edit_form_'. $form_id,
972
  'title' => empty($name) ? __( '(no title)') : $name,
973
+ 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ),
974
  ) );
975
  }
976
  }
1022
 
1023
  $frm_settings = FrmAppHelper::get_settings();
1024
 
1025
+ if ( self::is_viewable_draft_form( $form ) ) {
1026
+ // don't show a draft form on a page
1027
+ $form = __( 'Please select a valid form', 'formidable' );
1028
+ } else if ( self::user_should_login( $form ) ) {
1029
+ $form = do_shortcode( $frm_settings->login_msg );
1030
+ } else if ( self::user_has_permission_to_view( $form ) ) {
1031
+ $form = do_shortcode( $frm_settings->login_msg );
1032
+ } else {
1033
+ $form = self::get_form( $form, $title, $description, $atts );
1034
+
1035
+ /**
1036
+ * Use this shortcode to check for external shortcodes that may span
1037
+ * across multiple fields in the customizable HTML
1038
+ * @since 2.0.8
1039
+ */
1040
+ $form = apply_filters( 'frm_filter_final_form', $form );
1041
+ }
1042
 
1043
+ return $form;
1044
+ }
 
 
1045
 
1046
+ private static function is_viewable_draft_form( $form ) {
1047
+ global $post;
1048
+ $frm_settings = FrmAppHelper::get_settings();
1049
+ return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ( ! $post || $post->ID != $frm_settings->preview_page_id ) && ! FrmAppHelper::is_preview_page();
1050
+ }
1051
 
1052
+ private static function user_should_login( $form ) {
1053
+ return $form->logged_in && ! is_user_logged_in();
1054
+ }
1055
 
1056
+ private static function user_has_permission_to_view( $form ) {
1057
+ return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
1058
+ }
1059
 
1060
  public static function get_form( $form, $title, $description, $atts = array() ) {
1061
  ob_start();
1066
  $contents = ob_get_contents();
1067
  ob_end_clean();
1068
 
1069
+ self::maybe_minimize_form( $atts, $contents );
 
 
 
1070
 
1071
  return $contents;
1072
  }
1116
 
1117
  if ( $created && is_numeric($created) && $conf_method != 'message' ) {
1118
  do_action('frm_success_action', $conf_method, $form, $form->options, $created);
1119
+ do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) );
1120
  return;
1121
  }
1122
 
1141
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
1142
  }
1143
 
1144
+ do_action( 'frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form ) );
1145
  }
1146
+
1147
+ /**
1148
+ * @since 2.0.8
1149
+ */
1150
+ private static function maybe_minimize_form( $atts, &$content ) {
1151
+ // check if minimizing is turned on
1152
+ if ( self::is_minification_on( $atts ) ) {
1153
+ $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
1154
+ }
1155
+ }
1156
+
1157
+ /**
1158
+ * @since 2.0.8
1159
+ * @return boolean
1160
+ */
1161
+ private static function is_minification_on( $atts ) {
1162
+ return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
1163
+ }
1164
  }
classes/controllers/FrmHooksController.php CHANGED
@@ -203,4 +203,4 @@ class FrmHooksController {
203
  // drop tables when mu site is deleted
204
  add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
205
  }
206
- }
203
  // drop tables when mu site is deleted
204
  add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
205
  }
206
+ }
classes/controllers/FrmSettingsController.php CHANGED
@@ -34,7 +34,7 @@ class FrmSettingsController {
34
 
35
  $frm_settings = FrmAppHelper::get_settings();
36
 
37
- $process_form = FrmAppHelper::simple_request( array( 'param' => 'process_form', 'sanitize' => 'sanitize_text_field', 'type' => 'post' ) );
38
  if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
39
  wp_die( $frm_settings->admin_permission );
40
  }
34
 
35
  $frm_settings = FrmAppHelper::get_settings();
36
 
37
+ $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
38
  if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
39
  wp_die( $frm_settings->admin_permission );
40
  }
classes/controllers/FrmStylesController.php CHANGED
@@ -35,8 +35,8 @@ class FrmStylesController {
35
  'menu_name' => __( 'Style', 'formidable' ),
36
  'edit' => __( 'Edit' ),
37
  'add_new_item' => __( 'Create a New Style', 'formidable' ),
38
- 'edit_item' => __( 'Edit Style', 'formidable' )
39
- )
40
  ) );
41
  }
42
 
@@ -53,7 +53,7 @@ class FrmStylesController {
53
  wp_enqueue_script('jquery-ui-datepicker');
54
 
55
  $version = FrmAppHelper::plugin_version();
56
- wp_enqueue_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array( 'jquery'), $version);
57
 
58
  wp_enqueue_style('jquery-ui-base', FrmAppHelper::jquery_ui_base_url() .'/themes/base/ui.all.css');
59
  wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css');
@@ -157,7 +157,7 @@ class FrmStylesController {
157
 
158
  $form->options['custom_style'] = $_POST['style'][ $form->id ];
159
 
160
- $wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => maybe_serialize($form->options)), array( 'id' => $form->id));
161
  unset($form);
162
  }
163
 
35
  'menu_name' => __( 'Style', 'formidable' ),
36
  'edit' => __( 'Edit' ),
37
  'add_new_item' => __( 'Create a New Style', 'formidable' ),
38
+ 'edit_item' => __( 'Edit Style', 'formidable' ),
39
+ ),
40
  ) );
41
  }
42
 
53
  wp_enqueue_script('jquery-ui-datepicker');
54
 
55
  $version = FrmAppHelper::plugin_version();
56
+ wp_enqueue_script( 'jquery-frm-themepicker', FrmAppHelper::plugin_url() . '/js/jquery/jquery-ui-themepicker.js', array( 'jquery' ), $version );
57
 
58
  wp_enqueue_style('jquery-ui-base', FrmAppHelper::jquery_ui_base_url() .'/themes/base/ui.all.css');
59
  wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css');
157
 
158
  $form->options['custom_style'] = $_POST['style'][ $form->id ];
159
 
160
+ $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
161
  unset($form);
162
  }
163
 
classes/controllers/FrmXMLController.php CHANGED
@@ -15,7 +15,7 @@ class FrmXMLController {
15
  $set_err = libxml_use_internal_errors(true);
16
  $loader = libxml_disable_entity_loader( true );
17
 
18
- $files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
19
 
20
  foreach ( (array) $files as $file ) {
21
  FrmXMLHelper::import_xml($file);
@@ -98,8 +98,8 @@ class FrmXMLController {
98
  //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
99
 
100
  $export_format = apply_filters('frm_export_formats', array(
101
- 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
102
- ));
103
 
104
  $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
105
  if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
@@ -177,7 +177,7 @@ class FrmXMLController {
177
  'actions' => $wpdb->posts,
178
  );
179
 
180
- $defaults = array( 'ids' => false);
181
  $args = wp_parse_args( $args, $defaults );
182
 
183
  $sitename = sanitize_key( get_bloginfo( 'name' ) );
@@ -282,5 +282,4 @@ class FrmXMLController {
282
 
283
  return $mimes;
284
  }
285
-
286
- }
15
  $set_err = libxml_use_internal_errors(true);
16
  $loader = libxml_disable_entity_loader( true );
17
 
18
+ $files = apply_filters( 'frm_default_templates_files', array( FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml' ) );
19
 
20
  foreach ( (array) $files as $file ) {
21
  FrmXMLHelper::import_xml($file);
98
  //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
99
 
100
  $export_format = apply_filters('frm_export_formats', array(
101
+ 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
102
+ ) );
103
 
104
  $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
105
  if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
177
  'actions' => $wpdb->posts,
178
  );
179
 
180
+ $defaults = array( 'ids' => false );
181
  $args = wp_parse_args( $args, $defaults );
182
 
183
  $sitename = sanitize_key( get_bloginfo( 'name' ) );
282
 
283
  return $mimes;
284
  }
285
+ }
 
classes/helpers/FrmAppHelper.php CHANGED
@@ -10,7 +10,7 @@ class FrmAppHelper {
10
  /**
11
  * @since 2.0
12
  */
13
- public static $plug_version = '2.0.07';
14
 
15
  /**
16
  * @since 1.07.02
@@ -138,6 +138,14 @@ class FrmAppHelper {
138
  return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
139
  }
140
 
 
 
 
 
 
 
 
 
141
  /**
142
  * Check if on an admin page
143
  *
@@ -211,9 +219,9 @@ class FrmAppHelper {
211
  if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
212
  $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
213
  }
214
- self::sanitize_value( $value, $sanitize );
215
  } else {
216
- $value = self::simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
217
  }
218
 
219
  if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
@@ -231,20 +239,13 @@ class FrmAppHelper {
231
  }
232
 
233
  /**
234
- * @todo Deprecate this and use simple_request instead
235
  *
236
  * @param string $param
237
  * @param mixed $default
238
  * @param string $sanitize
239
  */
240
  public static function get_post_param( $param, $default = '', $sanitize = '' ) {
241
- return self::simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
242
- }
243
-
244
- public static function sanitize_value( &$value, $sanitize ) {
245
- if ( ! empty( $sanitize ) ) {
246
- $value = call_user_func( $sanitize, $value );
247
- }
248
  }
249
 
250
  /**
@@ -253,11 +254,9 @@ class FrmAppHelper {
253
  * @param string $param
254
  * @param string $sanitize
255
  * @param string $default
256
- *
257
- * @todo Deprecate this and use simple_request instead
258
  */
259
  public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
260
- return self::simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
261
  }
262
 
263
  /**
@@ -265,7 +264,7 @@ class FrmAppHelper {
265
  *
266
  * @since 2.0.6
267
  */
268
- public static function simple_request( $args ) {
269
  $defaults = array(
270
  'param' => '', 'default' => '',
271
  'type' => 'get', 'sanitize' => 'sanitize_text_field',
@@ -287,15 +286,40 @@ class FrmAppHelper {
287
  }
288
  }
289
 
290
- self::sanitize_value( $value, $args['sanitize'] );
291
  return $value;
292
  }
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  public static function sanitize_request( $sanitize_method, &$values ) {
295
  $temp_values = $values;
296
  foreach ( $temp_values as $k => $val ) {
297
  if ( isset( $sanitize_method[ $k ] ) ) {
298
- call_user_func( $sanitize_method[ $k ], $val );
299
  }
300
  }
301
  }
@@ -391,7 +415,9 @@ class FrmAppHelper {
391
  $results = $wpdb->{$type}($query);
392
  }
393
 
394
- wp_cache_set($cache_key, $results, $group, $time);
 
 
395
 
396
  return $results;
397
  }
@@ -765,7 +791,7 @@ class FrmAppHelper {
765
 
766
  public static function replace_quotes($val) {
767
  //Replace double quotes
768
- $val = str_replace( array( '“', '”', '″'), '"', $val);
769
  //Replace single quotes
770
  $val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val );
771
  return $val;
@@ -864,17 +890,17 @@ class FrmAppHelper {
864
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
865
  }
866
 
867
- if ( is_numeric($key) || in_array($key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')) ) {
868
  $key = $key .'a';
869
  }
870
 
871
- $key_check = FrmDb::get_var( $table_name, array($column => $key, 'ID !' => $id), $column );
872
 
873
  if ( $key_check || is_numeric($key_check) ) {
874
  $suffix = 2;
875
  do {
876
  $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
877
- $key_check = FrmDb::get_var( $table_name, array($column => $alt_post_name, 'ID !' => $id), $column );
878
  $suffix++;
879
  } while ($key_check || is_numeric($key_check));
880
  $key = $alt_post_name;
@@ -898,9 +924,9 @@ class FrmAppHelper {
898
  $post_values = stripslashes_deep($_POST);
899
  }
900
 
901
- $values = array( 'id' => $record->id, 'fields' => array());
902
 
903
- foreach ( array( 'name', 'description') as $var ) {
904
  $default_val = isset($record->{$var}) ? $record->{$var} : '';
905
  $values[ $var ] = self::get_param( $var, $default_val );
906
  unset($var, $default_val);
@@ -939,7 +965,7 @@ class FrmAppHelper {
939
  if ( ! isset($field->field_options['custom_field']) ) {
940
  $field->field_options['custom_field'] = '';
941
  }
942
- $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
943
  } else {
944
  $meta_value = self::get_meta_value($field->id, $record);
945
  }
@@ -1046,7 +1072,7 @@ class FrmAppHelper {
1046
  $values['custom_style'] = ( $post_values && isset( $post_values['options']['custom_style'] ) ) ? absint( $_POST['options']['custom_style'] ) : ( $frm_settings->load_style != 'none' );
1047
  }
1048
 
1049
- foreach ( array( 'before', 'after', 'submit') as $h ) {
1050
  if ( ! isset( $values[ $h .'_html' ] ) ) {
1051
  $values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) );
1052
  }
@@ -1144,27 +1170,31 @@ class FrmAppHelper {
1144
  $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1145
  }
1146
 
1147
- $do_time = ( date('H:i:s', strtotime($date)) == '00:00:00' ) ? false : true;
1148
-
1149
- $date = get_date_from_gmt($date);
1150
 
1151
- $formatted = date_i18n($date_format, strtotime($date));
1152
-
1153
- if ( $do_time ) {
1154
-
1155
- if ( empty($time_format) ) {
1156
- $time_format = get_option('time_format');
1157
- }
1158
 
1159
- $trimmed_format = trim($time_format);
1160
- if ( $time_format && ! empty($trimmed_format) ) {
1161
- $formatted .= ' '. __( 'at', 'formidable' ) .' '. date_i18n($time_format, strtotime($date));
1162
- }
1163
- }
1164
 
1165
  return $formatted;
1166
  }
1167
 
 
 
 
 
 
 
 
 
1168
  /**
1169
  * @return string The time ago in words
1170
  */
@@ -1498,7 +1528,7 @@ class FrmAppHelper {
1498
  $post_content = json_encode( $post_content );
1499
 
1500
  // add extra slashes for \r\n since WP strips them
1501
- $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t'), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t'), $post_content );
1502
 
1503
  // allow for &quot
1504
  $post_content = str_replace( '"', '\\"', $post_content );
@@ -1616,7 +1646,7 @@ class FrmAppHelper {
1616
  */
1617
  public static function load_admin_wide_js( $load = true ) {
1618
  $version = FrmAppHelper::plugin_version();
1619
- wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery'), $version );
1620
 
1621
  wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1622
  'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
10
  /**
11
  * @since 2.0
12
  */
13
+ public static $plug_version = '2.0.08';
14
 
15
  /**
16
  * @since 1.07.02
138
  return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
139
  }
140
 
141
+ /**
142
+ * @since 2.0.8
143
+ */
144
+ public static function prevent_caching() {
145
+ global $frm_vars;
146
+ return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
147
+ }
148
+
149
  /**
150
  * Check if on an admin page
151
  *
219
  if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
220
  $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
221
  }
222
+ self::sanitize_value( $sanitize, $value );
223
  } else {
224
+ $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
225
  }
226
 
227
  if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
239
  }
240
 
241
  /**
 
242
  *
243
  * @param string $param
244
  * @param mixed $default
245
  * @param string $sanitize
246
  */
247
  public static function get_post_param( $param, $default = '', $sanitize = '' ) {
248
+ return self::get_simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
 
 
 
 
 
 
249
  }
250
 
251
  /**
254
  * @param string $param
255
  * @param string $sanitize
256
  * @param string $default
 
 
257
  */
258
  public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
259
+ return self::get_simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
260
  }
261
 
262
  /**
264
  *
265
  * @since 2.0.6
266
  */
267
+ public static function get_simple_request( $args ) {
268
  $defaults = array(
269
  'param' => '', 'default' => '',
270
  'type' => 'get', 'sanitize' => 'sanitize_text_field',
286
  }
287
  }
288
 
289
+ self::sanitize_value( $args['sanitize'], $value );
290
  return $value;
291
  }
292
 
293
+ /**
294
+ * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
295
+ *
296
+ * @since 2.0.8
297
+ * @param string $value
298
+ * @return string $value
299
+ */
300
+ public static function preserve_backslashes( $value ) {
301
+ // If backslashes have already been added, don't add them again
302
+ if ( strpos( $value, '\\\\' ) === false ) {
303
+ $value = addslashes( $value );
304
+ }
305
+ return $value;
306
+ }
307
+
308
+ public static function sanitize_value( $sanitize, &$value ) {
309
+ if ( ! empty( $sanitize ) ) {
310
+ if ( is_array( $value ) ) {
311
+ $value = array_map( $sanitize, $value );
312
+ } else {
313
+ $value = call_user_func( $sanitize, $value );
314
+ }
315
+ }
316
+ }
317
+
318
  public static function sanitize_request( $sanitize_method, &$values ) {
319
  $temp_values = $values;
320
  foreach ( $temp_values as $k => $val ) {
321
  if ( isset( $sanitize_method[ $k ] ) ) {
322
+ $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
323
  }
324
  }
325
  }
415
  $results = $wpdb->{$type}($query);
416
  }
417
 
418
+ if ( ! self::prevent_caching() ) {
419
+ wp_cache_set( $cache_key, $results, $group, $time );
420
+ }
421
 
422
  return $results;
423
  }
791
 
792
  public static function replace_quotes($val) {
793
  //Replace double quotes
794
+ $val = str_replace( array( '“', '”', '″' ), '"', $val );
795
  //Replace single quotes
796
  $val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val );
797
  return $val;
890
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
891
  }
892
 
893
+ if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
894
  $key = $key .'a';
895
  }
896
 
897
+ $key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column );
898
 
899
  if ( $key_check || is_numeric($key_check) ) {
900
  $suffix = 2;
901
  do {
902
  $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
903
+ $key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column );
904
  $suffix++;
905
  } while ($key_check || is_numeric($key_check));
906
  $key = $alt_post_name;
924
  $post_values = stripslashes_deep($_POST);
925
  }
926
 
927
+ $values = array( 'id' => $record->id, 'fields' => array() );
928
 
929
+ foreach ( array( 'name', 'description' ) as $var ) {
930
  $default_val = isset($record->{$var}) ? $record->{$var} : '';
931
  $values[ $var ] = self::get_param( $var, $default_val );
932
  unset($var, $default_val);
965
  if ( ! isset($field->field_options['custom_field']) ) {
966
  $field->field_options['custom_field'] = '';
967
  }
968
+ $meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) );
969
  } else {
970
  $meta_value = self::get_meta_value($field->id, $record);
971
  }
1072
  $values['custom_style'] = ( $post_values && isset( $post_values['options']['custom_style'] ) ) ? absint( $_POST['options']['custom_style'] ) : ( $frm_settings->load_style != 'none' );
1073
  }
1074
 
1075
+ foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1076
  if ( ! isset( $values[ $h .'_html' ] ) ) {
1077
  $values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) );
1078
  }
1170
  $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1171
  }
1172
 
1173
+ $formatted = self::get_localized_date( $date_format, $date );
 
 
1174
 
1175
+ $do_time = ( date( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
1176
+ if ( $do_time ) {
1177
+ if ( empty($time_format) ) {
1178
+ $time_format = get_option('time_format');
1179
+ }
 
 
1180
 
1181
+ $trimmed_format = trim( $time_format );
1182
+ if ( $time_format && ! empty( $trimmed_format ) ) {
1183
+ $formatted .= ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
1184
+ }
1185
+ }
1186
 
1187
  return $formatted;
1188
  }
1189
 
1190
+ /**
1191
+ * @since 2.0.8
1192
+ */
1193
+ public static function get_localized_date( $date_format, $date ) {
1194
+ $date = get_date_from_gmt( $date );
1195
+ return date_i18n( $date_format, strtotime( $date ) );
1196
+ }
1197
+
1198
  /**
1199
  * @return string The time ago in words
1200
  */
1528
  $post_content = json_encode( $post_content );
1529
 
1530
  // add extra slashes for \r\n since WP strips them
1531
+ $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1532
 
1533
  // allow for &quot
1534
  $post_content = str_replace( '"', '\\"', $post_content );
1646
  */
1647
  public static function load_admin_wide_js( $load = true ) {
1648
  $version = FrmAppHelper::plugin_version();
1649
+ wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1650
 
1651
  wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1652
  'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -199,7 +199,7 @@ class FrmEntriesHelper {
199
  $p_val = FrmProEntryMetaHelper::get_post_value($atts['entry']->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
200
  'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
201
  'form_id' => $atts['entry']->form_id, 'field' => $f, 'type' => $f->type,
202
- 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
203
  ));
204
  if ( $p_val != '' ) {
205
  $atts['entry']->metas[ $f->id ] = $p_val;
@@ -218,7 +218,7 @@ class FrmEntriesHelper {
218
  }
219
  } else {
220
  $val = '';
221
- FrmProEntriesHelper::get_dfe_values( $f, $atts['entry'], $val );
222
  $atts['entry']->metas[ $f->id ] = $val;
223
  }
224
  }
@@ -227,7 +227,7 @@ class FrmEntriesHelper {
227
  $val = '';
228
  if ( $atts['entry'] ) {
229
  $prev_val = maybe_unserialize( $atts['entry']->metas[ $f->id ] );
230
- $meta = array( 'item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
231
 
232
  //This filter applies to the default-message shortcode and frm-show-entry shortcode only
233
  if ( isset($atts['filter']) && $atts['filter'] == false ) {
@@ -271,7 +271,7 @@ class FrmEntriesHelper {
271
  */
272
  public static function textarea_display_value( &$value, $type, $plain_text ) {
273
  if ( $type == 'textarea' && ! $plain_text ) {
274
- $value = str_replace( array("\r\n", "\r", "\n"), ' <br/>', $value);
275
  }
276
  }
277
 
@@ -280,36 +280,49 @@ class FrmEntriesHelper {
280
  return;
281
  }
282
 
283
- if ( isset($atts['entry']->description) ) {
284
- $data = maybe_unserialize($atts['entry']->description);
285
- } else if ( $atts['default_email'] ) {
286
- $atts['entry']->ip = '[ip]';
287
- $data = array(
288
- 'browser' => '[browser]',
289
- 'referrer' => '[referrer]',
290
- );
291
- } else {
292
- $data = array(
293
- 'browser' => '',
294
- 'referrer' => '',
295
- );
296
- }
297
 
298
  if ( $atts['format'] != 'text' ) {
299
  $values['ip'] = $atts['entry']->ip;
300
  $values['browser'] = self::get_browser($data['browser']);
301
  $values['referrer'] = $data['referrer'];
302
  } else {
303
- //$content .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n";
304
- $values['ip'] = array( 'label' => __( 'IP Address', 'formidable' ), 'val' => $atts['entry']->ip);
305
  $values['browser'] = array(
306
  'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
307
  'val' => self::get_browser($data['browser']),
308
  );
309
- $values['referrer'] = array( 'label' => __( 'Referrer', 'formidable' ), 'val' => $data['referrer']);
310
  }
311
  }
312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  public static function convert_entry_to_content($values, $atts, array &$content) {
314
 
315
  if ( $atts['plain_text'] ) {
@@ -359,6 +372,7 @@ class FrmEntriesHelper {
359
  $content[] = '<tr'. ( $odd ? $atts['bg_color'] : $bg_color_alt ) .'>';
360
  }
361
 
 
362
  if ( 'rtl' == $atts['direction'] ) {
363
  $content[] = '<td '. $row_style .'>'. $value['val'] .'</td><th '. $row_style .'>'. $value['label'] . '</th>';
364
  } else {
@@ -410,7 +424,7 @@ class FrmEntriesHelper {
410
  public static function prepare_display_value($entry, $field, $atts) {
411
  $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
412
  if ( FrmAppHelper::pro_is_installed() ) {
413
- FrmProEntriesHelper::get_dfe_values($field, $entry, $field_value);
414
  }
415
 
416
  if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
@@ -422,7 +436,7 @@ class FrmEntriesHelper {
422
 
423
  if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
424
  //this is a repeating section
425
- $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id) );
426
  } else {
427
  // get all values for this field
428
  $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
@@ -726,7 +740,7 @@ class FrmEntriesHelper {
726
  }
727
 
728
  // finally get the correct version number
729
- $known = array( 'Version', $ub, 'other');
730
  $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
731
  preg_match_all($pattern, $u_agent, $matches); // get the matching numbers
732
 
199
  $p_val = FrmProEntryMetaHelper::get_post_value($atts['entry']->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
200
  'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
201
  'form_id' => $atts['entry']->form_id, 'field' => $f, 'type' => $f->type,
202
+ 'exclude_cat' => ( isset( $f->field_options['exclude_cat'] ) ? $f->field_options['exclude_cat'] : 0 ),
203
  ));
204
  if ( $p_val != '' ) {
205
  $atts['entry']->metas[ $f->id ] = $p_val;
218
  }
219
  } else {
220
  $val = '';
221
+ FrmProEntriesHelper::get_dynamic_list_values( $f, $atts['entry'], $val );
222
  $atts['entry']->metas[ $f->id ] = $val;
223
  }
224
  }
227
  $val = '';
228
  if ( $atts['entry'] ) {
229
  $prev_val = maybe_unserialize( $atts['entry']->metas[ $f->id ] );
230
+ $meta = array( 'item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type );
231
 
232
  //This filter applies to the default-message shortcode and frm-show-entry shortcode only
233
  if ( isset($atts['filter']) && $atts['filter'] == false ) {
271
  */
272
  public static function textarea_display_value( &$value, $type, $plain_text ) {
273
  if ( $type == 'textarea' && ! $plain_text ) {
274
+ $value = str_replace( array( "\r\n", "\r", "\n" ), ' <br/>', $value );
275
  }
276
  }
277
 
280
  return;
281
  }
282
 
283
+ $data = self::get_entry_description_data( $atts );
284
+
285
+ if ( $atts['default_email'] ) {
286
+ $atts['entry']->ip = '[ip]';
287
+ }
 
 
 
 
 
 
 
 
 
288
 
289
  if ( $atts['format'] != 'text' ) {
290
  $values['ip'] = $atts['entry']->ip;
291
  $values['browser'] = self::get_browser($data['browser']);
292
  $values['referrer'] = $data['referrer'];
293
  } else {
294
+ $values['ip'] = array( 'label' => __( 'IP Address', 'formidable' ), 'val' => $atts['entry']->ip );
 
295
  $values['browser'] = array(
296
  'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
297
  'val' => self::get_browser($data['browser']),
298
  );
299
+ $values['referrer'] = array( 'label' => __( 'Referrer', 'formidable' ), 'val' => $data['referrer'] );
300
  }
301
  }
302
 
303
+ /**
304
+ * @param array $atts - include (object) entry, (boolean) default_email
305
+ * @since 2.0.8
306
+ */
307
+ public static function get_entry_description_data( $atts ) {
308
+ $default_data = array(
309
+ 'browser' => '',
310
+ 'referrer' => '',
311
+ );
312
+ $data = $default_data;
313
+
314
+ if ( isset( $atts['entry']->description ) ) {
315
+ $data = maybe_unserialize( $atts['entry']->description );
316
+ } else if ( $atts['default_email'] ) {
317
+ $data = array(
318
+ 'browser' => '[browser]',
319
+ 'referrer' => '[referrer]',
320
+ );
321
+ }
322
+
323
+ return array_merge( $default_data, $data );
324
+ }
325
+
326
  public static function convert_entry_to_content($values, $atts, array &$content) {
327
 
328
  if ( $atts['plain_text'] ) {
372
  $content[] = '<tr'. ( $odd ? $atts['bg_color'] : $bg_color_alt ) .'>';
373
  }
374
 
375
+ $value['val'] = str_replace( "\r\n", '<br/>', $value['val'] );
376
  if ( 'rtl' == $atts['direction'] ) {
377
  $content[] = '<td '. $row_style .'>'. $value['val'] .'</td><th '. $row_style .'>'. $value['label'] . '</th>';
378
  } else {
424
  public static function prepare_display_value($entry, $field, $atts) {
425
  $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
426
  if ( FrmAppHelper::pro_is_installed() ) {
427
+ FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
428
  }
429
 
430
  if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
436
 
437
  if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
438
  //this is a repeating section
439
+ $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
440
  } else {
441
  // get all values for this field
442
  $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
740
  }
741
 
742
  // finally get the correct version number
743
+ $known = array( 'Version', $ub, 'other' );
744
  $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
745
  preg_match_all($pattern, $u_agent, $matches); // get the matching numbers
746
 
classes/helpers/FrmEntriesListHelper.php CHANGED
@@ -1,6 +1,9 @@
1
  <?php
2
 
3
  class FrmEntriesListHelper extends FrmListHelper {
 
 
 
4
 
5
  public function prepare_items() {
6
  global $wpdb, $per_page;
@@ -32,7 +35,7 @@ class FrmEntriesListHelper extends FrmListHelper {
32
  $orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
33
  if ( strpos($orderby, 'meta') !== false ) {
34
  $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
35
- $orderby .= in_array( $order_field_type, array( 'number', 'scale') ) ? ' +0 ' : '';
36
  }
37
 
38
  $order = isset( $_REQUEST['order'] ) ? sanitize_title( $_REQUEST['order'] ) : $default_order;
@@ -92,7 +95,7 @@ class FrmEntriesListHelper extends FrmListHelper {
92
 
93
  if ( in_array( $column_name, $hidden ) ) {
94
  $class .= ' frm_hidden';
95
- } else if ( ! $action_col && ! in_array($column_name, array( 'cb', 'id', 'form_id', 'post_id')) ) {
96
  $action_col = $column_name;
97
  }
98
 
@@ -100,6 +103,7 @@ class FrmEntriesListHelper extends FrmListHelper {
100
  unset($class);
101
 
102
  $col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
 
103
 
104
  switch ( $col_name ) {
105
  case 'cb':
@@ -133,36 +137,10 @@ class FrmEntriesListHelper extends FrmListHelper {
133
  $val = $user->user_login;
134
  break;
135
  default:
136
- if ( strpos($col_name, 'frmsep_') === 0 ) {
137
- $sep_val = true;
138
- $col_name = str_replace('frmsep_', '', $col_name);
139
- } else {
140
- $sep_val = false;
141
- }
142
-
143
- if ( strpos($col_name, '-_-') ) {
144
- list($col_name, $embedded_field_id) = explode('-_-', $col_name);
145
- }
146
-
147
- $col = FrmField::getOne($col_name);
148
-
149
- $atts = array(
150
- 'type' => $col->type, 'truncate' => true,
151
- 'post_id' => $item->post_id, 'entry_id' => $item->id,
152
- 'embedded_field_id' => 0,
153
- );
154
-
155
- if ( $sep_val ) {
156
- $atts['saved_value'] = true;
157
- }
158
-
159
- if ( isset($embedded_field_id) ) {
160
- $atts['embedded_field_id'] = $embedded_field_id;
161
- unset($embedded_field_id);
162
- }
163
-
164
- $val = FrmEntriesHelper::prepare_display_value($item, $col, $atts);
165
-
166
  break;
167
  }
168
 
@@ -198,4 +176,37 @@ class FrmEntriesListHelper extends FrmListHelper {
198
  $actions = apply_filters('frm_row_actions', $actions, $item);
199
  }
200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
1
  <?php
2
 
3
  class FrmEntriesListHelper extends FrmListHelper {
4
+ protected $column_name;
5
+ protected $item;
6
+ protected $field;
7
 
8
  public function prepare_items() {
9
  global $wpdb, $per_page;
35
  $orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
36
  if ( strpos($orderby, 'meta') !== false ) {
37
  $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
38
+ $orderby .= in_array( $order_field_type, array( 'number', 'scale' ) ) ? ' +0 ' : '';
39
  }
40
 
41
  $order = isset( $_REQUEST['order'] ) ? sanitize_title( $_REQUEST['order'] ) : $default_order;
95
 
96
  if ( in_array( $column_name, $hidden ) ) {
97
  $class .= ' frm_hidden';
98
+ } else if ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) {
99
  $action_col = $column_name;
100
  }
101
 
103
  unset($class);
104
 
105
  $col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
106
+ $this->column_name = $col_name;
107
 
108
  switch ( $col_name ) {
109
  case 'cb':
137
  $val = $user->user_login;
138
  break;
139
  default:
140
+ $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
141
+ if ( $val === false ) {
142
+ $this->get_column_value( $item, $val );
143
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  break;
145
  }
146
 
176
  $actions = apply_filters('frm_row_actions', $actions, $item);
177
  }
178
 
179
+ private function get_column_value( $item, &$val ) {
180
+ $col_name = $this->column_name;
181
+
182
+ if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
183
+ $sep_val = true;
184
+ $col_name = str_replace( 'frmsep_', '', $col_name );
185
+ } else {
186
+ $sep_val = false;
187
+ }
188
+
189
+ if ( strpos( $col_name, '-_-' ) ) {
190
+ list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
191
+ }
192
+
193
+ $field = FrmField::getOne( $col_name );
194
+
195
+ $atts = array(
196
+ 'type' => $field->type, 'truncate' => true,
197
+ 'post_id' => $item->post_id, 'entry_id' => $item->id,
198
+ 'embedded_field_id' => 0,
199
+ );
200
+
201
+ if ( $sep_val ) {
202
+ $atts['saved_value'] = true;
203
+ }
204
+
205
+ if ( isset( $embedded_field_id ) ) {
206
+ $atts['embedded_field_id'] = $embedded_field_id;
207
+ unset( $embedded_field_id );
208
+ }
209
+
210
+ $val = FrmEntriesHelper::prepare_display_value( $item, $field, $atts );
211
+ }
212
  }
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -42,7 +42,7 @@ class FrmFieldsHelper {
42
  'user_id' => __( 'User ID (hidden)', 'formidable' ),
43
  'password' => __( 'Password', 'formidable' ),
44
  'html' => __( 'HTML', 'formidable' ),
45
- 'tag' => __( 'Tags', 'formidable' )
46
  //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
47
  //'city_selector' => 'US State/County/City selector',
48
  //'full_name' => 'First and Last Name',
@@ -177,8 +177,8 @@ class FrmFieldsHelper {
177
  }
178
 
179
  public static function setup_edit_vars( $record, $doing_ajax = false ) {
180
- $values = array( 'id' => $record->id, 'form_id' => $record->form_id);
181
- $defaults = array( 'name' => $record->name, 'description' => $record->description);
182
  $default_opts = array(
183
  'field_key' => $record->field_key, 'type' => $record->type,
184
  'default_value' => $record->default_value, 'field_order' => $record->field_order,
@@ -221,7 +221,7 @@ class FrmFieldsHelper {
221
 
222
  $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
223
 
224
- return apply_filters('frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax));
225
  }
226
 
227
  public static function get_default_field_opts( $type, $field, $limit = false ) {
@@ -276,8 +276,8 @@ class FrmFieldsHelper {
276
  $default_settings = $frm_settings->default_options();
277
 
278
  $defaults = array(
279
- 'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => $field->name.' '. __( 'must be unique', 'formidable' )),
280
- 'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => $field->name.' '. __( 'is invalid', 'formidable' ))
281
  );
282
 
283
  $msg = ( $field->field_options[ $error ] == $defaults[ $error ]['full'] || empty( $field->field_options[ $error ] ) ) ? $defaults[ $error ]['part'] : $field->field_options[ $error ];
@@ -292,9 +292,9 @@ class FrmFieldsHelper {
292
 
293
  public static function get_default_html( $type = 'text' ) {
294
  if ( apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
295
- $input = (in_array($type, array( 'radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
296
  $for = '';
297
- if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale') ) ) {
298
  $for = 'for="field_[key]"';
299
  }
300
 
@@ -380,7 +380,7 @@ DEFAULT_HTML;
380
  $html = str_replace('[field_name]', $field['name'], $html);
381
 
382
  //replace [error_class]
383
- $error_class = isset ( $errors[ 'field' . $field_id ] ) ? ' frm_blank_field' : '';
384
  self::get_more_field_classes( $error_class, $field, $field_id, $html );
385
  if ( $field['type'] == 'html' && strpos( $html, '[error_class]' ) === false ) {
386
  // there is no error_class shortcode to use for addign fields
@@ -399,7 +399,7 @@ DEFAULT_HTML;
399
 
400
  foreach ( $shortcodes[0] as $short_key => $tag ) {
401
  $atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
402
- $tag = self::get_shortcode_tag($shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false));
403
 
404
  $replace_with = '';
405
 
@@ -448,10 +448,9 @@ DEFAULT_HTML;
448
  $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
449
  }
450
 
451
- // remove [collapse_this] when running the free version
452
- if ( preg_match( '/\[(collapse_this)\]/s', $html ) ) {
453
- $html = str_replace( '[collapse_this]', '', $html );
454
- }
455
 
456
  return $html;
457
  }
@@ -473,7 +472,7 @@ DEFAULT_HTML;
473
  }
474
 
475
  //Add classes to inline confirmation field (if it doesn't already have classes set)
476
- if ( isset ( $field['conf_field'] ) && $field['conf_field'] == 'inline' && ! $field['classes'] ) {
477
  $error_class .= ' frm_first_half';
478
  }
479
 
@@ -498,7 +497,7 @@ DEFAULT_HTML;
498
  // If this is a repeating section that should be hidden with exclude_fields or fields shortcode, hide it
499
  if ( $field['repeat'] ) {
500
  global $frm_vars;
501
- if ( isset( $frm_vars['show_fields'] ) && ! empty ( $frm_vars['show_fields'] ) && ! in_array( $field['id'], $frm_vars['show_fields'] ) && ! in_array( $field['field_key'], $frm_vars['show_fields'] ) ) {
502
  $error_class .= ' frm_hidden';
503
  }
504
  }
@@ -525,7 +524,7 @@ DEFAULT_HTML;
525
  }
526
 
527
  public static function get_shortcode_tag($shortcodes, $short_key, $args) {
528
- $args = wp_parse_args($args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false));
529
  if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
530
  $args['conditional_check'] = true;
531
  }
@@ -554,6 +553,16 @@ DEFAULT_HTML;
554
  return $tag;
555
  }
556
 
 
 
 
 
 
 
 
 
 
 
557
  public static function display_recaptcha($field) {
558
  $frm_settings = FrmAppHelper::get_settings();
559
  $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
@@ -843,7 +852,7 @@ DEFAULT_HTML;
843
  case 'updated_by':
844
  case 'updated-by':
845
  $this_tag = str_replace('-', '_', $tag);
846
- $replace_with = self::get_display_value($entry->{$this_tag}, (object) array( 'type' => 'user_id'), $atts);
847
  unset($this_tag);
848
  break;
849
 
@@ -1200,9 +1209,39 @@ DEFAULT_HTML;
1200
  $classes[] = 'frm_other_full';
1201
  }
1202
 
1203
- ?><input type="text" class="<?php echo sanitize_text_field( implode( ' ', $classes ) ) ?>" <?php
 
 
 
1204
  echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' );
1205
- ?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>"><?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1206
  }
1207
 
1208
  public static function show_onfocus_js( $is_selected ) {
42
  'user_id' => __( 'User ID (hidden)', 'formidable' ),
43
  'password' => __( 'Password', 'formidable' ),
44
  'html' => __( 'HTML', 'formidable' ),
45
+ 'tag' => __( 'Tags', 'formidable' ),
46
  //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
47
  //'city_selector' => 'US State/County/City selector',
48
  //'full_name' => 'First and Last Name',
177
  }
178
 
179
  public static function setup_edit_vars( $record, $doing_ajax = false ) {
180
+ $values = array( 'id' => $record->id, 'form_id' => $record->form_id );
181
+ $defaults = array( 'name' => $record->name, 'description' => $record->description );
182
  $default_opts = array(
183
  'field_key' => $record->field_key, 'type' => $record->type,
184
  'default_value' => $record->default_value, 'field_order' => $record->field_order,
221
 
222
  $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
223
 
224
+ return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
225
  }
226
 
227
  public static function get_default_field_opts( $type, $field, $limit = false ) {
276
  $default_settings = $frm_settings->default_options();
277
 
278
  $defaults = array(
279
+ 'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => $field->name . ' ' . __( 'must be unique', 'formidable' ) ),
280
+ 'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => $field->name . ' ' . __( 'is invalid', 'formidable' ) ),
281
  );
282
 
283
  $msg = ( $field->field_options[ $error ] == $defaults[ $error ]['full'] || empty( $field->field_options[ $error ] ) ) ? $defaults[ $error ]['part'] : $field->field_options[ $error ];
292
 
293
  public static function get_default_html( $type = 'text' ) {
294
  if ( apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
295
+ $input = ( in_array( $type, array( 'radio', 'checkbox', 'data' ) ) ) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
296
  $for = '';
297
+ if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale' ) ) ) {
298
  $for = 'for="field_[key]"';
299
  }
300
 
380
  $html = str_replace('[field_name]', $field['name'], $html);
381
 
382
  //replace [error_class]
383
+ $error_class = isset( $errors[ 'field' . $field_id ] ) ? ' frm_blank_field' : '';
384
  self::get_more_field_classes( $error_class, $field, $field_id, $html );
385
  if ( $field['type'] == 'html' && strpos( $html, '[error_class]' ) === false ) {
386
  // there is no error_class shortcode to use for addign fields
399
 
400
  foreach ( $shortcodes[0] as $short_key => $tag ) {
401
  $atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
402
+ $tag = self::get_shortcode_tag( $shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false ) );
403
 
404
  $replace_with = '';
405
 
448
  $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
449
  }
450
 
451
+ self::remove_collapse_shortcode( $html );
452
+
453
+ $html = do_shortcode( $html );
 
454
 
455
  return $html;
456
  }
472
  }
473
 
474
  //Add classes to inline confirmation field (if it doesn't already have classes set)
475
+ if ( isset( $field['conf_field'] ) && $field['conf_field'] == 'inline' && ! $field['classes'] ) {
476
  $error_class .= ' frm_first_half';
477
  }
478
 
497
  // If this is a repeating section that should be hidden with exclude_fields or fields shortcode, hide it
498
  if ( $field['repeat'] ) {
499
  global $frm_vars;
500
+ if ( isset( $frm_vars['show_fields'] ) && ! empty( $frm_vars['show_fields'] ) && ! in_array( $field['id'], $frm_vars['show_fields'] ) && ! in_array( $field['field_key'], $frm_vars['show_fields'] ) ) {
501
  $error_class .= ' frm_hidden';
502
  }
503
  }
524
  }
525
 
526
  public static function get_shortcode_tag($shortcodes, $short_key, $args) {
527
+ $args = wp_parse_args( $args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false ) );
528
  if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
529
  $args['conditional_check'] = true;
530
  }
553
  return $tag;
554
  }
555
 
556
+ /**
557
+ * Remove [collapse_this] if it's still included after all processing
558
+ * @since 2.0.8
559
+ */
560
+ private static function remove_collapse_shortcode( &$html ) {
561
+ if ( preg_match( '/\[(collapse_this)\]/s', $html ) ) {
562
+ $html = str_replace( '[collapse_this]', '', $html );
563
+ }
564
+ }
565
+
566
  public static function display_recaptcha($field) {
567
  $frm_settings = FrmAppHelper::get_settings();
568
  $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
852
  case 'updated_by':
853
  case 'updated-by':
854
  $this_tag = str_replace('-', '_', $tag);
855
+ $replace_with = self::get_display_value( $entry->{$this_tag}, (object) array( 'type' => 'user_id' ), $atts );
856
  unset($this_tag);
857
  break;
858
 
1209
  $classes[] = 'frm_other_full';
1210
  }
1211
 
1212
+ // Set up HTML ID for Other field
1213
+ $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1214
+
1215
+ ?><input type="text" id="<?php echo esc_attr( $other_id ) ?>" class="<?php echo sanitize_text_field( implode( ' ', $classes ) ) ?>" <?php
1216
  echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' );
1217
+ ?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>" /><?php
1218
+ }
1219
+
1220
+ /**
1221
+ * Get the HTML id for an "Other" text field
1222
+ * Note: This does not affect fields in repeating sections
1223
+ *
1224
+ * @since 2.0.08
1225
+ * @param string $type - field type
1226
+ * @param string $html_id
1227
+ * @param string|boolean $opt_key
1228
+ * @return string $other_id
1229
+ */
1230
+ public static function get_other_field_html_id( $type, $html_id, $opt_key = false ){
1231
+ $other_id = $html_id;
1232
+
1233
+ // If hidden radio field, add an opt key of 0
1234
+ if ( $type == 'radio' && $opt_key === false ) {
1235
+ $opt_key = 0;
1236
+ }
1237
+
1238
+ if ( $opt_key !== false ) {
1239
+ $other_id .= '-' . $opt_key;
1240
+ }
1241
+
1242
+ $other_id .= '-otext';
1243
+
1244
+ return $other_id;
1245
  }
1246
 
1247
  public static function show_onfocus_js( $is_selected ) {
classes/helpers/FrmFormsHelper.php CHANGED
@@ -77,7 +77,7 @@ class FrmFormsHelper {
77
  $where = apply_filters( 'frm_forms_dropdown', array(), '' );
78
  $forms = FrmForm::get_published_forms( $where );
79
 
80
- $args = array( 'id' => 0, 'form' => 0);
81
  if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
82
  unset( $args['form'] );
83
  } else if ( isset( $_GET['form']) && ! isset( $_GET['id'] ) ) {
@@ -409,6 +409,8 @@ BEFORE_HTML;
409
  $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
410
  }
411
 
 
 
412
  return $html;
413
  }
414
 
@@ -620,7 +622,7 @@ BEFORE_HTML;
620
 
621
  public static function get_params() {
622
  $values = array();
623
- foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default ) {
624
  $values[ $var ] = FrmAppHelper::get_param( $var, $default );
625
  }
626
 
@@ -663,6 +665,6 @@ BEFORE_HTML;
663
 
664
  $message = $available_status[ $status ]['message'];
665
 
666
- FrmFormsController::display_forms_list( $params, $message, 1 );
667
  }
668
  }
77
  $where = apply_filters( 'frm_forms_dropdown', array(), '' );
78
  $forms = FrmForm::get_published_forms( $where );
79
 
80
+ $args = array( 'id' => 0, 'form' => 0 );
81
  if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
82
  unset( $args['form'] );
83
  } else if ( isset( $_GET['form']) && ! isset( $_GET['id'] ) ) {
409
  $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
410
  }
411
 
412
+ $html = do_shortcode( $html );
413
+
414
  return $html;
415
  }
416
 
622
 
623
  public static function get_params() {
624
  $values = array();
625
+ foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) {
626
  $values[ $var ] = FrmAppHelper::get_param( $var, $default );
627
  }
628
 
665
 
666
  $message = $available_status[ $status ]['message'];
667
 
668
+ FrmFormsController::display_forms_list( $params, $message );
669
  }
670
  }
classes/helpers/FrmFormsListHelper.php CHANGED
@@ -86,7 +86,7 @@ class FrmFormsListHelper extends FrmListHelper {
86
  public function get_bulk_actions() {
87
  $actions = array();
88
 
89
- if ( in_array($this->status, array( '', 'published')) ) {
90
  $actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
91
  }
92
 
86
  public function get_bulk_actions() {
87
  $actions = array();
88
 
89
+ if ( in_array( $this->status, array( '', 'published' ) ) ) {
90
  $actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
91
  }
92
 
classes/helpers/FrmListHelper.php CHANGED
@@ -8,7 +8,7 @@ class FrmListHelper extends WP_List_Table {
8
 
9
  public function __construct( $args ) {
10
  $args = wp_parse_args( $args, array(
11
- 'params' => array()
12
  ) );
13
 
14
  $this->params = $args['params'];
8
 
9
  public function __construct( $args ) {
10
  $args = wp_parse_args( $args, array(
11
+ 'params' => array(),
12
  ) );
13
 
14
  $this->params = $args['params'];
classes/helpers/FrmStylesHelper.php CHANGED
@@ -83,11 +83,11 @@ class FrmStylesHelper {
83
 
84
  public static function minus_icons() {
85
  return array(
86
- 0 => array( '-' => '62e', '+' => '62f'),
87
- 1 => array( '-' => '600', '+' => '602'),
88
- 2 => array( '-' => '604', '+' => '603'),
89
- 3 => array( '-' => '633', '+' => '632'),
90
- 4 => array( '-' => '613', '+' => '60f'),
91
  );
92
  }
93
 
@@ -95,13 +95,13 @@ class FrmStylesHelper {
95
  $minus_icons = self::minus_icons();
96
 
97
  return array(
98
- 6 => array( '-' => '62d', '+' => '62a'),
99
- 0 => array( '-' => '60d', '+' => '609'),
100
- 1 => array( '-' => '60e', '+' => '60c'),
101
- 2 => array( '-' => '630', '+' => '631'),
102
- 3 => array( '-' => '62b', '+' => '628'),
103
- 4 => array( '-' => '62c', '+' => '629'),
104
- 5 => array( '-' => '635', '+' => '634'),
105
  'p0' => $minus_icons[0],
106
  'p1' => $minus_icons[1],
107
  'p2' => $minus_icons[2],
@@ -117,12 +117,12 @@ class FrmStylesHelper {
117
  public static function icon_key_to_class($key, $icon = '+', $type = 'arrow') {
118
  if ( 'arrow' == $type && is_numeric($key) ) {
119
  //frm_arrowup6_icon
120
- $arrow = array( '-' => 'down', '+' => 'up');
121
  $class = 'frm_arrow' . $arrow[ $icon ];
122
  } else {
123
  //frm_minus1_icon
124
  $key = str_replace('p', '', $key);
125
- $plus = array( '-' => 'minus', '+' => 'plus');
126
  $class = 'frm_' . $plus[ $icon ];
127
  }
128
 
@@ -186,8 +186,8 @@ class FrmStylesHelper {
186
  $g = hexdec( substr($hex,2,2) );
187
  $b = hexdec( substr($hex,4,2) );
188
  }
189
- $rgb = array($r, $g, $b);
190
  return implode(',', $rgb); // returns the rgb values separated by commas
191
  //return $rgb; // returns an array with the rgb values
192
  }
193
- }
83
 
84
  public static function minus_icons() {
85
  return array(
86
+ 0 => array( '-' => '62e', '+' => '62f' ),
87
+ 1 => array( '-' => '600', '+' => '602' ),
88
+ 2 => array( '-' => '604', '+' => '603' ),
89
+ 3 => array( '-' => '633', '+' => '632' ),
90
+ 4 => array( '-' => '613', '+' => '60f' ),
91
  );
92
  }
93
 
95
  $minus_icons = self::minus_icons();
96
 
97
  return array(
98
+ 6 => array( '-' => '62d', '+' => '62a' ),
99
+ 0 => array( '-' => '60d', '+' => '609' ),
100
+ 1 => array( '-' => '60e', '+' => '60c' ),
101
+ 2 => array( '-' => '630', '+' => '631' ),
102
+ 3 => array( '-' => '62b', '+' => '628' ),
103
+ 4 => array( '-' => '62c', '+' => '629' ),
104
+ 5 => array( '-' => '635', '+' => '634' ),
105
  'p0' => $minus_icons[0],
106
  'p1' => $minus_icons[1],
107
  'p2' => $minus_icons[2],
117
  public static function icon_key_to_class($key, $icon = '+', $type = 'arrow') {
118
  if ( 'arrow' == $type && is_numeric($key) ) {
119
  //frm_arrowup6_icon
120
+ $arrow = array( '-' => 'down', '+' => 'up' );
121
  $class = 'frm_arrow' . $arrow[ $icon ];
122
  } else {
123
  //frm_minus1_icon
124
  $key = str_replace('p', '', $key);
125
+ $plus = array( '-' => 'minus', '+' => 'plus' );
126
  $class = 'frm_' . $plus[ $icon ];
127
  }
128
 
186
  $g = hexdec( substr($hex,2,2) );
187
  $b = hexdec( substr($hex,4,2) );
188
  }
189
+ $rgb = array( $r, $g, $b );
190
  return implode(',', $rgb); // returns the rgb values separated by commas
191
  //return $rgb; // returns an array with the rgb values
192
  }
193
+ }
classes/helpers/FrmXMLHelper.php CHANGED
@@ -31,8 +31,9 @@ class FrmXMLHelper {
31
 
32
  $imported = array(
33
  'imported' => $defaults,
34
- 'updated' => $defaults,
35
- 'forms' => array(),
 
36
  );
37
 
38
  unset($defaults);
@@ -80,23 +81,42 @@ class FrmXMLHelper {
80
  continue;
81
  }
82
 
83
- $term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
 
 
84
  'slug' => (string) $t->term_slug,
85
  'description' => (string) $t->term_description,
86
- 'term_parent' => (string) $t->term_parent,
87
  'slug' => (string) $t->term_slug,
88
  ));
89
 
90
- if ( $term_id ) {
91
  $imported['imported']['terms']++;
 
92
  }
93
 
94
- unset($term_id, $t);
95
  }
96
 
97
  return $imported;
98
  }
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  public static function import_xml_forms($forms, $imported) {
101
 
102
  // Keep track of repeating sections that are created
@@ -121,7 +141,7 @@ class FrmXMLHelper {
121
  $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
122
 
123
  // if template, allow to edit if form keys match, otherwise, creation date must also match
124
- $edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template']);
125
  if ( ! $form['is_template'] ) {
126
  $edit_query['created_at'] = $form['created_at'];
127
  }
@@ -186,7 +206,7 @@ class FrmXMLHelper {
186
  'form_id' => (int) $form_id,
187
  'required' => (int) $field->required,
188
  'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
189
- 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
190
  );
191
 
192
  if ( is_array($f['default_value']) && in_array($f['type'], array(
@@ -261,7 +281,7 @@ class FrmXMLHelper {
261
  }
262
 
263
  // Update field ids/keys to new ones
264
- do_action('frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id));
265
 
266
  $imported['forms'][ (int) $item->id ] = $form_id;
267
 
@@ -637,7 +657,7 @@ class FrmXMLHelper {
637
  unset($post_setting);
638
  }
639
 
640
- $new_action['event'] = array( 'create', 'update');
641
 
642
  if ( $switch ) {
643
  // Fields with string or int saved
@@ -665,14 +685,15 @@ class FrmXMLHelper {
665
  }
666
 
667
  /**
668
- * Switch old field IDs for new field IDs in emails and post
669
- *
670
- * @since 2.0
671
- * @param $post_content - string to check for old field IDs
672
- * @param $basic_fields - array of fields with string or int saved
673
- * @param $array_fields - array of fields with arrays saved
674
- * @return $post_content - string with new field IDs
675
- */
 
676
  private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
677
  global $frm_duplicate_ids;
678
 
@@ -758,10 +779,10 @@ class FrmXMLHelper {
758
  private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
759
  if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
760
  // add old settings into notification array
761
- $form_options['notification'] = array(0 => $form_options);
762
  } else if ( isset( $form_options['notification']['email_to'] ) ) {
763
  // make sure it's in the correct format
764
- $form_options['notification'] = array(0 => $form_options['notification']);
765
  }
766
 
767
  if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
@@ -804,11 +825,11 @@ class FrmXMLHelper {
804
  }
805
 
806
  // Format event
807
- $atts['event'] = array( 'create');
808
  if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
809
  $atts['event'][] = 'update';
810
  } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
811
- $atts['event'] = array( 'update');
812
  }
813
  }
814
 
@@ -855,7 +876,7 @@ class FrmXMLHelper {
855
  // Add more fields to the new notification
856
  $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
857
  foreach ( $add_fields as $add_field ) {
858
- if ( isset ( $notification[ $add_field ] ) ) {
859
  $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
860
  } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
861
  $new_notification['post_content'][ $add_field ] = 0;
@@ -934,5 +955,5 @@ class FrmXMLHelper {
934
  unset( $new_notification2 );
935
  }
936
  }
937
-
938
  }
 
31
 
32
  $imported = array(
33
  'imported' => $defaults,
34
+ 'updated' => $defaults,
35
+ 'forms' => array(),
36
+ 'terms' => array(),
37
  );
38
 
39
  unset($defaults);
81
  continue;
82
  }
83
 
84
+ $parent = self::get_term_parent_id( $t );
85
+
86
+ $term = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
87
  'slug' => (string) $t->term_slug,
88
  'description' => (string) $t->term_description,
89
+ 'parent' => empty( $parent ) ? 0 : $parent,
90
  'slug' => (string) $t->term_slug,
91
  ));
92
 
93
+ if ( $term && is_array( $term ) ) {
94
  $imported['imported']['terms']++;
95
+ $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
96
  }
97
 
98
+ unset( $term, $t );
99
  }
100
 
101
  return $imported;
102
  }
103
 
104
+ /**
105
+ * @since 2.0.8
106
+ */
107
+ private static function get_term_parent_id( $t ) {
108
+ $parent = (string) $t->term_parent;
109
+ if ( ! empty( $parent ) ) {
110
+ $parent = term_exists( (string) $t->term_parent, (string) $t->term_taxonomy );
111
+ if ( $parent ) {
112
+ $parent = $parent['term_id'];
113
+ } else {
114
+ $parent = 0;
115
+ }
116
+ }
117
+ return $parent;
118
+ }
119
+
120
  public static function import_xml_forms($forms, $imported) {
121
 
122
  // Keep track of repeating sections that are created
141
  $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
142
 
143
  // if template, allow to edit if form keys match, otherwise, creation date must also match
144
+ $edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template'] );
145
  if ( ! $form['is_template'] ) {
146
  $edit_query['created_at'] = $form['created_at'];
147
  }
206
  'form_id' => (int) $form_id,
207
  'required' => (int) $field->required,
208
  'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
209
+ 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ),
210
  );
211
 
212
  if ( is_array($f['default_value']) && in_array($f['type'], array(
281
  }
282
 
283
  // Update field ids/keys to new ones
284
+ do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
285
 
286
  $imported['forms'][ (int) $item->id ] = $form_id;
287
 
657
  unset($post_setting);
658
  }
659
 
660
+ $new_action['event'] = array( 'create', 'update' );
661
 
662
  if ( $switch ) {
663
  // Fields with string or int saved
685
  }
686
 
687
  /**
688
+ * Switch old field IDs for new field IDs in emails and post
689
+ *
690
+ * @since 2.0
691
+ * @param array $post_content - check for old field IDs
692
+ * @param array $basic_fields - fields with string or int saved
693
+ * @param array $array_fields - fields with arrays saved
694
+ *
695
+ * @return string $post_content - new field IDs
696
+ */
697
  private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
698
  global $frm_duplicate_ids;
699
 
779
  private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
780
  if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
781
  // add old settings into notification array
782
+ $form_options['notification'] = array( 0 => $form_options );
783
  } else if ( isset( $form_options['notification']['email_to'] ) ) {
784
  // make sure it's in the correct format
785
+ $form_options['notification'] = array( 0 => $form_options['notification'] );
786
  }
787
 
788
  if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
825
  }
826
 
827
  // Format event
828
+ $atts['event'] = array( 'create' );
829
  if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
830
  $atts['event'][] = 'update';
831
  } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
832
+ $atts['event'] = array( 'update' );
833
  }
834
  }
835
 
876
  // Add more fields to the new notification
877
  $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
878
  foreach ( $add_fields as $add_field ) {
879
+ if ( isset( $notification[ $add_field ] ) ) {
880
  $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
881
  } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
882
  $new_notification['post_content'][ $add_field ] = 0;
955
  unset( $new_notification2 );
956
  }
957
  }
 
958
  }
959
+
classes/models/FrmDb.php CHANGED
@@ -341,7 +341,7 @@ class FrmDb {
341
  */
342
  public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
343
  _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
344
- return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1), '', 'row' );
345
  }
346
 
347
  public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
@@ -419,7 +419,7 @@ class FrmDb {
419
 
420
  private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
421
  if ( ! is_array($args) ) {
422
- $args = array( 'order_by' => $args);
423
  }
424
 
425
  if ( ! empty( $order_by ) ) {
@@ -663,10 +663,10 @@ DEFAULT_HTML;
663
 
664
  if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
665
  $form->options['submit_html'] = $new_default_html;
666
- $wpdb->update($this->forms, array( 'options' => serialize($form->options)), array( 'id' => $form->id ));
667
  } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
668
  $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
669
- $wpdb->update($this->forms, array( 'options' => serialize($form->options)), array( 'id' => $form->id ));
670
  }
671
  unset($form);
672
  }
@@ -677,7 +677,7 @@ DEFAULT_HTML;
677
  global $wpdb;
678
 
679
  $no_save = array_merge( FrmFieldsHelper::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
680
- $fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save), 'id, field_options' );
681
 
682
  $default_html = <<<DEFAULT_HTML
683
  <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
@@ -704,7 +704,7 @@ DEFAULT_HTML;
704
  $field->field_options = maybe_unserialize($field->field_options);
705
  if ( ! isset( $field->field_options['custom_html'] ) || empty( $field->field_options['custom_html'] ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
706
  $field->field_options['custom_html'] = $new_default_html;
707
- $wpdb->update($this->fields, array( 'field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
708
  }
709
  unset($field);
710
  }
@@ -715,7 +715,7 @@ DEFAULT_HTML;
715
  global $wpdb;
716
  $user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
717
  foreach ( $user_ids as $user_id ) {
718
- $wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value), array( 'id' => $user_id->item_id) );
719
  }
720
  }
721
  }
341
  */
342
  public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
343
  _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
344
+ return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1 ), '', 'row' );
345
  }
346
 
347
  public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
419
 
420
  private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
421
  if ( ! is_array($args) ) {
422
+ $args = array( 'order_by' => $args );
423
  }
424
 
425
  if ( ! empty( $order_by ) ) {
663
 
664
  if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
665
  $form->options['submit_html'] = $new_default_html;
666
+ $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
667
  } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
668
  $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
669
+ $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
670
  }
671
  unset($form);
672
  }
677
  global $wpdb;
678
 
679
  $no_save = array_merge( FrmFieldsHelper::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
680
+ $fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
681
 
682
  $default_html = <<<DEFAULT_HTML
683
  <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
704
  $field->field_options = maybe_unserialize($field->field_options);
705
  if ( ! isset( $field->field_options['custom_html'] ) || empty( $field->field_options['custom_html'] ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
706
  $field->field_options['custom_html'] = $new_default_html;
707
+ $wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
708
  }
709
  unset($field);
710
  }
715
  global $wpdb;
716
  $user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
717
  foreach ( $user_ids as $user_id ) {
718
+ $wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
719
  }
720
  }
721
  }
classes/models/FrmEntry.php CHANGED
@@ -110,7 +110,7 @@ class FrmEntry {
110
 
111
  global $wpdb;
112
 
113
- $entry_exists = FrmDb::get_col( $wpdb->prefix .'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC') );
114
 
115
  if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
116
  return false;
@@ -178,7 +178,7 @@ class FrmEntry {
178
  FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
179
  self::clear_cache();
180
 
181
- do_action('frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id));
182
  return $entry_id;
183
  }
184
 
@@ -260,7 +260,7 @@ class FrmEntry {
260
  public static function &update_form( $id, $value, $form_id ) {
261
  global $wpdb;
262
  $form_id = isset($value) ? $form_id : null;
263
- $result = $wpdb->update( $wpdb->prefix .'frm_items', array( 'form_id' => $form_id), array( 'id' => $id ) );
264
  if ( $result ) {
265
  self::clear_cache();
266
  }
@@ -312,7 +312,7 @@ class FrmEntry {
312
  }
313
 
314
  global $wpdb;
315
- $metas = FrmDb::get_results( $wpdb->prefix .'frm_item_metas m LEFT JOIN '. $wpdb->prefix .'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0), 'field_id, meta_value, field_key, item_id' );
316
 
317
  $entry->metas = array();
318
 
@@ -365,7 +365,7 @@ class FrmEntry {
365
  }
366
 
367
  public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
368
- global $wpdb;
369
 
370
  $limit = FrmAppHelper::esc_limit($limit);
371
 
@@ -394,7 +394,9 @@ class FrmEntry {
394
  $entries = $wpdb->get_results($query, OBJECT_K);
395