Formidable Forms – Form Builder for WordPress - Version 2.05.08

Version Description

  • Fix: Hide extra columns on the Formidable -> Entries page more accurately
  • Fix: Prevent WP confirmation messages from showing when saving a form
  • Fix: Some tooltips were partially covered by the admin menu
  • Pro Version Forms
  • Enhancement: When [auto_id start=100] is higher than the last value in the entry, use 100.
  • Enhancement: Remove type="text/javascript" for new HTML5 validation requirements
  • Fix: The Formidable -> Views page didn't look good on small screens
  • Fix: All custom field rows were being removed in post settings when one was removed
  • Fix: Lookup calculations in repeating sections were returning javascript errors
Download this release

Release Info

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

Code changes from version 2.05.07 to 2.05.08

Files changed (116) hide show
  1. classes/controllers/FrmAddonsController.php +28 -5
  2. classes/controllers/FrmAppController.php +21 -9
  3. classes/controllers/FrmEntriesController.php +52 -42
  4. classes/controllers/FrmFieldsController.php +95 -92
  5. classes/controllers/FrmFormActionsController.php +10 -7
  6. classes/controllers/FrmFormsController.php +68 -25
  7. classes/controllers/FrmHooksController.php +2 -2
  8. classes/controllers/FrmSettingsController.php +4 -3
  9. classes/controllers/FrmStylesController.php +111 -111
  10. classes/controllers/FrmXMLController.php +227 -200
  11. classes/factories/FrmEntryFactory.php +1 -1
  12. classes/factories/FrmFieldFactory.php +1 -2
  13. classes/helpers/FrmAppHelper.php +142 -86
  14. classes/helpers/FrmCSVExportHelper.php +58 -59
  15. classes/helpers/FrmEmailHelper.php +1 -1
  16. classes/helpers/FrmEntriesHelper.php +16 -6
  17. classes/helpers/FrmEntriesListHelper.php +36 -15
  18. classes/helpers/FrmFieldsHelper.php +199 -171
  19. classes/helpers/FrmFormsHelper.php +68 -35
  20. classes/helpers/FrmFormsListHelper.php +53 -28
  21. classes/helpers/FrmListHelper.php +6 -11
  22. classes/helpers/FrmStylesHelper.php +83 -55
  23. classes/helpers/FrmTipsHelper.php +2 -2
  24. classes/helpers/FrmXMLHelper.php +33 -23
  25. classes/models/FrmAddon.php +44 -34
  26. classes/models/FrmCreateFile.php +4 -1
  27. classes/models/FrmDb.php +37 -30
  28. classes/models/FrmEDD_SL_Plugin_Updater.php +10 -2
  29. classes/models/FrmEmail.php +7 -7
  30. classes/models/FrmEntry.php +15 -13
  31. classes/models/FrmEntryFormat.php +17 -4
  32. classes/models/FrmEntryFormatter.php +6 -7
  33. classes/models/FrmEntryMeta.php +29 -17
  34. classes/models/FrmEntryShortcodeFormatter.php +1 -2
  35. classes/models/FrmEntryValidate.php +4 -1
  36. classes/models/FrmEntryValues.php +1 -1
  37. classes/models/FrmField.php +47 -13
  38. classes/models/FrmFieldOption.php +3 -4
  39. classes/models/FrmFieldValue.php +3 -2
  40. classes/models/FrmFieldValueSelector.php +1 -1
  41. classes/models/FrmForm.php +77 -28
  42. classes/models/FrmFormAction.php +19 -16
  43. classes/models/FrmMigrate.php +5 -1
  44. classes/models/FrmPointers.php +19 -6
  45. classes/models/FrmStyle.php +16 -10
  46. classes/models/FrmTableHTMLGenerator.php +2 -2
  47. classes/views/addons/list.php +5 -5
  48. classes/views/addons/settings.php +2 -2
  49. classes/views/addons/upgrade_to_pro.php +1 -1
  50. classes/views/frm-entries/_sidebar-shared-pub.php +2 -1
  51. classes/views/frm-entries/errors.php +8 -5
  52. classes/views/frm-entries/form.php +13 -13
  53. classes/views/frm-entries/list.php +1 -1
  54. classes/views/frm-entries/new.php +7 -13
  55. classes/views/frm-entries/no_entries.php +9 -15
  56. classes/views/frm-entries/show.php +13 -9
  57. classes/views/frm-entries/sidebar-shared.php +12 -12
  58. classes/views/frm-entries/sidebar-show.php +6 -5
  59. classes/views/frm-fields/back-end/automatic-width.php +2 -2
  60. classes/views/frm-fields/back-end/dropdown-field.php +23 -21
  61. classes/views/frm-fields/back-end/max.php +1 -1
  62. classes/views/frm-fields/back-end/pixels-wide.php +2 -2
  63. classes/views/frm-fields/front-end/dropdown-field.php +21 -12
  64. classes/views/frm-fields/import_choices.php +32 -27
  65. classes/views/frm-fields/input.php +69 -50
  66. classes/views/frm-fields/radio.php +1 -1
  67. classes/views/frm-fields/show-build.php +18 -15
  68. classes/views/frm-fields/single-option.php +10 -10
  69. classes/views/frm-form-actions/_action_inside.php +16 -9
  70. classes/views/frm-form-actions/_email_settings.php +71 -52
  71. classes/views/frm-form-actions/form_action.php +3 -3
  72. classes/views/frm-forms/_publish_box.php +23 -20
  73. classes/views/frm-forms/add_field.php +137 -105
  74. classes/views/frm-forms/add_field_links.php +65 -46
  75. classes/views/frm-forms/edit.php +2 -2
  76. classes/views/frm-forms/form.php +8 -7
  77. classes/views/frm-forms/insert_form_popup.php +49 -45
  78. classes/views/frm-forms/list.php +3 -2
  79. classes/views/frm-forms/mb_html_tab.php +46 -28
  80. classes/views/frm-forms/mb_insert_fields.php +5 -5
  81. classes/views/frm-forms/new.php +2 -2
  82. classes/views/frm-forms/settings.php +140 -94
  83. classes/views/frm-forms/shortcode_opts.php +12 -8
  84. classes/views/frm-settings/form.php +49 -40
  85. classes/views/frm-settings/license_box.php +4 -4
  86. classes/views/shared/errors.php +6 -5
  87. classes/views/shared/mb_adv_info.php +80 -58
  88. classes/views/styles/_buttons.php +111 -117
  89. classes/views/styles/_check-box-radio-fields.php +25 -15
  90. classes/views/styles/_field-colors.php +112 -96
  91. classes/views/styles/_field-description.php +24 -16
  92. classes/views/styles/_field-labels.php +17 -13
  93. classes/views/styles/_field-sizes.php +8 -8
  94. classes/views/styles/_form-description.php +8 -8
  95. classes/views/styles/_form-messages.php +45 -47
  96. classes/views/styles/_form-title.php +8 -8
  97. classes/views/styles/_general.php +28 -18
  98. classes/views/styles/_sample_form.php +17 -17
  99. classes/views/styles/custom_css.php +3 -2
  100. classes/views/styles/manage.php +30 -22
  101. classes/views/styles/show.php +21 -18
  102. classes/views/xml/forms_xml.php +2 -1
  103. classes/views/xml/import_form.php +94 -85
  104. classes/views/xml/posts_xml.php +27 -21
  105. classes/views/xml/xml.php +11 -11
  106. classes/widgets/FrmShowForm.php +25 -12
  107. css/_single_theme.css.php +23 -20
  108. css/custom_theme.css.php +10 -10
  109. formidable.php +5 -4
  110. js/formidable.js +23 -3
  111. js/formidable.min.js +73 -72
  112. js/formidable_admin.js +25 -19
  113. languages/formidable-da_DK.mo +0 -0
  114. languages/formidable-da_DK.po +7997 -0
  115. languages/formidable-fr_FR.mo +0 -0
  116. languages/formidable-fr_FR.po +5581 -0
classes/controllers/FrmAddonsController.php CHANGED
@@ -209,7 +209,10 @@ class FrmAddonsController {
209
 
210
  if ( $license && is_array( $license ) && isset( $license['license'] ) ) {
211
  $url = 'https://formidableforms.com/frm-edd-api/licenses?l=' . urlencode( base64_encode( $license['license'] ) );
212
- $licenses = self::send_api_request( $url, array( 'name' => 'frm_api_licence', 'expires' => 60 * 60 * 5 ) );
 
 
 
213
  echo json_encode( $licenses );
214
  }
215
 
@@ -250,10 +253,30 @@ class FrmAddonsController {
250
 
251
  private static function prepare_pro_info() {
252
  return array(
253
- 'personal' => array( 'id' => 2, 'download' => 19367654, 'price' => '49.00', 'name' => 'Personal' ),
254
- 'professional' => array( 'id' => 0, 'download' => 19367001, 'price' => '99.00', 'name' => 'Professional' ),
255
- 'smallbusiness' => array( 'id' => 0, 'download' => 19366995, 'price' => '199.00', 'name' => 'Small Business' ),
256
- 'enterprise' => array( 'id' => 0, 'download' => 19366992, 'price' => '399.00', 'name' => 'Enterprise' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  );
258
  }
259
 
209
 
210
  if ( $license && is_array( $license ) && isset( $license['license'] ) ) {
211
  $url = 'https://formidableforms.com/frm-edd-api/licenses?l=' . urlencode( base64_encode( $license['license'] ) );
212
+ $licenses = self::send_api_request( $url, array(
213
+ 'name' => 'frm_api_licence',
214
+ 'expires' => 60 * 60 * 5,
215
+ ) );
216
  echo json_encode( $licenses );
217
  }
218
 
253
 
254
  private static function prepare_pro_info() {
255
  return array(
256
+ 'personal' => array(
257
+ 'id' => 2,
258
+ 'download' => 19367654,
259
+ 'price' => '49.00',
260
+ 'name' => 'Personal',
261
+ ),
262
+ 'professional' => array(
263
+ 'id' => 0,
264
+ 'download' => 19367001,
265
+ 'price' => '99.00',
266
+ 'name' => 'Professional',
267
+ ),
268
+ 'smallbusiness' => array(
269
+ 'id' => 0,
270
+ 'download' => 19366995,
271
+ 'price' => '199.00',
272
+ 'name' => 'Small Business',
273
+ ),
274
+ 'enterprise' => array(
275
+ 'id' => 0,
276
+ 'download' => 19366992,
277
+ 'price' => '399.00',
278
+ 'name' => 'Enterprise',
279
+ ),
280
  );
281
  }
282
 
classes/controllers/FrmAppController.php CHANGED
@@ -13,7 +13,11 @@ class FrmAppController {
13
  }
14
 
15
  private static function get_menu_position() {
16
- $count = count( get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) );
 
 
 
 
17
  $pos = $count ? '22.7' : '29.3';
18
  $pos = apply_filters( 'frm_menu_position', $pos );
19
  return $pos;
@@ -81,7 +85,10 @@ class FrmAppController {
81
  ),
82
  );
83
 
84
- $nav_items = apply_filters( 'frm_form_nav_list', $nav_items, array( 'form_id' => $id, 'form' => $form ) );
 
 
 
85
  return $nav_items;
86
  }
87
 
@@ -115,7 +122,8 @@ class FrmAppController {
115
  '<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
116
  '<a href="#" class="frm_deauthorize_link">', '</a>'
117
  ), esc_url( $inst_install_url )
118
- ) ); ?>
 
119
  </div>
120
  <?php
121
  }
@@ -136,9 +144,9 @@ class FrmAppController {
136
  $tip = FrmTipsHelper::get_banner_tip();
137
  ?>
138
  <div class="update-nag frm-update-to-pro">
139
- <?php echo FrmAppHelper::kses( $tip['tip'] ) ?>
140
- <span><?php echo FrmAppHelper::kses( $tip['call'] ) ?></span>
141
- <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url('https://formidableforms.com?banner=1&tip=' . absint( $tip['num'] ) ) ) ?>" class="button">Upgrade to Pro</a>
142
  </div>
143
  <?php
144
  }
@@ -229,10 +237,14 @@ class FrmAppController {
229
  FrmAppHelper::load_admin_wide_js( false );
230
 
231
  wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
232
- 'formidable_admin_global', 'formidable', 'jquery',
233
- 'jquery-ui-core', 'jquery-ui-draggable',
 
 
 
234
  'jquery-ui-sortable',
235
- 'bootstrap_tooltip', 'bootstrap-multiselect',
 
236
  ), $version, true );
237
  wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
238
  wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' );
13
  }
14
 
15
  private static function get_menu_position() {
16
+ $count = count( get_post_types( array(
17
+ 'show_ui' => true,
18
+ '_builtin' => false,
19
+ 'show_in_menu' => true,
20
+ ) ) );
21
  $pos = $count ? '22.7' : '29.3';
22
  $pos = apply_filters( 'frm_menu_position', $pos );
23
  return $pos;
85
  ),
86
  );
87
 
88
+ $nav_items = apply_filters( 'frm_form_nav_list', $nav_items, array(
89
+ 'form_id' => $id,
90
+ 'form' => $form,
91
+ ) );
92
  return $nav_items;
93
  }
94
 
122
  '<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
123
  '<a href="#" class="frm_deauthorize_link">', '</a>'
124
  ), esc_url( $inst_install_url )
125
+ ) );
126
+ ?>
127
  </div>
128
  <?php
129
  }
144
  $tip = FrmTipsHelper::get_banner_tip();
145
  ?>
146
  <div class="update-nag frm-update-to-pro">
147
+ <?php echo FrmAppHelper::kses( $tip['tip'] ); ?>
148
+ <span><?php echo FrmAppHelper::kses( $tip['call'] ); ?></span>
149
+ <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url('https://formidableforms.com?banner=1&tip=' . absint( $tip['num'] ) ) ); ?>" class="button">Upgrade to Pro</a>
150
  </div>
151
  <?php
152
  }
237
  FrmAppHelper::load_admin_wide_js( false );
238
 
239
  wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
240
+ 'formidable_admin_global',
241
+ 'formidable',
242
+ 'jquery',
243
+ 'jquery-ui-core',
244
+ 'jquery-ui-draggable',
245
  'jquery-ui-sortable',
246
+ 'bootstrap_tooltip',
247
+ 'bootstrap-multiselect',
248
  ), $version, true );
249
  wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
250
  wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' );
classes/controllers/FrmEntriesController.php CHANGED
@@ -5,7 +5,7 @@ class FrmEntriesController {
5
  public static function menu() {
6
  FrmAppHelper::force_capability( 'frm_view_entries' );
7
 
8
- add_submenu_page('formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
9
 
10
  self::load_manage_entries_hooks();
11
  }
@@ -96,7 +96,11 @@ class FrmEntriesController {
96
 
97
  $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
98
  if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
99
- add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) );
 
 
 
 
100
  }
101
 
102
  return $columns;
@@ -120,16 +124,16 @@ class FrmEntriesController {
120
  continue;
121
  }
122
  $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
123
- unset($sub_form_col);
124
  }
125
  }
126
- unset($sub_form_cols);
127
  } else {
128
  $col_id = $form_col->field_key;
129
  if ( $form_col->form_id != $form_id ) {
130
  $col_id .= '-_-form' . $form_col->form_id;
131
  }
132
-
133
  $has_separate_value = ! FrmField::is_option_empty( $form_col, 'separate_value' );
134
  $is_post_status = FrmField::is_option_true( $form_col, 'post_field' ) && $form_col->field_options['post_field'] == 'post_status';
135
  if ( $has_separate_value && ! $is_post_status ) {
@@ -157,8 +161,8 @@ class FrmEntriesController {
157
  }
158
 
159
  global $frm_vars;
160
- //add a check so we don't create a loop
161
- $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
162
 
163
  return $check;
164
  }
@@ -170,10 +174,10 @@ class FrmEntriesController {
170
  return;
171
  }
172
 
173
- global $frm_vars;
174
- if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
175
- return; //don't continue if there's no previous value
176
- }
177
 
178
  foreach ( $meta_value as $mk => $mv ) {
179
  //remove blank values
@@ -182,8 +186,8 @@ class FrmEntriesController {
182
  }
183
  }
184
 
185
- $cur_form_prefix = reset($meta_value);
186
- $cur_form_prefix = explode('_', $cur_form_prefix);
187
  $cur_form_prefix = $cur_form_prefix[0];
188
  $save = false;
189
 
@@ -202,7 +206,7 @@ class FrmEntriesController {
202
 
203
  $meta_value[] = $prev_hidden;
204
  $save = true;
205
- unset($form_prefix);
206
  }
207
 
208
  if ( $save ) {
@@ -261,30 +265,25 @@ class FrmEntriesController {
261
 
262
  public static function hidden_columns( $result ) {
263
  $form_id = FrmForm::get_current_form_id();
264
- $max_columns = 8;
265
 
266
  $hidden = self::user_hidden_columns_for_form( $form_id, $result );
267
 
 
 
 
268
  if ( ! empty( $hidden ) ) {
269
- $max_columns = 11;
270
  $result = $hidden;
 
 
 
 
271
  }
272
 
273
- global $frm_vars;
274
- $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
275
  if ( $i <= $max_columns ) {
276
  return $result;
277
  }
278
 
279
- if ( $form_id ) {
280
- $result[] = $form_id . '_id';
281
- $i--;
282
- }
283
-
284
- $result[] = $form_id . '_item_key';
285
- $i--;
286
-
287
- self::remove_excess_cols( compact( 'i', 'max_columns' ), $result );
288
 
289
  return $result;
290
  }
@@ -316,16 +315,24 @@ class FrmEntriesController {
316
  private static function remove_excess_cols( $atts, &$result ) {
317
  global $frm_vars;
318
 
319
- $cols = $frm_vars['cols'];
320
- $cols = array_reverse( $cols, true );
 
 
 
 
321
  $i = $atts['i'];
322
 
323
  foreach ( $cols as $col_key => $col ) {
324
- if ( $i > $atts['max_columns'] ) {
 
 
 
 
325
  $result[] = $col_key;
 
326
  }
327
 
328
- $i--;
329
  unset( $col_key, $col );
330
  }
331
  }
@@ -355,14 +362,14 @@ class FrmEntriesController {
355
  if ( $pagenum > $total_pages && $total_pages > 0 ) {
356
  $url = add_query_arg( 'paged', $total_pages );
357
  if ( headers_sent() ) {
358
- echo FrmAppHelper::js_redirect($url);
359
  } else {
360
  wp_redirect( esc_url_raw( $url ) );
361
  }
362
  die();
363
  }
364
 
365
- if ( empty($message) && isset($_GET['import-message']) ) {
366
  $message = __( 'Your import is complete', 'formidable' );
367
  }
368
 
@@ -379,7 +386,7 @@ class FrmEntriesController {
379
 
380
  /* Back End CRUD */
381
  public static function show( $id = 0 ) {
382
- FrmAppHelper::permission_check('frm_view_entries');
383
 
384
  if ( ! $id ) {
385
  $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
@@ -389,7 +396,7 @@ class FrmEntriesController {
389
  }
390
  }
391
 
392
- $entry = FrmEntry::getOne($id, true);
393
  if ( ! $entry ) {
394
  echo '<div id="form_show_entry_page" class="wrap">' .
395
  __( 'You are trying to view an entry that does not exist.', 'formidable' ) .
@@ -397,7 +404,7 @@ class FrmEntriesController {
397
  return;
398
  }
399
 
400
- $data = maybe_unserialize($entry->description);
401
  if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
402
  $data = array( 'referrer' => $data );
403
  }
@@ -409,11 +416,11 @@ class FrmEntriesController {
409
  }
410
 
411
  public static function destroy() {
412
- FrmAppHelper::permission_check('frm_delete_entries');
413
 
414
  $params = FrmForm::get_admin_params();
415
 
416
- if ( isset($params['keep_post']) && $params['keep_post'] ) {
417
  //unlink entry from post
418
  global $wpdb;
419
  $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) );
@@ -579,7 +586,10 @@ class FrmEntriesController {
579
  $atts = shortcode_atts( $defaults, $atts );
580
 
581
  if ( $atts['default_email'] ) {
582
- $shortcode_atts = array( 'format' => $atts['format'], 'plain_text' => $atts['plain_text'] );
 
 
 
583
  $entry_shortcode_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
584
  $formatted_entry = $entry_shortcode_formatter->content();
585
 
@@ -599,9 +609,9 @@ class FrmEntriesController {
599
  }
600
 
601
  public static function entry_sidebar( $entry ) {
602
- $data = maybe_unserialize($entry->description);
603
- $date_format = get_option('date_format');
604
- $time_format = get_option('time_format');
605
  if ( isset( $data['browser'] ) ) {
606
  $browser = FrmEntriesHelper::get_browser( $data['browser'] );
607
  }
5
  public static function menu() {
6
  FrmAppHelper::force_capability( 'frm_view_entries' );
7
 
8
+ add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
9
 
10
  self::load_manage_entries_hooks();
11
  }
96
 
97
  $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
98
  if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
99
+ add_screen_option( 'per_page', array(
100
+ 'label' => __( 'Entries', 'formidable' ),
101
+ 'default' => 20,
102
+ 'option' => 'formidable_page_formidable_entries_per_page',
103
+ ) );
104
  }
105
 
106
  return $columns;
124
  continue;
125
  }
126
  $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
127
+ unset( $sub_form_col );
128
  }
129
  }
130
+ unset( $sub_form_cols );
131
  } else {
132
  $col_id = $form_col->field_key;
133
  if ( $form_col->form_id != $form_id ) {
134
  $col_id .= '-_-form' . $form_col->form_id;
135
  }
136
+
137
  $has_separate_value = ! FrmField::is_option_empty( $form_col, 'separate_value' );
138
  $is_post_status = FrmField::is_option_true( $form_col, 'post_field' ) && $form_col->field_options['post_field'] == 'post_status';
139
  if ( $has_separate_value && ! $is_post_status ) {
161
  }
162
 
163
  global $frm_vars;
164
+ //add a check so we don't create a loop
165
+ $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
166
 
167
  return $check;
168
  }
174
  return;
175
  }
176
 
177
+ global $frm_vars;
178
+ if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
179
+ return; //don't continue if there's no previous value
180
+ }
181
 
182
  foreach ( $meta_value as $mk => $mv ) {
183
  //remove blank values
186
  }
187
  }
188
 
189
+ $cur_form_prefix = reset( $meta_value );
190
+ $cur_form_prefix = explode( '_', $cur_form_prefix );
191
  $cur_form_prefix = $cur_form_prefix[0];
192
  $save = false;
193
 
206
 
207
  $meta_value[] = $prev_hidden;
208
  $save = true;
209
+ unset( $form_prefix );
210
  }
211
 
212
  if ( $save ) {
265
 
266
  public static function hidden_columns( $result ) {
267
  $form_id = FrmForm::get_current_form_id();
 
268
 
269
  $hidden = self::user_hidden_columns_for_form( $form_id, $result );
270
 
271
+ global $frm_vars;
272
+ $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
273
+
274
  if ( ! empty( $hidden ) ) {
 
275
  $result = $hidden;
276
+ $i = $i - count( $result );
277
+ $max_columns = 11;
278
+ } else {
279
+ $max_columns = 8;
280
  }
281
 
 
 
282
  if ( $i <= $max_columns ) {
283
  return $result;
284
  }
285
 
286
+ self::remove_excess_cols( compact( 'i', 'max_columns', 'form_id' ), $result );
 
 
 
 
 
 
 
 
287
 
288
  return $result;
289
  }
315
  private static function remove_excess_cols( $atts, &$result ) {
316
  global $frm_vars;
317
 
318
+ $remove_first = array(
319
+ $atts['form_id'] . '_item_key' => '',
320
+ $atts['form_id'] . '_id' => '',
321
+ );
322
+ $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
323
+
324
  $i = $atts['i'];
325
 
326
  foreach ( $cols as $col_key => $col ) {
327
+ if ( $i <= $atts['max_columns'] ) {
328
+ break;
329
+ }
330
+
331
+ if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
332
  $result[] = $col_key;
333
+ $i--;
334
  }
335
 
 
336
  unset( $col_key, $col );
337
  }
338
  }
362
  if ( $pagenum > $total_pages && $total_pages > 0 ) {
363
  $url = add_query_arg( 'paged', $total_pages );
364
  if ( headers_sent() ) {
365
+ echo FrmAppHelper::js_redirect( $url );
366
  } else {
367
  wp_redirect( esc_url_raw( $url ) );
368
  }
369
  die();
370
  }
371
 
372
+ if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
373
  $message = __( 'Your import is complete', 'formidable' );
374
  }
375
 
386
 
387
  /* Back End CRUD */
388
  public static function show( $id = 0 ) {
389
+ FrmAppHelper::permission_check( 'frm_view_entries' );
390
 
391
  if ( ! $id ) {
392
  $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
396
  }
397
  }
398
 
399
+ $entry = FrmEntry::getOne( $id, true );
400
  if ( ! $entry ) {
401
  echo '<div id="form_show_entry_page" class="wrap">' .
402
  __( 'You are trying to view an entry that does not exist.', 'formidable' ) .
404
  return;
405
  }
406
 
407
+ $data = maybe_unserialize( $entry->description );
408
  if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
409
  $data = array( 'referrer' => $data );
410
  }
416
  }
417
 
418
  public static function destroy() {
419
+ FrmAppHelper::permission_check( 'frm_delete_entries' );
420
 
421
  $params = FrmForm::get_admin_params();
422
 
423
+ if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
424
  //unlink entry from post
425
  global $wpdb;
426
  $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) );
586
  $atts = shortcode_atts( $defaults, $atts );
587
 
588
  if ( $atts['default_email'] ) {
589
+ $shortcode_atts = array(
590
+ 'format' => $atts['format'],
591
+ 'plain_text' => $atts['plain_text'],
592
+ );
593
  $entry_shortcode_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
594
  $formatted_entry = $entry_shortcode_formatter->content();
595
 
609
  }
610
 
611
  public static function entry_sidebar( $entry ) {
612
+ $data = maybe_unserialize( $entry->description );
613
+ $date_format = get_option( 'date_format' );
614
+ $time_format = get_option( 'time_format' );
615
  if ( isset( $data['browser'] ) ) {
616
  $browser = FrmEntriesHelper::get_browser( $data['browser'] );
617
  }
classes/controllers/FrmFieldsController.php CHANGED
@@ -3,7 +3,7 @@
3
  class FrmFieldsController {
4
 
5
  public static function load_field() {
6
- FrmAppHelper::permission_check('frm_edit_forms');
7
  check_ajax_referer( 'frm_ajax', 'nonce' );
8
 
9
  $fields = $_POST['field'];
@@ -34,7 +34,7 @@ class FrmFieldsController {
34
  }
35
 
36
  $field_name = 'item_meta[' . $field_id . ']';
37
- $html_id = FrmFieldsHelper::get_html_id($field);
38
 
39
  ob_start();
40
  include( $path . '/classes/views/frm-forms/add_field.php' );
@@ -42,9 +42,9 @@ class FrmFieldsController {
42
  ob_end_clean();
43
  }
44
 
45
- unset($path);
46
 
47
- echo json_encode($field_html);
48
 
49
  wp_die();
50
  }
@@ -53,7 +53,7 @@ class FrmFieldsController {
53
  * Create a new field with ajax
54
  */
55
  public static function create() {
56
- FrmAppHelper::permission_check('frm_edit_forms');
57
  check_ajax_referer( 'frm_ajax', 'nonce' );
58
 
59
  $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
@@ -61,8 +61,8 @@ class FrmFieldsController {
61
 
62
  $field = self::include_new_field( $field_type, $form_id );
63
 
64
- // this hook will allow for multiple fields to be added at once
65
- do_action('frm_after_field_created', $field, $form_id);
66
 
67
  wp_die();
68
  }
@@ -75,10 +75,10 @@ class FrmFieldsController {
75
  * @return array|bool
76
  */
77
  public static function include_new_field( $field_type, $form_id ) {
78
- $values = array();
79
- if ( FrmAppHelper::pro_is_installed() ) {
80
- $values['post_type'] = FrmProFormsHelper::post_type($form_id);
81
- }
82
 
83
  $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
84
  $field_values = apply_filters( 'frm_before_field_created', $field_values );
@@ -89,27 +89,27 @@ class FrmFieldsController {
89
  return false;
90
  }
91
 
92
- $field = self::include_single_field($field_id, $values, $form_id);
93
 
94
  return $field;
95
  }
96
 
97
  public static function edit_name( $field = 'name', $id = '' ) {
98
- FrmAppHelper::permission_check('frm_edit_forms');
99
- check_ajax_referer( 'frm_ajax', 'nonce' );
100
 
101
- if ( empty($field) ) {
102
- $field = 'name';
103
- }
104
 
105
- if ( empty($id) ) {
106
  $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
107
  $id = str_replace( 'field_label_', '', $id );
108
  }
109
 
110
  $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' );
111
  $value = trim( $value );
112
- if ( trim(strip_tags($value)) == '' ) {
113
  // set blank value if there is no content
114
  $value = '';
115
  }
@@ -123,7 +123,7 @@ class FrmFieldsController {
123
  }
124
 
125
  public static function update_ajax_option() {
126
- FrmAppHelper::permission_check('frm_edit_forms');
127
  check_ajax_referer( 'frm_ajax', 'nonce' );
128
 
129
  $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
@@ -136,18 +136,18 @@ class FrmFieldsController {
136
  if ( isset( $_POST['separate_value'] ) ) {
137
  $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
138
  $field->field_options['separate_value'] = $new_val;
139
- unset($new_val);
140
  }
141
 
142
  FrmField::update( $field_id, array(
143
  'field_options' => $field->field_options,
144
- 'form_id' => $field->form_id,
145
  ) );
146
  wp_die();
147
  }
148
 
149
  public static function duplicate() {
150
- FrmAppHelper::permission_check('frm_edit_forms');
151
  check_ajax_referer( 'frm_ajax', 'nonce' );
152
 
153
  global $wpdb;
@@ -172,7 +172,7 @@ class FrmFieldsController {
172
  wp_die();
173
  }
174
 
175
- self::include_single_field($field_id, $values);
176
 
177
  wp_die();
178
  }
@@ -181,9 +181,9 @@ class FrmFieldsController {
181
  * Load a single field in the form builder along with all needed variables
182
  */
183
  public static function include_single_field( $field_id, $values, $form_id = 0 ) {
184
- $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
185
  $field_name = 'item_meta[' . $field_id . ']';
186
- $html_id = FrmFieldsHelper::get_html_id($field);
187
  $id = $form_id ? $form_id : $field['form_id'];
188
  if ( $field['type'] == 'html' ) {
189
  $field['stop_filter'] = true;
@@ -195,7 +195,7 @@ class FrmFieldsController {
195
  }
196
 
197
  public static function destroy() {
198
- FrmAppHelper::permission_check('frm_edit_forms');
199
  check_ajax_referer( 'frm_ajax', 'nonce' );
200
 
201
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
@@ -207,14 +207,14 @@ class FrmFieldsController {
207
 
208
  //Add Single Option or Other Option
209
  public static function add_option() {
210
- FrmAppHelper::permission_check('frm_edit_forms');
211
  check_ajax_referer( 'frm_ajax', 'nonce' );
212
 
213
  $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
214
  $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
215
  $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' );
216
 
217
- $field = FrmField::getOne($id);
218
 
219
  if ( 'other' == $opt_type ) {
220
  $opt = __( 'Other', 'formidable' );
@@ -284,9 +284,9 @@ class FrmFieldsController {
284
 
285
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
286
  $prepop = array();
287
- FrmFieldsHelper::get_bulk_prefilled_opts($prepop);
288
 
289
- $field = FrmField::getOne($field_id);
290
 
291
  wp_enqueue_script( 'utils' );
292
  wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' );
@@ -296,38 +296,41 @@ class FrmFieldsController {
296
  wp_die();
297
  }
298
 
299
- public static function import_options() {
300
- FrmAppHelper::permission_check('frm_edit_forms');
301
- check_ajax_referer( 'frm_ajax', 'nonce' );
302
 
303
- if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
304
- return;
305
- }
306
 
307
  $field_id = absint( $_POST['field_id'] );
308
- $field = FrmField::getOne($field_id);
309
 
310
  if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
311
  return;
312
  }
313
 
314
- $field = FrmFieldsHelper::setup_edit_vars($field);
315
  $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
316
  $opts = explode( "\n", rtrim( $opts, "\n" ) );
317
  $opts = array_map( 'trim', $opts );
318
 
319
- if ( $field['separate_value'] ) {
320
- foreach ( $opts as $opt_key => $opt ) {
321
- if ( strpos($opt, '|') !== false ) {
322
- $vals = explode('|', $opt);
323
- if ( $vals[0] != $vals[1] ) {
324
- $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) );
325
- }
326
- unset($vals);
327
- }
328
- unset($opt_key, $opt);
329
- }
330
- }
 
 
 
331
 
332
  //Keep other options after bulk update
333
  if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
@@ -336,12 +339,12 @@ class FrmFieldsController {
336
  if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
337
  $other_array[ $opt_key ] = $opt;
338
  }
339
- unset($opt_key, $opt);
340
- }
341
- if ( ! empty($other_array) ) {
342
- $opts = array_merge( $opts, $other_array);
343
- }
344
- }
345
 
346
  $field['options'] = $opts;
347
 
@@ -353,14 +356,14 @@ class FrmFieldsController {
353
 
354
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' );
355
  } else {
356
- FrmFieldsHelper::show_single_option($field);
357
  }
358
 
359
  wp_die();
360
  }
361
 
362
  public static function update_order() {
363
- FrmAppHelper::permission_check('frm_edit_forms');
364
  check_ajax_referer( 'frm_ajax', 'nonce' );
365
 
366
  $fields = FrmAppHelper::get_post_param( 'frm_field_id' );
@@ -397,18 +400,18 @@ class FrmFieldsController {
397
  $display['invalid'] = true;
398
  $display['default_blank'] = false;
399
  $display['captcha_size'] = true;
400
- break;
401
  case 'radio':
402
  $display['default_blank'] = false;
403
- break;
404
  case 'text':
405
  case 'textarea':
406
  $display['size'] = true;
407
  $display['clear_on_focus'] = true;
408
- break;
409
  case 'select':
410
  $display['size'] = true;
411
- break;
412
  case 'url':
413
  case 'website':
414
  case 'email':
@@ -422,19 +425,19 @@ class FrmFieldsController {
422
 
423
  public static function input_html( $field, $echo = true ) {
424
  $class = array(); //$field['type'];
425
- self::add_input_classes($field, $class);
426
 
427
- $add_html = array();
428
- self::add_html_size($field, $add_html);
429
- self::add_html_length($field, $add_html);
430
- self::add_html_placeholder($field, $add_html, $class);
431
  self::add_validation_messages( $field, $add_html );
432
 
433
- $class = apply_filters('frm_field_classes', implode(' ', $class), $field);
434
 
435
  FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
436
 
437
- self::add_shortcodes_to_html($field, $add_html);
438
 
439
  $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
440
  $add_html = ' ' . implode( ' ', $add_html ) . ' ';
@@ -447,17 +450,17 @@ class FrmFieldsController {
447
  }
448
 
449
  private static function add_input_classes( $field, array &$class ) {
450
- if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
451
- $class[] = $field['input_class'];
452
- }
453
 
454
  if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
455
  return;
456
  }
457
 
458
- if ( isset($field['size']) && $field['size'] > 0 ) {
459
- $class[] = 'auto_width';
460
- }
461
  }
462
 
463
  private static function add_html_size( $field, array &$add_html ) {
@@ -469,15 +472,15 @@ class FrmFieldsController {
469
  return;
470
  }
471
 
472
- if ( is_numeric($field['size']) ) {
473
- $field['size'] .= 'px';
474
- }
475
 
476
- $important = apply_filters('frm_use_important_width', 1, $field);
477
  // Note: This inline styling must stay since we cannot realistically set a class for every possible field size
478
  $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
479
 
480
- self::add_html_cols($field, $add_html);
481
  }
482
 
483
  private static function add_html_cols( $field, array &$add_html ) {
@@ -493,8 +496,8 @@ class FrmFieldsController {
493
  'em' => 0.544,
494
  );
495
 
496
- // include "col" for valid html
497
- $unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
498
 
499
  if ( ! isset( $calc[ $unit ] ) ) {
500
  return;
@@ -511,7 +514,7 @@ class FrmFieldsController {
511
  return;
512
  }
513
 
514
- if ( FrmAppHelper::is_admin_page('formidable' ) ) {
515
  // don't load on form builder page
516
  return;
517
  }
@@ -591,7 +594,7 @@ class FrmFieldsController {
591
  private static function add_placeholder_to_input( $field, &$add_html ) {
592
  if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
593
  $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"';
594
- wp_enqueue_script('jquery-placeholder');
595
  }
596
  }
597
 
@@ -626,7 +629,7 @@ class FrmFieldsController {
626
  continue;
627
  }
628
 
629
- if ( is_numeric($k) && strpos($v, '=') ) {
630
  $add_html[] = $v;
631
  } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
632
  $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
@@ -634,7 +637,7 @@ class FrmFieldsController {
634
  $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
635
  }
636
 
637
- unset($k, $v);
638
  }
639
  }
640
 
@@ -650,10 +653,10 @@ class FrmFieldsController {
650
  }
651
 
652
  public static function check_label( $opt ) {
653
- if ( is_array($opt) ) {
654
- $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
655
- }
656
 
657
- return $opt;
658
- }
659
  }
3
  class FrmFieldsController {
4
 
5
  public static function load_field() {
6
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
7
  check_ajax_referer( 'frm_ajax', 'nonce' );
8
 
9
  $fields = $_POST['field'];
34
  }
35
 
36
  $field_name = 'item_meta[' . $field_id . ']';
37
+ $html_id = FrmFieldsHelper::get_html_id( $field );
38
 
39
  ob_start();
40
  include( $path . '/classes/views/frm-forms/add_field.php' );
42
  ob_end_clean();
43
  }
44
 
45
+ unset( $path );
46
 
47
+ echo json_encode( $field_html );
48
 
49
  wp_die();
50
  }
53
  * Create a new field with ajax
54
  */
55
  public static function create() {
56
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
57
  check_ajax_referer( 'frm_ajax', 'nonce' );
58
 
59
  $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61
 
62
  $field = self::include_new_field( $field_type, $form_id );
63
 
64
+ // this hook will allow for multiple fields to be added at once
65
+ do_action( 'frm_after_field_created', $field, $form_id );
66
 
67
  wp_die();
68
  }
75
  * @return array|bool
76
  */
77
  public static function include_new_field( $field_type, $form_id ) {
78
+ $values = array();
79
+ if ( FrmAppHelper::pro_is_installed() ) {
80
+ $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
81
+ }
82
 
83
  $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
84
  $field_values = apply_filters( 'frm_before_field_created', $field_values );
89
  return false;
90
  }
91
 
92
+ $field = self::include_single_field( $field_id, $values, $form_id );
93
 
94
  return $field;
95
  }
96
 
97
  public static function edit_name( $field = 'name', $id = '' ) {
98
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
99
+ check_ajax_referer( 'frm_ajax', 'nonce' );
100
 
101
+ if ( empty( $field ) ) {
102
+ $field = 'name';
103
+ }
104
 
105
+ if ( empty( $id ) ) {
106
  $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
107
  $id = str_replace( 'field_label_', '', $id );
108
  }
109
 
110
  $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' );
111
  $value = trim( $value );
112
+ if ( trim( strip_tags( $value ) ) === '' ) {
113
  // set blank value if there is no content
114
  $value = '';
115
  }
123
  }
124
 
125
  public static function update_ajax_option() {
126
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
127
  check_ajax_referer( 'frm_ajax', 'nonce' );
128
 
129
  $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
136
  if ( isset( $_POST['separate_value'] ) ) {
137
  $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
138
  $field->field_options['separate_value'] = $new_val;
139
+ unset( $new_val );
140
  }
141
 
142
  FrmField::update( $field_id, array(
143
  'field_options' => $field->field_options,
144
+ 'form_id' => $field->form_id,
145
  ) );
146
  wp_die();
147
  }
148
 
149
  public static function duplicate() {
150
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
151
  check_ajax_referer( 'frm_ajax', 'nonce' );
152
 
153
  global $wpdb;
172
  wp_die();
173
  }
174
 
175
+ self::include_single_field( $field_id, $values );
176
 
177
  wp_die();
178
  }
181
  * Load a single field in the form builder along with all needed variables
182
  */
183
  public static function include_single_field( $field_id, $values, $form_id = 0 ) {
184
+ $field = FrmFieldsHelper::setup_edit_vars( FrmField::getOne( $field_id ) );
185
  $field_name = 'item_meta[' . $field_id . ']';
186
+ $html_id = FrmFieldsHelper::get_html_id( $field );
187
  $id = $form_id ? $form_id : $field['form_id'];
188
  if ( $field['type'] == 'html' ) {
189
  $field['stop_filter'] = true;
195
  }
196
 
197
  public static function destroy() {
198
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
199
  check_ajax_referer( 'frm_ajax', 'nonce' );
200
 
201
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
207
 
208
  //Add Single Option or Other Option
209
  public static function add_option() {
210
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
211
  check_ajax_referer( 'frm_ajax', 'nonce' );
212
 
213
  $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
214
  $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
215
  $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' );
216
 
217
+ $field = FrmField::getOne( $id );
218
 
219
  if ( 'other' == $opt_type ) {
220
  $opt = __( 'Other', 'formidable' );
284
 
285
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
286
  $prepop = array();
287
+ FrmFieldsHelper::get_bulk_prefilled_opts( $prepop );
288
 
289
+ $field = FrmField::getOne( $field_id );
290
 
291
  wp_enqueue_script( 'utils' );
292
  wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' );
296
  wp_die();
297
  }
298
 
299
+ public static function import_options() {
300
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
301
+ check_ajax_referer( 'frm_ajax', 'nonce' );
302
 
303
+ if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
304
+ return;
305
+ }
306
 
307
  $field_id = absint( $_POST['field_id'] );
308
+ $field = FrmField::getOne( $field_id );
309
 
310
  if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
311
  return;
312
  }
313
 
314
+ $field = FrmFieldsHelper::setup_edit_vars( $field );
315
  $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
316
  $opts = explode( "\n", rtrim( $opts, "\n" ) );
317
  $opts = array_map( 'trim', $opts );
318
 
319
+ if ( $field['separate_value'] ) {
320
+ foreach ( $opts as $opt_key => $opt ) {
321
+ if ( strpos( $opt, '|' ) !== false ) {
322
+ $vals = explode( '|', $opt );
323
+ if ( $vals[0] != $vals[1] ) {
324
+ $opts[ $opt_key ] = array(
325
+ 'label' => trim( $vals[0] ),
326
+ 'value' => trim( $vals[1] ),
327
+ );
328
+ }
329
+ unset( $vals );
330
+ }
331
+ unset( $opt_key, $opt );
332
+ }
333
+ }
334
 
335
  //Keep other options after bulk update
336
  if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
339
  if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
340
  $other_array[ $opt_key ] = $opt;
341
  }
342
+ unset( $opt_key, $opt );
343
+ }
344
+ if ( ! empty( $other_array ) ) {
345
+ $opts = array_merge( $opts, $other_array );
346
+ }
347
+ }
348
 
349
  $field['options'] = $opts;
350
 
356
 
357
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' );
358
  } else {
359
+ FrmFieldsHelper::show_single_option( $field );
360
  }
361
 
362
  wp_die();
363
  }
364
 
365
  public static function update_order() {
366
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
367
  check_ajax_referer( 'frm_ajax', 'nonce' );
368
 
369
  $fields = FrmAppHelper::get_post_param( 'frm_field_id' );
400
  $display['invalid'] = true;
401
  $display['default_blank'] = false;
402
  $display['captcha_size'] = true;
403
+ break;
404
  case 'radio':
405
  $display['default_blank'] = false;
406
+ break;
407
  case 'text':
408
  case 'textarea':
409
  $display['size'] = true;
410
  $display['clear_on_focus'] = true;
411
+ break;
412
  case 'select':
413
  $display['size'] = true;
414
+ break;
415
  case 'url':
416
  case 'website':
417
  case 'email':
425
 
426
  public static function input_html( $field, $echo = true ) {
427
  $class = array(); //$field['type'];
428
+ self::add_input_classes( $field, $class );
429
 
430
+ $add_html = array();
431
+ self::add_html_size( $field, $add_html );
432
+ self::add_html_length( $field, $add_html );
433
+ self::add_html_placeholder( $field, $add_html, $class );
434
  self::add_validation_messages( $field, $add_html );
435
 
436
+ $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field );
437
 
438
  FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
439
 
440
+ self::add_shortcodes_to_html( $field, $add_html );
441
 
442
  $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
443
  $add_html = ' ' . implode( ' ', $add_html ) . ' ';
450
  }
451
 
452
  private static function add_input_classes( $field, array &$class ) {
453
+ if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
454
+ $class[] = $field['input_class'];
455
+ }
456
 
457
  if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
458
  return;
459
  }
460
 
461
+ if ( isset( $field['size'] ) && $field['size'] > 0 ) {
462
+ $class[] = 'auto_width';
463
+ }
464
  }
465
 
466
  private static function add_html_size( $field, array &$add_html ) {
472
  return;
473
  }
474
 
475
+ if ( is_numeric( $field['size'] ) ) {
476
+ $field['size'] .= 'px';
477
+ }
478
 
479
+ $important = apply_filters( 'frm_use_important_width', 1, $field );
480
  // Note: This inline styling must stay since we cannot realistically set a class for every possible field size
481
  $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
482
 
483
+ self::add_html_cols( $field, $add_html );
484
  }
485
 
486
  private static function add_html_cols( $field, array &$add_html ) {
496
  'em' => 0.544,
497
  );
498
 
499
+ // include "col" for valid html
500
+ $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
501
 
502
  if ( ! isset( $calc[ $unit ] ) ) {
503
  return;
514
  return;
515
  }
516
 
517
+ if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
518
  // don't load on form builder page
519
  return;
520
  }
594
  private static function add_placeholder_to_input( $field, &$add_html ) {
595
  if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
596
  $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"';
597
+ wp_enqueue_script( 'jquery-placeholder' );
598
  }
599
  }
600
 
629
  continue;
630
  }
631
 
632
+ if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
633
  $add_html[] = $v;
634
  } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
635
  $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
637
  $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
638
  }
639
 
640
+ unset( $k, $v );
641
  }
642
  }
643
 
653
  }
654
 
655
  public static function check_label( $opt ) {
656
+ if ( is_array( $opt ) ) {
657
+ $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
658
+ }
659
 
660
+ return $opt;
661
+ }
662
  }
classes/controllers/FrmFormActionsController.php CHANGED
@@ -14,10 +14,7 @@ class FrmFormActionsController {
14
  'show_in_nav_menus' => false,
15
  'show_in_menu' => true,
16
  'capability_type' => 'page',
17
- 'supports' => array(
18
- 'title', 'editor', 'excerpt', 'custom-fields',
19
- 'page-attributes',
20
- ),
21
  'has_archive' => false,
22
  ) );
23
 
@@ -183,7 +180,10 @@ class FrmFormActionsController {
183
  private static function fields_to_values( $form_id, array &$values ) {
184
  $form = FrmForm::getOne($form_id);
185
 
186
- $values = array( 'fields' => array(), 'id' => $form->id );
 
 
 
187
 
188
  $fields = FrmField::get_all_for_form($form->id);
189
  foreach ( $fields as $k => $f ) {
@@ -205,7 +205,10 @@ class FrmFormActionsController {
205
 
206
  $registered_actions = self::$registered_actions->actions;
207
 
208
- $old_actions = FrmDb::get_col( $wpdb->posts, array( 'post_type' => self::$action_post_type, 'menu_order' => $form_id ), 'ID' );
 
 
 
209
  $new_actions = array();
210
 
211
  foreach ( $registered_actions as $registered_action ) {
@@ -332,7 +335,7 @@ class FrmFormActionsController {
332
  return;
333
  }
334
 
335
- $action_controls = self::get_form_actions( );
336
 
337
  foreach ( $action_controls as $action_control ) {
338
  $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
14
  'show_in_nav_menus' => false,
15
  'show_in_menu' => true,
16
  'capability_type' => 'page',
17
+ 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'page-attributes' ),
 
 
 
18
  'has_archive' => false,
19
  ) );
20
 
180
  private static function fields_to_values( $form_id, array &$values ) {
181
  $form = FrmForm::getOne($form_id);
182
 
183
+ $values = array(
184
+ 'fields' => array(),
185
+ 'id' => $form->id,
186
+ );
187
 
188
  $fields = FrmField::get_all_for_form($form->id);
189
  foreach ( $fields as $k => $f ) {
205
 
206
  $registered_actions = self::$registered_actions->actions;
207
 
208
+ $old_actions = FrmDb::get_col( $wpdb->posts, array(
209
+ 'post_type' => self::$action_post_type,
210
+ 'menu_order' => $form_id,
211
+ ), 'ID' );
212
  $new_actions = array();
213
 
214
  foreach ( $registered_actions as $registered_action ) {
335
  return;
336
  }
337
 
338
+ $action_controls = self::get_form_actions();
339
 
340
  foreach ( $action_controls as $action_control ) {
341
  $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
classes/controllers/FrmFormsController.php CHANGED
@@ -253,7 +253,7 @@ class FrmFormsController {
253
 
254
  $params = FrmForm::list_page_params();
255
  $form = FrmForm::duplicate( $params['id'], $params['template'], true );
256
- $message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
257
  if ( $form ) {
258
  return self::get_edit_vars( $form, array(), $message, true );
259
  } else {
@@ -335,8 +335,14 @@ class FrmFormsController {
335
  */
336
  public static function change_form_status( $status ) {
337
  $available_status = array(
338
- 'untrash' => array( 'permission' => 'frm_edit_forms', 'new_status' => 'published' ),
339
- 'trash' => array( 'permission' => 'frm_delete_forms', 'new_status' => 'trash' ),
 
 
 
 
 
 
340
  );
341
 
342
  if ( ! isset( $available_status[ $status ] ) ) {
@@ -355,7 +361,11 @@ class FrmFormsController {
355
  $count++;
356
  }
357
 
358
- $form_type = FrmAppHelper::get_simple_request( array( 'param' => 'form_type', 'type' => 'request' ) );
 
 
 
 
359
  $available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
360
  $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
361
 
@@ -374,7 +384,10 @@ class FrmFormsController {
374
  }
375
  }
376
 
377
- $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type', 'type' => 'request' ) );
 
 
 
378
  $message = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' );
379
 
380
  return $message;
@@ -458,7 +471,10 @@ class FrmFormsController {
458
  FrmAppHelper::load_admin_wide_js();
459
 
460
  $shortcodes = array(
461
- 'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' ) ),
 
 
 
462
  );
463
 
464
  $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
@@ -485,13 +501,21 @@ class FrmFormsController {
485
  $opts = array(
486
  'form_id' => 'id',
487
  //'key' => ',
488
- 'title' => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' ) ),
489
- 'description' => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' ) ),
490
- 'minimize' => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' ) ),
 
 
 
 
 
 
 
 
 
491
  );
492
- break;
493
  }
494
- $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
495
 
496
  if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
497
  // allow other shortcodes to use the required form id option
@@ -538,7 +562,11 @@ class FrmFormsController {
538
  $columns['cb'] = '<input type="checkbox" />';
539
  $columns['id'] = 'ID';
540
 
541
- $type = FrmAppHelper::get_simple_request( array( 'param' => 'form_type', 'type' => 'request', 'default' => 'published' ) );
 
 
 
 
542
 
543
  if ( 'template' == $type ) {
544
  $columns['name'] = __( 'Template Name', 'formidable' );
@@ -553,7 +581,11 @@ class FrmFormsController {
553
 
554
  $columns['created_at'] = __( 'Date', 'formidable' );
555
 
556
- add_screen_option( 'per_page', array( 'label' => __( 'Forms', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_per_page' ) );
 
 
 
 
557
 
558
  return $columns;
559
  }
@@ -569,7 +601,10 @@ class FrmFormsController {
569
  }
570
 
571
  public static function hidden_columns( $hidden_columns ) {
572
- $type = FrmAppHelper::get_simple_request( array( 'param' => 'form_type', 'type' => 'request' ) );
 
 
 
573
 
574
  if ( $type === 'template' ) {
575
  $hidden_columns[] = 'id';
@@ -835,16 +870,15 @@ class FrmFormsController {
835
  switch ( $bulkaction ) {
836
  case 'delete':
837
  $message = self::bulk_destroy( $ids );
838
- break;
839
  case 'trash':
840
  $message = self::bulk_trash( $ids );
841
- break;
842
  case 'untrash':
843
  $message = self::bulk_untrash( $ids );
844
- break;
845
  case 'create_template':
846
  $message = self::bulk_create_template( $ids );
847
- break;
848
  }
849
 
850
  if ( isset( $message ) && ! empty( $message ) ) {
@@ -1050,12 +1084,18 @@ class FrmFormsController {
1050
  return $sc . ']';
1051
  }
1052
 
1053
- $shortcode_atts = shortcode_atts( array(
1054
- 'id' => '', 'key' => '', 'title' => false, 'description' => false,
1055
- 'readonly' => false, 'entry_id' => false, 'fields' => array(),
1056
- 'exclude_fields' => array(), 'minimize' => false,
1057
- ), $atts);
1058
- do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
 
 
 
 
 
 
1059
 
1060
  return self::show_form(
1061
  $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
@@ -1178,7 +1218,10 @@ class FrmFormsController {
1178
  $pass_args['entry_id'] = $entry_id;
1179
  self::show_message_after_save( $pass_args );
1180
  }
1181
- do_action( 'frm_after_entry_processed', array( 'entry_id' => $entry_id, 'form' => $form ) );
 
 
 
1182
  }
1183
  }
1184
  }
253
 
254
  $params = FrmForm::list_page_params();
255
  $form = FrmForm::duplicate( $params['id'], $params['template'], true );
256
+ $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
257
  if ( $form ) {
258
  return self::get_edit_vars( $form, array(), $message, true );
259
  } else {
335
  */
336
  public static function change_form_status( $status ) {
337
  $available_status = array(
338
+ 'untrash' => array(
339
+ 'permission' => 'frm_edit_forms',
340
+ 'new_status' => 'published',
341
+ ),
342
+ 'trash' => array(
343
+ 'permission' => 'frm_delete_forms',
344
+ 'new_status' => 'trash',
345
+ ),
346
  );
347
 
348
  if ( ! isset( $available_status[ $status ] ) ) {
361
  $count++;
362
  }
363
 
364
+ $form_type = FrmAppHelper::get_simple_request( array(
365
+ 'param' => 'form_type',
366
+ 'type' => 'request',
367
+ ) );
368
+
369
  $available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
370
  $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
371
 
384
  }
385
  }
386
 
387
+ $current_page = FrmAppHelper::get_simple_request( array(
388
+ 'param' => 'form_type',
389
+ 'type' => 'request',
390
+ ) );
391
  $message = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' );
392
 
393
  return $message;
471
  FrmAppHelper::load_admin_wide_js();
472
 
473
  $shortcodes = array(
474
+ 'formidable' => array(
475
+ 'name' => __( 'Form', 'formidable' ),
476
+ 'label' => __( 'Insert a Form', 'formidable' ),
477
+ ),
478
  );
479
 
480
  $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
501
  $opts = array(
502
  'form_id' => 'id',
503
  //'key' => ',
504
+ 'title' => array(
505
+ 'val' => 1,
506
+ 'label' => __( 'Display form title', 'formidable' ),
507
+ ),
508
+ 'description' => array(
509
+ 'val' => 1,
510
+ 'label' => __( 'Display form description', 'formidable' ),
511
+ ),
512
+ 'minimize' => array(
513
+ 'val' => 1,
514
+ 'label' => __( 'Minimize form HTML', 'formidable' ),
515
+ ),
516
  );
 
517
  }
518
+ $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
519
 
520
  if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
521
  // allow other shortcodes to use the required form id option
562
  $columns['cb'] = '<input type="checkbox" />';
563
  $columns['id'] = 'ID';
564
 
565
+ $type = FrmAppHelper::get_simple_request( array(
566
+ 'param' => 'form_type',
567
+ 'type' => 'request',
568
+ 'default' => 'published',
569
+ ) );
570
 
571
  if ( 'template' == $type ) {
572
  $columns['name'] = __( 'Template Name', 'formidable' );
581
 
582
  $columns['created_at'] = __( 'Date', 'formidable' );
583
 
584
+ add_screen_option( 'per_page', array(
585
+ 'label' => __( 'Forms', 'formidable' ),
586
+ 'default' => 20,
587
+ 'option' => 'formidable_page_formidable_per_page',
588
+ ) );
589
 
590
  return $columns;
591
  }
601
  }
602
 
603
  public static function hidden_columns( $hidden_columns ) {
604
+ $type = FrmAppHelper::get_simple_request( array(
605
+ 'param' => 'form_type',
606
+ 'type' => 'request',
607
+ ) );
608
 
609
  if ( $type === 'template' ) {
610
  $hidden_columns[] = 'id';
870
  switch ( $bulkaction ) {
871
  case 'delete':
872
  $message = self::bulk_destroy( $ids );
873
+ break;
874
  case 'trash':
875
  $message = self::bulk_trash( $ids );
876
+ break;
877
  case 'untrash':
878
  $message = self::bulk_untrash( $ids );
879
+ break;
880
  case 'create_template':
881
  $message = self::bulk_create_template( $ids );
 
882
  }
883
 
884
  if ( isset( $message ) && ! empty( $message ) ) {
1084
  return $sc . ']';
1085
  }
1086
 
1087
+ $shortcode_atts = shortcode_atts( array(
1088
+ 'id' => '',
1089
+ 'key' => '',
1090
+ 'title' => false,
1091
+ 'description' => false,
1092
+ 'readonly' => false,
1093
+ 'entry_id' => false,
1094
+ 'fields' => array(),
1095
+ 'exclude_fields' => array(),
1096
+ 'minimize' => false,
1097
+ ), $atts );
1098
+ do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1099
 
1100
  return self::show_form(
1101
  $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
1218
  $pass_args['entry_id'] = $entry_id;
1219
  self::show_message_after_save( $pass_args );
1220
  }
1221
+ do_action( 'frm_after_entry_processed', array(
1222
+ 'entry_id' => $entry_id,
1223
+ 'form' => $form,
1224
+ ) );
1225
  }
1226
  }
1227
  }
classes/controllers/FrmHooksController.php CHANGED
@@ -140,8 +140,8 @@ class FrmHooksController {
140
  add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
141
 
142
  // Addons
143
- add_action('wp_ajax_frm_addon_activate', 'FrmAddon::activate' );
144
- add_action('wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' );
145
  add_action( 'wp_ajax_frm_fill_licenses', 'FrmAddonsController::get_licenses' );
146
 
147
  // Fields Controller
140
  add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
141
 
142
  // Addons
143
+ add_action( 'wp_ajax_frm_addon_activate', 'FrmAddon::activate' );
144
+ add_action( 'wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' );
145
  add_action( 'wp_ajax_frm_fill_licenses', 'FrmAddonsController::get_licenses' );
146
 
147
  // Fields Controller
classes/controllers/FrmSettingsController.php CHANGED
@@ -34,9 +34,10 @@ class FrmSettingsController {
34
  $sections = array();
35
  if ( apply_filters( 'frm_include_addon_page', false ) ) {
36
  $sections['licenses'] = array(
37
- 'class' => 'FrmAddonsController', 'function' => 'license_settings',
38
- 'name' => __( 'Plugin Licenses', 'formidable' ),
39
- 'ajax' => true,
 
40
  );
41
  }
42
  $sections = apply_filters( 'frm_add_settings_section', $sections );
34
  $sections = array();
35
  if ( apply_filters( 'frm_include_addon_page', false ) ) {
36
  $sections['licenses'] = array(
37
+ 'class' => 'FrmAddonsController',
38
+ 'function' => 'license_settings',
39
+ 'name' => __( 'Plugin Licenses', 'formidable' ),
40
+ 'ajax' => true,
41
  );
42
  }
43
  $sections = apply_filters( 'frm_add_settings_section', $sections );
classes/controllers/FrmStylesController.php CHANGED
@@ -17,12 +17,12 @@ class FrmStylesController {
17
  'show_ui' => false,
18
  'capability_type' => 'page',
19
  'capabilities' => array(
20
- 'edit_post' => 'frm_change_settings',
21
- 'edit_posts' => 'frm_change_settings',
22
  'edit_others_posts' => 'frm_change_settings',
23
  'publish_posts' => 'frm_change_settings',
24
- 'delete_post' => 'frm_change_settings',
25
- 'delete_posts' => 'frm_change_settings',
26
  'read_private_posts' => 'read_private_posts',
27
  ),
28
  'supports' => array(
@@ -41,13 +41,13 @@ class FrmStylesController {
41
  }
42
 
43
  public static function menu() {
44
- add_submenu_page('formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
45
  }
46
 
47
- public static function admin_init() {
48
- if ( ! FrmAppHelper::is_admin_page('formidable-styles') ) {
49
- return;
50
- }
51
 
52
  self::load_pro_hooks();
53
 
@@ -57,15 +57,15 @@ class FrmStylesController {
57
  return;
58
  }
59
 
60
- wp_enqueue_script('jquery-ui-datepicker');
61
 
62
  $version = FrmAppHelper::plugin_version();
63
  $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
64
  wp_enqueue_script( 'jquery-frm-themepicker', FrmAppHelper::plugin_url() . '/js/jquery/jquery-ui-themepicker' . $suffix . '.js', array( 'jquery' ), $version );
65
 
66
- wp_enqueue_style( 'frm-custom-theme', admin_url('admin-ajax.php?action=frmpro_css' ) );
67
 
68
- $style = apply_filters('frm_style_head', false);
69
  if ( $style ) {
70
  wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ) );
71
  }
@@ -163,51 +163,51 @@ class FrmStylesController {
163
  }
164
 
165
  public static function new_style( $return = '' ) {
166
- self::load_styler('default');
167
- }
168
 
169
  public static function duplicate() {
170
- self::load_styler('default');
171
  }
172
 
173
  public static function edit( $style_id = false, $message = '' ) {
174
- if ( ! $style_id ) {
175
  $style_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
176
- if ( empty($style_id) ) {
177
- $style_id = 'default';
178
- }
179
- }
180
 
181
- if ( 'default' == $style_id ) {
182
- $style = 'default';
183
- } else {
184
- $frm_style = new FrmStyle($style_id);
185
- $style = $frm_style->get_one();
186
- $style = $style->ID;
187
- }
188
 
189
- self::load_styler($style, $message);
190
- }
191
 
192
- public static function save() {
193
- $frm_style = new FrmStyle();
194
- $message = '';
195
  $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
196
  $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
197
 
198
  if ( $post_id !== false && wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
199
- $id = $frm_style->update($post_id);
200
- if ( empty($post_id) && ! empty($id) ) {
201
- // set the post id to the new style so it will be loaded for editing
202
- $post_id = reset($id);
203
- }
204
- // include the CSS that includes this style
205
  echo '<link href="' . esc_url( admin_url( 'admin-ajax.php?action=frmpro_css' ) ) . '" type="text/css" rel="Stylesheet" class="frm-custom-theme" />';
206
- $message = __( 'Your styling settings have been saved.', 'formidable' );
207
- }
208
 
209
- return self::edit($post_id, $message);
210
- }
211
 
212
  public static function load_styler( $style, $message = '' ) {
213
  global $frm_settings;
@@ -215,11 +215,11 @@ class FrmStylesController {
215
  $frm_style = new FrmStyle();
216
  $styles = $frm_style->get_all();
217
 
218
- if ( is_numeric($style) ) {
219
- $style = $styles[ $style ];
220
- } else if ( 'default' == $style ) {
221
- $style = $frm_style->get_default_style($styles);
222
- }
223
 
224
  self::add_meta_boxes();
225
 
@@ -231,16 +231,16 @@ class FrmStylesController {
231
  * @param array|object $forms
232
  */
233
  private static function manage( $message = '', $forms = array() ) {
234
- $frm_style = new FrmStyle();
235
- $styles = $frm_style->get_all();
236
- $default_style = $frm_style->get_default_style($styles);
237
 
238
- if ( empty($forms) ) {
239
- $forms = FrmForm::get_published_forms();
240
- }
241
 
242
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php' );
243
- }
244
 
245
  private static function manage_styles() {
246
  $style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' );
@@ -259,15 +259,15 @@ class FrmStylesController {
259
  $form->options['custom_style'] = $_POST['style'][ $form->id ];
260
 
261
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
262
- unset($form);
263
  }
264
 
265
  $message = __( 'Your form styles have been saved.', 'formidable' );
266
- return self::manage($message, $forms);
267
  }
268
 
269
  public static function custom_css( $message = '', $style = null ) {
270
- if ( function_exists('wp_enqueue_code_editor') ) {
271
  $id = 'frm_codemirror_box';
272
  $settings = wp_enqueue_code_editor( array(
273
  'type' => 'text/css',
@@ -279,32 +279,32 @@ class FrmStylesController {
279
  } else {
280
  $id = 'frm_custom_css_box';
281
  $settings = array();
282
- wp_enqueue_style('codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css');
283
- wp_enqueue_script('codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7');
284
  wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), '4.7' );
285
  }
286
 
287
- if ( ! isset($style) ) {
288
- $frm_style = new FrmStyle();
289
- $style = $frm_style->get_default_style();
290
- }
291
 
292
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php' );
293
- }
294
 
295
- public static function save_css() {
296
- $frm_style = new FrmStyle();
297
 
298
- $message = '';
299
  $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_text_field' );
300
  $nonce = FrmAppHelper::get_post_param( 'frm_custom_css', '', 'sanitize_text_field' );
301
  if ( wp_verify_nonce( $nonce, 'frm_custom_css_nonce' ) ) {
302
- $frm_style->update($post_id);
303
- $message = __( 'Your styling settings have been saved.', 'formidable' );
304
- }
305
 
306
- return self::custom_css($message);
307
- }
308
 
309
  public static function route() {
310
  $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
@@ -332,7 +332,7 @@ class FrmStylesController {
332
  }
333
 
334
  public static function reset_styling() {
335
- FrmAppHelper::permission_check('frm_change_settings');
336
  check_ajax_referer( 'frm_ajax', 'nonce' );
337
 
338
  $frm_style = new FrmStyle();
@@ -342,25 +342,25 @@ class FrmStylesController {
342
  wp_die();
343
  }
344
 
345
- public static function change_styling() {
346
- check_ajax_referer( 'frm_ajax', 'nonce' );
347
 
348
- $frm_style = new FrmStyle();
349
- $defaults = $frm_style->get_defaults();
350
  $style = '';
351
 
352
- // remove the # from the colors
353
- foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) {
354
- if ( ! is_array($v) && strpos($v, '#') === 0 ) {
355
- $_GET['frm_style_setting']['post_content'][ $k ] = str_replace( '#', '', $v );
356
- }
357
- }
358
 
359
- echo '<style type="text/css">';
360
  include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
361
- echo '</style>';
362
- wp_die();
363
- }
364
 
365
  private static function add_meta_boxes() {
366
 
@@ -384,14 +384,14 @@ class FrmStylesController {
384
  */
385
  $meta_boxes = apply_filters( 'frm_style_boxes', $meta_boxes );
386
 
387
- foreach ( $meta_boxes as $nicename => $name ) {
388
  add_meta_box( $nicename . '-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename );
389
- unset($nicename, $name);
390
- }
391
- }
392
 
393
  public static function include_style_section( $atts, $sec ) {
394
- extract($atts);
395
  $current_tab = FrmAppHelper::simple_get( 'page-tab', 'sanitize_title', 'default' );
396
  $file_name = FrmAppHelper::plugin_path() . '/classes/views/styles/_' . $sec['args'] . '.php';
397
 
@@ -408,7 +408,7 @@ class FrmStylesController {
408
  }
409
 
410
  public static function load_css() {
411
- header('Content-type: text/css');
412
 
413
  $frm_style = new FrmStyle();
414
  $defaults = $frm_style->get_defaults();
@@ -469,32 +469,32 @@ class FrmStylesController {
469
  * @param string $style
470
  */
471
  public static function get_form_style_class( $class, $style ) {
472
- if ( 1 == $style ) {
473
- $style = 'default';
474
- }
475
 
476
- $frm_style = new FrmStyle($style);
477
- $style = $frm_style->get_one();
478
 
479
- if ( $style ) {
480
  $class .= ' frm_style_' . $style->post_name;
481
- }
482
 
483
- return $class;
484
- }
485
 
486
  /**
487
  * @param string $val
488
  */
489
  public static function get_style_val( $val, $form = 'default' ) {
490
- $style = self::get_form_style($form);
491
- if ( $style && isset( $style->post_content[ $val ] ) ) {
492
- return $style->post_content[ $val ];
493
- }
494
- }
495
 
496
  public static function show_entry_styles( $default_styles ) {
497
- $frm_style = new FrmStyle('default');
498
  $style = $frm_style->get_one();
499
 
500
  if ( ! $style ) {
@@ -509,14 +509,14 @@ class FrmStylesController {
509
  $setting = 'bg_color_active';
510
  }
511
  $default_styles[ $name ] = $style->post_content[ $setting ];
512
- unset($name, $val);
513
  }
514
 
515
  return $default_styles;
516
  }
517
 
518
  public static function &important_style( $important, $field ) {
519
- $important = self::get_style_val('important_style', $field['form_id']);
520
  return $important;
521
  }
522
 
@@ -562,7 +562,7 @@ class FrmStylesController {
562
 
563
  ?>
564
  <div class="postbox <?php echo esc_attr( $box['id'] ); ?>">
565
- <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ) ?>"><br/></div>
566
  <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
567
  <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
568
  <div class="inside">
17
  'show_ui' => false,
18
  'capability_type' => 'page',
19
  'capabilities' => array(
20
+ 'edit_post' => 'frm_change_settings',
21
+ 'edit_posts' => 'frm_change_settings',
22
  'edit_others_posts' => 'frm_change_settings',
23
  'publish_posts' => 'frm_change_settings',
24
+ 'delete_post' => 'frm_change_settings',
25
+ 'delete_posts' => 'frm_change_settings',
26
  'read_private_posts' => 'read_private_posts',
27
  ),
28
  'supports' => array(
41
  }
42
 
43
  public static function menu() {
44
+ add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
45
  }
46
 
47
+ public static function admin_init() {
48
+ if ( ! FrmAppHelper::is_admin_page( 'formidable-styles' ) ) {
49
+ return;
50
+ }
51
 
52
  self::load_pro_hooks();
53
 
57
  return;
58
  }
59
 
60
+ wp_enqueue_script( 'jquery-ui-datepicker' );
61
 
62
  $version = FrmAppHelper::plugin_version();
63
  $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
64
  wp_enqueue_script( 'jquery-frm-themepicker', FrmAppHelper::plugin_url() . '/js/jquery/jquery-ui-themepicker' . $suffix . '.js', array( 'jquery' ), $version );
65
 
66
+ wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ) );
67
 
68
+ $style = apply_filters( 'frm_style_head', false );
69
  if ( $style ) {
70
  wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ) );
71
  }
163
  }
164
 
165
  public static function new_style( $return = '' ) {
166
+ self::load_styler( 'default' );
167
+ }
168
 
169
  public static function duplicate() {
170
+ self::load_styler( 'default' );
171
  }
172
 
173
  public static function edit( $style_id = false, $message = '' ) {
174
+ if ( ! $style_id ) {
175
  $style_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
176
+ if ( empty( $style_id ) ) {
177
+ $style_id = 'default';
178
+ }
179
+ }
180
 
181
+ if ( 'default' == $style_id ) {
182
+ $style = 'default';
183
+ } else {
184
+ $frm_style = new FrmStyle( $style_id );
185
+ $style = $frm_style->get_one();
186
+ $style = $style->ID;
187
+ }
188
 
189
+ self::load_styler( $style, $message );
190
+ }
191
 
192
+ public static function save() {
193
+ $frm_style = new FrmStyle();
194
+ $message = '';
195
  $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
196
  $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
197
 
198
  if ( $post_id !== false && wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
199
+ $id = $frm_style->update( $post_id );
200
+ if ( empty( $post_id ) && ! empty( $id ) ) {
201
+ // set the post id to the new style so it will be loaded for editing
202
+ $post_id = reset( $id );
203
+ }
204
+ // include the CSS that includes this style
205
  echo '<link href="' . esc_url( admin_url( 'admin-ajax.php?action=frmpro_css' ) ) . '" type="text/css" rel="Stylesheet" class="frm-custom-theme" />';
206
+ $message = __( 'Your styling settings have been saved.', 'formidable' );
207
+ }
208
 
209
+ return self::edit( $post_id, $message );
210
+ }
211
 
212
  public static function load_styler( $style, $message = '' ) {
213
  global $frm_settings;
215
  $frm_style = new FrmStyle();
216
  $styles = $frm_style->get_all();
217
 
218
+ if ( is_numeric( $style ) ) {
219
+ $style = $styles[ $style ];
220
+ } elseif ( 'default' == $style ) {
221
+ $style = $frm_style->get_default_style( $styles );
222
+ }
223
 
224
  self::add_meta_boxes();
225
 
231
  * @param array|object $forms
232
  */
233
  private static function manage( $message = '', $forms = array() ) {
234
+ $frm_style = new FrmStyle();
235
+ $styles = $frm_style->get_all();
236
+ $default_style = $frm_style->get_default_style( $styles );
237
 
238
+ if ( empty( $forms ) ) {
239
+ $forms = FrmForm::get_published_forms();
240
+ }
241
 
242
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php' );
243
+ }
244
 
245
  private static function manage_styles() {
246
  $style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' );
259
  $form->options['custom_style'] = $_POST['style'][ $form->id ];
260
 
261
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
262
+ unset( $form );
263
  }
264
 
265
  $message = __( 'Your form styles have been saved.', 'formidable' );
266
+ return self::manage( $message, $forms );
267
  }
268
 
269
  public static function custom_css( $message = '', $style = null ) {
270
+ if ( function_exists( 'wp_enqueue_code_editor' ) ) {
271
  $id = 'frm_codemirror_box';
272
  $settings = wp_enqueue_code_editor( array(
273
  'type' => 'text/css',
279
  } else {
280
  $id = 'frm_custom_css_box';
281
  $settings = array();
282
+ wp_enqueue_style( 'codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css' );
283
+ wp_enqueue_script( 'codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7' );
284
  wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), '4.7' );
285
  }
286
 
287
+ if ( ! isset( $style ) ) {
288
+ $frm_style = new FrmStyle();
289
+ $style = $frm_style->get_default_style();
290
+ }
291
 
292
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php' );
293
+ }
294
 
295
+ public static function save_css() {
296
+ $frm_style = new FrmStyle();
297
 
298
+ $message = '';
299
  $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_text_field' );
300
  $nonce = FrmAppHelper::get_post_param( 'frm_custom_css', '', 'sanitize_text_field' );
301
  if ( wp_verify_nonce( $nonce, 'frm_custom_css_nonce' ) ) {
302
+ $frm_style->update( $post_id );
303
+ $message = __( 'Your styling settings have been saved.', 'formidable' );
304
+ }
305
 
306
+ return self::custom_css( $message );
307
+ }
308
 
309
  public static function route() {
310
  $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
332
  }
333
 
334
  public static function reset_styling() {
335
+ FrmAppHelper::permission_check( 'frm_change_settings' );
336
  check_ajax_referer( 'frm_ajax', 'nonce' );
337
 
338
  $frm_style = new FrmStyle();
342
  wp_die();
343
  }
344
 
345
+ public static function change_styling() {
346
+ check_ajax_referer( 'frm_ajax', 'nonce' );
347
 
348
+ $frm_style = new FrmStyle();
349
+ $defaults = $frm_style->get_defaults();
350
  $style = '';
351
 
352
+ // remove the # from the colors
353
+ foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) {
354
+ if ( ! is_array( $v ) && strpos( $v, '#' ) === 0 ) {
355
+ $_GET['frm_style_setting']['post_content'][ $k ] = str_replace( '#', '', $v );
356
+ }
357
+ }
358
 
359
+ echo '<style type="text/css">';
360
  include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
361
+ echo '</style>';
362
+ wp_die();
363
+ }
364
 
365
  private static function add_meta_boxes() {
366
 
384
  */
385
  $meta_boxes = apply_filters( 'frm_style_boxes', $meta_boxes );
386
 
387
+ foreach ( $meta_boxes as $nicename => $name ) {
388
  add_meta_box( $nicename . '-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename );
389
+ unset( $nicename, $name );
390
+ }
391
+ }
392
 
393
  public static function include_style_section( $atts, $sec ) {
394
+ extract( $atts );
395
  $current_tab = FrmAppHelper::simple_get( 'page-tab', 'sanitize_title', 'default' );
396
  $file_name = FrmAppHelper::plugin_path() . '/classes/views/styles/_' . $sec['args'] . '.php';
397
 
408
  }
409
 
410
  public static function load_css() {
411
+ header( 'Content-type: text/css' );
412
 
413
  $frm_style = new FrmStyle();
414
  $defaults = $frm_style->get_defaults();
469
  * @param string $style
470
  */
471
  public static function get_form_style_class( $class, $style ) {
472
+ if ( 1 == $style ) {
473
+ $style = 'default';
474
+ }
475
 
476
+ $frm_style = new FrmStyle( $style );
477
+ $style = $frm_style->get_one();
478
 
479
+ if ( $style ) {
480
  $class .= ' frm_style_' . $style->post_name;
481
+ }
482
 
483
+ return $class;
484
+ }
485
 
486
  /**
487
  * @param string $val
488
  */
489
  public static function get_style_val( $val, $form = 'default' ) {
490
+ $style = self::get_form_style( $form );
491
+ if ( $style && isset( $style->post_content[ $val ] ) ) {
492
+ return $style->post_content[ $val ];
493
+ }
494
+ }
495
 
496
  public static function show_entry_styles( $default_styles ) {
497
+ $frm_style = new FrmStyle( 'default' );
498
  $style = $frm_style->get_one();
499
 
500
  if ( ! $style ) {
509
  $setting = 'bg_color_active';
510
  }
511
  $default_styles[ $name ] = $style->post_content[ $setting ];
512
+ unset( $name, $val );
513
  }
514
 
515
  return $default_styles;
516
  }
517
 
518
  public static function &important_style( $important, $field ) {
519
+ $important = self::get_style_val( 'important_style', $field['form_id'] );
520
  return $important;
521
  }
522
 
562
 
563
  ?>
564
  <div class="postbox <?php echo esc_attr( $box['id'] ); ?>">
565
+ <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ); ?>"><br/></div>
566
  <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
567
  <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
568
  <div class="inside">
classes/controllers/FrmXMLController.php CHANGED
@@ -2,109 +2,120 @@
2
 
3
  class FrmXMLController {
4
 
5
- public static function menu() {
6
  add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' );
7
- }
8
 
9
- public static function add_default_templates() {
10
  if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
11
- // XML import is not enabled on your server
12
- return;
13
- }
14
 
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);
22
- unset($file);
23
- }
24
- /*
25
- if(is_wp_error($result))
26
- $errors[] = $result->get_error_message();
27
- else if($result)
28
- $message = $result;
29
- */
30
-
31
- unset( $files );
32
-
33
- libxml_use_internal_errors( $set_err );
34
- libxml_disable_entity_loader( $loader );
35
- }
36
-
37
- public static function route() {
38
- $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
39
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
40
- if ( $action == 'import_xml' ) {
41
- return self::import_xml();
42
- } else if ( $action == 'export_xml' ) {
43
- return self::export_xml();
44
- } else {
45
- if ( apply_filters( 'frm_xml_route', true, $action ) ) {
46
- return self::form();
47
- }
48
- }
49
- }
50
-
51
- public static function form( $errors = array(), $message = '' ) {
52
  $where = array(
53
  'status' => array( null, '', 'published' ),
54
  );
55
  $forms = FrmForm::getAll( $where, 'name' );
56
 
57
- $export_types = apply_filters( 'frm_xml_export_types',
58
- array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) )
59
- );
 
60
 
61
- $export_format = apply_filters( 'frm_export_formats', array(
62
- 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
63
- 'csv' => array( 'name' => 'CSV', 'support' => 'items', 'count' => 'single' ),
64
- ) );
 
 
 
 
 
 
 
 
65
 
66
  include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' );
67
- }
68
-
69
- public static function import_xml() {
70
- $errors = array();
71
- $message = '';
72
-
73
- $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce');
74
- if ( $permission_error !== false ) {
75
- $errors[] = $permission_error;
76
- self::form($errors);
77
- return;
78
- }
79
-
80
- if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) {
81
- $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
82
- self::form($errors);
83
- return;
84
- }
85
-
86
- $file = $_FILES['frm_import_file']['tmp_name'];
87
-
88
- if ( ! is_uploaded_file( $file ) ) {
89
- unset($file);
90
- $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
91
- self::form($errors);
92
- return;
93
- }
94
-
95
- //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
96
-
97
- $export_format = apply_filters('frm_export_formats', array(
98
- 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
 
 
 
 
99
  ) );
100
 
101
- $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
102
- if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
103
- // allow other file types to be imported
104
  do_action( 'frm_before_import_' . $file_type );
105
- return;
106
- }
107
- unset($file_type);
108
 
109
  if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
110
  $errors[] = __( 'XML import is not enabled on your server.', 'formidable' );
@@ -123,145 +134,150 @@ class FrmXMLController {
123
  libxml_use_internal_errors( $set_err );
124
  libxml_disable_entity_loader( $loader );
125
 
126
- self::form($errors, $message);
127
- }
128
 
129
- public static function export_xml() {
130
- $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
131
- if ( ! empty($error) ) {
132
- wp_die( $error );
133
- }
134
 
135
  $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() );
136
  $type = FrmAppHelper::get_post_param( 'type', array() );
137
  $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
138
 
139
- if ( ! headers_sent() && ! $type ) {
140
- wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
141
- die();
142
- }
143
 
144
- if ( $format == 'xml' ) {
145
- self::generate_xml($type, compact('ids'));
146
- } if ( $format == 'csv' ) {
147
- self::generate_csv( compact('ids') );
148
- } else {
149
- do_action( 'frm_export_format_' . $format, compact('ids') );
150
- }
151
 
152
- wp_die();
153
- }
154
 
155
  public static function generate_xml( $type, $args = array() ) {
156
- global $wpdb;
157
 
158
- self::prepare_types_array( $type );
159
 
160
- $tables = array(
161
  'items' => $wpdb->prefix . 'frm_items',
162
  'forms' => $wpdb->prefix . 'frm_forms',
163
- 'posts' => $wpdb->posts,
164
- 'styles' => $wpdb->posts,
165
- 'actions' => $wpdb->posts,
166
- );
167
 
168
- $defaults = array( 'ids' => false );
169
- $args = wp_parse_args( $args, $defaults );
 
 
170
 
171
- $sitename = sanitize_key( get_bloginfo( 'name' ) );
172
 
173
- if ( ! empty( $sitename ) ) {
174
  $sitename .= '.';
175
  }
176
- $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
177
 
178
- header( 'Content-Description: File Transfer' );
179
- header( 'Content-Disposition: attachment; filename=' . $filename );
180
- header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
181
 
182
- //make sure ids are numeric
183
- if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
184
- $args['ids'] = array_filter( $args['ids'], 'is_numeric' );
185
- }
186
 
187
- $records = array();
188
 
189
  foreach ( $type as $tb_type ) {
190
- $where = array();
191
  $join = '';
192
- $table = $tables[ $tb_type ];
193
 
194
  $select = $table . '.id';
195
- $query_vars = array();
196
-
197
- switch ( $tb_type ) {
198
- case 'forms':
199
- //add forms
200
- if ( $args['ids'] ) {
201
- $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids'] );
202
- } else {
 
 
 
 
203
  $where[ $table . '.status !' ] = 'draft';
204
- }
205
- break;
206
- case 'actions':
207
  $select = $table . '.ID';
208
  $where['post_type'] = FrmFormActionsController::$action_post_type;
209
- if ( ! empty($args['ids']) ) {
210
  $where['menu_order'] = $args['ids'];
211
- }
212
- break;
213
- case 'items':
214
- //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
215
- if ( $args['ids'] ) {
216
  $where[ $table . '.form_id' ] = $args['ids'];
217
- }
218
- break;
219
- case 'styles':
220
- // Loop through all exported forms and get their selected style IDs
221
  $frm_style = new FrmStyle();
222
  $default_style = $frm_style->get_default_style();
223
- $form_ids = $args['ids'];
224
- $style_ids = array();
225
- foreach ( $form_ids as $form_id ) {
226
- $form_data = FrmForm::getOne( $form_id );
227
- // For forms that have not been updated while running 2.0, check if custom_style is set
228
- if ( isset( $form_data->options['custom_style'] ) ) {
229
- if ( $form_data->options['custom_style'] == 1 ) {
230
  $style_ids[] = $default_style->ID;
231
  } else {
232
  $style_ids[] = $form_data->options['custom_style'];
233
  }
234
- }
235
- unset( $form_id, $form_data );
236
- }
237
  $select = $table . '.ID';
238
- $where['post_type'] = 'frm_styles';
239
-
240
- // Only export selected styles
241
- if ( ! empty( $style_ids ) ) {
242
- $where['ID'] = $style_ids;
243
- }
244
- break;
245
- default:
246
  $select = $table . '.ID';
247
- $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
248
- $where['pm.meta_key'] = 'frm_form_id';
249
-
250
- if ( empty($args['ids']) ) {
251
- $where['pm.meta_value >'] = 1;
252
- } else {
253
- $where['pm.meta_value'] = $args['ids'];
254
- }
255
- break;
256
- }
257
 
258
  $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select );
259
- unset($tb_type);
260
- }
261
 
262
- echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n";
263
  include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' );
264
- }
265
 
266
  private static function prepare_types_array( &$type ) {
267
  $type = (array) $type;
@@ -279,7 +295,7 @@ class FrmXMLController {
279
  public static function generate_csv( $atts ) {
280
  $form_ids = $atts['ids'];
281
  if ( empty( $form_ids ) ) {
282
- wp_die( __( 'Please select a form', 'formidable' ) );
283
  }
284
  self::csv( reset( $form_ids ) );
285
  }
@@ -297,10 +313,10 @@ class FrmXMLController {
297
  $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
298
  }
299
 
300
- set_time_limit(0); //Remove time limit to execute this function
301
- $mem_limit = str_replace('M', '', ini_get('memory_limit'));
302
  if ( (int) $mem_limit < 256 ) {
303
- ini_set('memory_limit', '256M');
304
  }
305
 
306
  global $wpdb;
@@ -315,7 +331,9 @@ class FrmXMLController {
315
  $item_id = explode( ',', $item_id );
316
  }
317
 
318
- $query = array( 'form_id' => $form_id );
 
 
319
 
320
  if ( $item_id ) {
321
  $query['id'] = $item_id;
@@ -352,12 +370,21 @@ class FrmXMLController {
352
  */
353
  private static function get_fields_for_csv_export( $form_id, $form ) {
354
  // Phase frm_csv_field_ids out by 2.01.05
355
- $csv_field_ids = apply_filters( 'frm_csv_field_ids', '', $form_id, array( 'form' => $form ) );
 
 
356
 
357
  if ( $csv_field_ids ) {
358
  _deprecated_function( 'The frm_csv_field_ids filter', '2.0.19', 'the frm_csv_columns filter' );
359
- $where = array( 'fi.type not' => FrmField::no_save_fields() );
360
- $where[] = array( 'or' => 1, 'fi.form_id' => $form->id, 'fr.parent_form_id' => $form->id );
 
 
 
 
 
 
 
361
  if ( ! is_array( $csv_field_ids ) ) {
362
  $csv_field_ids = explode( ',', $csv_field_ids );
363
  }
@@ -369,7 +396,7 @@ class FrmXMLController {
369
  $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
370
  $no_export_fields = FrmField::no_save_fields();
371
  foreach ( $csv_fields as $k => $f ) {
372
- if ( in_array( $f->type, $no_export_fields ) ) {
373
  unset( $csv_fields[ $k ] );
374
  }
375
  }
@@ -379,16 +406,16 @@ class FrmXMLController {
379
  }
380
 
381
  public static function allow_mime( $mimes ) {
382
- if ( ! isset( $mimes['csv'] ) ) {
383
- // allow csv files
384
- $mimes['csv'] = 'text/csv';
385
- }
386
-
387
- if ( ! isset( $mimes['xml'] ) ) {
388
- // allow xml
389
- $mimes['xml'] = 'text/xml';
390
- }
391
-
392
- return $mimes;
393
- }
394
  }
2
 
3
  class FrmXMLController {
4
 
5
+ public static function menu() {
6
  add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' );
7
+ }
8
 
9
+ public static function add_default_templates() {
10
  if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
11
+ // XML import is not enabled on your server
12
+ return;
13
+ }
14
 
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 );
22
+ unset( $file );
23
+ }
24
+ /*
25
+ if(is_wp_error($result))
26
+ $errors[] = $result->get_error_message();
27
+ else if($result)
28
+ $message = $result;
29
+ */
30
+
31
+ unset( $files );
32
+
33
+ libxml_use_internal_errors( $set_err );
34
+ libxml_disable_entity_loader( $loader );
35
+ }