Formidable Forms – Form Builder for WordPress - Version 3.06.06

Version Description

  • Remove complete Spanish translations
  • Increase PHP requirements to 5.6
  • Increase minimum WP version to 4.6
Download this release

Release Info

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

Code changes from version 4.0b1 to 3.06.06

Files changed (118) hide show
  1. classes/controllers/FrmAddonsController.php +34 -48
  2. classes/controllers/FrmAppController.php +146 -161
  3. classes/controllers/FrmEntriesController.php +219 -212
  4. classes/controllers/FrmFieldsController.php +296 -373
  5. classes/controllers/FrmFormActionsController.php +187 -336
  6. classes/controllers/FrmFormsController.php +491 -664
  7. classes/controllers/FrmHooksController.php +137 -133
  8. classes/controllers/FrmSettingsController.php +44 -137
  9. classes/controllers/FrmSimpleBlocksController.php +4 -5
  10. classes/controllers/FrmStylesController.php +244 -199
  11. classes/controllers/FrmXMLController.php +43 -50
  12. classes/factories/FrmFieldFactory.php +0 -5
  13. classes/helpers/FrmAppHelper.php +742 -869
  14. classes/helpers/FrmCSVExportHelper.php +43 -49
  15. classes/helpers/FrmEmailHelper.php +1 -3
  16. classes/helpers/FrmEntriesHelper.php +230 -308
  17. classes/helpers/FrmEntriesListHelper.php +55 -58
  18. classes/helpers/FrmFieldsHelper.php +276 -643
  19. classes/helpers/FrmFormsHelper.php +280 -506
  20. classes/helpers/FrmFormsListHelper.php +117 -131
  21. classes/helpers/FrmListHelper.php +81 -116
  22. classes/helpers/FrmShortcodeHelper.php +4 -6
  23. classes/helpers/FrmStylesHelper.php +77 -170
  24. classes/helpers/FrmTipsHelper.php +7 -13
  25. classes/helpers/FrmXMLHelper.php +463 -553
  26. classes/models/FrmAddon.php +34 -45
  27. classes/models/FrmCreateFile.php +11 -13
  28. classes/models/FrmDb.php +172 -196
  29. classes/models/FrmEmail.php +3 -6
  30. classes/models/FrmEntry.php +322 -372
  31. classes/models/FrmEntryFormatter.php +21 -21
  32. classes/models/FrmEntryMeta.php +127 -132
  33. classes/models/FrmEntryShortcodeFormatter.php +1 -2
  34. classes/models/FrmEntryValidate.php +67 -77
  35. classes/models/FrmEntryValues.php +5 -5
  36. classes/models/FrmField.php +266 -291
  37. classes/models/FrmFieldFormHtml.php +9 -9
  38. classes/models/FrmFieldOption.php +1 -1
  39. classes/models/FrmFieldValue.php +3 -4
  40. classes/models/FrmFieldValueSelector.php +2 -1
  41. classes/models/FrmForm.php +277 -311
  42. classes/models/FrmFormAction.php +221 -283
  43. classes/models/FrmFormApi.php +3 -8
  44. classes/models/FrmFormMigrator.php +20 -30
  45. classes/models/FrmMigrate.php +87 -165
  46. classes/models/FrmNotification.php +0 -1
  47. classes/models/FrmPersonalData.php +2 -13
  48. classes/models/FrmReviews.php +4 -6
  49. classes/models/FrmSettings.php +122 -123
  50. classes/models/FrmStyle.php +278 -287
  51. classes/models/FrmTableHTMLGenerator.php +7 -15
  52. classes/models/fields/FrmFieldCaptcha.php +12 -18
  53. classes/models/fields/FrmFieldCheckbox.php +7 -2
  54. classes/models/fields/FrmFieldEmail.php +0 -1
  55. classes/models/fields/FrmFieldHTML.php +1 -13
  56. classes/models/fields/FrmFieldHidden.php +1 -3
  57. classes/models/fields/FrmFieldNumber.php +1 -1
  58. classes/models/fields/FrmFieldPhone.php +0 -1
  59. classes/models/fields/FrmFieldRadio.php +7 -2
  60. classes/models/fields/FrmFieldSelect.php +1 -11
  61. classes/models/fields/FrmFieldTextarea.php +2 -2
  62. classes/models/fields/FrmFieldType.php +71 -158
  63. classes/models/fields/FrmFieldUrl.php +3 -3
  64. classes/models/fields/FrmFieldUserID.php +4 -6
  65. classes/views/addons/list.php +11 -28
  66. classes/views/addons/settings.php +8 -8
  67. classes/views/addons/upgrade_to_pro.php +7 -7
  68. classes/views/frm-entries/_sidebar-shared-pub.php +17 -24
  69. classes/views/frm-entries/direct.php +1 -1
  70. classes/views/frm-entries/errors.php +22 -22
  71. classes/views/frm-entries/form.php +10 -19
  72. classes/views/frm-entries/list.php +22 -41
  73. classes/views/frm-entries/new.php +5 -5
  74. classes/views/frm-entries/no_entries.php +5 -38
  75. classes/views/frm-entries/show.php +73 -54
  76. classes/views/frm-entries/sidebar-shared.php +90 -115
  77. classes/views/frm-entries/sidebar-show.php +24 -2
  78. classes/views/frm-fields/back-end/ajax-field-placeholder.php +2 -2
  79. classes/views/frm-fields/back-end/automatic-width.php +9 -6
  80. classes/views/frm-fields/back-end/bulk-options-overlay.php +0 -35
  81. classes/views/frm-fields/back-end/dropdown-field.php +10 -4
  82. classes/views/frm-fields/back-end/field-captcha.php +4 -7
  83. classes/views/frm-fields/back-end/field-description.php +0 -8
  84. classes/views/frm-fields/back-end/field-hidden.php +2 -2
  85. classes/views/frm-fields/back-end/field-html.php +5 -5
  86. classes/views/frm-fields/back-end/field-multiple.php +7 -5
  87. classes/views/frm-fields/back-end/field-user-id.php +3 -4
  88. classes/views/frm-fields/back-end/html-content.php +5 -6
  89. classes/views/frm-fields/back-end/inline-modal.php +0 -15
  90. classes/views/frm-fields/back-end/input-mask-info.php +0 -28
  91. classes/views/frm-fields/back-end/layout-classes.php +0 -44
  92. classes/views/frm-fields/back-end/max.php +1 -12
  93. classes/views/frm-fields/back-end/number-range.php +15 -19
  94. classes/views/frm-fields/back-end/pixels-wide.php +17 -15
  95. classes/views/frm-fields/back-end/radio-field.php +0 -48
  96. classes/views/frm-fields/back-end/settings.php +0 -382
  97. classes/views/frm-fields/back-end/smart-values.php +0 -18
  98. classes/views/frm-fields/back-end/value-format.php +7 -9
  99. classes/views/frm-fields/front-end/checkbox-field.php +27 -36
  100. classes/views/frm-fields/front-end/dropdown-field.php +1 -16
  101. classes/views/frm-fields/front-end/radio-field.php +29 -36
  102. classes/views/frm-fields/import_choices.php +61 -0
  103. classes/views/frm-fields/single-option.php +16 -11
  104. classes/views/frm-form-actions/_action_icon.php +0 -23
  105. classes/views/frm-form-actions/_action_inside.php +24 -30
  106. classes/views/frm-form-actions/_email_settings.php +84 -80
  107. classes/views/frm-form-actions/default_actions.php +10 -74
  108. classes/views/frm-form-actions/email_action.php +17 -17
  109. classes/views/frm-form-actions/form_action.php +23 -24
  110. classes/views/frm-form-actions/settings.php +0 -80
  111. classes/views/frm-forms/_publish_box.php +31 -17
  112. classes/views/frm-forms/actions-dropdown.php +9 -9
  113. classes/views/frm-forms/add-new.php +1 -6
  114. classes/views/frm-forms/add_field.php +335 -54
  115. classes/views/frm-forms/add_field_links.php +126 -114
  116. classes/views/frm-forms/edit.php +27 -19
  117. classes/views/frm-forms/form.php +43 -37
  118. classes/views/frm-forms/insert_form_popup.php +23 -57
classes/controllers/FrmAddonsController.php CHANGED
@@ -16,15 +16,12 @@ class FrmAddonsController {
16
 
17
  public static function list_addons() {
18
  $installed_addons = apply_filters( 'frm_installed_addons', array() );
19
- $license_type = '';
20
 
21
  $addons = self::get_api_addons();
22
  $errors = array();
23
-
24
  if ( isset( $addons['error'] ) ) {
25
  $api = new FrmFormApi();
26
  $errors = $api->get_error_from_response( $addons );
27
- $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
28
  unset( $addons['error'] );
29
  }
30
  self::prepare_addons( $addons );
@@ -38,7 +35,6 @@ class FrmAddonsController {
38
  $plugins = apply_filters( 'frm_installed_addons', array() );
39
  if ( empty( $plugins ) ) {
40
  esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
41
-
42
  return;
43
  }
44
 
@@ -48,7 +44,7 @@ class FrmAddonsController {
48
  }
49
 
50
  private static function get_api_addons() {
51
- $api = new FrmFormApi();
52
  $addons = $api->get_api_info();
53
 
54
  if ( empty( $addons ) ) {
@@ -78,64 +74,64 @@ class FrmAddonsController {
78
  'docs' => '',
79
  'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
80
  ),
81
- 'mailchimp' => array(
82
  'title' => 'MailChimp Forms',
83
  'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.',
84
  ),
85
- 'registration' => array(
86
  'title' => 'User Registration Forms',
87
  'link' => 'downloads/user-registration/',
88
  'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
89
  ),
90
- 'paypal' => array(
91
  'title' => 'PayPal Standard Forms',
92
  'link' => 'downloads/paypal-standard/',
93
  'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
94
  ),
95
- 'stripe' => array(
96
  'title' => 'Stripe Forms',
97
  'docs' => 'knowledgebase/stripe/',
98
  'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
99
  ),
100
- 'authorize-net' => array(
101
  'title' => 'Authorize.net AIM Forms',
102
  'link' => 'downloads/authorize-net-aim/',
103
  'docs' => 'knowledgebase/authorize-net-aim/',
104
  'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
105
  ),
106
- 'woocommerce' => array(
107
  'title' => 'WooCommerce Forms',
108
  'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
109
  ),
110
- 'autoresponder' => array(
111
  'title' => 'Form Action Automation',
112
  'docs' => 'knowledgebase/schedule-autoresponder/',
113
  'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
114
  ),
115
- 'modal' => array(
116
  'title' => 'Bootstrap Modal Forms',
117
  'link' => 'downloads/bootstrap-modal/',
118
  'docs' => 'knowledgebase/bootstrap-modal/',
119
  'excerpt' => 'Open a view or form in a Bootstrap popup.',
120
  ),
121
- 'bootstrap' => array(
122
  'title' => 'Bootstrap Style Forms',
123
  'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
124
  ),
125
- 'zapier' => array(
126
  'title' => 'Zapier Forms',
127
  'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
128
  ),
129
- 'signature' => array(
130
  'title' => 'Digital Signature Forms',
131
  'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
132
  ),
133
- 'api' => array(
134
  'title' => 'Formidable Forms API',
135
  'link' => 'downloads/formidable-api/',
136
  'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
137
  ),
138
- 'twilio' => array(
139
  'title' => 'Twilio SMS Forms',
140
  'docs' => 'knowledgebase/twilio-add-on/',
141
  'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
@@ -150,8 +146,8 @@ class FrmAddonsController {
150
  * @return string
151
  */
152
  public static function get_pro_download_url() {
153
- $pro_cred_store = 'frmpro-credentials';
154
- $pro_wpmu_store = 'frmpro-wpmu-sitewide';
155
  if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
156
  $creds = get_site_option( $pro_cred_store );
157
  } else {
@@ -172,9 +168,9 @@ class FrmAddonsController {
172
  $license = strtoupper( $license );
173
  }
174
 
175
- $api = new FrmFormApi( $license );
176
  $downloads = $api->get_api_info();
177
- $pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array();
178
 
179
  return isset( $pro['url'] ) ? $pro['url'] : '';
180
  }
@@ -219,8 +215,8 @@ class FrmAddonsController {
219
  $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
220
 
221
  if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
222
- $slug = explode( '/', $folder );
223
- $plugin->slug = $slug[0];
224
  $transient->response[ $folder ] = $plugin;
225
  }
226
 
@@ -235,9 +231,7 @@ class FrmAddonsController {
235
  * Check if a plugin is installed before showing an update for it
236
  *
237
  * @since 3.05
238
- *
239
  * @param string $plugin - the folder/filename.php for a plugin
240
- *
241
  * @return bool - True if installed
242
  */
243
  private static function is_installed( $plugin ) {
@@ -246,7 +240,6 @@ class FrmAddonsController {
246
  }
247
 
248
  $all_plugins = get_plugins();
249
-
250
  return isset( $all_plugins[ $plugin ] );
251
  }
252
 
@@ -331,10 +324,6 @@ class FrmAddonsController {
331
  'url' => $addon['url'],
332
  'class' => 'frm-install-addon',
333
  );
334
- } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) {
335
- $link = array(
336
- 'categories' => $addon['categories'],
337
- );
338
  }
339
 
340
  return $link;
@@ -343,15 +332,13 @@ class FrmAddonsController {
343
 
344
  /**
345
  * @since 3.04.03
346
- *
347
  * @param array $addons
348
  * @param object $license The FrmAddon object
349
- *
350
  * @return array
351
  */
352
  public static function get_addon_for_license( $addons, $license ) {
353
  $download_id = $license->download_id;
354
- $plugin = array();
355
  if ( empty( $download_id ) && ! empty( $addons ) ) {
356
  foreach ( $addons as $addon ) {
357
  if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
@@ -374,7 +361,7 @@ class FrmAddonsController {
374
  $loop_addons = $addons;
375
  foreach ( $loop_addons as $id => $addon ) {
376
  if ( is_numeric( $id ) ) {
377
- $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
378
  $file_name = $addon['plugin'];
379
  } else {
380
  $slug = $id;
@@ -392,8 +379,8 @@ class FrmAddonsController {
392
  if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) {
393
  $addon['activate_url'] = add_query_arg(
394
  array(
395
- '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
396
- 'plugin' => $file_name,
397
  ),
398
  $activate_url
399
  );
@@ -422,13 +409,13 @@ class FrmAddonsController {
422
  if ( strpos( $link, 'http' ) !== 0 ) {
423
  $link = $site_url . $link;
424
  }
425
- $link = FrmAppHelper::make_affiliate_url( $link );
426
  $query_args = array(
427
  'utm_source' => 'WordPress',
428
  'utm_medium' => 'addons',
429
  'utm_campaign' => 'liteplugin',
430
  );
431
- $link = add_query_arg( $query_args, $link );
432
  }
433
 
434
  /**
@@ -666,13 +653,13 @@ class FrmAddonsController {
666
 
667
  private static function prepare_pro_info() {
668
  return array(
669
- 'personal' => array(
670
  'id' => 2,
671
  'download' => 19367654,
672
  'price' => '49.00',
673
  'name' => 'Personal',
674
  ),
675
- 'professional' => array(
676
  'id' => 0,
677
  'download' => 19367001,
678
  'price' => '99.00',
@@ -684,7 +671,7 @@ class FrmAddonsController {
684
  'price' => '199.00',
685
  'name' => 'Business',
686
  ),
687
- 'enterprise' => array(
688
  'id' => 0,
689
  'download' => 19366992,
690
  'price' => '399.00',
@@ -722,10 +709,10 @@ class FrmAddonsController {
722
  ob_start();
723
 
724
  $show_form = false;
725
- $method = '';
726
- $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
727
- $url = esc_url_raw( $url );
728
- $creds = request_filesystem_credentials( $url, $method, false, false, null );
729
 
730
  if ( false === $creds ) {
731
  $show_form = true;
@@ -753,7 +740,7 @@ class FrmAddonsController {
753
  private static function install_addon() {
754
  require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
755
 
756
- $download_url = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
757
 
758
  // Create the plugin upgrader with our custom skin.
759
  $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
@@ -761,7 +748,6 @@ class FrmAddonsController {
761
 
762
  // Flush the cache and return the newly installed plugin basename.
763
  wp_cache_flush();
764
-
765
  return $installer->plugin_info();
766
  }
767
 
16
 
17
  public static function list_addons() {
18
  $installed_addons = apply_filters( 'frm_installed_addons', array() );
 
19
 
20
  $addons = self::get_api_addons();
21
  $errors = array();
 
22
  if ( isset( $addons['error'] ) ) {
23
  $api = new FrmFormApi();
24
  $errors = $api->get_error_from_response( $addons );
 
25
  unset( $addons['error'] );
26
  }
27
  self::prepare_addons( $addons );
35
  $plugins = apply_filters( 'frm_installed_addons', array() );
36
  if ( empty( $plugins ) ) {
37
  esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
 
38
  return;
39
  }
40
 
44
  }
45
 
46
  private static function get_api_addons() {
47
+ $api = new FrmFormApi();
48
  $addons = $api->get_api_info();
49
 
50
  if ( empty( $addons ) ) {
74
  'docs' => '',
75
  'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
76
  ),
77
+ 'mailchimp' => array(
78
  'title' => 'MailChimp Forms',
79
  'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.',
80
  ),
81
+ 'registration' => array(
82
  'title' => 'User Registration Forms',
83
  'link' => 'downloads/user-registration/',
84
  'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
85
  ),
86
+ 'paypal' => array(
87
  'title' => 'PayPal Standard Forms',
88
  'link' => 'downloads/paypal-standard/',
89
  'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
90
  ),
91
+ 'stripe' => array(
92
  'title' => 'Stripe Forms',
93
  'docs' => 'knowledgebase/stripe/',
94
  'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
95
  ),
96
+ 'authorize-net' => array(
97
  'title' => 'Authorize.net AIM Forms',
98
  'link' => 'downloads/authorize-net-aim/',
99
  'docs' => 'knowledgebase/authorize-net-aim/',
100
  'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
101
  ),
102
+ 'woocommerce' => array(
103
  'title' => 'WooCommerce Forms',
104
  'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
105
  ),
106
+ 'autoresponder' => array(
107
  'title' => 'Form Action Automation',
108
  'docs' => 'knowledgebase/schedule-autoresponder/',
109
  'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
110
  ),
111
+ 'modal' => array(
112
  'title' => 'Bootstrap Modal Forms',
113
  'link' => 'downloads/bootstrap-modal/',
114
  'docs' => 'knowledgebase/bootstrap-modal/',
115
  'excerpt' => 'Open a view or form in a Bootstrap popup.',
116
  ),
117
+ 'bootstrap' => array(
118
  'title' => 'Bootstrap Style Forms',
119
  'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
120
  ),
121
+ 'zapier' => array(
122
  'title' => 'Zapier Forms',
123
  'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
124
  ),
125
+ 'signature' => array(
126
  'title' => 'Digital Signature Forms',
127
  'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
128
  ),
129
+ 'api' => array(
130
  'title' => 'Formidable Forms API',
131
  'link' => 'downloads/formidable-api/',
132
  'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
133
  ),
134
+ 'twilio' => array(
135
  'title' => 'Twilio SMS Forms',
136
  'docs' => 'knowledgebase/twilio-add-on/',
137
  'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
146
  * @return string
147
  */
148
  public static function get_pro_download_url() {
149
+ $pro_cred_store = 'frmpro-credentials';
150
+ $pro_wpmu_store = 'frmpro-wpmu-sitewide';
151
  if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
152
  $creds = get_site_option( $pro_cred_store );
153
  } else {
168
  $license = strtoupper( $license );
169
  }
170
 
171
+ $api = new FrmFormApi( $license );
172
  $downloads = $api->get_api_info();
173
+ $pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array();
174
 
175
  return isset( $pro['url'] ) ? $pro['url'] : '';
176
  }
215
  $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
216
 
217
  if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
218
+ $slug = explode( '/', $folder );
219
+ $plugin->slug = $slug[0];
220
  $transient->response[ $folder ] = $plugin;
221
  }
222
 
231
  * Check if a plugin is installed before showing an update for it
232
  *
233
  * @since 3.05
 
234
  * @param string $plugin - the folder/filename.php for a plugin
 
235
  * @return bool - True if installed
236
  */
237
  private static function is_installed( $plugin ) {
240
  }
241
 
242
  $all_plugins = get_plugins();
 
243
  return isset( $all_plugins[ $plugin ] );
244
  }
245
 
324
  'url' => $addon['url'],
325
  'class' => 'frm-install-addon',
326
  );
 
 
 
 
327
  }
328
 
329
  return $link;
332
 
333
  /**
334
  * @since 3.04.03
 
335
  * @param array $addons
336
  * @param object $license The FrmAddon object
 
337
  * @return array
338
  */
339
  public static function get_addon_for_license( $addons, $license ) {
340
  $download_id = $license->download_id;
341
+ $plugin = array();
342
  if ( empty( $download_id ) && ! empty( $addons ) ) {
343
  foreach ( $addons as $addon ) {
344
  if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
361
  $loop_addons = $addons;
362
  foreach ( $loop_addons as $id => $addon ) {
363
  if ( is_numeric( $id ) ) {
364
+ $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
365
  $file_name = $addon['plugin'];
366
  } else {
367
  $slug = $id;
379
  if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) {
380
  $addon['activate_url'] = add_query_arg(
381
  array(
382
+ '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
383
+ 'plugin' => $file_name,
384
  ),
385
  $activate_url
386
  );
409
  if ( strpos( $link, 'http' ) !== 0 ) {
410
  $link = $site_url . $link;
411
  }
412
+ $link = FrmAppHelper::make_affiliate_url( $link );
413
  $query_args = array(
414
  'utm_source' => 'WordPress',
415
  'utm_medium' => 'addons',
416
  'utm_campaign' => 'liteplugin',
417
  );
418
+ $link = add_query_arg( $query_args, $link );
419
  }
420
 
421
  /**
653
 
654
  private static function prepare_pro_info() {
655
  return array(
656
+ 'personal' => array(
657
  'id' => 2,
658
  'download' => 19367654,
659
  'price' => '49.00',
660
  'name' => 'Personal',
661
  ),
662
+ 'professional' => array(
663
  'id' => 0,
664
  'download' => 19367001,
665
  'price' => '99.00',
671
  'price' => '199.00',
672
  'name' => 'Business',
673
  ),
674
+ 'enterprise' => array(
675
  'id' => 0,
676
  'download' => 19366992,
677
  'price' => '399.00',
709
  ob_start();
710
 
711
  $show_form = false;
712
+ $method = '';
713
+ $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
714
+ $url = esc_url_raw( $url );
715
+ $creds = request_filesystem_credentials( $url, $method, false, false, null );
716
 
717
  if ( false === $creds ) {
718
  $show_form = true;
740
  private static function install_addon() {
741
  require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
742
 
743
+ $download_url = esc_url_raw( $_POST['plugin'] );
744
 
745
  // Create the plugin upgrader with our custom skin.
746
  $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
748
 
749
  // Flush the cache and return the newly installed plugin basename.
750
  wp_cache_flush();
 
751
  return $installer->plugin_info();
752
  }
753
 
classes/controllers/FrmAppController.php CHANGED
@@ -3,14 +3,14 @@
3
  class FrmAppController {
4
 
5
  public static function menu() {
6
- FrmAppHelper::maybe_add_permissions();
7
- if ( ! current_user_can( 'frm_view_forms' ) ) {
8
- return;
9
- }
10
 
11
  $menu_name = FrmAppHelper::get_menu_name();
12
  add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() );
13
- }
14
 
15
  private static function get_menu_position() {
16
  return apply_filters( 'frm_menu_position', '29.3' );
@@ -27,7 +27,6 @@ class FrmAppController {
27
  )
28
  );
29
  $icon = 'data:image/svg+xml;base64,' . base64_encode( $icon );
30
-
31
  return apply_filters( 'frm_icon', $icon );
32
  }
33
 
@@ -38,10 +37,6 @@ class FrmAppController {
38
  if ( self::is_white_page() ) {
39
  $classes .= ' frm-white-body ';
40
  }
41
- if ( FrmAppHelper::is_full_screen() ) {
42
- $classes .= ' frm-full-screen';
43
- }
44
-
45
  return $classes;
46
  }
47
 
@@ -49,45 +44,33 @@ class FrmAppController {
49
  * @since 3.0
50
  */
51
  private static function is_white_page() {
52
- $white_pages = array(
53
- 'formidable',
54
- 'formidable-entries',
55
- 'formidable-pro-upgrade',
56
- 'formidable-addons',
57
- 'formidable-import',
58
- 'formidable-settings',
59
- 'formidable-styles',
60
- );
61
-
62
- $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
63
- $is_white_page = in_array( $get_page, $white_pages );
64
-
65
  if ( ! $is_white_page ) {
66
- $screen = get_current_screen();
67
- $is_white_page = ( $screen && strpos( $screen->id, 'frm_display' ) !== false );
68
  }
69
 
70
  return $is_white_page;
71
  }
72
 
73
- public static function load_wp_admin_style() {
74
- FrmAppHelper::load_font_style();
75
- }
76
 
77
  public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) {
78
  $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' );
79
- if ( empty( $show_nav ) || ! $form ) {
80
- return;
81
- }
82
 
83
  FrmForm::maybe_get_form( $form );
84
  if ( ! is_object( $form ) ) {
85
  return;
86
  }
87
 
88
- $id = $form->id;
89
  $current_page = self::get_current_page();
90
- $nav_items = self::get_form_nav_items( $form );
91
 
92
  include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' );
93
  }
@@ -95,8 +78,8 @@ class FrmAppController {
95
  private static function get_current_page() {
96
  global $pagenow;
97
 
98
- $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
99
- $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
100
  $current_page = isset( $_GET['page'] ) ? $page : $post_type;
101
  if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
102
  $current_page = 'frm_display';
@@ -110,24 +93,24 @@ class FrmAppController {
110
 
111
  $nav_items = array(
112
  array(
113
- 'link' => FrmForm::get_edit_link( $id ),
114
- 'label' => __( 'Build', 'formidable' ),
115
- 'current' => array( 'edit', 'new', 'duplicate' ),
116
- 'page' => 'formidable',
117
  'permission' => 'frm_edit_forms',
118
  ),
119
  array(
120
- 'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ),
121
- 'label' => __( 'Settings', 'formidable' ),
122
- 'current' => array( 'settings' ),
123
- 'page' => 'formidable',
124
  'permission' => 'frm_edit_forms',
125
  ),
126
  array(
127
- 'link' => admin_url( 'admin.php?page=formidable-entries&frm-full=1&frm_action=list&form=' . absint( $id ) ),
128
- 'label' => __( 'Entries', 'formidable' ),
129
- 'current' => array(),
130
- 'page' => 'formidable-entries',
131
  'permission' => 'frm_view_entries',
132
  ),
133
  );
@@ -158,32 +141,32 @@ class FrmAppController {
158
  'data-medium' => 'reports-nav',
159
  ),
160
  );
 
161
  }
162
 
163
  $nav_args = array(
164
  'form_id' => $id,
165
  'form' => $form,
166
  );
167
-
168
  return apply_filters( 'frm_form_nav_list', $nav_items, $nav_args );
169
  }
170
 
171
- // Adds a settings link to the plugins page
172
- public static function settings_link( $links ) {
173
  $settings = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
174
- array_unshift( $links, $settings );
175
 
176
- return $links;
177
- }
178
 
179
- public static function pro_get_started_headline() {
180
  self::maybe_show_upgrade_bar();
181
  self::review_request();
182
 
183
- // Don't display this error as we're upgrading the thing, or if the user shouldn't see the message
184
- if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) || ! current_user_can( 'update_plugins' ) ) {
185
- return;
186
- }
187
 
188
  $pro_installed = is_dir( WP_PLUGIN_DIR . '/formidable-pro' );
189
  $authorized = get_site_option( 'frmpro-authorized' ) && ! is_callable( 'load_formidable_pro' );
@@ -200,32 +183,31 @@ class FrmAppController {
200
  $inst_install_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=formidable-pro/formidable-pro.php' ), 'activate-plugin_formidable-pro/formidable-pro.php' );
201
  } else {
202
  $inst_install_url = '#';
203
- $download_url = FrmAddonsController::get_pro_download_url();
204
 
205
  if ( empty( $download_url ) ) {
206
  $inst_install_url = 'https://formidableforms.com/knowledgebase/install-formidable-forms/?utm_source=WordPress&utm_medium=get-started&utm_campaign=liteplugin';
207
  }
208
  }
209
- ?>
210
- <div class="error frm_previous_install">
211
- <?php
212
- echo apply_filters( // WPCS: XSS ok.
213
- 'frm_pro_update_msg',
214
- sprintf(
215
- /* translators: %1$s: Start link HTML, %2$s: End link HTML, %3$s: Start link HTML, %4$s: End link HTML */
216
- esc_html__( 'This site has been previously authorized to run Formidable Forms. %1$sInstall Formidable Pro%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
217
- '<br/><a href="' . esc_url( $inst_install_url ) . '" id="frm_install_link" target="_blank" data-prourl="' . esc_url( $download_url ) . '">',
218
- '</a>',
219
- '<a href="#" class="frm_deauthorize_link">',
220
- '</a>'
221
- ),
222
- esc_url( $inst_install_url )
223
- );
224
- ?>
225
- <div id="frm_install_message" class="hidden frm_hidden"></div>
226
- </div>
227
  <?php
228
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
  private static function maybe_show_upgrade_bar() {
231
  if ( ! FrmAppHelper::is_formidable_admin() || FrmAppHelper::pro_is_installed() ) {
@@ -234,17 +216,15 @@ class FrmAppController {
234
 
235
  $affiliate = FrmAppHelper::get_affiliate();
236
  if ( ! empty( $affiliate ) ) {
237
- $tip = FrmTipsHelper::get_banner_tip();
238
  $link = FrmAppHelper::admin_upgrade_link( 'banner' );
239
- ?>
240
- <div class="update-nag frm-update-to-pro">
241
- <?php echo FrmAppHelper::kses( $tip['tip'] ); // WPCS: XSS ok. ?>
242
- <span><?php echo FrmAppHelper::kses( $tip['call'] ); // WPCS: XSS ok. ?></span>
243
- <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( $link ) ); ?>" class="button">
244
- Upgrade to Pro
245
- </a>
246
- </div>
247
- <?php
248
  }
249
  }
250
 
@@ -314,7 +294,6 @@ class FrmAppController {
314
  }
315
  }
316
  }
317
-
318
  return $upsell;
319
  }
320
 
@@ -347,7 +326,6 @@ class FrmAppController {
347
  if ( ! $needs_upgrade ) {
348
  $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
349
  }
350
-
351
  return $needs_upgrade;
352
  }
353
 
@@ -362,10 +340,10 @@ class FrmAppController {
362
  if ( strpos( $db_version, '-' ) === false ) {
363
  $needs_upgrade = true;
364
  } else {
365
- $last_upgrade = explode( '-', $db_version );
366
  $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version'];
367
- $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' );
368
- $needs_upgrade = $needs_db_upgrade || $new_version;
369
  }
370
 
371
  return $needs_upgrade;
@@ -384,13 +362,13 @@ class FrmAppController {
384
  }
385
 
386
  $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
387
- if ( ! FrmAppHelper::doing_ajax() ) {
388
  // don't continue during ajax calls
389
  self::admin_js();
390
  }
391
  }
392
 
393
- public static function admin_js() {
394
  $version = FrmAppHelper::plugin_version();
395
  FrmAppHelper::load_admin_wide_js( false );
396
 
@@ -411,29 +389,29 @@ class FrmAppController {
411
 
412
  wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', $dependecies, $version, true );
413
  wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
414
- wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' );
415
  wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version );
416
 
417
  // load multselect js
418
- $depends_on = array( 'jquery', 'bootstrap_tooltip' );
419
- wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', $depends_on, '0.9.8', true );
420
 
421
- $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
422
  $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
423
 
424
  global $pagenow;
425
  if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
426
 
427
- wp_enqueue_script( 'admin-widgets' );
428
- wp_enqueue_style( 'widgets' );
429
- wp_enqueue_script( 'formidable' );
430
- wp_enqueue_script( 'formidable_admin' );
431
  FrmAppHelper::localize_script( 'admin' );
432
 
433
  wp_enqueue_style( 'formidable-admin' );
434
  if ( 'formidable-styles' !== $page ) {
435
  wp_enqueue_style( 'formidable-grids' );
436
  wp_enqueue_style( 'formidable-dropzone' );
 
437
  } else {
438
  $settings = FrmAppHelper::get_settings();
439
  if ( empty( $settings->old_css ) ) {
@@ -441,36 +419,36 @@ class FrmAppController {
441
  }
442
  }
443
 
444
- do_action( 'frm_enqueue_builder_scripts' );
445
- self::include_upgrade_overlay();
446
- } elseif ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
447
- if ( isset( $_REQUEST['post_type'] ) ) {
448
- $post_type = sanitize_title( wp_unslash( $_REQUEST['post_type'] ) );
449
- } elseif ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
450
- $post = get_post( absint( wp_unslash( $_REQUEST['post'] ) ) );
451
- if ( ! $post ) {
452
- return;
453
- }
454
- $post_type = $post->post_type;
455
- } else {
456
- return;
457
- }
458
 
459
- if ( $post_type == 'frm_display' ) {
460
- wp_enqueue_style( 'formidable-grids' );
461
- wp_enqueue_script( 'jquery-ui-draggable' );
462
- wp_enqueue_script( 'formidable_admin' );
463
- wp_enqueue_style( 'formidable-admin' );
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  FrmAppHelper::localize_script( 'admin' );
465
- }
466
- } elseif ( $pagenow == 'widgets.php' ) {
467
- FrmAppHelper::load_admin_wide_js();
468
- }
469
- }
470
 
471
- public static function load_lang() {
472
- load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
473
- }
474
 
475
  /**
476
  * Check if the styles are updated when a form is loaded on the front-end
@@ -532,7 +510,6 @@ class FrmAppController {
532
  delete_option( 'frm_install_running' );
533
  }
534
  }
535
-
536
  return true;
537
  }
538
 
@@ -547,14 +524,14 @@ class FrmAppController {
547
  wp_die();
548
  }
549
 
550
- public static function install() {
551
- $frmdb = new FrmMigrate();
552
- $frmdb->upgrade();
553
- }
554
 
555
- public static function uninstall() {
556
  FrmAppHelper::permission_check( 'administrator' );
557
- check_ajax_referer( 'frm_ajax', 'nonce' );
558
 
559
  $frmdb = new FrmMigrate();
560
  $frmdb->uninstall();
@@ -563,35 +540,42 @@ class FrmAppController {
563
  deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false );
564
  echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
565
 
566
- wp_die();
567
- }
568
-
569
- public static function drop_tables( $tables ) {
570
- global $wpdb;
571
- $tables[] = $wpdb->prefix . 'frm_fields';
572
- $tables[] = $wpdb->prefix . 'frm_forms';
573
- $tables[] = $wpdb->prefix . 'frm_items';
574
- $tables[] = $wpdb->prefix . 'frm_item_metas';
575
 
576
- return $tables;
577
- }
 
 
 
 
 
 
578
 
579
- public static function deauthorize() {
580
  FrmAppHelper::permission_check( 'frm_change_settings' );
581
- check_ajax_referer( 'frm_ajax', 'nonce' );
582
 
583
- delete_option( 'frmpro-credentials' );
584
- delete_option( 'frmpro-authorized' );
585
- delete_site_option( 'frmpro-credentials' );
586
- delete_site_option( 'frmpro-authorized' );
587
- wp_die();
588
- }
589
 
590
  public static function set_footer_text( $text ) {
591
  if ( FrmAppHelper::is_formidable_admin() ) {
592
- $text = '';
 
 
 
 
 
 
 
 
 
593
  }
594
-
595
  return $text;
596
  }
597
 
@@ -599,9 +583,9 @@ class FrmAppController {
599
  * @deprecated 1.07.05
600
  * @codeCoverageIgnore
601
  */
602
- public static function get_form_shortcode( $atts ) {
603
- return FrmDeprecated::get_form_shortcode( $atts );
604
- }
605
 
606
  /**
607
  * @deprecated 2.5.4
@@ -621,6 +605,7 @@ class FrmAppController {
621
  FrmDeprecated::front_head();
622
  }
623
 
 
624
  /**
625
  * @deprecated 3.0.04
626
  * @codeCoverageIgnore
3
  class FrmAppController {
4
 
5
  public static function menu() {
6
+ FrmAppHelper::maybe_add_permissions();
7
+ if ( ! current_user_can( 'frm_view_forms' ) ) {
8
+ return;
9
+ }
10
 
11
  $menu_name = FrmAppHelper::get_menu_name();
12
  add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() );
13
+ }
14
 
15
  private static function get_menu_position() {
16
  return apply_filters( 'frm_menu_position', '29.3' );
27
  )
28
  );
29
  $icon = 'data:image/svg+xml;base64,' . base64_encode( $icon );
 
30
  return apply_filters( 'frm_icon', $icon );
31
  }
32
 
37
  if ( self::is_white_page() ) {
38
  $classes .= ' frm-white-body ';
39
  }
 
 
 
 
40
  return $classes;
41
  }
42
 
44
  * @since 3.0
45
  */
46
  private static function is_white_page() {
47
+ $is_white_page = ( FrmAppHelper::is_admin_page( 'formidable' ) || FrmAppHelper::is_admin_page( 'formidable-entries' ) || FrmAppHelper::is_admin_page( 'formidable-pro-upgrade' ) || FrmAppHelper::is_admin_page( 'formidable-addons' ) || FrmAppHelper::is_admin_page( 'formidable-import' ) );
 
 
 
 
 
 
 
 
 
 
 
 
48
  if ( ! $is_white_page ) {
49
+ $screen = get_current_screen();
50
+ $is_white_page = ( $screen && $screen->id === 'edit-frm_display' );
51
  }
52
 
53
  return $is_white_page;
54
  }
55
 
56
+ public static function load_wp_admin_style() {
57
+ FrmAppHelper::load_font_style();
58
+ }
59
 
60
  public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) {
61
  $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' );
62
+ if ( empty( $show_nav ) || ! $form ) {
63
+ return;
64
+ }
65
 
66
  FrmForm::maybe_get_form( $form );
67
  if ( ! is_object( $form ) ) {
68
  return;
69
  }
70
 
71
+ $id = $form->id;
72
  $current_page = self::get_current_page();
73
+ $nav_items = self::get_form_nav_items( $form );
74
 
75
  include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' );
76
  }
78
  private static function get_current_page() {
79
  global $pagenow;
80
 
81
+ $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
82
+ $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
83
  $current_page = isset( $_GET['page'] ) ? $page : $post_type;
84
  if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
85
  $current_page = 'frm_display';
93
 
94
  $nav_items = array(
95
  array(
96
+ 'link' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $id ) ),
97
+ 'label' => __( 'Build', 'formidable' ),
98
+ 'current' => array( 'edit', 'new', 'duplicate' ),
99
+ 'page' => 'formidable',
100
  'permission' => 'frm_edit_forms',
101
  ),
102
  array(
103
+ 'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ),
104
+ 'label' => __( 'Settings', 'formidable' ),
105
+ 'current' => array( 'settings' ),
106
+ 'page' => 'formidable',
107
  'permission' => 'frm_edit_forms',
108
  ),
109
  array(
110
+ 'link' => admin_url( 'admin.php?page=formidable-entries&frm_action=list&form=' . absint( $id ) ),
111
+ 'label' => __( 'Entries', 'formidable' ),
112
+ 'current' => array(),
113
+ 'page' => 'formidable-entries',
114
  'permission' => 'frm_view_entries',
115
  ),
116
  );
141
  'data-medium' => 'reports-nav',
142
  ),
143
  );
144
+ self::include_upgrade_overlay();
145
  }
146
 
147
  $nav_args = array(
148
  'form_id' => $id,
149
  'form' => $form,
150
  );
 
151
  return apply_filters( 'frm_form_nav_list', $nav_items, $nav_args );
152
  }
153
 
154
+ // Adds a settings link to the plugins page
155
+ public static function settings_link( $links ) {
156
  $settings = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
157
+ array_unshift( $links, $settings );
158
 
159
+ return $links;
160
+ }
161
 
162
+ public static function pro_get_started_headline() {
163
  self::maybe_show_upgrade_bar();
164
  self::review_request();
165
 
166
+ // Don't display this error as we're upgrading the thing, or if the user shouldn't see the message
167
+ if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) || ! current_user_can( 'update_plugins' ) ) {
168
+ return;
169
+ }
170
 
171
  $pro_installed = is_dir( WP_PLUGIN_DIR . '/formidable-pro' );
172
  $authorized = get_site_option( 'frmpro-authorized' ) && ! is_callable( 'load_formidable_pro' );
183
  $inst_install_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=formidable-pro/formidable-pro.php' ), 'activate-plugin_formidable-pro/formidable-pro.php' );
184
  } else {
185
  $inst_install_url = '#';
186
+ $download_url = FrmAddonsController::get_pro_download_url();
187
 
188
  if ( empty( $download_url ) ) {
189
  $inst_install_url = 'https://formidableforms.com/knowledgebase/install-formidable-forms/?utm_source=WordPress&utm_medium=get-started&utm_campaign=liteplugin';
190
  }
191
  }
192
+ ?>
193
+ <div class="error frm_previous_install">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  <?php
195
+ echo apply_filters( // WPCS: XSS ok.
196
+ 'frm_pro_update_msg',
197
+ sprintf(
198
+ esc_html__( 'This site has been previously authorized to run Formidable Forms. %1$sInstall Formidable Pro%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
199
+ '<br/><a href="' . esc_url( $inst_install_url ) . '" id="frm_install_link" target="_blank" data-prourl="' . esc_url( $download_url ) . '">',
200
+ '</a>',
201
+ '<a href="#" class="frm_deauthorize_link">',
202
+ '</a>'
203
+ ),
204
+ esc_url( $inst_install_url )
205
+ );
206
+ ?>
207
+ <div id="frm_install_message" class="hidden frm_hidden"></div>
208
+ </div>
209
+ <?php
210
+ }
211
 
212
  private static function maybe_show_upgrade_bar() {
213
  if ( ! FrmAppHelper::is_formidable_admin() || FrmAppHelper::pro_is_installed() ) {
216
 
217
  $affiliate = FrmAppHelper::get_affiliate();
218
  if ( ! empty( $affiliate ) ) {
219
+ $tip = FrmTipsHelper::get_banner_tip();
220
  $link = FrmAppHelper::admin_upgrade_link( 'banner' );
221
+ ?>
222
+ <div class="update-nag frm-update-to-pro">
223
+ <?php echo FrmAppHelper::kses( $tip['tip'] ); // WPCS: XSS ok. ?>
224
+ <span><?php echo FrmAppHelper::kses( $tip['call'] ); // WPCS: XSS ok. ?></span>
225
+ <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( $link ) ); ?>" class="button">Upgrade to Pro</a>
226
+ </div>
227
+ <?php
 
 
228
  }
229
  }
230
 
294
  }
295
  }
296
  }
 
297
  return $upsell;
298
  }
299
 
326
  if ( ! $needs_upgrade ) {
327
  $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
328
  }
 
329
  return $needs_upgrade;
330
  }
331
 
340
  if ( strpos( $db_version, '-' ) === false ) {
341
  $needs_upgrade = true;
342
  } else {
343
+ $last_upgrade = explode( '-', $db_version );
344
  $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version'];
345
+ $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' );
346
+ $needs_upgrade = $needs_db_upgrade || $new_version;
347
  }
348
 
349
  return $needs_upgrade;
362
  }
363
 
364
  $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
365
+ if ( ! FrmAppHelper::doing_ajax() || $action == 'frm_import_choices' ) {
366
  // don't continue during ajax calls
367
  self::admin_js();
368
  }
369
  }
370
 
371
+ public static function admin_js() {
372
  $version = FrmAppHelper::plugin_version();
373
  FrmAppHelper::load_admin_wide_js( false );
374
 
389
 
390
  wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', $dependecies, $version, true );
391
  wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
392
+ wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' );
393
  wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version );
394
 
395
  // load multselect js
396
+ wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
 
397
 
398
+ $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
399
  $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
400
 
401
  global $pagenow;
402
  if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
403
 
404
+ wp_enqueue_script( 'admin-widgets' );
405
+ wp_enqueue_style( 'widgets' );
406
+ wp_enqueue_script( 'formidable' );
407
+ wp_enqueue_script( 'formidable_admin' );
408
  FrmAppHelper::localize_script( 'admin' );
409
 
410
  wp_enqueue_style( 'formidable-admin' );
411
  if ( 'formidable-styles' !== $page ) {
412
  wp_enqueue_style( 'formidable-grids' );
413
  wp_enqueue_style( 'formidable-dropzone' );
414
+ add_thickbox();
415
  } else {
416
  $settings = FrmAppHelper::get_settings();
417
  if ( empty( $settings->old_css ) ) {
419
  }
420
  }
421
 
422
+ wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() . '/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
 
 
 
 
 
 
 
 
 
 
 
 
 
423
 
424
+ do_action( 'frm_enqueue_builder_scripts' );
425
+ } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
426
+ if ( isset( $_REQUEST['post_type'] ) ) {
427
+ $post_type = sanitize_title( $_REQUEST['post_type'] );
428
+ } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
429
+ $post = get_post( absint( $_REQUEST['post'] ) );
430
+ if ( ! $post ) {
431
+ return;
432
+ }
433
+ $post_type = $post->post_type;
434
+ } else {
435
+ return;
436
+ }
437
+
438
+ if ( $post_type == 'frm_display' ) {
439
+ wp_enqueue_script( 'jquery-ui-draggable' );
440
+ wp_enqueue_script( 'formidable_admin' );
441
+ wp_enqueue_style( 'formidable-admin' );
442
  FrmAppHelper::localize_script( 'admin' );
443
+ }
444
+ } else if ( $pagenow == 'widgets.php' ) {
445
+ FrmAppHelper::load_admin_wide_js();
446
+ }
447
+ }
448
 
449
+ public static function load_lang() {
450
+ load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
451
+ }
452
 
453
  /**
454
  * Check if the styles are updated when a form is loaded on the front-end
510
  delete_option( 'frm_install_running' );
511
  }
512
  }
 
513
  return true;
514
  }
515
 
524
  wp_die();
525
  }
526
 
527
+ public static function install() {
528
+ $frmdb = new FrmMigrate();
529
+ $frmdb->upgrade();
530
+ }
531
 
532
+ public static function uninstall() {
533
  FrmAppHelper::permission_check( 'administrator' );
534
+ check_ajax_referer( 'frm_ajax', 'nonce' );
535
 
536
  $frmdb = new FrmMigrate();
537
  $frmdb->uninstall();
540
  deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false );
541
  echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
542
 
543
+ wp_die();
544
+ }
 
 
 
 
 
 
 
545
 
546
+ public static function drop_tables( $tables ) {
547
+ global $wpdb;
548
+ $tables[] = $wpdb->prefix . 'frm_fields';
549
+ $tables[] = $wpdb->prefix . 'frm_forms';
550
+ $tables[] = $wpdb->prefix . 'frm_items';
551
+ $tables[] = $wpdb->prefix . 'frm_item_metas';
552
+ return $tables;
553
+ }
554
 
555
+ public static function deauthorize() {
556
  FrmAppHelper::permission_check( 'frm_change_settings' );
557
+ check_ajax_referer( 'frm_ajax', 'nonce' );
558
 
559
+ delete_option( 'frmpro-credentials' );
560
+ delete_option( 'frmpro-authorized' );
561
+ delete_site_option( 'frmpro-credentials' );
562
+ delete_site_option( 'frmpro-authorized' );
563
+ wp_die();
564
+ }
565
 
566
  public static function set_footer_text( $text ) {
567
  if ( FrmAppHelper::is_formidable_admin() ) {
568
+ $link = FrmAppHelper::admin_upgrade_link( 'footer' );
569
+ $text = sprintf(
570
+ __( 'Help us spread the %1$sFormidable Forms%2$s love with %3$s %5$s on WordPress.org%4$s. Thank you heaps!', 'formidable' ),
571
+ '<a href="' . esc_url( FrmAppHelper::make_affiliate_url( $link ) ) . '" target="_blank">',
572
+ '</a>',
573
+ '<a href="https://wordpress.org/support/plugin/formidable/reviews/?filter=5#new-post" target="_blank">',
574
+ '</a>',
575
+ '&#9733;&#9733;&#9733;&#9733;&#9733;'
576
+ );
577
+ $text = '<span id="footer-thankyou">' . $text . '</span>';
578
  }
 
579
  return $text;
580
  }
581
 
583
  * @deprecated 1.07.05
584
  * @codeCoverageIgnore
585
  */
586
+ public static function get_form_shortcode( $atts ) {
587
+ return FrmDeprecated::get_form_shortcode( $atts );
588
+ }
589
 
590
  /**
591
  * @deprecated 2.5.4
605
  FrmDeprecated::front_head();
606
  }
607
 
608
+
609
  /**
610
  * @deprecated 3.0.04
611
  * @codeCoverageIgnore
classes/controllers/FrmEntriesController.php CHANGED
@@ -16,7 +16,7 @@ class FrmEntriesController {
16
  private static function load_manage_entries_hooks() {
17
  if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new' ) ) ) {
18
  $menu_name = FrmAppHelper::get_menu_name();
19
- $base = self::base_column_key( $menu_name );
20
 
21
  add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
22
  add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
@@ -26,25 +26,61 @@ class FrmEntriesController {
26
  }
27
  }
28
 
29
- /* Display in Back End */
30
- public static function route() {
31
  $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
32
 
33
- switch ( $action ) {
34
- case 'show':
35
- case 'destroy':
36
- case 'destroy_all':
37
- return self::$action();
38
 
39
- default:
40
- do_action( 'frm_entry_action_route', $action );
41
- if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
42
- return;
43
- }
44
 
45
- return self::display_list();
46
- }
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  /**
50
  * Prevent the "screen options" tab from showing when
@@ -62,17 +98,17 @@ class FrmEntriesController {
62
  }
63
 
64
  public static function manage_columns( $columns ) {
65
- global $frm_vars;
66
  $form_id = FrmForm::get_current_form_id();
67
 
68
- $columns[ $form_id . '_id' ] = 'ID';
69
  $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
70
 
71
  if ( $form_id ) {
72
  self::get_columns_for_form( $form_id, $columns );
73
  } else {
74
  $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
75
- $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
76
  $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' );
77
  }
78
 
@@ -80,7 +116,7 @@ class FrmEntriesController {
80
  $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
81
  self::maybe_add_ip_col( $form_id, $columns );
82
 
83
- $frm_vars['cols'] = $columns;
84
 
85
  $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
86
  if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
@@ -92,10 +128,10 @@ class FrmEntriesController {
92
  'option' => 'formidable_page_formidable_entries_per_page',
93
  )
94
  );
95
- }
96
 
97
- return $columns;
98
- }
99
 
100
  private static function get_columns_for_form( $form_id, &$columns ) {
101
  $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
@@ -160,76 +196,73 @@ class FrmEntriesController {
160
  public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
161
  $this_page_name = self::hidden_column_key();
162
  if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
163
- return $check;
164
- }
165
 
166
  if ( empty( $prev_value ) ) {
167
  $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
168
  }
169
 
170
- global $frm_vars;
171
  //add a check so we don't create a loop
172
  $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
173
 
174
- return $check;
175
- }
176
 
177
- /**
178
- * Add hidden columns back from other forms
179
- */
180
  public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
181
  $this_page_name = self::hidden_column_key();
182
  if ( $meta_key != $this_page_name ) {
183
- return;
184
- }
185
 
186
  global $frm_vars;
187
  if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
188
- return; // Don't continue if there's no previous value.
189
  }
190
 
191
- foreach ( $meta_value as $mk => $mv ) {
192
- // Remove blank values.
193
- if ( empty( $mv ) ) {
194
- unset( $meta_value[ $mk ] );
195
- }
196
- }
197
 
198
  $cur_form_prefix = reset( $meta_value );
199
  $cur_form_prefix = explode( '_', $cur_form_prefix );
200
- $cur_form_prefix = $cur_form_prefix[0];
201
- $save = false;
202
 
203
- foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
204
  if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
205
- // Don't add blank cols or process included cols.
206
- continue;
207
- }
208
 
209
  $form_prefix = explode( '_', $prev_hidden );
210
- $form_prefix = $form_prefix[0];
211
- if ( $form_prefix == $cur_form_prefix ) {
212
- // Don't add back columns that are meant to be hidden.
213
- continue;
214
- }
215
-
216
- $meta_value[] = $prev_hidden;
217
- $save = true;
218
  unset( $form_prefix );
219
- }
220
 
221
  if ( $save ) {
222
  $user_id = get_current_user_id();
223
  update_user_option( $user_id, $this_page_name, $meta_value, true );
224
- }
225
- }
226
 
227
  /**
228
  * @since 2.05.07
229
  */
230
  private static function hidden_column_key( $menu_name = '' ) {
231
  $base = self::base_column_key( $menu_name );
232
-
233
  return 'manage' . $base . 'columnshidden';
234
  }
235
 
@@ -240,21 +273,19 @@ class FrmEntriesController {
240
  if ( empty( $menu_name ) ) {
241
  $menu_name = FrmAppHelper::get_menu_name();
242
  }
243
-
244
  return sanitize_title( $menu_name ) . '_page_formidable-entries';
245
  }
246
 
247
  public static function save_per_page( $save, $option, $value ) {
248
- if ( $option == 'formidable_page_formidable_entries_per_page' ) {
249
- $save = (int) $value;
250
- }
251
-
252
- return $save;
253
- }
254
 
255
  public static function sortable_columns() {
256
  $form_id = FrmForm::get_current_form_id();
257
- $fields = FrmField::get_all_for_form( $form_id );
258
 
259
  $columns = array(
260
  $form_id . '_id' => 'id',
@@ -284,8 +315,8 @@ class FrmEntriesController {
284
  $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
285
 
286
  if ( ! empty( $hidden ) ) {
287
- $result = $hidden;
288
- $i = $i - count( $result );
289
  $max_columns = 11;
290
  } else {
291
  $max_columns = 8;
@@ -316,7 +347,6 @@ class FrmEntriesController {
316
  unset( $form_prefix );
317
  }
318
  }
319
-
320
  return $hidden;
321
  }
322
 
@@ -332,7 +362,7 @@ class FrmEntriesController {
332
  $atts['form_id'] . '_item_key' => '',
333
  $atts['form_id'] . '_id' => '',
334
  );
335
- $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
336
 
337
  $i = $atts['i'];
338
 
@@ -351,72 +381,69 @@ class FrmEntriesController {
351
  }
352
 
353
  public static function display_list( $message = '', $errors = array() ) {
354
- global $wpdb, $frm_vars;
355
 
356
- $form = FrmForm::maybe_get_current_form();
357
  $params = FrmForm::get_admin_params( $form );
358
 
359
- if ( $form ) {
360
- $params['form'] = $form->id;
361
- $frm_vars['current_form'] = $form;
362
 
363
  self::get_delete_form_time( $form, $errors );
364
  }
365
 
366
- $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
367
 
368
- $wp_list_table = new $table_class( array( 'params' => $params ) );
369
 
370
- $pagenum = $wp_list_table->get_pagenum();
371
 
372
- $wp_list_table->prepare_items();
373
 
374
- $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
375
- if ( $pagenum > $total_pages && $total_pages > 0 ) {
376
  $url = add_query_arg( 'paged', $total_pages );
377
- if ( headers_sent() ) {
378
  echo FrmAppHelper::js_redirect( $url ); // WPCS: XSS ok.
379
- } else {
380
- wp_redirect( esc_url_raw( $url ) );
381
- }
382
- die();
383
- }
384
 
385
  if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
386
- $message = __( 'Your import is complete', 'formidable' );
387
- }
388
 
389
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' );
390
- }
391
 
392
  private static function get_delete_form_time( $form, &$errors ) {
393
  if ( 'trash' == $form->status ) {
394
  $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
395
- $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
396
-
397
- /* translators: %1$s: Time string */
398
- $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
399
  }
400
  }
401
 
402
- /* Back End CRUD */
403
  public static function show( $id = 0 ) {
404
  FrmAppHelper::permission_check( 'frm_view_entries' );
405
 
406
- if ( ! $id ) {
407
  $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
408
 
409
- if ( ! $id ) {
410
  $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
411
- }
412
- }
413
 
414
  $entry = FrmEntry::getOne( $id, true );
415
  if ( ! $entry ) {
416
  echo '<div id="form_show_entry_page" class="wrap">' .
417
  esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
418
  '</div>';
419
-
420
  return;
421
  }
422
 
@@ -425,67 +452,67 @@ class FrmEntriesController {
425
  $data = array( 'referrer' => $data );
426
  }
427
 
428
- $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
429
- $form = FrmForm::getOne( $entry->form_id );
 
430
 
431
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
432
- }
433
 
434
- public static function destroy() {
435
  FrmAppHelper::permission_check( 'frm_delete_entries' );
436
 
437
  $params = FrmForm::get_admin_params();
438
 
439
  if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
440
  self::unlink_post( $params['id'] );
441
- }
442
-
443
- $message = '';
444
- if ( FrmEntry::destroy( $params['id'] ) ) {
445
- $message = __( 'Entry was Successfully Deleted', 'formidable' );
446
- }
447
-
448
- self::display_list( $message );
449
- }
450
 
451
- public static function destroy_all() {
452
- if ( ! current_user_can( 'frm_delete_entries' ) ) {
453
- $frm_settings = FrmAppHelper::get_settings();
454
- wp_die( esc_html( $frm_settings->admin_permission ) );
455
- }
456
 
457
- $params = FrmForm::get_admin_params();
458
- $message = '';
459
- $errors = array();
460
- $form_id = (int) $params['form'];
461
 
462
- if ( $form_id ) {
463
- $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
464
- $action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 );
465
-
466
- if ( $action ) {
467
- // This action takes a while, so only trigger it if there are posts to delete.
468
- foreach ( $entry_ids as $entry_id ) {
469
- do_action( 'frm_before_destroy_entry', $entry_id );
470
- unset( $entry_id );
471
- }
472
- }
473
 
474
- $results = self::delete_form_entries( $form_id );
475
- if ( $results ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
  FrmEntry::clear_cache();
477
- $message = __( 'Entries Successfully Deleted', 'formidable' );
478
- }
479
- } else {
480
- $errors = __( 'No Entries Selected', 'formidable' );
481
- }
482
 
483
- self::display_list( $message, $errors );
484
- }
485
 
486
  /**
487
  * @since 3.01
488
- *
489
  * @param int $form_id
490
  */
491
  private static function delete_form_entries( $form_id ) {
@@ -493,28 +520,26 @@ class FrmEntriesController {
493
 
494
  $form_ids = self::get_child_form_ids( $form_id );
495
 
496
- $meta_query = $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) WHERE form_id=%d", $form_id );
497
  $entry_query = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id );
498
 
499
  if ( ! empty( $form_ids ) ) {
500
- $form_query = ' OR form_id in (' . $form_ids . ')';
501
- $meta_query .= $form_query;
502
  $entry_query .= $form_query;
503
  }
504
 
505
  $wpdb->query( $meta_query ); // WPCS: unprepared SQL ok.
506
-
507
  return $wpdb->query( $entry_query ); // WPCS: unprepared SQL ok.
508
  }
509
 
510
  /**
511
  * @since 3.01
512
- *
513
  * @param int $form_id
514
  * @param bool|string $implode
515
  */
516
  private static function get_child_form_ids( $form_id, $implode = ',' ) {
517
- $form_ids = array();
518
  $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) );
519
  if ( $child_form_ids ) {
520
  $form_ids = $child_form_ids;
@@ -523,37 +548,36 @@ class FrmEntriesController {
523
  if ( $implode ) {
524
  $form_ids = implode( $implode, $form_ids );
525
  }
526
-
527
  return $form_ids;
528
  }
529
 
530
- public static function process_entry( $errors = '', $ajax = false ) {
531
  $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
532
  if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
533
- return;
534
- }
535
 
536
- global $frm_vars;
537
 
538
  $form = FrmForm::getOne( $form_id );
539
- if ( ! $form ) {
540
- return;
541
- }
542
 
543
  $params = FrmForm::get_params( $form );
544
 
545
- if ( ! isset( $frm_vars['form_params'] ) ) {
546
- $frm_vars['form_params'] = array();
547
- }
548
  $frm_vars['form_params'][ $form->id ] = $params;
549
 
550
  if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
551
- return;
552
- }
553
 
554
- if ( $errors == '' && ! $ajax ) {
555
  $errors = FrmEntryValidate::validate( $_POST );
556
- }
557
 
558
  /**
559
  * Use this filter to add trigger actions and add errors after
@@ -565,25 +589,24 @@ class FrmEntriesController {
565
 
566
  $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
567
 
568
- if ( empty( $errors ) ) {
569
  $_POST['frm_skip_cookie'] = 1;
570
- $do_success = false;
571
- if ( $params['action'] == 'create' ) {
572
  if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
573
  $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
574
-
575
  $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
576
- $do_success = true;
577
- }
578
- }
579
 
580
- do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
581
  if ( $do_success ) {
582
  FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
583
  }
584
  unset( $_POST['frm_skip_cookie'] );
585
- }
586
- }
587
 
588
  /**
589
  * Escape url entities before redirect
@@ -591,39 +614,33 @@ class FrmEntriesController {
591
  * @since 3.0
592
  *
593
  * @param string $url
594
- *
595
  * @return string
596
  */
597
  public static function prepare_redirect_url( $url ) {
598
  return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
599
  }
600
 
601
- public static function delete_entry_before_redirect( $url, $form, $atts ) {
602
- self::_delete_entry( $atts['id'], $form );
 
 
603
 
604
- return $url;
605
- }
606
-
607
- /**
608
- * Delete entry if not redirected.
609
- *
610
- * @param array $atts
611
- */
612
- public static function delete_entry_after_save( $atts ) {
613
- self::_delete_entry( $atts['entry_id'], $atts['form'] );
614
- }
615
 
616
- private static function _delete_entry( $entry_id, $form ) {
617
- if ( ! $form ) {
618
- return;
619
- }
620
 
621
- $form->options = maybe_unserialize( $form->options );
622
- if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
623
  self::unlink_post( $entry_id );
624
- FrmEntry::destroy( $entry_id );
625
- }
626
- }
627
 
628
  /**
629
  * Unlink entry from post
@@ -658,7 +675,6 @@ class FrmEntriesController {
658
  'border_color' => '',
659
  'bg_color' => '',
660
  'alt_bg_color' => '',
661
- 'class' => '',
662
  'clickable' => false,
663
  'exclude_fields' => '',
664
  'include_fields' => '',
@@ -675,9 +691,8 @@ class FrmEntriesController {
675
  'format' => $atts['format'],
676
  'plain_text' => $atts['plain_text'],
677
  );
678
-
679
- $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
680
- $formatted_entry = $entry_formatter->content();
681
 
682
  } else {
683
 
@@ -689,8 +704,8 @@ class FrmEntriesController {
689
  return $formatted_entry;
690
  }
691
 
692
- public static function entry_sidebar( $entry = false ) {
693
- $data = maybe_unserialize( $entry->description );
694
  $date_format = get_option( 'date_format' );
695
  $time_format = get_option( 'time_format' );
696
  if ( isset( $data['browser'] ) ) {
@@ -698,15 +713,7 @@ class FrmEntriesController {
698
  }
699
 
700
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
701
- }
702
-
703
- /**
704
- * @deprecated 4.0
705
- */
706
- public static function contextual_help( $help, $screen_id, $screen ) {
707
- _deprecated_function( __METHOD__, '4.0' );
708
- return $help;
709
- }
710
 
711
  /**
712
  * @deprecated 1.07.05
16
  private static function load_manage_entries_hooks() {
17
  if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new' ) ) ) {
18
  $menu_name = FrmAppHelper::get_menu_name();
19
+ $base = self::base_column_key( $menu_name );
20
 
21
  add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
22
  add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
26
  }
27
  }
28
 
29
+ /* Display in Back End */
30
+ public static function route() {
31
  $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
32
 
33
+ switch ( $action ) {
34
+ case 'show':
35
+ case 'destroy':
36
+ case 'destroy_all':
37
+ return self::$action();
38
 
39
+ default:
40
+ do_action( 'frm_entry_action_route', $action );
41
+ if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
42
+ return;
43
+ }
44
 
45
+ return self::display_list();
46
+ }
47
+ }
48
+
49
+ public static function contextual_help( $help, $screen_id, $screen ) {
50
+ // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
51
+ if ( ! method_exists( $screen, 'add_help_tab' ) ) {
52
+ return $help;
53
+ }
54
+
55
+ $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
56
+ $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
57
+ $show_help = ( $page == 'formidable-entries' && ( empty( $action ) || $action == 'list' ) );
58
+ if ( ! $show_help ) {
59
+ return $help;
60
+ }
61
+
62
+ unset( $action, $page );
63
+
64
+ $screen->add_help_tab(
65
+ array(
66
+ 'id' => 'formidable-entries-tab',
67
+ 'title' => __( 'Overview', 'formidable' ),
68
+ 'content' => '<p>' .
69
+ esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .
70
+ '</p> <p>' .
71
+ esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) .
72
+ '</p>',
73
+ )
74
+ );
75
+
76
+ $screen->set_help_sidebar(
77
+ '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' .
78
+ '<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/knowledgebase/manage-entries-from-the-back-end/?utm_source=WordPress&utm_medium=entries&utm_campaign=liteplugin' ) ) . '" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' .
79
+ '<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/support/?utm_source=WordPress&utm_medium=entries&utm_campaign=liteplugin' ) ) . '" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>'
80
+ );
81
+
82
+ return $help;
83
+ }
84
 
85
  /**
86
  * Prevent the "screen options" tab from showing when
98
  }
99
 
100
  public static function manage_columns( $columns ) {
101
+ global $frm_vars;
102
  $form_id = FrmForm::get_current_form_id();
103
 
104
+ $columns[ $form_id . '_id' ] = 'ID';
105
  $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
106
 
107
  if ( $form_id ) {
108
  self::get_columns_for_form( $form_id, $columns );
109
  } else {
110
  $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
111
+ $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
112
  $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' );
113
  }
114
 
116
  $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
117
  self::maybe_add_ip_col( $form_id, $columns );
118
 
119
+ $frm_vars['cols'] = $columns;
120
 
121
  $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
122
  if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
128
  'option' => 'formidable_page_formidable_entries_per_page',
129
  )
130
  );
131
+ }
132
 
133
+ return $columns;
134
+ }
135
 
136
  private static function get_columns_for_form( $form_id, &$columns ) {
137
  $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
196
  public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
197
  $this_page_name = self::hidden_column_key();
198
  if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
199
+ return $check;
200
+ }
201
 
202
  if ( empty( $prev_value ) ) {
203
  $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
204
  }
205
 
206
+ global $frm_vars;
207
  //add a check so we don't create a loop
208
  $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
209
 
210
+ return $check;
211
+ }
212
 
213
+ //add hidden columns back from other forms
 
 
214
  public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
215
  $this_page_name = self::hidden_column_key();
216
  if ( $meta_key != $this_page_name ) {
217
+ return;
218
+ }
219
 
220
  global $frm_vars;
221
  if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
222
+ return; //don't continue if there's no previous value
223
  }
224
 
225
+ foreach ( $meta_value as $mk => $mv ) {
226
+ //remove blank values
227
+ if ( empty( $mv ) ) {
228
+ unset( $meta_value[ $mk ] );
229
+ }
230
+ }
231
 
232
  $cur_form_prefix = reset( $meta_value );
233
  $cur_form_prefix = explode( '_', $cur_form_prefix );
234
+ $cur_form_prefix = $cur_form_prefix[0];
235
+ $save = false;
236
 
237
+ foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
238
  if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
239
+ //don't add blank cols or process included cols
240
+ continue;
241
+ }
242
 
243
  $form_prefix = explode( '_', $prev_hidden );
244
+ $form_prefix = $form_prefix[0];
245
+ if ( $form_prefix == $cur_form_prefix ) {
246
+ //don't add back columns that are meant to be hidden
247
+ continue;
248
+ }
249
+
250
+ $meta_value[] = $prev_hidden;
251
+ $save = true;
252
  unset( $form_prefix );
253
+ }
254
 
255
  if ( $save ) {
256
  $user_id = get_current_user_id();
257
  update_user_option( $user_id, $this_page_name, $meta_value, true );
258
+ }
259
+ }
260
 
261
  /**
262
  * @since 2.05.07
263
  */
264
  private static function hidden_column_key( $menu_name = '' ) {
265
  $base = self::base_column_key( $menu_name );
 
266
  return 'manage' . $base . 'columnshidden';
267
  }
268
 
273
  if ( empty( $menu_name ) ) {
274
  $menu_name = FrmAppHelper::get_menu_name();
275
  }
 
276
  return sanitize_title( $menu_name ) . '_page_formidable-entries';
277
  }
278
 
279
  public static function save_per_page( $save, $option, $value ) {
280
+ if ( $option == 'formidable_page_formidable_entries_per_page' ) {
281
+ $save = (int) $value;
282
+ }
283
+ return $save;
284
+ }
 
285
 
286
  public static function sortable_columns() {
287
  $form_id = FrmForm::get_current_form_id();
288
+ $fields = FrmField::get_all_for_form( $form_id );
289
 
290
  $columns = array(
291
  $form_id . '_id' => 'id',
315
  $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
316
 
317
  if ( ! empty( $hidden ) ) {
318
+ $result = $hidden;
319
+ $i = $i - count( $result );
320
  $max_columns = 11;
321
  } else {
322
  $max_columns = 8;
347
  unset( $form_prefix );
348
  }
349
  }
 
350
  return $hidden;
351
  }
352
 
362
  $atts['form_id'] . '_item_key' => '',
363
  $atts['form_id'] . '_id' => '',
364
  );
365
+ $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
366
 
367
  $i = $atts['i'];
368
 
381
  }
382
 
383
  public static function display_list( $message = '', $errors = array() ) {
384
+ global $wpdb, $frm_vars;
385
 
386
+ $form = FrmForm::maybe_get_current_form();
387
  $params = FrmForm::get_admin_params( $form );
388
 
389
+ if ( $form ) {
390
+ $params['form'] = $form->id;
391
+ $frm_vars['current_form'] = $form;
392
 
393
  self::get_delete_form_time( $form, $errors );
394
  }
395
 
396
+ $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
397
 
398
+ $wp_list_table = new $table_class( array( 'params' => $params ) );
399
 
400
+ $pagenum = $wp_list_table->get_pagenum();
401
 
402
+ $wp_list_table->prepare_items();
403
 
404
+ $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
405
+ if ( $pagenum > $total_pages && $total_pages > 0 ) {
406
  $url = add_query_arg( 'paged', $total_pages );
407
+ if ( headers_sent() ) {
408
  echo FrmAppHelper::js_redirect( $url ); // WPCS: XSS ok.
409
+ } else {
410
+ wp_redirect( esc_url_raw( $url ) );
411
+ }
412
+ die();
413
+ }
414
 
415
  if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
416
+ $message = __( 'Your import is complete', 'formidable' );
417
+ }
418
 
419
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' );
420
+ }
421
 
422
  private static function get_delete_form_time( $form, &$errors ) {
423
  if ( 'trash' == $form->status ) {
424
  $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
425
+ $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
426
+ $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
 
 
427
  }
428
  }
429
 
430
+ /* Back End CRUD */
431
  public static function show( $id = 0 ) {
432
  FrmAppHelper::permission_check( 'frm_view_entries' );
433
 
434
+ if ( ! $id ) {
435
  $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
436
 
437
+ if ( ! $id ) {
438
  $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
439
+ }
440
+ }
441
 
442
  $entry = FrmEntry::getOne( $id, true );
443
  if ( ! $entry ) {
444
  echo '<div id="form_show_entry_page" class="wrap">' .
445
  esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
446
  '</div>';
 
447
  return;
448
  }
449
 
452
  $data = array( 'referrer' => $data );
453
  }
454
 
455
+ $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
456
+ $to_emails = array();
457
+ $form = FrmForm::getOne( $entry->form_id );
458
 
459
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
460
+ }
461
 
462
+ public static function destroy() {
463
  FrmAppHelper::permission_check( 'frm_delete_entries' );
464
 
465
  $params = FrmForm::get_admin_params();
466
 
467
  if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
468
  self::unlink_post( $params['id'] );
469
+ }
 
 
 
 
 
 
 
 
470
 
471
+ $message = '';
472
+ if ( FrmEntry::destroy( $params['id'] ) ) {
473
+ $message = __( 'Entry was Successfully Destroyed', 'formidable' );
474
+ }
 
475
 
476
+ self::display_list( $message );
477
+ }
 
 
478
 
479
+ public static function destroy_all() {
480
+ if ( ! current_user_can( 'frm_delete_entries' ) ) {
481
+ $frm_settings = FrmAppHelper::get_settings();
482
+ wp_die( esc_html( $frm_settings->admin_permission ) );
483
+ }
 
 
 
 
 
 
484
 
485
+ $params = FrmForm::get_admin_params();
486
+ $message = '';
487
+ $errors = array();
488
+ $form_id = (int) $params['form'];
489
+
490
+ if ( $form_id ) {
491
+ $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
492
+ $action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 );
493
+
494
+ if ( $action ) {
495
+ // this action takes a while, so only trigger it if there are posts to delete
496
+ foreach ( $entry_ids as $entry_id ) {
497
+ do_action( 'frm_before_destroy_entry', $entry_id );
498
+ unset( $entry_id );
499
+ }
500
+ }
501
+
502
+ $results = self::delete_form_entries( $form_id );
503
+ if ( $results ) {
504
  FrmEntry::clear_cache();
505
+ $message = __( 'Entries were Successfully Destroyed', 'formidable' );
506
+ }
507
+ } else {
508
+ $errors = __( 'No entries were specified', 'formidable' );
509
+ }
510
 
511
+ self::display_list( $message, $errors );
512
+ }
513
 
514
  /**
515
  * @since 3.01
 
516
  * @param int $form_id
517
  */
518
  private static function delete_form_entries( $form_id ) {
520
 
521
  $form_ids = self::get_child_form_ids( $form_id );
522
 
523
+ $meta_query = $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) WHERE form_id=%d", $form_id );
524
  $entry_query = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id );
525
 
526
  if ( ! empty( $form_ids ) ) {
527
+ $form_query = ' OR form_id in (' . $form_ids . ')';
528
+ $meta_query .= $form_query;
529
  $entry_query .= $form_query;
530
  }
531
 
532
  $wpdb->query( $meta_query ); // WPCS: unprepared SQL ok.
 
533
  return $wpdb->query( $entry_query ); // WPCS: unprepared SQL ok.
534
  }
535
 
536
  /**
537
  * @since 3.01
 
538
  * @param int $form_id
539
  * @param bool|string $implode
540
  */
541
  private static function get_child_form_ids( $form_id, $implode = ',' ) {
542
+ $form_ids = array();
543
  $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) );
544
  if ( $child_form_ids ) {
545
  $form_ids = $child_form_ids;
548
  if ( $implode ) {
549
  $form_ids = implode( $implode, $form_ids );
550
  }
 
551
  return $form_ids;
552
  }
553
 
554
+ public static function process_entry( $errors = '', $ajax = false ) {
555
  $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
556
  if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
557
+ return;
558
+ }
559
 
560
+ global $frm_vars;
561
 
562
  $form = FrmForm::getOne( $form_id );
563
+ if ( ! $form ) {
564
+ return;
565
+ }
566
 
567
  $params = FrmForm::get_params( $form );
568
 
569
+ if ( ! isset( $frm_vars['form_params'] ) ) {
570
+ $frm_vars['form_params'] = array();
571
+ }
572
  $frm_vars['form_params'][ $form->id ] = $params;
573
 
574
  if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
575
+ return;
576
+ }
577
 
578
+ if ( $errors == '' && ! $ajax ) {
579
  $errors = FrmEntryValidate::validate( $_POST );
580
+ }
581
 
582
  /**
583
  * Use this filter to add trigger actions and add errors after
589
 
590
  $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
591
 
592
+ if ( empty( $errors ) ) {
593
  $_POST['frm_skip_cookie'] = 1;
594
+ $do_success = false;
595
+ if ( $params['action'] == 'create' ) {
596
  if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
597
  $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
 
598
  $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
599
+ $do_success = true;
600
+ }
601
+ }
602
 
603
+ do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
604
  if ( $do_success ) {
605
  FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
606
  }
607
  unset( $_POST['frm_skip_cookie'] );
608
+ }
609
+ }
610
 
611
  /**
612
  * Escape url entities before redirect
614
  * @since 3.0
615
  *
616
  * @param string $url
 
617
  * @return string
618
  */
619
  public static function prepare_redirect_url( $url ) {
620
  return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
621
  }
622
 
623
+ public static function delete_entry_before_redirect( $url, $form, $atts ) {
624
+ self::_delete_entry( $atts['id'], $form );
625
+ return $url;
626
+ }
627
 
628
+ //Delete entry if not redirected
629
+ public static function delete_entry_after_save( $atts ) {
630
+ self::_delete_entry( $atts['entry_id'], $atts['form'] );
631
+ }
 
 
 
 
 
 
 
632
 
633
+ private static function _delete_entry( $entry_id, $form ) {
634
+ if ( ! $form ) {
635
+ return;
636
+ }
637
 
638
+ $form->options = maybe_unserialize( $form->options );
639
+ if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
640
  self::unlink_post( $entry_id );
641
+ FrmEntry::destroy( $entry_id );
642
+ }
643
+ }
644
 
645
  /**
646
  * Unlink entry from post
675
  'border_color' => '',
676
  'bg_color' => '',
677
  'alt_bg_color' => '',
 
678
  'clickable' => false,
679
  'exclude_fields' => '',
680
  'include_fields' => '',
691
  'format' => $atts['format'],
692
  'plain_text' => $atts['plain_text'],
693
  );
694
+ $entry_shortcode_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
695
+ $formatted_entry = $entry_shortcode_formatter->content();
 
696
 
697
  } else {
698
 
704
  return $formatted_entry;
705
  }
706
 
707
+ public static function entry_sidebar( $entry ) {
708
+ $data = maybe_unserialize( $entry->description );
709
  $date_format = get_option( 'date_format' );
710
  $time_format = get_option( 'time_format' );
711
  if ( isset( $data['browser'] ) ) {
713
  }
714
 
715
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
716
+ }
 
 
 
 
 
 
 
 
717
 
718
  /**
719
  * @deprecated 1.07.05
classes/controllers/FrmFieldsController.php CHANGED
@@ -2,24 +2,25 @@
2
 
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 = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
10
- if ( empty( $fields ) ) {
11
- wp_die();
12
- }
13
 
14
- $_GET['page'] = 'formidable';
 
15
 
16
- $values = array(
17
- 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
18
  'doing_ajax' => true,
19
  );
20
- $field_html = array();
21
 
22
- foreach ( $fields as $field ) {
23
  $field = htmlspecialchars_decode( nl2br( $field ) );
24
  $field = json_decode( $field );
25
  if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
@@ -31,55 +32,54 @@ class FrmFieldsController {
31
  $field->value = '';
32
  }
33
  $field->field_options = json_decode( json_encode( $field->field_options ), true );
34
- $field->options = json_decode( json_encode( $field->options ), true );
35
  $field->default_value = json_decode( json_encode( $field->default_value ), true );
36
 
37
  ob_start();
38
  self::load_single_field( $field, $values );
39
  $field_html[ absint( $field->id ) ] = ob_get_contents();
40
  ob_end_clean();
41
- }
42
 
43
  echo json_encode( $field_html );
44
 
45
- wp_die();
46
- }
47
 
48
  /**
49
  * Create a new field with ajax
50
  */
51
- public static function create() {
52
  FrmAppHelper::permission_check( 'frm_edit_forms' );
53
- check_ajax_referer( 'frm_ajax', 'nonce' );
54
 
55
  $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
56
- $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
57
 
58
  $field = self::include_new_field( $field_type, $form_id );
59
 
60
  // this hook will allow for multiple fields to be added at once
61
  do_action( 'frm_after_field_created', $field, $form_id );
62
 
63
- wp_die();
64
- }
65
 
66
- /**
67
- * Set up and create a new field
68
- *
69
- * @param string $field_type
70
- * @param integer $form_id
71
- *
72
- * @return array|bool
73
- */
74
  public static function include_new_field( $field_type, $form_id ) {
75
  $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
76
- $field_values = apply_filters( 'frm_before_field_created', $field_values );
77
 
78
- $field_id = FrmField::create( $field_values );
79
 
80
- if ( ! $field_id ) {
81
- return false;
82
- }
83
 
84
  $field = self::get_field_array_from_id( $field_id );
85
 
@@ -95,20 +95,47 @@ class FrmFieldsController {
95
 
96
  self::load_single_field( $field, $values, $form_id );
97
 
98
- return $field;
99
- }
100
 
101
- public static function duplicate() {
102
  FrmAppHelper::permission_check( 'frm_edit_forms' );
103
- check_ajax_referer( 'frm_ajax', 'nonce' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
106
- $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
107
 
108
  $copy_field = FrmField::getOne( $field_id );
109
- if ( ! $copy_field ) {
110
  wp_die();
111
- }
112
 
113
  do_action( 'frm_duplicate_field', $copy_field, $form_id );
114
  do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id );
@@ -124,8 +151,8 @@ class FrmFieldsController {
124
  self::load_single_field( $field_id, $values );
125
  }
126
 
127
- wp_die();
128
- }
129
 
130
  /**
131
  * @since 3.0
@@ -136,7 +163,6 @@ class FrmFieldsController {
136
  */
137
  public static function get_field_array_from_id( $field_id ) {
138
  $field = FrmField::getOne( $field_id );
139
-
140
  return FrmFieldsHelper::setup_edit_vars( $field );
141
  }
142
 
@@ -154,23 +180,28 @@ class FrmFieldsController {
154
  if ( is_numeric( $field_object ) ) {
155
  $field_object = FrmField::getOne( $field_object );
156
  } elseif ( is_array( $field_object ) ) {
157
- $field = $field_object;
158
  $field_object = FrmField::getOne( $field['id'] );
159
  }
160
 
161
  $field_obj = FrmFieldFactory::get_field_factory( $field_object );
162
- $display = self::display_field_options( array(), $field_obj );
163
 
164
- $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
165
  $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
166
 
167
  if ( $ajax_loading && $ajax_this_field ) {
168
  $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
169
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
170
  } else {
 
 
 
 
 
 
171
  if ( ! isset( $field ) && is_object( $field_object ) ) {
172
  $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
173
-
174
  $field = FrmFieldsHelper::setup_edit_vars( $field_object );
175
  }
176
 
@@ -186,24 +217,98 @@ class FrmFieldsController {
186
  */
187
  private static function get_classes_for_builder_field( $field, $display, $field_info ) {
188
  $li_classes = $field_info->form_builder_classes( $display['type'] );
189
- $li_classes .= ' frm_form_field frmstart ' . ( isset( $field['classes'] ) ? $field['classes'] : '' ) . ' frmend';
190
  if ( ! empty( $field ) ) {
191
  $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
192
  }
193
-
194
  return $li_classes;
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' );
202
  FrmField::destroy( $field_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  wp_die();
204
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
- /* Field Options */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
 
208
  public static function import_options() {
209
  FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -213,39 +318,38 @@ class FrmFieldsController {
213
  return;
214
  }
215
 
216
- $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
217
- $field = FrmField::getOne( $field_id );
218
 
219
  if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
220
- return;
221
- }
222
 
223
  $field = FrmFieldsHelper::setup_edit_vars( $field );
224
- $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
225
- $opts = explode( "\n", rtrim( $opts, "\n" ) );
226
- $opts = array_map( 'trim', $opts );
227
-
228
- $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
229
- $field['separate_value'] = ( $separate === 'true' );
230
 
231
  if ( $field['separate_value'] ) {
232
  foreach ( $opts as $opt_key => $opt ) {
233
  if ( strpos( $opt, '|' ) !== false ) {
234
  $vals = explode( '|', $opt );
235
- $opts[ $opt_key ] = array(
236
- 'label' => trim( $vals[0] ),
237
- 'value' => trim( $vals[1] ),
238
- );
 
 
239
  unset( $vals );
240
  }
241
  unset( $opt_key, $opt );
242
  }
243
  }
244
 
245
- // Keep other options after bulk update.
246
- if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
247
- $other_array = array();
248
- foreach ( $field['options'] as $opt_key => $opt ) {
249
  if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
250
  $other_array[ $opt_key ] = $opt;
251
  }
@@ -256,153 +360,45 @@ class FrmFieldsController {
256
  }
257
  }
258
 
259
- $field['options'] = $opts;
260
 
261
  FrmFieldsHelper::show_single_option( $field );
262
 
263
- wp_die();
264
- }
265
-
266
- /**
267
- * @since 4.0
268
- *
269
- * @param array $atts - Includes field array, field_obj, display array, values array.
270
- */
271
- public static function load_single_field_settings( $atts ) {
272
- $field = $atts['field'];
273
- $field_obj = $atts['field_obj'];
274
- $values = $atts['values'];
275
- $display = $atts['display'];
276
- unset( $atts );
277
-
278
- if ( ! isset( $field['unique'] ) ) {
279
- $field['unique'] = false;
280
- }
281
-
282
- if ( ! isset( $field['read_only'] ) ) {
283
- $field['read_only'] = false;
284
- }
285
-
286
- $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
287
- $pro_field_selection = FrmField::pro_field_selection();
288
- $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
289
- $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
290
- $frm_settings = FrmAppHelper::get_settings();
291
-
292
- if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
293
- // Add fallback for an add-on field type that has been deactivated.
294
- $all_field_types[ $field['type'] ] = array(
295
- 'name' => ucfirst( $field['type'] ),
296
- 'icon' => 'frm_icon_font frm_pencil_icon',
297
- );
298
- } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
299
- // Fallback for fields added in a more basic way.
300
- FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
301
- }
302
-
303
- $display_type = self::displayed_field_type( $field );
304
-
305
- if ( $display['default'] ) {
306
- $default_value_types = self::default_value_types( $field, compact( 'display' ) );
307
- }
308
-
309
- if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
310
- $field['placeholder'] = implode( $field['placeholder'], ', ' );
311
- }
312
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
313
- }
314
-
315
- /**
316
- * Get the type of field being displayed for lookups and dynamic fields.
317
- *
318
- * @since 4.0
319
- * @return array
320
- */
321
- private static function displayed_field_type( $field ) {
322
- $display_type = array(
323
- 'radio' => FrmField::is_field_type( $field, 'radio' ),
324
- 'checkbox' => FrmField::is_field_type( $field, 'checkbox' ),
325
- 'select' => FrmField::is_field_type( $field, 'select' ),
326
- 'lookup' => FrmField::is_field_type( $field, 'lookup' ),
327
- );
328
- return array_filter( $display_type );
329
- }
330
-
331
- /**
332
- * Get the list of default value types that can be toggled in the builder.
333
- *
334
- * @since 4.0
335
- * @return array
336
- */
337
- private static function default_value_types( $field, $atts ) {
338
- $types = array(
339
- 'default_value' => array(
340
- 'class' => '',
341
- 'icon' => 'frm_icon_font frm_text2_icon',
342
- 'title' => __( 'Default Value (Text)', 'formidable' ),
343
- 'data' => array(
344
- 'frmshow' => '#default-value-for-',
345
- ),
346
- ),
347
- 'calc' => array(
348
- 'class' => 'frm_show_upgrade frm_noallow',
349
- 'title' => __( 'Default Value (Calculation)', 'formidable' ),
350
- 'icon' => 'frm_icon_font frm_calculator_icon',
351
- 'data' => array(
352
- 'medium' => 'calculations',
353
- 'upgrade' => __( 'Calculator forms', 'formidable' ),
354
- ),
355
- ),
356
- 'get_values_field' => array(
357
- 'class' => 'frm_show_upgrade frm_noallow',
358
- 'title' => __( 'Default Value (Lookup)', 'formidable' ),
359
- 'icon' => 'frm_icon_font frm_search_icon',
360
- 'data' => array(
361
- 'medium' => 'lookup',
362
- 'upgrade' => __( 'Lookup fields', 'formidable' ),
363
- ),
364
- ),
365
- );
366
-
367
- $types = apply_filters( 'frm_default_value_types', $types, $atts );
368
 
369
- // Set active class.
370
- $settings = array_keys( $types );
371
- $active = 'default_value';
372
 
373
- foreach ( $settings as $type ) {
374
- if ( ! empty( $field[ $type ] ) ) {
375
- $active = $type;
376
- }
377
  }
378
-
379
- $types[ $active ]['class'] .= ' current';
380
- $types[ $active ]['current'] = true;
381
-
382
- return $types;
383
- }
384
 
385
  public static function change_type( $type ) {
386
- $type_switch = array(
387
- 'scale' => 'radio',
388
- 'star' => 'radio',
389
- '10radio' => 'radio',
390
- 'rte' => 'textarea',
391
- 'website' => 'url',
392
- 'image' => 'url',
393
- );
394
- if ( isset( $type_switch[ $type ] ) ) {
395
- $type = $type_switch[ $type ];
396
- }
397
 
398
  $pro_fields = FrmField::pro_field_selection();
399
- $types = array_keys( $pro_fields );
400
  if ( in_array( $type, $types ) ) {
401
  $type = 'text';
402
  }
403
 
404
- return $type;
405
- }
406
 
407
  /**
408
  * @param array $settings
@@ -412,26 +408,25 @@ class FrmFieldsController {
412
  */
413
  public static function display_field_options( $settings, $field_info = null ) {
414
  if ( $field_info ) {
415
- $settings = $field_info->display_field_settings();
416
  $settings['field_data'] = $field_info->field;
417
  }
418
 
419
  return apply_filters( 'frm_display_field_options', $settings );
420
- }
421
 
422
  /**
423
  * Display the format option
424
  *
425
  * @since 3.0
426
- *
427
  * @param array $field
428
  */
429
  public static function show_format_option( $field ) {
430
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
431
  }
432
 
433
- public static function input_html( $field, $echo = true ) {
434
- $class = array();
435
  self::add_input_classes( $field, $class );
436
 
437
  $add_html = array();
@@ -450,113 +445,103 @@ class FrmFieldsController {
450
  $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
451
  $add_html = ' ' . implode( ' ', $add_html ) . ' ';
452
 
453
- if ( $echo ) {
454
- echo $add_html; // WPCS: XSS ok.
455
- }
456
 
457
- return $add_html;
458
- }
459
 
460
  private static function add_input_classes( $field, array &$class ) {
461
  if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
462
  $class[] = $field['input_class'];
463
  }
464
 
465
- if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
466
- return;
467
- }
468
 
469
  if ( isset( $field['size'] ) && $field['size'] > 0 ) {
470
  $class[] = 'auto_width';
471
  }
472
- }
473
 
474
  private static function add_html_size( $field, array &$add_html ) {
475
- $size_fields = array(
476
- 'select',
477
- 'data',
478
- 'time',
479
- 'hidden',
480
- 'file',
481
- 'lookup',
482
- );
483
-
484
- if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
485
- return;
486
- }
487
 
488
  if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
489
- return;
490
- }
491
 
492
  if ( is_numeric( $field['size'] ) ) {
493
  $field['size'] .= 'px';
494
  }
495
 
496
  $important = apply_filters( 'frm_use_important_width', 1, $field );
497
- // Note: This inline styling must stay since we cannot realistically set a class for every possible field size.
498
  $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
499
 
500
  self::add_html_cols( $field, $add_html );
501
- }
502
 
503
  private static function add_html_cols( $field, array &$add_html ) {
504
  if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
505
- return;
506
- }
507
 
508
- // Convert to cols for textareas.
509
- $calc = array(
510
- '' => 9,
511
- 'px' => 9,
512
- 'rem' => 0.444,
513
- 'em' => 0.544,
514
- );
515
 
516
  // include "col" for valid html
517
  $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
518
 
519
- if ( ! isset( $calc[ $unit ] ) ) {
520
- return;
521
- }
522
 
523
- $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
524
 
525
  $add_html['cols'] = 'cols="' . absint( $size ) . '"';
526
- }
527
 
528
  private static function add_html_length( $field, array &$add_html ) {
529
- // Check for max setting and if this field accepts maxlength.
530
- $fields = array(
531
- 'textarea',
532
- 'rte',
533
- 'hidden',
534
- 'file',
535
- );
536
-
537
- if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
538
- return;
539
- }
540
 
541
  if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
542
- // Don't load on form builder page.
543
- return;
544
- }
545
 
546
  $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
547
- }
548
 
549
  private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
550
- if ( $field['default_value'] != '' ) {
 
 
 
 
551
  if ( is_array( $field['default_value'] ) ) {
552
- $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
 
553
  } else {
554
  self::add_frmval_to_input( $field, $add_html );
555
  }
 
556
  }
557
 
558
- $field['placeholder'] = self::prepare_placeholder( $field );
559
- if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
560
  // don't include a json placeholder
561
  return;
562
  }
@@ -570,22 +555,24 @@ class FrmFieldsController {
570
 
571
  $class[] = 'frm_toggle_default';
572
 
573
- if ( $field['value'] == $field['placeholder'] ) {
574
  $class[] = 'frm_default';
575
  }
576
  }
577
  }
578
 
579
- private static function prepare_placeholder( $field ) {
580
  $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
581
- $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ) );
582
 
583
- $placeholder = $field['placeholder'];
584
- if ( empty( $placeholder ) && $is_placeholder_field && ! $is_combo_field ) {
585
- $placeholder = self::get_default_value_from_name( $field );
 
 
586
  }
587
 
588
- return $placeholder;
589
  }
590
 
591
  /**
@@ -605,7 +592,6 @@ class FrmFieldsController {
605
  } else {
606
  $default_value = '';
607
  }
608
-
609
  return $default_value;
610
  }
611
 
@@ -617,33 +603,32 @@ class FrmFieldsController {
617
  */
618
  private static function add_placeholder_to_input( $field, &$add_html ) {
619
  if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
620
- $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
621
  }
622
  }
623
 
624
  private static function add_frmval_to_input( $field, &$add_html ) {
625
- if ( $field['placeholder'] != '' ) {
626
- $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
627
 
628
  if ( 'select' === $field['type'] ) {
629
- $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
 
 
 
630
  }
631
  }
632
-
633
- if ( $field['default_value'] != '' ) {
634
- $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
635
- }
636
  }
637
 
638
  private static function add_validation_messages( $field, array &$add_html ) {
639
  if ( FrmField::is_required( $field ) ) {
640
- $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
641
  $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
642
  self::maybe_add_html_required( $field, $add_html );
643
  }
644
 
645
  if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
646
- $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
647
  $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
648
  }
649
  }
@@ -668,38 +653,37 @@ class FrmFieldsController {
668
  }
669
  }
670
 
671
- private static function add_shortcodes_to_html( $field, array &$add_html ) {
672
- if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
673
- return;
674
- }
675
 
676
- foreach ( $field['shortcodes'] as $k => $v ) {
677
- if ( 'opt' === $k ) {
678
- continue;
679
- }
680
 
681
  if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
682
- $add_html[] = $v;
683
- } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
684
  $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
685
- } else {
686
  $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
687
- }
688
 
689
  unset( $k, $v );
690
- }
691
- }
692
 
693
  /**
694
  * Add pattern attribute
695
  *
696
  * @since 3.0
697
- *
698
  * @param array $field
699
  * @param array $add_html
700
  */
701
  private static function add_pattern_attribute( $field, array &$add_html ) {
702
- $has_format = FrmField::is_option_true_in_array( $field, 'format' );
703
  $format_field = FrmField::is_field_type( $field, 'text' );
704
 
705
  if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
@@ -707,24 +691,22 @@ class FrmFieldsController {
707
 
708
  if ( $frm_settings->use_html ) {
709
  $format = FrmEntryValidate::phone_format( $field );
710
- $format = substr( $format, 2, - 1 );
711
-
712
  $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
713
  }
714
  }
715
  }
716
 
717
- public static function check_value( $opt, $opt_key, $field ) {
718
- if ( is_array( $opt ) ) {
719
- if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
720
- $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
721
- } else {
722
- $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
723
- }
724
- }
725
-
726
- return $opt;
727
- }
728
 
729
  public static function check_label( $opt ) {
730
  if ( is_array( $opt ) ) {
@@ -734,65 +716,6 @@ class FrmFieldsController {
734
  return $opt;
735
  }
736
 
737
- /**
738
- * @deprecated 4.0
739
- */
740
- public static function update_ajax_option() {
741
- _deprecated_function( __METHOD__, '4.0' );
742
- FrmAppHelper::permission_check( 'frm_edit_forms' );
743
- check_ajax_referer( 'frm_ajax', 'nonce' );
744
-
745
- $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
746
- if ( ! $field_id ) {
747
- wp_die();
748
- }
749
-
750
- $field = FrmField::getOne( $field_id );
751
-
752
- if ( isset( $_POST['separate_value'] ) ) {
753
- $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
754
-
755
- $field->field_options['separate_value'] = $new_val;
756
- unset( $new_val );
757
- }
758
-
759
- FrmField::update(
760
- $field_id,
761
- array(
762
- 'field_options' => $field->field_options,
763
- 'form_id' => $field->form_id,
764
- )
765
- );
766
- wp_die();
767
- }
768
-
769
- /**
770
- * @deprecated 4.0
771
- */
772
- public static function import_choices() {
773
- _deprecated_function( __METHOD__, '4.0' );
774
- wp_die();
775
- }
776
-
777
- /**
778
- * Add Single Option or Other Option.
779
- *
780
- * @deprecated 4.0 Moved to Pro for Other option only.
781
- */
782
- public static function add_option() {
783
- _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
784
- if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
785
- FrmProFormsController::add_other_option();
786
- }
787
- }
788
-
789
- /**
790
- * @deprecated 4.0
791
- */
792
- public static function update_order() {
793
- FrmDeprecated::update_order();
794
- }
795
-
796
  /**
797
  * @deprecated 3.0
798
  * @codeCoverageIgnore
2
 
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'];
10
+ if ( empty( $fields ) ) {
11
+ wp_die();
12
+ }
13
 
14
+ $_GET['page'] = 'formidable';
15
+ $fields = stripslashes_deep( $fields );
16
 
17
+ $values = array(
18
+ 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
19
  'doing_ajax' => true,
20
  );
21
+ $field_html = array();
22
 
23
+ foreach ( $fields as $field ) {
24
  $field = htmlspecialchars_decode( nl2br( $field ) );
25
  $field = json_decode( $field );
26
  if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
32
  $field->value = '';
33
  }
34
  $field->field_options = json_decode( json_encode( $field->field_options ), true );
35
+ $field->options = json_decode( json_encode( $field->options ), true );
36
  $field->default_value = json_decode( json_encode( $field->default_value ), true );
37
 
38
  ob_start();
39
  self::load_single_field( $field, $values );
40
  $field_html[ absint( $field->id ) ] = ob_get_contents();
41
  ob_end_clean();
42
+ }
43
 
44
  echo json_encode( $field_html );
45
 
46
+ wp_die();
47
+ }
48
 
49
  /**
50
  * Create a new field with ajax
51
  */
52
+ public static function create() {
53
  FrmAppHelper::permission_check( 'frm_edit_forms' );
54
+ check_ajax_referer( 'frm_ajax', 'nonce' );
55
 
56
  $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
57
+ $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
58
 
59
  $field = self::include_new_field( $field_type, $form_id );
60
 
61
  // this hook will allow for multiple fields to be added at once
62
  do_action( 'frm_after_field_created', $field, $form_id );
63
 
64
+ wp_die();
65
+ }
66
 
67
+ /**
68
+ * Set up and create a new field
69
+ *
70
+ * @param string $field_type
71
+ * @param integer $form_id
72
+ * @return array|bool
73
+ */
 
74
  public static function include_new_field( $field_type, $form_id ) {
75
  $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
76
+ $field_values = apply_filters( 'frm_before_field_created', $field_values );
77
 
78
+ $field_id = FrmField::create( $field_values );
79
 
80
+ if ( ! $field_id ) {
81
+ return false;
82
+ }
83
 
84
  $field = self::get_field_array_from_id( $field_id );
85
 
95
 
96
  self::load_single_field( $field, $values, $form_id );
97
 
98
+ return $field;
99
+ }
100
 
101
+ public static function update_ajax_option() {
102
  FrmAppHelper::permission_check( 'frm_edit_forms' );
103
+ check_ajax_referer( 'frm_ajax', 'nonce' );
104
+
105
+ $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
106
+ if ( ! $field_id ) {
107
+ wp_die();
108
+ }
109
+
110
+ $field = FrmField::getOne( $field_id );
111
+
112
+ if ( isset( $_POST['separate_value'] ) ) {
113
+ $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
114
+ $field->field_options['separate_value'] = $new_val;
115
+ unset( $new_val );
116
+ }
117
+
118
+ FrmField::update(
119
+ $field_id,
120
+ array(
121
+ 'field_options' => $field->field_options,
122
+ 'form_id' => $field->form_id,
123
+ )
124
+ );
125
+ wp_die();
126
+ }
127
+
128
+ public static function duplicate() {
129
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
130
+ check_ajax_referer( 'frm_ajax', 'nonce' );
131
 
132
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133
+ $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
134
 
135
  $copy_field = FrmField::getOne( $field_id );
136
+ if ( ! $copy_field ) {
137
  wp_die();
138
+ }
139
 
140
  do_action( 'frm_duplicate_field', $copy_field, $form_id );
141
  do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id );
151
  self::load_single_field( $field_id, $values );
152
  }
153
 
154
+ wp_die();
155
+ }
156
 
157
  /**
158
  * @since 3.0
163
  */
164
  public static function get_field_array_from_id( $field_id ) {
165
  $field = FrmField::getOne( $field_id );
 
166
  return FrmFieldsHelper::setup_edit_vars( $field );
167
  }
168
 
180
  if ( is_numeric( $field_object ) ) {
181
  $field_object = FrmField::getOne( $field_object );
182
  } elseif ( is_array( $field_object ) ) {
183
+ $field = $field_object;
184
  $field_object = FrmField::getOne( $field['id'] );
185
  }
186
 
187
  $field_obj = FrmFieldFactory::get_field_factory( $field_object );
188
+ $display = self::display_field_options( array(), $field_obj );
189
 
190
+ $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
191
  $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
192
 
193
  if ( $ajax_loading && $ajax_this_field ) {
194
  $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
195
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
196
  } else {
197
+ $frm_settings = FrmAppHelper::get_settings();
198
+
199
+ $pro_field_selection = FrmField::pro_field_selection();
200
+ $frm_all_field_selection = array_merge( FrmField::field_selection(), $pro_field_selection );
201
+ $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
202
+
203
  if ( ! isset( $field ) && is_object( $field_object ) ) {
204
  $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
 
205
  $field = FrmFieldsHelper::setup_edit_vars( $field_object );
206
  }
207
 
217
  */
218
  private static function get_classes_for_builder_field( $field, $display, $field_info ) {
219
  $li_classes = $field_info->form_builder_classes( $display['type'] );
 
220
  if ( ! empty( $field ) ) {
221
  $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
222
  }
 
223
  return $li_classes;
224
  }
225
 
226
+ public static function destroy() {
227
  FrmAppHelper::permission_check( 'frm_edit_forms' );
228
+ check_ajax_referer( 'frm_ajax', 'nonce' );
229
 
230
  $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
231
  FrmField::destroy( $field_id );
232
+ wp_die();
233
+ }
234
+
235
+ /* Field Options */
236
+
237
+ //Add Single Option or Other Option
238
+ public static function add_option() {
239
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
240
+ check_ajax_referer( 'frm_ajax', 'nonce' );
241
+
242
+ $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
243
+ $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
244
+ $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' );
245
+
246
+ $field = FrmField::getOne( $id );
247
+
248
+ if ( 'other' == $opt_type ) {
249
+ $opt = __( 'Other', 'formidable' );
250
+ $opt_key = 'other_' . $opt_key;
251
+ } else {
252
+ $opt = __( 'New Option', 'formidable' );
253
+ }
254
+
255
+ $field_data = $field;
256
+ $field = (array) $field;
257
+ $field['separate_value'] = isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0;
258
+ unset( $field_data );
259
+ $field['html_name'] = 'item_meta[' . $field['id'] . ']';
260
+
261
+ $field['options'] = array( $opt_key => $opt );
262
+ FrmFieldsHelper::show_single_option( $field );
263
+
264
  wp_die();
265
+ }
266
+
267
+ public static function import_choices() {
268
+ FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' );
269
+
270
+ $field_id = absint( $_REQUEST['field_id'] );
271
+
272
+ global $current_screen, $hook_suffix;
273
+
274
+ // Catch plugins that include admin-header.php before admin.php completes.
275
+ if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) {
276
+ $hook_suffix = '';
277
+ set_current_screen();
278
+ }
279
+
280
+ if ( function_exists( 'register_admin_color_schemes' ) ) {
281
+ register_admin_color_schemes();
282
+ }
283
+
284
+ $hook_suffix = '';
285
+ $admin_body_class = '';
286
 
287
+ if ( get_user_setting( 'mfold' ) == 'f' ) {
288
+ $admin_body_class .= ' folded';
289
+ }
290
+
291
+ if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
292
+ $admin_body_class .= ' admin-bar';
293
+ }
294
+
295
+ if ( is_rtl() ) {
296
+ $admin_body_class .= ' rtl';
297
+ }
298
+
299
+ $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
300
+ $prepop = array();
301
+ FrmFieldsHelper::get_bulk_prefilled_opts( $prepop );
302
+
303
+ $field = FrmField::getOne( $field_id );
304
+
305
+ wp_enqueue_script( 'utils' );
306
+ wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), FrmAppHelper::plugin_version() );
307
+ FrmAppHelper::load_admin_wide_js();
308
+
309
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' );
310
+ wp_die();
311
+ }
312
 
313
  public static function import_options() {
314
  FrmAppHelper::permission_check( 'frm_edit_forms' );
318
  return;
319
  }
320
 
321
+ $field_id = absint( $_POST['field_id'] );
322
+ $field = FrmField::getOne( $field_id );
323
 
324
  if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
325
+ return;
326
+ }
327
 
328
  $field = FrmFieldsHelper::setup_edit_vars( $field );
329
+ $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
330
+ $opts = explode( "\n", rtrim( $opts, "\n" ) );
331
+ $opts = array_map( 'trim', $opts );
 
 
 
332
 
333
  if ( $field['separate_value'] ) {
334
  foreach ( $opts as $opt_key => $opt ) {
335
  if ( strpos( $opt, '|' ) !== false ) {
336
  $vals = explode( '|', $opt );
337
+ if ( $vals[0] != $vals[1] ) {
338
+ $opts[ $opt_key ] = array(
339
+ 'label' => trim( $vals[0] ),
340
+ 'value' => trim( $vals[1] ),
341
+ );
342
+ }
343
  unset( $vals );
344
  }
345
  unset( $opt_key, $opt );
346
  }
347
  }
348
 
349
+ //Keep other options after bulk update
350
+ if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
351
+ $other_array = array();
352
+ foreach ( $field['options'] as $opt_key => $opt ) {
353
  if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
354
  $other_array[ $opt_key ] = $opt;
355
  }
360
  }
361
  }
362
 
363
+ $field['options'] = $opts;
364
 
365
  FrmFieldsHelper::show_single_option( $field );
366
 
367
+ wp_die();
368
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
 
370
+ public static function update_order() {
371
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
372
+ check_ajax_referer( 'frm_ajax', 'nonce' );
373
 
374
+ $fields = FrmAppHelper::get_post_param( 'frm_field_id' );
375
+ foreach ( (array) $fields as $position => $item ) {
376
+ FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) );
 
377
  }
378
+ wp_die();
379
+ }
 
 
 
 
380
 
381
  public static function change_type( $type ) {
382
+ $type_switch = array(
383
+ 'scale' => 'radio',
384
+ 'star' => 'radio',
385
+ '10radio' => 'radio',
386
+ 'rte' => 'textarea',
387
+ 'website' => 'url',
388
+ 'image' => 'url',
389
+ );
390
+ if ( isset( $type_switch[ $type ] ) ) {
391
+ $type = $type_switch[ $type ];
392
+ }
393
 
394
  $pro_fields = FrmField::pro_field_selection();
395
+ $types = array_keys( $pro_fields );
396
  if ( in_array( $type, $types ) ) {
397
  $type = 'text';
398
  }
399
 
400
+ return $type;
401
+ }
402
 
403
  /**
404
  * @param array $settings
408
  */
409
  public static function display_field_options( $settings, $field_info = null ) {
410
  if ( $field_info ) {
411
+ $settings = $field_info->display_field_settings();
412
  $settings['field_data'] = $field_info->field;
413
  }
414
 
415
  return apply_filters( 'frm_display_field_options', $settings );
416
+ }
417
 
418
  /**
419
  * Display the format option
420
  *
421
  * @since 3.0
 
422
  * @param array $field
423
  */
424
  public static function show_format_option( $field ) {
425
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
426
  }
427
 
428
+ public static function input_html( $field, $echo = true ) {
429
+ $class = array(); //$field['type'];
430
  self::add_input_classes( $field, $class );
431
 
432
  $add_html = array();
445
  $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
446
  $add_html = ' ' . implode( ' ', $add_html ) . ' ';
447
 
448
+ if ( $echo ) {
449
+ echo $add_html; // WPCS: XSS ok.
450
+ }
451
 
452
+ return $add_html;
453
+ }
454
 
455
  private static function add_input_classes( $field, array &$class ) {
456
  if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
457
  $class[] = $field['input_class'];
458
  }
459
 
460
+ if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
461
+ return;
462
+ }
463
 
464
  if ( isset( $field['size'] ) && $field['size'] > 0 ) {
465
  $class[] = 'auto_width';
466
  }
467
+ }
468
 
469
  private static function add_html_size( $field, array &$add_html ) {
470
+ if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) {
471
+ return;
472
+ }
 
 
 
 
 
 
 
 
 
473
 
474
  if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
475
+ return;
476
+ }
477
 
478
  if ( is_numeric( $field['size'] ) ) {
479
  $field['size'] .= 'px';
480
  }
481
 
482
  $important = apply_filters( 'frm_use_important_width', 1, $field );
483
+ // Note: This inline styling must stay since we cannot realistically set a class for every possible field size
484
  $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
485
 
486
  self::add_html_cols( $field, $add_html );
487
+ }
488
 
489
  private static function add_html_cols( $field, array &$add_html ) {
490
  if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
491
+ return;
492
+ }
493
 
494
+ // convert to cols for textareas
495
+ $calc = array(
496
+ '' => 9,
497
+ 'px' => 9,
498
+ 'rem' => 0.444,
499
+ 'em' => 0.544,
500
+ );
501
 
502
  // include "col" for valid html
503
  $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
504
 
505
+ if ( ! isset( $calc[ $unit ] ) ) {
506
+ return;
507
+ }
508
 
509
+ $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
510
 
511
  $add_html['cols'] = 'cols="' . absint( $size ) . '"';
512
+ }
513
 
514
  private static function add_html_length( $field, array &$add_html ) {
515
+ // check for max setting and if this field accepts maxlength
516
+ if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) {
517
+ return;
518
+ }
 
 
 
 
 
 
 
519
 
520
  if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
521
+ // don't load on form builder page
522
+ return;
523
+ }
524
 
525
  $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
526
+ }
527
 
528
  private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
529
+ if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
530
+ return;
531
+ }
532
+
533
+ if ( $field['default_value'] != '' && ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) {
534
  if ( is_array( $field['default_value'] ) ) {
535
+ $field['default_value'] = json_encode( $field['default_value'] );
536
+ $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
537
  } else {
538
  self::add_frmval_to_input( $field, $add_html );
539
  }
540
+ $field['default_value'] = '';
541
  }
542
 
543
+ $field['default_value'] = self::prepare_default_value( $field );
544
+ if ( $field['default_value'] == '' || is_array( $field['default_value'] ) ) {
545
  // don't include a json placeholder
546
  return;
547
  }
555
 
556
  $class[] = 'frm_toggle_default';
557
 
558
+ if ( $field['value'] == $field['default_value'] ) {
559
  $class[] = 'frm_default';
560
  }
561
  }
562
  }
563
 
564
+ private static function prepare_default_value( $field ) {
565
  $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
566
+ $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ) );
567
 
568
+ $default_value = $field['default_value'];
569
+ if ( empty( $default_value ) ) {
570
+ if ( $is_placeholder_field && ! $is_combo_field ) {
571
+ $default_value = self::get_default_value_from_name( $field );
572
+ }
573
  }
574
 
575
+ return $default_value;
576
  }
577
 
578
  /**
592
  } else {
593
  $default_value = '';
594
  }
 
595
  return $default_value;
596
  }
597
 
603
  */
604
  private static function add_placeholder_to_input( $field, &$add_html ) {
605
  if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
606
+ $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"';
607
  }
608
  }
609
 
610
  private static function add_frmval_to_input( $field, &$add_html ) {
611
+ if ( $field['default_value'] != '' ) {
612
+ $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
613
 
614
  if ( 'select' === $field['type'] ) {
615
+ $is_placeholder = FrmField::is_option_true( $field, 'default_blank' );
616
+ if ( $is_placeholder ) {
617
+ $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['default_value'] ) . '"';
618
+ }
619
  }
620
  }
 
 
 
 
621
  }
622
 
623
  private static function add_validation_messages( $field, array &$add_html ) {
624
  if ( FrmField::is_required( $field ) ) {
625
+ $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
626
  $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
627
  self::maybe_add_html_required( $field, $add_html );
628
  }
629
 
630
  if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
631
+ $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
632
  $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
633
  }
634
  }
653
  }
654
  }
655
 
656
+ private static function add_shortcodes_to_html( $field, array &$add_html ) {
657
+ if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
658
+ return;
659
+ }
660
 
661
+ foreach ( $field['shortcodes'] as $k => $v ) {
662
+ if ( 'opt' === $k ) {
663
+ continue;
664
+ }
665
 
666
  if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
667
+ $add_html[] = $v;
668
+ } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
669
  $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
670
+ } else {
671
  $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
672
+ }
673
 
674
  unset( $k, $v );
675
+ }
676
+ }
677
 
678
  /**
679
  * Add pattern attribute
680
  *
681
  * @since 3.0
 
682
  * @param array $field
683
  * @param array $add_html
684
  */
685
  private static function add_pattern_attribute( $field, array &$add_html ) {
686
+ $has_format = FrmField::is_option_true_in_array( $field, 'format' );
687
  $format_field = FrmField::is_field_type( $field, 'text' );
688
 
689
  if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
691
 
692
  if ( $frm_settings->use_html ) {
693
  $format = FrmEntryValidate::phone_format( $field );
694
+ $format = substr( $format, 2, -1 );
 
695
  $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
696
  }
697
  }
698
  }
699
 
700
+ public static function check_value( $opt, $opt_key, $field ) {
701
+ if ( is_array( $opt ) ) {
702
+ if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
703
+ $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
704
+ } else {
705
+ $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
706
+ }
707
+ }
708
+ return $opt;
709
+ }
 
710
 
711
  public static function check_label( $opt ) {
712
  if ( is_array( $opt ) ) {
716
  return $opt;
717
  }
718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
719
  /**
720
  * @deprecated 3.0
721
  * @codeCoverageIgnore
classes/controllers/FrmFormActionsController.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
 
3
  class FrmFormActionsController {
4
- public static $action_post_type = 'frm_form_actions';
5
- public static $registered_actions;
6
 
7
  /**
8
  * Variables saved in the post:
@@ -10,250 +10,102 @@ class FrmFormActionsController {
10
  * menu_order: form id
11
  * post_excerpt: action type
12
  */
13
- public static function register_post_types() {
14
  register_post_type(
15
  self::$action_post_type,
16
  array(
17
- 'label' => __( 'Form Actions', 'formidable' ),
18
- 'description' => '',
19
- 'public' => false,
20
- 'show_ui' => false,
21
  'exclude_from_search' => true,
22
- 'show_in_nav_menus' => false,
23
- 'show_in_menu' => true,
24
- 'capability_type' => 'page',
25
- 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'page-attributes' ),
26
- 'has_archive' => false,
27
  )
28
  );
29
 
30
- self::actions_init();
31
- }
32
 
33
- public static function actions_init() {
34
- self::$registered_actions = new Frm_Form_Action_Factory();
35
- self::register_actions();
36
- do_action( 'frm_form_actions_init' );
37
- }
38
 
39
- public static function register_actions() {
40
  $action_classes = array(
41
- 'email' => 'FrmEmailAction',
42
- 'wppost' => 'FrmDefPostAction',
43
- 'register' => 'FrmDefRegAction',
44
- 'paypal' => 'FrmDefPayPalAction',
45
- 'payment' => 'FrmDefHrsAction',
46
- 'mailchimp' => 'FrmDefMlcmpAction',
 
 
47
  'api' => 'FrmDefApiAction',
48
-
49
- 'salesforce' => 'FrmDefSalesforceAction',
50
- 'activecampaign' => 'FrmDefActiveCampaignAction',
51
- 'constantcontact' => 'FrmDefConstContactAction',
52
- 'getresponse' => 'FrmDefGetResponseAction',
53
- 'hubspot' => 'FrmDefHubspotAction',
54
- 'twilio' => 'FrmDefTwilioAction',
55
- 'highrise' => 'FrmDefHighriseAction',
56
- 'mailpoet' => 'FrmDefMailpoetAction',
57
- 'aweber' => 'FrmDefAweberAction',
58
- );
59
-
60
  $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
61
 
62
  include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' );
63
  include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' );
64
 
65
- foreach ( $action_classes as $action_class ) {
66
  self::$registered_actions->register( $action_class );
67
- }
68
- }
69
-
70
- /**
71
- * @since 4.0
72
- *
73
- * @param array $values
74
- */
75
- public static function email_settings( $values ) {
76
- $form = FrmForm::getOne( $values['id'] );
77
- $groups = self::form_action_groups();
78
-
79
- $action_controls = self::get_form_actions();
80
- self::maybe_add_action_to_group( $action_controls, $groups );
81
-
82
- $allowed = self::active_actions( $action_controls );
83
-
84
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php' );
85
- }
86
-
87
- /**
88
- * Add unknown actions to a group.
89
- *
90
- * @since 4.0
91
- */
92
- private static function maybe_add_action_to_group( $action_controls, &$groups ) {
93
- $grouped = array();
94
- foreach ( $groups as $group ) {
95
- if ( isset( $group['actions'] ) ) {
96
- $grouped = array_merge( $grouped, $group['actions'] );
97
- }
98
- }
99
-
100
- foreach ( $action_controls as $action ) {
101
- if ( isset( $groups[ $action->id_base ] ) || in_array( $action->id_base, $grouped ) ) {
102
- continue;
103
- }
104
-
105
- $this_group = $action->action_options['group'];
106
- if ( ! isset( $groups[ $this_group ] ) ) {
107
- $this_group = 'misc';
108
- }
109
-
110
- if ( ! isset( $groups[ $this_group ]['actions'] ) ) {
111
- $groups[ $this_group ]['actions'] = array();
112
- }
113
- $groups[ $this_group ]['actions'][] = $action->id_base;
114
-
115
- unset( $action );
116
- }
117
- }
118
-
119
- /**
120
- * @since 4.0
121
- *
122
- * @return array
123
- */
124
- public static function form_action_groups() {
125
- $groups = array(
126
- 'misc' => array(
127
- 'name' => '',
128
- 'icon' => 'frm_icon_font frm_shuffle_icon',
129
- 'actions' => array(
130
- 'email',
131
- 'wppost',
132
- 'register',
133
- 'twilio',
134
- ),
135
- ),
136
- 'payment' => array(
137
- 'name' => __( 'eCommerce', 'formidable' ),
138
- 'icon' => 'frm_icon_font frm_credit_card_alt_icon',
139
- 'actions' => array(
140
- 'paypal',
141
- 'payment',
142
- ),
143
- ),
144
- 'marketing' => array(
145
- 'name' => __( 'Email Marketing', 'formidable' ),
146
- 'icon' => 'frm_icon_font frm_mail_bulk_icon',
147
- 'actions' => array(
148
- 'mailchimp',
149
- 'activecampaign',
150
- 'constantcontact',
151
- 'getresponse',
152
- 'aweber',
153
- 'mailpoet',
154
- ),
155
- ),
156
- 'crm' => array(
157
- 'name' => __( 'CRM', 'formidable' ),
158
- 'icon' => 'frm_icon_font frm_address_card_icon',
159
- 'actions' => array(
160
- 'salesforce',
161
- 'hubspot',
162
- 'highrise',
163
- ),
164
- ),
165
- );
166
-
167
- return apply_filters( 'frm_action_groups', $groups );
168
- }
169
-
170
- /**
171
- * Get the number of currently active form actions.
172
- *
173
- * @since 4.0
174
- *
175
- * @return array
176
- */
177
- private static function active_actions( $action_controls ) {
178
- $allowed = array();
179
- foreach ( $action_controls as $action_control ) {
180
- if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
181
- $allowed[] = $action_control->id_base;
182
- }
183
- }
184
- return $allowed;
185
- }
186
-
187
- /**
188
- * For each add-on, add an li, class, and javascript function. If active, add an additional class.
189
- *
190
- * @since 4.0
191
- * @param object $action_control
192
- * @param array $allowed
193
- */
194
- public static function show_action_icon_link( $action_control, $allowed ) {
195
- $data = array();
196
- $classes = ' frm_' . $action_control->id_base . '_action frm_single_action frm_bstooltip';
197
-
198
- $group_class = ' frm-group-' . $action_control->action_options['group'];
199
-
200
- /* translators: %s: Name of form action */
201
- $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] );
202
-
203
- $default_shown = array( 'wppost', 'register', 'paypal', 'payment', 'mailchimp' );
204
- $default_shown = array_values( array_diff( $default_shown, $allowed ) );
205
- $default_position = array_search( $action_control->id_base, $default_shown );
206
- $allowed_count = count( $allowed );
207
-
208
- if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
209
- $classes .= ' frm_active_action';
210
- } else {
211
- $classes .= ' frm_inactive_action';
212
- if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) {
213
- $group_class .= ' frm-default-show';
214
- }
215
-
216
- $data['data-upgrade'] = $upgrade_label;
217
- $data['data-medium'] = 'settings-' . $action_control->id_base;
218
-
219
- $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] );
220
- if ( isset( $upgrading['url'] ) ) {
221
- $data['data-oneclick'] = json_encode( $upgrading );
222
- }
223
- }
224
-
225
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php' );
226
- }
227
 
228
  public static function get_form_actions( $action = 'all' ) {
229
- $temp_actions = self::$registered_actions;
230
  if ( empty( $temp_actions ) ) {
231
- self::actions_init();
232
- $temp_actions = self::$registered_actions->actions;
233
- } else {
234
- $temp_actions = $temp_actions->actions;
235
- }
236
 
237
- $actions = array();
238
 
239
- foreach ( $temp_actions as $a ) {
240
- if ( 'all' != $action && $a->id_base == $action ) {
241
- return $a;
242
- }
243
 
244
  $actions[ $a->id_base ] = $a;
245
- }
246
-
247
- return $actions;
248
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
  /**
251
  * @since 2.0
252
  */
253
- public static function list_actions( $form, $values ) {
254
- if ( empty( $form ) ) {
255
- return;
256
- }
257
 
258
  /**
259
  * Use this hook to migrate old settings into a new action
@@ -262,28 +114,28 @@ class FrmFormActionsController {
262
  */
263
  do_action( 'frm_before_list_actions', $form );
264
 
265
- $filters = array(
266
  'post_status' => 'all',
267
  );
268
  $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
269
 
270
- $action_controls = self::get_form_actions();
271
 
272
- $action_map = array();
273
 
274
  foreach ( $action_controls as $key => $control ) {
275
- $action_map[ $control->id_base ] = $key;
276
- }
277
 
278
- foreach ( $form_actions as $action ) {
279
- if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
280
- // don't try and show settings if action no longer exists
281
- continue;
282
- }
283
 
284
- self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
285
- }
286
- }
287
 
288
  public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
289
  $action_control->_set( $action_key );
@@ -291,54 +143,54 @@ class FrmFormActionsController {
291
  $use_logging = self::should_show_log_message( $form_action->post_excerpt );
292
 
293
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
294
- }
295
 
296
- public static function add_form_action() {
297
  FrmAppHelper::permission_check( 'frm_edit_forms' );
298
- check_ajax_referer( 'frm_ajax', 'nonce' );
299
 
300
- global $frm_vars;
301
 
302
- $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
303
- $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
304
 
305
- $action_control = self::get_form_actions( $action_type );
306
  $action_control->_set( $action_key );
307
 
308
- $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
309
 
310
  $form_action = $action_control->prepare_new( $form_id );
311
  $use_logging = self::should_show_log_message( $action_type );
312
 
313
- $values = array();
314
- $form = self::fields_to_values( $form_id, $values );
315
 
316
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
317
- wp_die();
318
- }
319
 
320
- public static function fill_action() {
321
  FrmAppHelper::permission_check( 'frm_edit_forms' );
322
- check_ajax_referer( 'frm_ajax', 'nonce' );
323
 
324
- $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
325
- $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
326
 
327
- $action_control = self::get_form_actions( $action_type );
328
  if ( empty( $action_control ) ) {
329
- wp_die();
330
- }
331
 
332
- $form_action = $action_control->get_single_action( $action_key );
333
 
334
- $values = array();
335
- $form = self::fields_to_values( $form_action->menu_order, $values );
336
 
337
  $use_logging = self::should_show_log_message( $action_type );
338
 
339
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
340
- wp_die();
341
- }
342
 
343
  /**
344
  * @since 3.06.04
@@ -358,19 +210,19 @@ class FrmFormActionsController {
358
  );
359
 
360
  $fields = FrmField::get_all_for_form( $form->id );
361
- foreach ( $fields as $k => $f ) {
362
- $f = (array) $f;
363
- $opts = (array) $f['field_options'];
364
- $f = array_merge( $opts, $f );
365
- if ( ! isset( $f['post_field'] ) ) {
366
- $f['post_field'] = '';
367
- }
368
- $values['fields'][] = $f;
369
  unset( $k, $f );
370
- }
371
 
372
- return $form;
373
- }
374
 
375
  public static function update_settings( $form_id ) {
376
  $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
@@ -378,9 +230,9 @@ class FrmFormActionsController {
378
  wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) );
379
  }
380
 
381
- global $wpdb;
382
 
383
- $registered_actions = self::$registered_actions->actions;
384
 
385
  $old_actions = FrmDb::get_col(
386
  $wpdb->posts,
@@ -390,23 +242,23 @@ class FrmFormActionsController {
390
  ),
391
  'ID'
392
  );
393
- $new_actions = array();
394
 
395
- foreach ( $registered_actions as $registered_action ) {
396
  $action_ids = $registered_action->update_callback( $form_id );
397
- if ( ! empty( $action_ids ) ) {
398
- $new_actions[] = $action_ids;
399
- }
400
- }
401
 
402
- // Only use array_merge if there are new actions.
403
- if ( ! empty( $new_actions ) ) {
404
- $new_actions = call_user_func_array( 'array_merge', $new_actions );
405
- }
406
- $old_actions = array_diff( $old_actions, $new_actions );
407
 
408
  self::delete_missing_actions( $old_actions );
409
- }
410
 
411
  public static function delete_missing_actions( $old_actions ) {
412
  if ( ! empty( $old_actions ) ) {
@@ -418,18 +270,17 @@ class FrmFormActionsController {
418
  }
419
 
420
  public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
421
- $filter_args = $args;
422
  $filter_args['entry_id'] = $entry_id;
423
  $filter_args['form_id'] = $form_id;
424
-
425
  $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
426
 
427
  self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
428
  }
429
 
430
- /**
431
- * @param string $event
432
- */
433
  public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
434
  $action_status = array(
435
  'post_status' => 'publish',
@@ -437,17 +288,17 @@ class FrmFormActionsController {
437
  $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
438
 
439
  if ( empty( $form_actions ) ) {
440
- return;
441
- }
442
 
443
  FrmForm::maybe_get_form( $form );
444
 
445
- $link_settings = self::get_form_actions( $type );
446
- if ( 'all' != $type ) {
447
- $link_settings = array( $type => $link_settings );
448
- }
449
 
450
- $stored_actions = array();
451
  $action_priority = array();
452
 
453
  if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
@@ -456,17 +307,17 @@ class FrmFormActionsController {
456
  $this_event = $event;
457
  }
458
 
459
- foreach ( $form_actions as $action ) {
460
 
461
  $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
462
  $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
463
  if ( $skip_this_action ) {
464
- continue;
465
- }
466
 
467
- if ( ! is_object( $entry ) ) {
468
- $entry = FrmEntry::getOne( $entry, true );
469
- }
470
 
471
  if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
472
  continue;
@@ -480,67 +331,67 @@ class FrmFormActionsController {
480
  if ( ! $trigger_children ) {
481
  continue;
482
  }
483
- }
484
 
485
- // Check conditional logic.
486
  $stop = FrmFormAction::action_conditions_met( $action, $entry );
487
- if ( $stop ) {
488
- continue;
489
- }
490
 
491
- // Store actions so they can be triggered with the correct priority.
492
- $stored_actions[ $action->ID ] = $action;
493
- $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
494
 
495
  unset( $action );
496
- }
497
 
498
- if ( ! empty( $stored_actions ) ) {
499
  asort( $action_priority );
500
 
501
- // Make sure hooks are loaded.
502
- new FrmNotification();
503
 
504
- foreach ( $action_priority as $action_id => $priority ) {
505
- $action = $stored_actions[ $action_id ];
506
  do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
507
  do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
508
 
509
- // If post is created, get updated $entry object.
510
- if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
511
  $entry = FrmEntry::getOne( $entry->id, true );
512
- }
513
- }
514
- }
515
- }
516
 
517
  public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
518
  if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
519
- // Continue if we know which actions to copy.
520
- return;
521
- }
522
 
523
  $action_controls = self::get_form_actions();
524
 
525
- foreach ( $action_controls as $action_control ) {
526
- $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
527
- unset( $action_control );
528
- }
529
- }
530
-
531
- public static function limit_by_type( $where ) {
532
- global $frm_vars, $wpdb;
533
 
534
- if ( ! isset( $frm_vars['action_type'] ) ) {
535
- return $where;
536
- }
537
 
538
- $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
 
 
539
 
540
- return $where;
541
- }
 
542
  }
543
 
 
544
  class Frm_Form_Action_Factory {
545
  public $actions = array();
546
 
@@ -564,7 +415,7 @@ class Frm_Form_Action_Factory {
564
  foreach ( $keys as $key ) {
565
  // don't register new action if old action with the same id is already registered
566
  if ( ! isset( $this->actions[ $key ] ) ) {
567
- $this->actions[ $key ]->_register();
568
  }
569
  }
570
  }
1
  <?php
2
 
3
  class FrmFormActionsController {
4
+ public static $action_post_type = 'frm_form_actions';
5
+ public static $registered_actions;
6
 
7
  /**
8
  * Variables saved in the post:
10
  * menu_order: form id
11
  * post_excerpt: action type
12
  */
13
+ public static function register_post_types() {
14
  register_post_type(
15
  self::$action_post_type,
16
  array(
17
+ 'label' => __( 'Form Actions', 'formidable' ),
18
+ 'description' => '',
19
+ 'public' => false,
20
+ 'show_ui' => false,
21
  'exclude_from_search' => true,
22
+ 'show_in_nav_menus' => false,
23
+ 'show_in_menu' => true,
24
+ 'capability_type' => 'page',
25
+ 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'page-attributes' ),
26
+ 'has_archive' => false,
27
  )
28
  );
29
 
30
+ self::actions_init();
31
+ }
32
 
33
+ public static function actions_init() {
34
+ self::$registered_actions = new Frm_Form_Action_Factory();
35
+ self::register_actions();
36
+ do_action( 'frm_form_actions_init' );
37
+ }
38
 
39
+ public static function register_actions() {
40
  $action_classes = array(
41
+ 'email' => 'FrmEmailAction',
42
+ 'wppost' => 'FrmDefPostAction',
43
+ 'register' => 'FrmDefRegAction',
44
+ 'paypal' => 'FrmDefPayPalAction',
45
+ //'aweber' => 'FrmDefAweberAction',
46
+ 'mailchimp' => 'FrmDefMlcmpAction',
47
+ 'twilio' => 'FrmDefTwilioAction',
48
+ 'payment' => 'FrmDefHrsAction',
49
  'api' => 'FrmDefApiAction',
50
+ );
 
 
 
 
 
 
 
 
 
 
 
51
  $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
52
 
53
  include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' );
54
  include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' );
55
 
56
+ foreach ( $action_classes as $action_class ) {
57
  self::$registered_actions->register( $action_class );
58
+ }
59
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  public static function get_form_actions( $action = 'all' ) {
62
+ $temp_actions = self::$registered_actions;
63
  if ( empty( $temp_actions ) ) {
64
+ self::actions_init();
65
+ $temp_actions = self::$registered_actions->actions;
66
+ } else {
67
+ $temp_actions = $temp_actions->actions;
68
+ }
69
 
70
+ $actions = array();
71
 
72
+ foreach ( $temp_actions as $a ) {
73
+ if ( 'all' != $action && $a->id_base == $action ) {
74
+ return $a;
75
+ }
76
 
77
  $actions[ $a->id_base ] = $a;
78
+ }
79
+ unset( $temp_actions, $a );
80
+
81
+ $action_limit = 10;
82
+ if ( count( $actions ) <= $action_limit ) {
83
+ return $actions;
84
+ }
85
+
86
+ // remove the last few inactive icons if there are too many
87
+ $temp_actions = $actions;
88
+ arsort( $temp_actions );
89
+ foreach ( $temp_actions as $type => $a ) {
90
+ if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) {
91
+ unset( $actions[ $type ] );
92
+ if ( count( $actions ) <= $action_limit ) {
93
+ break;
94
+ }
95
+ }
96
+ unset( $type, $a );
97
+ }
98
+
99
+ return $actions;
100
+ }
101
 
102
  /**
103
  * @since 2.0
104
  */
105
+ public static function list_actions( $form, $values ) {
106
+ if ( empty( $form ) ) {
107
+ return;
108
+ }
109
 
110
  /**
111
  * Use this hook to migrate old settings into a new action
114
  */
115
  do_action( 'frm_before_list_actions', $form );
116
 
117
+ $filters = array(
118
  'post_status' => 'all',
119
  );
120
  $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
121
 
122
+ $action_controls = self::get_form_actions();
123
 
124
+ $action_map = array();
125
 
126
  foreach ( $action_controls as $key => $control ) {
127
+ $action_map[ $control->id_base ] = $key;
128
+ }
129
 
130
+ foreach ( $form_actions as $action ) {
131
+ if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
132
+ // don't try and show settings if action no longer exists
133
+ continue;
134
+ }
135
 
136
+ self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
137
+ }
138
+ }
139
 
140
  public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
141
  $action_control->_set( $action_key );
143
  $use_logging = self::should_show_log_message( $form_action->post_excerpt );
144
 
145
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
146
+ }
147
 
148
+ public static function add_form_action() {
149
  FrmAppHelper::permission_check( 'frm_edit_forms' );
150
+ check_ajax_referer( 'frm_ajax', 'nonce' );
151
 
152
+ global $frm_vars;
153
 
154
+ $action_key = absint( $_POST['list_id'] );
155
+ $action_type = sanitize_text_field( $_POST['type'] );
156
 
157
+ $action_control = self::get_form_actions( $action_type );
158
  $action_control->_set( $action_key );
159
 
160
+ $form_id = absint( $_POST['form_id'] );
161
 
162
  $form_action = $action_control->prepare_new( $form_id );
163
  $use_logging = self::should_show_log_message( $action_type );
164
 
165
+ $values = array();
166
+ $form = self::fields_to_values( $form_id, $values );
167
 
168
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
169
+ wp_die();
170
+ }
171
 
172
+ public static function fill_action() {
173
  FrmAppHelper::permission_check( 'frm_edit_forms' );
174
+ check_ajax_referer( 'frm_ajax', 'nonce' );
175
 
176
+ $action_key = absint( $_POST['action_id'] );
177
+ $action_type = sanitize_text_field( $_POST['action_type'] );
178
 
179
+ $action_control = self::get_form_actions( $action_type );
180
  if ( empty( $action_control ) ) {
181
+ wp_die();
182
+ }
183
 
184
+ $form_action = $action_control->get_single_action( $action_key );
185
 
186
+ $values = array();
187
+ $form = self::fields_to_values( $form_action->menu_order, $values );
188
 
189
  $use_logging = self::should_show_log_message( $action_type );
190
 
191
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
192
+ wp_die();
193
+ }
194
 
195
  /**
196
  * @since 3.06.04
210
  );
211
 
212
  $fields = FrmField::get_all_for_form( $form->id );
213
+ foreach ( $fields as $k => $f ) {
214
+ $f = (array) $f;
215
+ $opts = (array) $f['field_options'];
216
+ $f = array_merge( $opts, $f );
217
+ if ( ! isset( $f['post_field'] ) ) {
218
+ $f['post_field'] = '';
219
+ }
220
+ $values['fields'][] = $f;
221
  unset( $k, $f );
222
+ }
223
 
224
+ return $form;
225
+ }
226
 
227
  public static function update_settings( $form_id ) {
228
  $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
230
  wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) );
231
  }
232
 
233
+ global $wpdb;
234
 
235
+ $registered_actions = self::$registered_actions->actions;
236
 
237
  $old_actions = FrmDb::get_col(
238
  $wpdb->posts,
242
  ),
243
  'ID'
244
  );
245
+ $new_actions = array();
246
 
247
+ foreach ( $registered_actions as $registered_action ) {
248
  $action_ids = $registered_action->update_callback( $form_id );
249
+ if ( ! empty( $action_ids ) ) {
250
+ $new_actions[] = $action_ids;
251
+ }
252
+ }
253
 
254
+ //Only use array_merge if there are new actions
255
+ if ( ! empty( $new_actions ) ) {
256
+ $new_actions = call_user_func_array( 'array_merge', $new_actions );
257
+ }
258
+ $old_actions = array_diff( $old_actions, $new_actions );
259
 
260
  self::delete_missing_actions( $old_actions );
261
+ }
262
 
263
  public static function delete_missing_actions( $old_actions ) {
264
  if ( ! empty( $old_actions ) ) {
270
  }
271
 
272
  public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
273
+ $filter_args = $args;
274
  $filter_args['entry_id'] = $entry_id;
275
  $filter_args['form_id'] = $form_id;
 
276
  $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
277
 
278
  self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
279
  }
280
 
281
+ /**
282
+ * @param string $event
283
+ */
284
  public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
285
  $action_status = array(
286
  'post_status' => 'publish',
288
  $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
289
 
290
  if ( empty( $form_actions ) ) {
291
+ return;
292
+ }
293
 
294
  FrmForm::maybe_get_form( $form );
295
 
296
+ $link_settings = self::get_form_actions( $type );
297
+ if ( 'all' != $type ) {
298
+ $link_settings = array( $type => $link_settings );
299
+ }
300
 
301
+ $stored_actions = array();
302
  $action_priority = array();
303
 
304
  if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
307
  $this_event = $event;
308
  }
309
 
310
+ foreach ( $form_actions as $action ) {
311
 
312
  $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
313
  $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
314
  if ( $skip_this_action ) {
315
+ continue;
316
+ }
317
 
318
+ if ( ! is_object( $entry ) ) {
319
+ $entry = FrmEntry::getOne( $entry, true );
320
+ }
321
 
322
  if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
323
  continue;
331
  if ( ! $trigger_children ) {
332
  continue;
333
  }
334
+ }
335
 
336
+ // check conditional logic
337
  $stop = FrmFormAction::action_conditions_met( $action, $entry );
338
+ if ( $stop ) {
339
+ continue;
340
+ }
341
 
342
+ // store actions so they can be triggered with the correct priority
343
+ $stored_actions[ $action->ID ] = $action;
344
+ $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
345
 
346
  unset( $action );
347
+ }
348
 
349
+ if ( ! empty( $stored_actions ) ) {
350
  asort( $action_priority );
351
 
352
+ // make sure hooks are loaded
353
+ new FrmNotification();
354
 
355
+ foreach ( $action_priority as $action_id => $priority ) {
356
+ $action = $stored_actions[ $action_id ];
357
  do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
358
  do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
359
 
360
+ // If post is created, get updated $entry object
361
+ if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
362
  $entry = FrmEntry::getOne( $entry->id, true );
363
+ }
364
+ }
365
+ }
366
+ }
367
 
368
  public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
369
  if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
370
+ // continue if we know which actions to copy
371
+ return;
372
+ }
373
 
374
  $action_controls = self::get_form_actions();
375
 
376
+ foreach ( $action_controls as $action_control ) {
377
+ $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
378
+ unset( $action_control );
379
+ }
380
+ }
 
 
 
381
 
382
+ public static function limit_by_type( $where ) {
383
+ global $frm_vars, $wpdb;
 
384
 
385
+ if ( ! isset( $frm_vars['action_type'] ) ) {
386
+ return $where;
387
+ }
388
 
389
+ $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
390
+ return $where;
391
+ }
392
  }
393
 
394
+
395
  class Frm_Form_Action_Factory {
396
  public $actions = array();
397
 
415
  foreach ( $keys as $key ) {
416
  // don't register new action if old action with the same id is already registered
417
  if ( ! isset( $this->actions[ $key ] ) ) {
418
+ $this->actions[ $key ]->_register();
419
  }
420
  }
421
  }
classes/controllers/FrmFormsController.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  class FrmFormsController {
4
 
5
- public static function menu() {
6
  $menu_label = __( 'Forms', 'formidable' );
7
  if ( ! FrmAppHelper::pro_is_installed() ) {
8
  $menu_label .= ' (Lite)';
@@ -10,7 +10,7 @@ class FrmFormsController {
10
  add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
11
 
12
  self::maybe_load_listing_hooks();
13
- }
14
 
15
  public static function maybe_load_listing_hooks() {
16
  $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
@@ -24,11 +24,13 @@ class FrmFormsController {
24
  add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
25
  }
26
 
27
- public static function head() {
28
- if ( wp_is_mobile() ) {
29
- wp_enqueue_script( 'jquery-touch-punch' );
30
- }
31
- }
 
 
32
 
33
  public static function register_widgets() {
34
  require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' );
@@ -43,7 +45,6 @@ class FrmFormsController {
43
  */
44
  public static function prevent_divi_conflict( $shortcodes ) {
45
  $shortcodes[] = 'formidable';
46
-
47
  return $shortcodes;
48
  }
49
 
@@ -51,8 +52,8 @@ class FrmFormsController {
51
  FrmAppHelper::permission_check( 'frm_view_forms' );
52
 
53
  $message = '';
54
- $params = FrmForm::list_page_params();
55
- $errors = self::process_bulk_form_actions( array() );
56
  if ( isset( $errors['message'] ) ) {
57
  $message = $errors['message'];
58
  unset( $errors['message'] );
@@ -68,19 +69,34 @@ class FrmFormsController {
68
  * @since 3.06
69
  */
70
  public static function add_new() {
71
- self::init_modal();
72
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add-new.php' );
73
  }
74
 
75
- /**
76
- * Load the scripts before a modal can be triggered.
77
- *
78
- * @since 4.0
79
- */
80
- private static function init_modal() {
81
- wp_enqueue_script( 'jquery-ui-dialog' );
82
- wp_enqueue_style( 'jquery-ui-dialog' );
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  /**
86
  * Create the default email action
@@ -89,35 +105,72 @@ class FrmFormsController {
89
  *
90
  * @param object $form
91
  */
92
- private static function create_default_email_action( $form ) {
93
- FrmForm::maybe_get_form( $form );
94
- $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
95
 
96
- if ( $create_email ) {
97
- $action_control = FrmFormActionsController::get_form_actions( 'email' );
98
- $action_control->create( $form->id );
99
- }
100
- }
101
 
102
- public static function edit( $values = false ) {
103
  FrmAppHelper::permission_check( 'frm_edit_forms' );
104
 
 
 
 
 
 
 
 
 
 
 
105
  $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  return self::get_edit_vars( $id );
108
- }
109
 
110
- public static function settings( $id = false, $message = '' ) {
111
  FrmAppHelper::permission_check( 'frm_edit_forms' );
112
 
113
  if ( ! $id || ! is_numeric( $id ) ) {
114
  $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
115
- }
116
-
117
  return self::get_settings_vars( $id, array(), $message );
118
- }
119
 
120
- public static function update_settings() {
121
  FrmAppHelper::permission_check( 'frm_edit_forms' );
122
 
123
  $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
@@ -131,34 +184,33 @@ class FrmFormsController {
131
 
132
  FrmForm::update( $id, $_POST );
133
 
134
- $message = __( 'Settings Successfully Updated', 'formidable' );
135
-
136
  return self::get_settings_vars( $id, array(), $message );
137
- }
138
 
139
  public static function update( $values = array() ) {
140
  if ( empty( $values ) ) {
141
- $values = $_POST;
142
- }
143
 
144
- // Set radio button and checkbox meta equal to "other" value.
145
- if ( FrmAppHelper::pro_is_installed() ) {
146
- $values = FrmProEntry::mod_other_vals( $values, 'back' );
147
- }
148
 
149
- $errors = FrmForm::validate( $values );
150
- $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
151
- if ( $permission_error !== false ) {
152
- $errors['form'] = $permission_error;
153
- }
154
 
155
  $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
156
 
157
  if ( count( $errors ) > 0 ) {
158
- return self::get_edit_vars( $id, $errors );
159
  } else {
160
- FrmForm::update( $id, $values );
161
- $message = __( 'Form was successfully updated.', 'formidable' );
162
 
163
  if ( self::is_too_long( $values ) ) {
164
  $message .= '<br/> ' . sprintf(
@@ -169,13 +221,12 @@ class FrmFormsController {
169
  );
170
  }
171
 
172
- if ( defined( 'DOING_AJAX' ) ) {
173
- wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // WPCS: XSS ok.
174
- }
175
-
176
  return self::get_edit_vars( $id, array(), $message );
177
- }
178
- }
179
 
180
  /**
181
  * Check if the value at the end of the form was included.
@@ -202,7 +253,7 @@ class FrmFormsController {
202
  check_ajax_referer( 'frm_ajax', 'nonce' );
203
 
204
  $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
205
- $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
206
 
207
  if ( $current_form ) {
208
  FrmForm::destroy( $current_form );
@@ -212,30 +263,30 @@ class FrmFormsController {
212
  wp_die();
213
  }
214
 
215
- public static function duplicate() {
216
  FrmAppHelper::permission_check( 'frm_edit_forms' );
217
 
218
- $params = FrmForm::list_page_params();
219
- $form = FrmForm::duplicate( $params['id'], $params['template'], true );
220
- $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
221
- if ( $form ) {
222
  return self::get_edit_vars( $form, array(), $message, true );
223
- } else {
224
  return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) );
225
- }
226
- }
227
 
228
- public static function page_preview() {
229
  $params = FrmForm::list_page_params();
230
- if ( ! $params['form'] ) {
231
- return;
232
- }
233
 
234
- $form = FrmForm::getOne( $params['form'] );
235
  if ( $form ) {
236
  return self::show_form( $form->id, '', true, true );
237
  }
238
- }
239
 
240
  /**
241
  * @since 3.0
@@ -244,11 +295,11 @@ class FrmFormsController {
244
  echo self::page_preview(); // WPCS: XSS ok.
245
  }
246
 
247
- public static function preview() {
248
- do_action( 'frm_wp' );
249
 
250
- global $frm_vars;
251
- $frm_vars['preview'] = true;
252
 
253
  self::load_wp();
254
 
@@ -309,6 +360,7 @@ class FrmFormsController {
309
  get_template_part( 'page' );
310
  }
311
 
 
312
  /**
313
  * Set the page title for the theme preview page
314
  *
@@ -318,7 +370,6 @@ class FrmFormsController {
318
  if ( in_the_loop() ) {
319
  $title = self::preview_title( $title );
320
  }
321
-
322
  return $title;
323
  }
324
 
@@ -340,7 +391,6 @@ class FrmFormsController {
340
  if ( in_the_loop() ) {
341
  $content = self::show_page_preview();
342
  }
343
-
344
  return $content;
345
  }
346
 
@@ -363,20 +413,18 @@ class FrmFormsController {
363
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
364
  }
365
 
366
- public static function untrash() {
367
  self::change_form_status( 'untrash' );
368
- }
369
 
370
  public static function bulk_untrash( $ids ) {
371
  FrmAppHelper::permission_check( 'frm_edit_forms' );
372
 
373
- $count = FrmForm::set_status( $ids, 'published' );
374
 
375
- /* translators: %1$s: Number of forms */
376
  $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
377
-
378
- return $message;
379
- }
380
 
381
  /**
382
  * @since 3.06
@@ -389,9 +437,9 @@ class FrmFormsController {
389
  wp_die();
390
  }
391
 
392
- public static function trash() {
393
  self::change_form_status( 'trash' );
394
- }
395
 
396
  /**
397
  * @param string $status
@@ -423,21 +471,18 @@ class FrmFormsController {
423
 
424
  $count = 0;
425
  if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
426
- $count ++;
427
  }
428
 
429
  $form_type = FrmAppHelper::get_simple_request(
430
  array(
431
  'param' => 'form_type',
432
- 'type' => 'request',
433
  )
434
  );
435
 
436
- /* translators: %1$s: Number of forms */
437
  $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
438
-
439
- /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
440
- $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>' );
441
 
442
  $message = $available_status[ $status ]['message'];
443
 
@@ -447,108 +492,76 @@ class FrmFormsController {
447
  public static function bulk_trash( $ids ) {
448
  FrmAppHelper::permission_check( 'frm_delete_forms' );
449
 
450
- $count = 0;
451
- foreach ( $ids as $id ) {
452
- if ( FrmForm::trash( $id ) ) {
453
- $count ++;
454
- }
455
- }
456
 
457
  $current_page = FrmAppHelper::get_simple_request(
458
  array(
459
  'param' => 'form_type',
460
- 'type' => 'request',
461
  )
462
  );
463
- $message = sprintf(
464
- /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
465
  _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' ),
466
  $count,
467
  '<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' ) ) . '">',
468
  '</a>'
469
  );
470
 
471
- return $message;
472
- }
473
 
474
- public static function destroy() {
475
  FrmAppHelper::permission_check( 'frm_delete_forms' );
476
 
477
  $params = FrmForm::list_page_params();
478
 
479
- // Check nonce url.
480
  check_admin_referer( 'destroy_form_' . $params['id'] );
481
 
482
- $count = 0;
483
- if ( FrmForm::destroy( $params['id'] ) ) {
484
- $count ++;
485
- }
486
 
487
- /* translators: %1$s: Number of forms */
488
- $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
489
 
490
  self::display_forms_list( $params, $message );
491
- }
492
 
493
  public static function bulk_destroy( $ids ) {
494
  FrmAppHelper::permission_check( 'frm_delete_forms' );
495
 
496
- $count = 0;
497
- foreach ( $ids as $id ) {
498
- $d = FrmForm::destroy( $id );
499
- if ( $d ) {
500
- $count ++;
501
- }
502
- }
503
 
504
- /* translators: %1$s: Number of forms */
505
  $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
506
 
507
- return $message;
508
- }
509
 
510
- private static function delete_all() {
511
- // Check nonce url.
512
  $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
513
- if ( $permission_error !== false ) {
514
  self::display_forms_list( array(), '', array( $permission_error ) );
 
 
515
 
516
- return;
517
- }
518
-
519
- $count = FrmForm::scheduled_delete( time() );
520
-
521
- /* translators: %1$s: Number of forms */
522
  $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
523
 
524
  self::display_forms_list( array(), $message );
525
- }
526
-
527
- /**
528
- * Create a new form from the modal.
529
- *
530
- * @since 4.0
531
- */
532
- public static function build_new_form() {
533
- global $wpdb;
534
-
535
- FrmAppHelper::permission_check( 'frm_edit_forms' );
536
- check_ajax_referer( 'frm_ajax', 'nonce' );
537
-
538
- $new_values = self::get_modal_values();
539
- $new_values['form_key'] = $new_values['name'];
540
-
541
- $form_id = FrmForm::create( $new_values );
542
-
543
- self::create_default_email_action( $form_id );
544
-
545
- $response = array(
546
- 'redirect' => FrmForm::get_edit_link( $form_id ),
547
- );
548
-
549
- echo wp_json_encode( $response );
550
- wp_die();
551
- }
552
 
553
  /**
554
  * Create a custom template from a form
@@ -568,7 +581,14 @@ class FrmFormsController {
568
  'message' => __( 'There was an error creating a template.', 'formidable' ),
569
  );
570
  } else {
571
- $new_values = self::get_modal_values();
 
 
 
 
 
 
 
572
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
573
  if ( $query_results ) {
574
  FrmForm::clear_form_cache();
@@ -584,88 +604,74 @@ class FrmFormsController {
584
  }
585
 
586
  /**
587
- * Before creating a new form, get the name and description from the modal.
588
- *
589
- * @since 4.0
590
- */
591
- private static function get_modal_values() {
592
- $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
593
- $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
594
-
595
- return array(
596
- 'name' => $name,
597
- 'description' => $desc,
598
- );
599
- }
600
-
601
- /**
602
- * Inserts Formidable button
603
- * Hook exists since 2.5.0
604
- *
605
- * @since 2.0.15
606
- */
607
  public static function insert_form_button() {
608
  if ( current_user_can( 'frm_view_forms' ) ) {
609
  $menu_name = FrmAppHelper::get_menu_name();
610
- $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
611
  echo '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' .
612
  FrmAppHelper::kses( $icon, 'all' ) .
613
  ' ' . esc_html( $menu_name ) . '</a>'; // WPCS: XSS ok.
614
  }
615
  }
616
 
617
- public static function insert_form_popup() {
618
  $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
619
  if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
620
- return;
621
- }
622
 
623
- FrmAppHelper::load_admin_wide_js();
624
 
625
- $shortcodes = array(
626
  'formidable' => array(
627
  'name' => __( 'Form', 'formidable' ),
628
  'label' => __( 'Insert a Form', 'formidable' ),
629
  ),
630
- );
631
 
632
  $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
633
 
634
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' );
635
- }
636
 
637
- public static function get_shortcode_opts() {
638
  FrmAppHelper::permission_check( 'frm_view_forms' );
639
- check_ajax_referer( 'frm_ajax', 'nonce' );
640
 
641
  $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
642
  if ( empty( $shortcode ) ) {
643
- wp_die();
644
- }
645
 
646
  echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
647
  echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />';
648
 
649
- $form_id = '';
650
- $opts = array();
651
  switch ( $shortcode ) {
652
- case 'formidable':
653
- $opts = array(
654
- 'form_id' => 'id',
655
- 'title' => array(
 
656
  'val' => 1,
657
  'label' => __( 'Display form title', 'formidable' ),
658
  ),
659
- 'description' => array(
660
  'val' => 1,
661
  'label' => __( 'Display form description', 'formidable' ),
662
  ),
663
- 'minimize' => array(
664
  'val' => 1,
665
  'label' => __( 'Minimize form HTML', 'formidable' ),
666
  ),
667
- );
668
- }
669
  $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
670
 
671
  if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
@@ -676,38 +682,38 @@ class FrmFormsController {
676
 
677
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
678
 
679
- echo '</div>';
680
 
681
- wp_die();
682
- }
683
 
684
  public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
685
- FrmAppHelper::permission_check( 'frm_view_forms' );
686
 
687
- global $wpdb, $frm_vars;
688
 
689
  if ( empty( $params ) ) {
690
  $params = FrmForm::list_page_params();
691
- }
692
 
693
- $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
694
 
695
- $pagenum = $wp_list_table->get_pagenum();
696
 
697
- $wp_list_table->prepare_items();
698
 
699
- $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
700
- if ( $pagenum > $total_pages && $total_pages > 0 ) {
701
  wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
702
- die();
703
- }
704
 
705
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' );
706
- }
707
 
708
  public static function get_columns( $columns ) {
709
- $columns['cb'] = '<input type="checkbox" />';
710
- $columns['id'] = 'ID';
711
 
712
  $type = FrmAppHelper::get_simple_request(
713
  array(
@@ -717,18 +723,18 @@ class FrmFormsController {
717
  )
718
  );
719
 
720
- if ( 'template' == $type ) {
721
- $columns['name'] = __( 'Template Name', 'formidable' );
722
- $columns['type'] = __( 'Type', 'formidable' );
723
- $columns['form_key'] = __( 'Key', 'formidable' );
724
- } else {
725
- $columns['name'] = __( 'Form Title', 'formidable' );
726
- $columns['entries'] = __( 'Entries', 'formidable' );
727
- $columns['form_key'] = __( 'Key', 'formidable' );
728
- $columns['shortcode'] = __( 'Shortcodes', 'formidable' );
729
- }
730
 
731
- $columns['created_at'] = __( 'Date', 'formidable' );
732
 
733
  add_screen_option(
734
  'per_page',
@@ -739,16 +745,16 @@ class FrmFormsController {
739
  )
740
  );
741
 
742
- return $columns;
743
  }
744
 
745
  public static function get_sortable_columns() {
746
  return array(
747
- 'id' => 'id',
748
- 'name' => 'name',
749
- 'description' => 'description',
750
- 'form_key' => 'form_key',
751
- 'created_at' => 'created_at',
752
  );
753
  }
754
 
@@ -769,12 +775,11 @@ class FrmFormsController {
769
  }
770
 
771
  public static function save_per_page( $save, $option, $value ) {
772
- if ( $option == 'formidable_page_formidable_per_page' ) {
773
- $save = (int) $value;
774
- }
775
-
776
- return $save;
777
- }
778
 
779
  /**
780
  * Show the template listing page
@@ -782,56 +787,31 @@ class FrmFormsController {
782
  * @since 3.06
783
  */
784
  private static function list_templates() {
785
- self::init_modal();
 
786
 
787
  $where = apply_filters( 'frm_forms_dropdown', array(), '' );
788
  $forms = FrmForm::get_published_forms( $where );
789
 
790
- $api = new FrmFormTemplateApi();
791
  $templates = $api->get_api_info();
792
  self::add_user_templates( $templates );
793
 
794
  $error = '';
795
  $expired = false;
796
- $license_type = '';
797
  if ( isset( $templates['error'] ) ) {
798
  $error = $templates['error']['message'];
799
  $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
800
  $expired = ( $templates['error']['code'] === 'expired' );
801
-
802
- $license_type = isset( $templates['error']['type'] ) ? $templates['error']['type'] : '';
803
  unset( $templates['error'] );
804
  }
805
 
806
  $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
807
-
808
- self::put_allowed_templates_first( $templates );
809
 
810
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list-templates.php' );
811
  }
812
 
813
- /**
814
- * @since 4.0
815
- */
816
- private static function put_allowed_templates_first( &$templates ) {
817
- $allowed = array();
818
-
819
- // Include contact form first.
820
- $contact_us = 20872734;
821
- $allowed[ $contact_us ] = $templates[ $contact_us ];
822
- unset( $templates[ $contact_us ] );
823
-
824
- foreach ( $templates as $k => $template ) {
825
- if ( isset( $template['url'] ) && ! empty( $template['url'] ) ) {
826
- $allowed[ $k ] = $template;
827
- unset( $templates[ $k ] );
828
- }
829
- }
830
-
831
- $allowed += $templates;
832
- $templates = $allowed;
833
- }
834
-
835
  private static function add_user_templates( &$templates ) {
836
  $user_templates = array(
837
  'is_template' => 1,
@@ -854,189 +834,75 @@ class FrmFormsController {
854
  }
855
 
856
  private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
857
- global $frm_vars;
858
 
859
- $form = FrmForm::getOne( $id );
860
- if ( ! $form ) {
861
- wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
862
- }
863
 
864
- if ( $form->parent_form_id ) {
865
- /* translators: %1$s: Start link HTML, %2$s: End link HTML */
866
- wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) );
867
- }
868
 
869
  $frm_field_selection = FrmField::field_selection();
870
-
871
  $fields = FrmField::get_all_for_form( $form->id );
872
 
873
- // Automatically add end section fields if they don't exist (2.0 migration).
874
- $reset_fields = false;
875
- FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
876
 
877
- if ( $reset_fields ) {
878
- $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
879
- }
880
 
881
  unset( $end_section_values, $last_order, $open, $reset_fields );
882
 
883
- $args = array( 'parent_form_id' => $form->id );
884
- $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args );
885
  $values['fields'] = $fields;
886
 
887
- $edit_message = __( 'Form was successfully updated.', 'formidable' );
888
- if ( $form->is_template && $message == $edit_message ) {
889
- $message = __( 'Template was successfully updated.', 'formidable' );
890
- }
891
 
892
  $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
893
 
894
  if ( defined( 'DOING_AJAX' ) ) {
895
- wp_die();
896
- } else {
 
 
897
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
898
- }
899
- }
900
 
901
  public static function get_settings_vars( $id, $errors = array(), $message = '' ) {
902
  FrmAppHelper::permission_check( 'frm_edit_forms' );
903
 
904
- global $frm_vars;
 
 
905
 
906
- $form = FrmForm::getOne( $id );
907
  $fields = FrmField::get_all_for_form( $id );
908
  $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
909
 
910
  self::clean_submit_html( $values );
911
 
912
- $sections = self::get_settings_tabs( $values );
913
- $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
914
-
915
- require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
916
- }
917
-
918
- /**
919
- * @since 4.0
920
- */
921
- public static function form_publish_button( $atts ) {
922
- $values = $atts['values'];
923
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
924
- }
925
-
926
- /**
927
- * Get a list of all the settings tabs for the form settings page.
928
- *
929
- * @since 4.0
930
- *
931
- * @param array $values
932
- * @return array
933
- */
934
- private static function get_settings_tabs( $values ) {
935
- $sections = array(
936
- 'advanced' => array(
937
- 'name' => __( 'General', 'formidable' ),
938
- 'title' => __( 'General Form Settings', 'formidable' ),
939
- 'function' => array( __CLASS__, 'advanced_settings' ),
940
- 'icon' => 'frm_icon_font frm_settings_icon',
941
- ),
942
- 'email' => array(
943
- 'name' => __( 'Actions & Notifications', 'formidable' ),
944
- 'function' => array( 'FrmFormActionsController', 'email_settings' ),
945
- 'id' => 'frm_notification_settings',
946
- 'icon' => 'frm_icon_font frm_mail_bulk_icon',
947
- ),
948
- 'permissions' => array(
949
- 'name' => __( 'Form Permissions', 'formidable' ),
950
- 'icon' => 'frm_icon_font frm_lock_icon',
951
- 'html_class' => 'frm_show_upgrade frm_noallow',
952
- 'data' => array(
953
- 'medium' => 'permissions',
954
- 'upgrade' => __( 'Form Permissions', 'formidable' ),
955
- ),
956
- ),
957
- 'scheduling' => array(
958
- 'name' => __( 'Form Scheduling', 'formidable' ),
959
- 'icon' => 'frm_icon_font frm_calendar_icon',
960
- 'html_class' => 'frm_show_upgrade frm_noallow',
961
- 'data' => array(
962
- 'medium' => 'scheduling',
963
- 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
964
- ),
965
- ),
966
- 'buttons' => array(
967
- 'name' => __( 'Styling & Buttons', 'formidable' ),
968
- 'class' => __CLASS__,
969
- 'function' => 'buttons_settings',
970
- 'icon' => 'frm_icon_font frm_pallet_icon',
971
- ),
972
- 'html' => array(
973
- 'name' => __( 'Customize HTML', 'formidable' ),
974
- 'class' => __CLASS__,
975
- 'function' => 'html_settings',
976
- 'icon' => 'frm_icon_font frm_code_icon',
977
- ),
978
- );
979
-
980
- $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
981
 
982
- foreach ( $sections as $key => $section ) {
983
- $defaults = array(
984
- 'html_class' => '',
985
- 'name' => ucfirst( $key ),
986
- 'icon' => 'frm_icon_font frm_settings_icon',
987
- );
988
-
989
- $section = array_merge( $defaults, $section );
990
-
991
- if ( ! isset( $section['anchor'] ) ) {
992
- $section['anchor'] = $key;
993
- }
994
- $section['anchor'] .= '_settings';
995
-
996
- if ( ! isset( $section['title'] ) ) {
997
- $section['title'] = $section['name'];
998
- }
999
-
1000
- if ( ! isset( $section['id'] ) ) {
1001
- $section['id'] = $section['anchor'];
1002
- }
1003
-
1004
- $sections[ $key ] = $section;
1005
- }
1006
 
1007
- return $sections;
1008
- }
1009
 
1010
- /**
1011
- * @since 4.0
1012
- *
1013
- * @param array $values
1014
- */
1015
- public static function advanced_settings( $values ) {
1016
  $first_h3 = 'frm_first_h3';
1017
 
1018
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php' );
1019
- }
1020
 
1021
- /**
1022
- * @since 4.0
1023
- *
1024
- * @param array $values
1025
- */
1026
- public static function buttons_settings( $values ) {
1027
- $styles = apply_filters( 'frm_get_style_opts', array() );
1028
-
1029
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1030
- }
1031
-
1032
- /**
1033
- * @since 4.0
1034
- *
1035
- * @param array $values
1036
- */
1037
- public static function html_settings( $values ) {
1038
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1039
- }
1040
 
1041
  /**
1042
  * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1051,19 +917,19 @@ class FrmFormsController {
1051
  }
1052
  }
1053
 
1054
- public static function mb_tags_box( $form_id, $class = '' ) {
1055
- $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1056
- $linked_forms = array();
1057
- $col = 'one';
1058
  $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1059
 
1060
- $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1061
  $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1062
 
1063
  $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1064
 
1065
  include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1066
- }
1067
 
1068
  /**
1069
  * @since 3.04.01
@@ -1071,7 +937,7 @@ class FrmFormsController {
1071
  private static function advanced_helpers( $atts ) {
1072
  $advanced_helpers = array(
1073
  'default' => array(
1074
- 'heading' => __( 'Customize field values with the following parameters.', 'formidable' ),
1075
  'codes' => self::get_advanced_shortcodes(),
1076
  ),
1077
  );
@@ -1085,6 +951,7 @@ class FrmFormsController {
1085
  }
1086
 
1087
  $advanced_helpers['user_id'] = array(
 
1088
  'codes' => $user_helpers,
1089
  );
1090
  }
@@ -1093,7 +960,6 @@ class FrmFormsController {
1093
  * Add extra helper shortcodes on the Advanced tab in form settings and views
1094
  *
1095
  * @since 3.04.01
1096
- *
1097
  * @param array $atts - Includes fields and form_id
1098
  */
1099
  return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
@@ -1111,19 +977,14 @@ class FrmFormsController {
1111
  'label' => __( 'Separator', 'formidable' ),
1112
  'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
1113
  ),
1114
- 'x format="d-m-Y"' => array(
1115
- 'label' => __( 'Date Format', 'formidable' ),
1116
- ),
1117
- 'x show="field_label"' => array(
1118
- 'label' => __( 'Field Label', 'formidable' ),
1119
- ),
1120
  'x wpautop=0' => array(
1121
  'label' => __( 'No Auto P', 'formidable' ),
1122
  'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1123
  ),
1124
  );
1125
  $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1126
-
1127
  // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1128
 
1129
  return $adv_shortcodes;
@@ -1134,16 +995,15 @@ class FrmFormsController {
1134
  */
1135
  private static function user_shortcodes() {
1136
  $options = array(
1137
- 'ID' => __( 'User ID', 'formidable' ),
1138
- 'first_name' => __( 'First Name', 'formidable' ),
1139
- 'last_name' => __( 'Last Name', 'formidable' ),
1140
- 'display_name' => __( 'Display Name', 'formidable' ),
1141
- 'user_login' => __( 'User Login', 'formidable' ),
1142
- 'user_email' => __( 'Email', 'formidable' ),
1143
- 'avatar' => __( 'Avatar', 'formidable' ),
1144
- 'author_link' => __( 'Author Link', 'formidable' ),
1145
  );
1146
-
1147
  return apply_filters( 'frm_user_shortcodes', $options );
1148
  }
1149
 
@@ -1154,16 +1014,16 @@ class FrmFormsController {
1154
  */
1155
  private static function get_shortcode_helpers( $settings_tab ) {
1156
  $entry_shortcodes = array(
1157
- 'id' => __( 'Entry ID', 'formidable' ),
1158
- 'key' => __( 'Entry Key', 'formidable' ),
1159
- 'post_id' => __( 'Post ID', 'formidable' ),
1160
- 'ip' => __( 'User IP', 'formidable' ),
1161
  'created-at' => __( 'Entry created', 'formidable' ),
1162
  'updated-at' => __( 'Entry updated', 'formidable' ),
1163
- '' => '',
1164
- 'siteurl' => __( 'Site URL', 'formidable' ),
1165
- 'sitename' => __( 'Site Name', 'formidable' ),
1166
- );
1167
 
1168
  if ( ! FrmAppHelper::pro_is_installed() ) {
1169
  unset( $entry_shortcodes['post_id'] );
@@ -1171,8 +1031,8 @@ class FrmFormsController {
1171
 
1172
  if ( $settings_tab ) {
1173
  $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1174
- $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1175
- $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1176
  }
1177
 
1178
  /**
@@ -1213,21 +1073,21 @@ class FrmFormsController {
1213
  wp_die();
1214
  }
1215
 
1216
- public static function filter_content( $content, $form, $entry = false ) {
1217
  self::get_entry_by_param( $entry );
1218
- if ( ! $entry ) {
1219
- return $content;
1220
- }
1221
 
1222
- if ( is_object( $form ) ) {
1223
- $form = $form->id;
1224
- }
1225
 
1226
- $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1227
- $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1228
 
1229
- return $content;
1230
- }
1231
 
1232
  private static function get_entry_by_param( &$entry ) {
1233
  if ( ! $entry || ! is_object( $entry ) ) {
@@ -1239,156 +1099,153 @@ class FrmFormsController {
1239
  }
1240
  }
1241
 
1242
- public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1243
- return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1244
- }
1245
 
1246
- public static function process_bulk_form_actions( $errors ) {
1247
- if ( ! $_REQUEST ) {
1248
- return $errors;
1249
- }
1250
 
1251
  $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1252
- if ( $bulkaction == - 1 ) {
1253
  $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1254
- }
1255
 
1256
- if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
1257
- FrmAppHelper::remove_get_action();
1258
 
1259
- $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1260
- }
1261
 
1262
  $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1263
- if ( empty( $ids ) ) {
1264
- $errors[] = __( 'No forms were specified', 'formidable' );
1265
-
1266
- return $errors;
1267
- }
1268
-
1269
- $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
1270
- if ( $permission_error !== false ) {
1271
- $errors[] = $permission_error;
1272
-
1273
- return $errors;
1274
- }
1275
-
1276
- if ( ! is_array( $ids ) ) {
1277
- $ids = explode( ',', $ids );
1278
- }
1279
-
1280
- switch ( $bulkaction ) {
1281
- case 'delete':
1282
- $message = self::bulk_destroy( $ids );
1283
  break;
1284
- case 'trash':
1285
- $message = self::bulk_trash( $ids );
1286
  break;
1287
- case 'untrash':
1288
- $message = self::bulk_untrash( $ids );
1289
- }
1290
 
1291
- if ( isset( $message ) && ! empty( $message ) ) {
1292
  $errors['message'] = $message;
1293
- }
1294
 
1295
- return $errors;
1296
- }
1297
 
1298
- public static function route() {
1299
  $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1300
- $vars = array();
1301
  if ( isset( $_POST['frm_compact_fields'] ) ) {
1302
  FrmAppHelper::permission_check( 'frm_edit_forms' );
1303
 
1304
- $json_vars = htmlspecialchars_decode( nl2br( wp_unslash( str_replace( '&quot;', '\\\"', $_POST['frm_compact_fields'] ) ) ) );
1305
  $json_vars = json_decode( $json_vars, true );
1306
  if ( empty( $json_vars ) ) {
1307
- // json decoding failed so we should return an error message.
1308
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1309
- if ( 'edit' == $action ) {
1310
- $action = 'update';
1311
- }
1312
 
1313
  add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1314
- } else {
1315
- $vars = FrmAppHelper::json_to_array( $json_vars );
1316
- $action = $vars[ $action ];
1317
  unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1318
  $_REQUEST = array_merge( $_REQUEST, $vars );
1319
- $_POST = array_merge( $_POST, $_REQUEST );
1320
- }
1321
- } else {
1322
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1323
- if ( isset( $_REQUEST['delete_all'] ) ) {
1324
- // Override the action for this page.
1325
- $action = 'delete_all';
1326
- }
1327
- }
1328
 
1329
  add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1330
- FrmAppHelper::trigger_hook_load( 'form' );
1331
 
1332
- switch ( $action ) {
1333
- case 'new':
1334
  return self::new_form( $vars );
1335
- case 'create':
1336
  case 'add_new':
1337
  case 'list_templates':
1338
- case 'edit':
1339
- case 'update':
1340
- case 'duplicate':
1341
- case 'trash':
1342
- case 'untrash':
1343
- case 'destroy':
1344
- case 'delete_all':
1345
- case 'settings':
1346
- case 'update_settings':
 
1347
  return self::$action( $vars );
1348
- default:
1349
  do_action( 'frm_form_action_' . $action );
1350
  if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1351
- return;
1352
- }
1353
 
1354
  $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1355
- if ( $action == - 1 ) {
1356
  $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1357
- }
1358
 
1359
  if ( strpos( $action, 'bulk_' ) === 0 ) {
1360
- FrmAppHelper::remove_get_action();
 
 
1361
 
1362
- return self::list_form();
1363
- }
1364
-
1365
- return self::display_forms_list();
1366
- }
1367
- }
1368
 
1369
- public static function json_error( $errors ) {
1370
- $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
 
 
1371
 
1372
- return $errors;
1373
- }
1374
 
1375
- /* FRONT-END FORMS */
1376
- public static function admin_bar_css() {
1377
  if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1378
- return;
1379
- }
1380
 
1381
  add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1382
  FrmAppHelper::load_font_style();
1383
  }
1384
 
1385
  public static function admin_bar_configure() {
1386
- global $frm_vars;
1387
  if ( empty( $frm_vars['forms_loaded'] ) ) {
1388
- return;
1389
- }
1390
 
1391
- $actions = array();
1392
  foreach ( $frm_vars['forms_loaded'] as $form ) {
1393
  if ( is_object( $form ) ) {
1394
  $actions[ $form->id ] = $form->name;
@@ -1434,77 +1291,72 @@ class FrmFormsController {
1434
 
1435
  $wp_admin_bar->add_node(
1436
  array(
1437
- 'parent' => 'frm-forms',
1438
- 'id' => 'edit_form_' . $form_id,
1439
- 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
1440
- 'href' => FrmForm::get_edit_link( $form_id ),
1441
  )
1442
  );
1443
  }
1444
  }
1445
 
1446
- /**
1447
- * The formidable shortcode
1448
- *
1449
- * @param array $atts The params from the shortcode.
1450
- */
1451
  public static function get_form_shortcode( $atts ) {
1452
- global $frm_vars;
1453
  if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1454
- $sc = '[formidable';
1455
  if ( ! empty( $atts ) ) {
1456
  foreach ( $atts as $k => $v ) {
1457
  $sc .= ' ' . $k . '="' . esc_attr( $v ) . '"';
1458
  }
1459
  }
1460
-
1461
  return $sc . ']';
1462
- }
1463
 
1464
  $shortcode_atts = shortcode_atts(
1465
  array(
1466
- 'id' => '',
1467
- 'key' => '',
1468
- 'title' => false,
1469
- 'description' => false,
1470
- 'readonly' => false,
1471
- 'entry_id' => false,
1472
- 'fields' => array(),
1473
  'exclude_fields' => array(),
1474
- 'minimize' => false,
1475
  ),
1476
  $atts
1477
  );
1478
  do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1479
 
1480
- return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1481
- }
1482
 
1483
- public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1484
- if ( empty( $id ) ) {
1485
- $id = $key;
1486
- }
1487
 
1488
- $form = self::maybe_get_form_to_show( $id );
1489
- if ( ! $form ) {
1490
- return __( 'Please select a valid form', 'formidable' );
1491
- }
1492
 
1493
  FrmAppController::maybe_update_styles();
1494
 
1495
  add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1496
- FrmAppHelper::trigger_hook_load( 'form', $form );
1497
 
1498
- $form = apply_filters( 'frm_pre_display_form', $form );
1499
 
1500
- $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1501
 
1502
  if ( self::is_viewable_draft_form( $form ) ) {
1503
  // don't show a draft form on a page
1504
  $form = __( 'Please select a valid form', 'formidable' );
1505
- } elseif ( self::user_should_login( $form ) ) {
1506
  $form = do_shortcode( $frm_settings->login_msg );
1507
- } elseif ( self::user_has_permission_to_view( $form ) ) {
1508
  $form = do_shortcode( $frm_settings->login_msg );
1509
  } else {
1510
  do_action( 'frm_pre_get_form', $form );
@@ -1520,7 +1372,7 @@ class FrmFormsController {
1520
  }
1521
 
1522
  return $form;
1523
- }
1524
 
1525
  private static function maybe_get_form_to_show( $id ) {
1526
  $form = false;
@@ -1538,7 +1390,6 @@ class FrmFormsController {
1538
  private static function is_viewable_draft_form( $form ) {
1539
  global $post;
1540
  $frm_settings = FrmAppHelper::get_settings();
1541
-
1542
  return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1543
  }
1544
 
@@ -1550,31 +1401,31 @@ class FrmFormsController {
1550
  return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
1551
  }
1552
 
1553
- public static function get_form( $form, $title, $description, $atts = array() ) {
1554
  ob_start();
1555
 
1556
  do_action( 'frm_before_get_form', $atts );
1557
 
1558
- self::get_form_contents( $form, $title, $description, $atts );
1559
  self::enqueue_scripts( FrmForm::get_params( $form ) );
1560
 
1561
- $contents = ob_get_contents();
1562
- ob_end_clean();
1563
 
1564
  self::maybe_minimize_form( $atts, $contents );
1565
 
1566
- return $contents;
1567
- }
1568
 
1569
  public static function enqueue_scripts( $params ) {
1570
  do_action( 'frm_enqueue_form_scripts', $params );
1571
  }
1572
 
1573
  public static function get_form_contents( $form, $title, $description, $atts ) {
1574
- $params = FrmForm::get_params( $form );
1575
- $errors = self::get_saved_errors( $form, $params );
1576
- $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1577
- $reset = false;
1578
  $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1579
 
1580
  $handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
@@ -1592,9 +1443,9 @@ class FrmFormsController {
1592
  do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1593
 
1594
  if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1595
- $entry_id = self::just_created_entry( $form->id );
1596
- $pass_args['entry_id'] = $entry_id;
1597
- $pass_args['reset'] = true;
1598
  $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1599
 
1600
  self::run_success_action( $pass_args );
@@ -1623,7 +1474,6 @@ class FrmFormsController {
1623
  } else {
1624
  $errors = array();
1625
  }
1626
-
1627
  return $errors;
1628
  }
1629
 
@@ -1632,7 +1482,6 @@ class FrmFormsController {
1632
  */
1633
  public static function just_created_entry( $form_id ) {
1634
  global $frm_vars;
1635
-
1636
  return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
1637
  }
1638
 
@@ -1640,7 +1489,7 @@ class FrmFormsController {
1640
  * @since 3.0
1641
  */
1642
  private static function get_confirmation_method( $atts ) {
1643
- $opt = 'success_action';
1644
  $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1645
  $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1646
 
@@ -1696,7 +1545,6 @@ class FrmFormsController {
1696
  do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1697
 
1698
  $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1699
-
1700
  $args['success_opt'] = $opt;
1701
  if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1702
  self::load_page_after_submit( $args );
@@ -1714,10 +1562,10 @@ class FrmFormsController {
1714
  global $post;
1715
  $opt = $args['success_opt'];
1716
  if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1717
- $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1718
  $old_post = $post;
1719
- $post = $page;
1720
- $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1721
  echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1722
  $post = $old_post;
1723
  }
@@ -1731,7 +1579,7 @@ class FrmFormsController {
1731
 
1732
  add_filter( 'frm_use_wpautop', '__return_false' );
1733
 
1734
- $opt = $args['success_opt'];
1735
  $success_url = trim( $args['form']->options[ $opt . '_url' ] );
1736
  $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1737
  $success_url = do_shortcode( $success_url );
@@ -1764,14 +1612,12 @@ class FrmFormsController {
1764
 
1765
  /**
1766
  * @since 3.0
1767
- *
1768
  * @param string $success_url
1769
  * @param string $success_msg
1770
  * @param array $args
1771
  */
1772
  private static function get_redirect_message( $success_url, $success_msg, $args ) {
1773
  $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' .
1774
- /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1775
  sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1776
  '</div></div>';
1777
 
@@ -1780,7 +1626,6 @@ class FrmFormsController {
1780
  'form_id' => $args['form']->id,
1781
  'form' => $args['form'],
1782
  );
1783
-
1784
  return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1785
  }
1786
 
@@ -1807,10 +1652,10 @@ class FrmFormsController {
1807
  private static function show_form_after_submit( $args ) {
1808
  self::fill_atts_for_form_display( $args );
1809
 
1810
- $errors = $args['errors'];
1811
- $message = $args['message'];
1812
- $form = $args['form'];
1813
- $title = $args['title'];
1814
  $description = $args['description'];
1815
 
1816
  if ( empty( $args['fields'] ) ) {
@@ -1823,7 +1668,7 @@ class FrmFormsController {
1823
  $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1824
 
1825
  $frm_settings = FrmAppHelper::get_settings();
1826
- $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1827
 
1828
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' );
1829
  }
@@ -1835,15 +1680,15 @@ class FrmFormsController {
1835
  */
1836
  private static function fill_atts_for_form_display( &$args ) {
1837
  $defaults = array(
1838
- 'errors' => array(),
1839
- 'message' => '',
1840
- 'fields' => array(),
1841
- 'form' => array(),
1842
- 'title' => true,
1843
  'description' => false,
1844
- 'reset' => false,
1845
  );
1846
- $args = wp_parse_args( $args, $defaults );
1847
  }
1848
 
1849
  /**
@@ -1857,9 +1702,8 @@ class FrmFormsController {
1857
  self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
1858
 
1859
  $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
1860
-
1861
- $errors = array();
1862
- $form = $atts['form'];
1863
  $message = $atts['message'];
1864
 
1865
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
@@ -1875,20 +1719,19 @@ class FrmFormsController {
1875
 
1876
  if ( $entry_id && is_numeric( $entry_id ) ) {
1877
  $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
1878
- $class = 'frm_message';
1879
  } else {
1880
  $message = $frm_settings->failed_msg;
1881
- $class = FrmFormsHelper::form_error_class();
1882
  }
1883
 
1884
  $message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
1885
-
1886
  return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
1887
  }
1888
 
1889
  public static function front_head() {
1890
  $version = FrmAppHelper::plugin_version();
1891
- $suffix = FrmAppHelper::js_suffix();
1892
 
1893
  if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
1894
  wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
@@ -1925,11 +1768,10 @@ class FrmFormsController {
1925
  }
1926
 
1927
  public static function defer_script_loading( $tag, $handle ) {
1928
- if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
1929
- $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
1930
  }
1931
-
1932
- return $tag;
1933
  }
1934
 
1935
  public static function footer_js( $location = 'footer' ) {
@@ -1938,7 +1780,7 @@ class FrmFormsController {
1938
  FrmStylesController::enqueue_css();
1939
 
1940
  if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
1941
- // load formidable js
1942
  wp_enqueue_script( 'formidable' );
1943
  }
1944
  }
@@ -1961,21 +1803,6 @@ class FrmFormsController {
1961
  return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
1962
  }
1963
 
1964
- /**
1965
- * @deprecated 4.0
1966
- */
1967
- public static function new_form( $values = array() ) {
1968
- FrmDeprecated::new_form( $values );
1969
- }
1970
-
1971
- /**
1972
- * @deprecated 4.0
1973
- */
1974
- public static function create( $values = array() ) {
1975
- _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
1976
- self::update( $values );
1977
- }
1978
-
1979
  /**
1980
  * @deprecated 1.07.05
1981
  * @codeCoverageIgnore
2
 
3
  class FrmFormsController {
4
 
5
+ public static function menu() {
6
  $menu_label = __( 'Forms', 'formidable' );
7
  if ( ! FrmAppHelper::pro_is_installed() ) {
8
  $menu_label .= ' (Lite)';
10
  add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
11
 
12
  self::maybe_load_listing_hooks();
13
+ }
14
 
15
  public static function maybe_load_listing_hooks() {
16
  $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
24
  add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
25
  }
26
 
27
+ public static function head() {
28
+ wp_enqueue_script( 'formidable-editinplace' );
29
+
30
+ if ( wp_is_mobile() ) {
31
+ wp_enqueue_script( 'jquery-touch-punch' );
32
+ }
33
+ }
34
 
35
  public static function register_widgets() {
36
  require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' );
45
  */
46
  public static function prevent_divi_conflict( $shortcodes ) {
47
  $shortcodes[] = 'formidable';
 
48
  return $shortcodes;
49
  }
50
 
52
  FrmAppHelper::permission_check( 'frm_view_forms' );
53
 
54
  $message = '';
55
+ $params = FrmForm::list_page_params();
56
+ $errors = self::process_bulk_form_actions( array() );
57
  if ( isset( $errors['message'] ) ) {
58
  $message = $errors['message'];
59
  unset( $errors['message'] );
69
  * @since 3.06
70
  */
71
  public static function add_new() {
 
72
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add-new.php' );
73
  }
74
 
75
+ public static function new_form( $values = array() ) {
76
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
77
+
78
+ global $frm_vars;
79
+
80
+ $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
81
+ $action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ];
82
+
83
+ if ( $action == 'create' ) {
84
+ self::create( $values );
85
+ return;
86
+ } else if ( $action == 'new' ) {
87
+ $frm_field_selection = FrmField::field_selection();
88
+ $values = FrmFormsHelper::setup_new_vars( $values );
89
+ $id = FrmForm::create( $values );
90
+ $form = FrmForm::getOne( $id );
91
+
92
+ self::create_default_email_action( $form );
93
+
94
+ $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
95
+
96
+ $values['id'] = $id;
97
+ require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
98
+ }
99
+ }
100
 
101
  /**
102
  * Create the default email action
105
  *
106
  * @param object $form
107
  */
108
+ private static function create_default_email_action( $form ) {
109
+ $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
 
110
 
111
+ if ( $create_email ) {
112
+ $action_control = FrmFormActionsController::get_form_actions( 'email' );
113
+ $action_control->create( $form->id );
114
+ }
115
+ }
116
 
117
+ public static function create( $values = array() ) {
118
  FrmAppHelper::permission_check( 'frm_edit_forms' );
119
 
120
+ global $frm_vars;
121
+ if ( empty( $values ) ) {
122
+ $values = $_POST;
123
+ }
124
+
125
+ //Set radio button and checkbox meta equal to "other" value
126
+ if ( FrmAppHelper::pro_is_installed() ) {
127
+ $values = FrmProEntry::mod_other_vals( $values, 'back' );
128
+ }
129
+
130
  $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
131
 
132
+ if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
133
+ $frm_settings = FrmAppHelper::get_settings();
134
+ $errors = array( 'form' => $frm_settings->admin_permission );
135
+ } else {
136
+ $errors = FrmForm::validate( $values );
137
+ }
138
+
139
+ if ( count( $errors ) > 0 ) {
140
+ $hide_preview = true;
141
+ $frm_field_selection = FrmField::field_selection();
142
+ $form = FrmForm::getOne( $id );
143
+ $fields = FrmField::get_all_for_form( $id );
144
+
145
+ $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true );
146
+ $values['fields'] = $fields;
147
+ $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
148
+
149
+ require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
150
+ } else {
151
+ FrmForm::update( $id, $values, true );
152
+ $url = admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id );
153
+ die( FrmAppHelper::js_redirect( $url ) ); // WPCS: XSS ok.
154
+ }
155
+ }
156
+
157
+ public static function edit( $values = false ) {
158
+ FrmAppHelper::permission_check( 'frm_edit_forms' );
159
+
160
+ $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
161
  return self::get_edit_vars( $id );
162
+ }
163
 
164
+ public static function settings( $id = false, $message = '' ) {
165
  FrmAppHelper::permission_check( 'frm_edit_forms' );
166
 
167
  if ( ! $id || ! is_numeric( $id ) ) {
168
  $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
169
+ }
 
170
  return self::get_settings_vars( $id, array(), $message );
171
+ }
172
 
173
+ public static function update_settings() {
174
  FrmAppHelper::permission_check( 'frm_edit_forms' );
175
 
176
  $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
184
 
185
  FrmForm::update( $id, $_POST );
186
 
187
+ $message = __( 'Settings Successfully Updated', 'formidable' );
 
188
  return self::get_settings_vars( $id, array(), $message );
189
+ }
190
 
191
  public static function update( $values = array() ) {
192
  if ( empty( $values ) ) {
193
+ $values = $_POST;
194
+ }
195
 
196
+ //Set radio button and checkbox meta equal to "other" value
197
+ if ( FrmAppHelper::pro_is_installed() ) {
198
+ $values = FrmProEntry::mod_other_vals( $values, 'back' );
199
+ }
200
 
201
+ $errors = FrmForm::validate( $values );
202
+ $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
203
+ if ( $permission_error !== false ) {
204
+ $errors['form'] = $permission_error;
205
+ }
206
 
207
  $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
208
 
209
  if ( count( $errors ) > 0 ) {
210
+ return self::get_edit_vars( $id, $errors );
211
  } else {
212
+ FrmForm::update( $id, $values );
213
+ $message = __( 'Form was Successfully Updated', 'formidable' );
214
 
215
  if ( self::is_too_long( $values ) ) {
216
  $message .= '<br/> ' . sprintf(
221
  );
222
  }
223
 
224
+ if ( defined( 'DOING_AJAX' ) ) {
225
+ wp_die( esc_html( $message ) );
226
+ }
 
227
  return self::get_edit_vars( $id, array(), $message );
228
+ }
229
+ }
230
 
231
  /**
232
  * Check if the value at the end of the form was included.
253
  check_ajax_referer( 'frm_ajax', 'nonce' );
254
 
255
  $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
256
+ $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
257
 
258
  if ( $current_form ) {
259
  FrmForm::destroy( $current_form );
263
  wp_die();
264
  }
265
 
266
+ public static function duplicate() {
267
  FrmAppHelper::permission_check( 'frm_edit_forms' );
268
 
269
+ $params = FrmForm::list_page_params();
270
+ $form = FrmForm::duplicate( $params['id'], $params['template'], true );
271
+ $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
272
+ if ( $form ) {
273
  return self::get_edit_vars( $form, array(), $message, true );
274
+ } else {
275
  return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) );
276
+ }
277
+ }
278
 
279
+ public static function page_preview() {
280
  $params = FrmForm::list_page_params();
281
+ if ( ! $params['form'] ) {
282
+ return;
283
+ }
284
 
285
+ $form = FrmForm::getOne( $params['form'] );
286
  if ( $form ) {
287
  return self::show_form( $form->id, '', true, true );
288
  }
289
+ }
290
 
291
  /**
292
  * @since 3.0
295
  echo self::page_preview(); // WPCS: XSS ok.
296
  }
297
 
298
+ public static function preview() {
299
+ do_action( 'frm_wp' );
300
 
301
+ global $frm_vars;
302
+ $frm_vars['preview'] = true;
303
 
304
  self::load_wp();
305
 
360
  get_template_part( 'page' );
361
  }
362
 
363
+
364
  /**
365
  * Set the page title for the theme preview page
366
  *
370
  if ( in_the_loop() ) {
371
  $title = self::preview_title( $title );
372
  }
 
373
  return $title;
374
  }
375
 
391
  if ( in_the_loop() ) {
392
  $content = self::show_page_preview();
393
  }
 
394
  return $content;
395
  }
396
 
413
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
414
  }
415
 
416
+ public static function untrash() {
417
  self::change_form_status( 'untrash' );
418
+ }
419
 
420
  public static function bulk_untrash( $ids ) {
421
  FrmAppHelper::permission_check( 'frm_edit_forms' );
422
 
423
+ $count = FrmForm::set_status( $ids, 'published' );
424
 
 
425
  $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
426
+ return $message;
427
+ }
 
428
 
429
  /**
430
  * @since 3.06
437
  wp_die();
438
  }
439
 
440
+ public static function trash() {
441
  self::change_form_status( 'trash' );
442
+ }
443
 
444
  /**
445
  * @param string $status
471
 
472
  $count = 0;
473
  if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
474
+ $count++;
475
  }
476
 
477
  $form_type = FrmAppHelper::get_simple_request(
478
  array(
479
  'param' => 'form_type',
480
+ 'type' => 'request',
481
  )
482
  );
483
 
 
484
  $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
485
+ $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>' );
 
 
486
 
487
  $message = $available_status[ $status ]['message'];
488
 
492
  public static function bulk_trash( $ids ) {
493
  FrmAppHelper::permission_check( 'frm_delete_forms' );
494
 
495
+ $count = 0;
496
+ foreach ( $ids as $id ) {
497
+ if ( FrmForm::trash( $id ) ) {
498
+ $count++;
499
+ }
500
+ }
501
 
502
  $current_page = FrmAppHelper::get_simple_request(
503
  array(
504
  'param' => 'form_type',
505
+ 'type' => 'request',
506
  )
507
  );
508
+ $message = sprintf(
 
509
  _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' ),
510
  $count,
511
  '<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' ) ) . '">',
512
  '</a>'
513
  );
514
 
515
+ return $message;
516
+ }
517
 
518
+ public static function destroy() {
519
  FrmAppHelper::permission_check( 'frm_delete_forms' );
520
 
521
  $params = FrmForm::list_page_params();
522
 
523
+ //check nonce url
524
  check_admin_referer( 'destroy_form_' . $params['id'] );
525
 
526
+ $count = 0;
527
+ if ( FrmForm::destroy( $params['id'] ) ) {
528
+ $count++;
529
+ }
530
 
531
+ $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
 
532
 
533
  self::display_forms_list( $params, $message );
534
+ }
535
 
536
  public static function bulk_destroy( $ids ) {
537
  FrmAppHelper::permission_check( 'frm_delete_forms' );
538
 
539
+ $count = 0;
540
+ foreach ( $ids as $id ) {
541
+ $d = FrmForm::destroy( $id );
542
+ if ( $d ) {
543
+ $count++;
544
+ }
545
+ }
546
 
 
547
  $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
548
 
549
+ return $message;
550
+ }
551
 
552
+ private static function delete_all() {
553
+ //check nonce url
554
  $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
555
+ if ( $permission_error !== false ) {
556
  self::display_forms_list( array(), '', array( $permission_error ) );
557
+ return;
558
+ }
559
 
560
+ $count = FrmForm::scheduled_delete( time() );
 
 
 
 
 
561
  $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
562
 
563
  self::display_forms_list( array(), $message );
564
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
 
566
  /**
567
  * Create a custom template from a form
581
  'message' => __( 'There was an error creating a template.', 'formidable' ),
582
  );
583
  } else {
584
+ // Update the new form name and description.
585
+ $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
586
+ $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
587
+
588
+ $new_values = array(
589
+ 'name' => $name,
590
+ 'description' => $desc,
591
+ );
592
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
593
  if ( $query_results ) {
594
  FrmForm::clear_form_cache();
604
  }
605
 
606
  /**
607
+ * Inserts Formidable button
608
+ * Hook exists since 2.5.0
609
+ *
610
+ * @since 2.0.15
611
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
  public static function insert_form_button() {
613
  if ( current_user_can( 'frm_view_forms' ) ) {
614
  $menu_name = FrmAppHelper::get_menu_name();
615
+ $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
616
  echo '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' .
617
  FrmAppHelper::kses( $icon, 'all' ) .
618
  ' ' . esc_html( $menu_name ) . '</a>'; // WPCS: XSS ok.
619
  }
620
  }
621
 
622
+ public static function insert_form_popup() {
623
  $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
624
  if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
625
+ return;
626
+ }
627
 
628
+ FrmAppHelper::load_admin_wide_js();
629
 
630
+ $shortcodes = array(
631
  'formidable' => array(
632
  'name' => __( 'Form', 'formidable' ),
633
  'label' => __( 'Insert a Form', 'formidable' ),
634
  ),
635
+ );
636
 
637
  $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
638
 
639
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' );
640
+ }
641
 
642
+ public static function get_shortcode_opts() {
643
  FrmAppHelper::permission_check( 'frm_view_forms' );
644
+ check_ajax_referer( 'frm_ajax', 'nonce' );
645
 
646
  $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
647
  if ( empty( $shortcode ) ) {
648
+ wp_die();
649
+ }
650
 
651
  echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
652
  echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />';
653
 
654
+ $form_id = '';
655
+ $opts = array();
656
  switch ( $shortcode ) {
657
+ case 'formidable':
658
+ $opts = array(
659
+ 'form_id' => 'id',
660
+ //'key' => ',
661
+ 'title' => array(
662
  'val' => 1,
663
  'label' => __( 'Display form title', 'formidable' ),
664
  ),
665
+ 'description' => array(
666
  'val' => 1,
667
  'label' => __( 'Display form description', 'formidable' ),
668
  ),
669
+ 'minimize' => array(
670
  'val' => 1,
671
  'label' => __( 'Minimize form HTML', 'formidable' ),
672
  ),
673
+ );
674
+ }
675
  $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
676
 
677
  if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
682
 
683
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
684
 
685
+ echo '</div>';
686
 
687
+ wp_die();
688
+ }
689
 
690
  public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
691
+ FrmAppHelper::permission_check( 'frm_view_forms' );
692
 
693
+ global $wpdb, $frm_vars;
694
 
695
  if ( empty( $params ) ) {
696
  $params = FrmForm::list_page_params();
697
+ }
698
 
699
+ $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
700
 
701
+ $pagenum = $wp_list_table->get_pagenum();
702
 
703
+ $wp_list_table->prepare_items();
704
 
705
+ $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
706
+ if ( $pagenum > $total_pages && $total_pages > 0 ) {
707
  wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
708
+ die();
709
+ }
710
 
711
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' );
712
+ }
713
 
714
  public static function get_columns( $columns ) {
715
+ $columns['cb'] = '<input type="checkbox" />';
716
+ $columns['id'] = 'ID';
717
 
718
  $type = FrmAppHelper::get_simple_request(
719
  array(
723
  )
724
  );
725
 
726
+ if ( 'template' == $type ) {
727
+ $columns['name'] = __( 'Template Name', 'formidable' );
728
+ $columns['type'] = __( 'Type', 'formidable' );
729
+ $columns['form_key'] = __( 'Key', 'formidable' );
730
+ } else {
731
+ $columns['name'] = __( 'Form Title', 'formidable' );
732
+ $columns['entries'] = __( 'Entries', 'formidable' );
733
+ $columns['form_key'] = __( 'Key', 'formidable' );
734
+ $columns['shortcode'] = __( 'Shortcodes', 'formidable' );
735
+ }
736
 
737
+ $columns['created_at'] = __( 'Date', 'formidable' );
738
 
739
  add_screen_option(
740
  'per_page',
745
  )
746
  );
747
 
748
+ return $columns;
749
  }
750
 
751
  public static function get_sortable_columns() {
752
  return array(
753
+ 'id' => 'id',
754
+ 'name' => 'name',
755
+ 'description' => 'description',
756
+ 'form_key' => 'form_key',
757
+ 'created_at' => 'created_at',
758
  );
759
  }
760
 
775
  }
776
 
777
  public static function save_per_page( $save, $option, $value ) {
778
+ if ( $option == 'formidable_page_formidable_per_page' ) {
779
+ $save = (int) $value;
780
+ }
781
+ return $save;
782
+ }
 
783
 
784
  /**
785
  * Show the template listing page
787
  * @since 3.06
788
  */
789
  private static function list_templates() {
790
+ wp_enqueue_script( 'jquery-ui-dialog' );
791
+ wp_enqueue_style( 'jquery-ui-dialog' );
792
 
793
  $where = apply_filters( 'frm_forms_dropdown', array(), '' );
794
  $forms = FrmForm::get_published_forms( $where );
795
 
796
+ $api = new FrmFormTemplateApi();
797
  $templates = $api->get_api_info();
798
  self::add_user_templates( $templates );
799
 
800
  $error = '';
801
  $expired = false;
 
802
  if ( isset( $templates['error'] ) ) {
803
  $error = $templates['error']['message'];
804
  $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
805
  $expired = ( $templates['error']['code'] === 'expired' );
 
 
806
  unset( $templates['error'] );
807
  }
808
 
809
  $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
810
+ $plans = array( 'free', 'Personal', 'Business', 'Elite' );
 
811
 
812
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list-templates.php' );
813
  }
814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
815
  private static function add_user_templates( &$templates ) {
816
  $user_templates = array(
817
  'is_template' => 1,
834
  }
835
 
836
  private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
837
+ global $frm_vars;
838
 
839
+ $form = FrmForm::getOne( $id );
840
+ if ( ! $form ) {
841
+ wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
842
+ }
843
 
844
+ if ( $form->parent_form_id ) {
845
+ wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ) );
846
+ }
 
847
 
848
  $frm_field_selection = FrmField::field_selection();
 
849
  $fields = FrmField::get_all_for_form( $form->id );
850
 
851
+ // Automatically add end section fields if they don't exist (2.0 migration)
852
+ $reset_fields = false;
853
+ FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
854
 
855
+ if ( $reset_fields ) {
856
+ $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
857
+ }
858
 
859
  unset( $end_section_values, $last_order, $open, $reset_fields );
860
 
861
+ $args = array( 'parent_form_id' => $form->id );
862
+ $values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args );
863
  $values['fields'] = $fields;
864
 
865
+ $edit_message = __( 'Form was Successfully Updated', 'formidable' );
866
+ if ( $form->is_template && $message == $edit_message ) {
867
+ $message = __( 'Template was Successfully Updated', 'formidable' );
868
+ }
869
 
870
  $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
871
 
872
  if ( defined( 'DOING_AJAX' ) ) {
873
+ wp_die();
874
+ } else if ( $create_link ) {
875
+ require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
876
+ } else {
877
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
878
+ }
879
+ }
880
 
881
  public static function get_settings_vars( $id, $errors = array(), $message = '' ) {
882
  FrmAppHelper::permission_check( 'frm_edit_forms' );
883
 
884
+ global $frm_vars;
885
+
886
+ $form = FrmForm::getOne( $id );
887
 
 
888
  $fields = FrmField::get_all_for_form( $id );
889
  $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
890
 
891
  self::clean_submit_html( $values );
892
 
893
+ $action_controls = FrmFormActionsController::get_form_actions();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
894
 
895
+ $sections = apply_filters( 'frm_add_form_settings_section', array(), $values );
896
+ $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
897
 
898
+ $styles = apply_filters( 'frm_get_style_opts', array() );
 
899
 
 
 
 
 
 
 
900
  $first_h3 = 'frm_first_h3';
901
 
902
+ FrmAppController::include_upgrade_overlay();
 
903
 
904
+ require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
905
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
906
 
907
  /**
908
  * Replace old Submit Button href with new href to avoid errors in Chrome
917
  }
918
  }
919
 
920
+ public static function mb_tags_box( $form_id, $class = '' ) {
921
+ $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
922
+ $linked_forms = array();
923
+ $col = 'one';
924
  $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
925
 
926
+ $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
927
  $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
928
 
929
  $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
930
 
931
  include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
932
+ }
933
 
934
  /**
935
  * @since 3.04.01
937
  private static function advanced_helpers( $atts ) {
938
  $advanced_helpers = array(
939
  'default' => array(
940
+ 'heading' => __( 'Customize the field values with the following parameters. Click to see a sample.', 'formidable' ),
941
  'codes' => self::get_advanced_shortcodes(),
942
  ),
943
  );
951
  }
952
 
953
  $advanced_helpers['user_id'] = array(
954
+ 'heading' => __( 'Insert user information', 'formidable' ),
955
  'codes' => $user_helpers,
956
  );
957
  }
960
  * Add extra helper shortcodes on the Advanced tab in form settings and views
961
  *
962
  * @since 3.04.01
 
963
  * @param array $atts - Includes fields and form_id
964
  */
965
  return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
977
  'label' => __( 'Separator', 'formidable' ),
978
  'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
979
  ),
980
+ 'x format="d-m-Y"' => __( 'Date Format', 'formidable' ),
981
+ 'x show="field_label"' => __( 'Field Label', 'formidable' ),
 
 
 
 
982
  'x wpautop=0' => array(
983
  'label' => __( 'No Auto P', 'formidable' ),
984
  'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
985
  ),
986
  );
987
  $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
 
988
  // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
989
 
990
  return $adv_shortcodes;
995
  */
996
  private static function user_shortcodes() {
997
  $options = array(
998
+ 'ID' => __( 'User ID', 'formidable' ),
999
+ 'first_name' => __( 'First Name', 'formidable' ),
1000
+ 'last_name' => __( 'Last Name', 'formidable' ),
1001
+ 'display_name' => __( 'Display Name', 'formidable' ),
1002
+ 'user_login' => __( 'User Login', 'formidable' ),
1003
+ 'user_email' => __( 'Email', 'formidable' ),
1004
+ 'avatar' => __( 'Avatar', 'formidable' ),
1005
+ 'author_link' => __( 'Author Link', 'formidable' ),
1006
  );
 
1007
  return apply_filters( 'frm_user_shortcodes', $options );
1008
  }
1009
 
1014
  */
1015
  private static function get_shortcode_helpers( $settings_tab ) {
1016
  $entry_shortcodes = array(
1017
+ 'id' => __( 'Entry ID', 'formidable' ),
1018
+ 'key' => __( 'Entry Key', 'formidable' ),
1019
+ 'post_id' => __( 'Post ID', 'formidable' ),
1020
+ 'ip' => __( 'User IP', 'formidable' ),
1021
  'created-at' => __( 'Entry created', 'formidable' ),
1022
  'updated-at' => __( 'Entry updated', 'formidable' ),
1023
+ '' => '',
1024
+ 'siteurl' => __( 'Site URL', 'formidable' ),
1025
+ 'sitename' => __( 'Site Name', 'formidable' ),
1026
+ );
1027
 
1028
  if ( ! FrmAppHelper::pro_is_installed() ) {
1029
  unset( $entry_shortcodes['post_id'] );
1031
 
1032
  if ( $settings_tab ) {
1033
  $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1034
+ $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1035
+ $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1036
  }
1037
 
1038
  /**
1073
  wp_die();
1074
  }
1075
 
1076
+ public static function filter_content( $content, $form, $entry = false ) {
1077
  self::get_entry_by_param( $entry );
1078
+ if ( ! $entry ) {
1079
+ return $content;
1080
+ }
1081
 
1082
+ if ( is_object( $form ) ) {
1083
+ $form = $form->id;
1084
+ }
1085
 
1086
+ $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1087
+ $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1088
 
1089
+ return $content;
1090
+ }
1091
 
1092
  private static function get_entry_by_param( &$entry ) {
1093
  if ( ! $entry || ! is_object( $entry ) ) {
1099
  }
1100
  }
1101
 
1102
+ public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1103
+ return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1104
+ }
1105
 
1106
+ public static function process_bulk_form_actions( $errors ) {
1107
+ if ( ! $_REQUEST ) {
1108
+ return $errors;
1109
+ }
1110
 
1111
  $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1112
+ if ( $bulkaction == -1 ) {
1113
  $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1114
+ }
1115
 
1116
+ if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
1117
+ FrmAppHelper::remove_get_action();
1118
 
1119
+ $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1120
+ }
1121
 
1122
  $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1123
+ if ( empty( $ids ) ) {
1124
+ $errors[] = __( 'No forms were specified', 'formidable' );
1125
+ return $errors;
1126
+ }
1127
+
1128
+ $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
1129
+ if ( $permission_error !== false ) {
1130
+ $errors[] = $permission_error;
1131
+ return $errors;
1132
+ }
1133
+
1134
+ if ( ! is_array( $ids ) ) {
1135
+ $ids = explode( ',', $ids );
1136
+ }
1137
+
1138
+ switch ( $bulkaction ) {
1139
+ case 'delete':
1140
+ $message = self::bulk_destroy( $ids );
 
 
1141
  break;
1142
+ case 'trash':
1143
+ $message = self::bulk_trash( $ids );
1144
  break;
1145
+ case 'untrash':
1146
+ $message = self::bulk_untrash( $ids );
1147
+ }
1148
 
1149
+ if ( isset( $message ) && ! empty( $message ) ) {
1150
  $errors['message'] = $message;
1151
+ }
1152
 
1153
+ return $errors;
1154
+ }
1155
 
1156
+ public static function route() {
1157
  $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1158
+ $vars = array();
1159
  if ( isset( $_POST['frm_compact_fields'] ) ) {
1160
  FrmAppHelper::permission_check( 'frm_edit_forms' );
1161
 
1162
+ $json_vars = htmlspecialchars_decode( nl2br( stripslashes( str_replace( '&quot;', '\\\"', $_POST['frm_compact_fields'] ) ) ) );
1163
  $json_vars = json_decode( $json_vars, true );
1164
  if ( empty( $json_vars ) ) {
1165
+ // json decoding failed so we should return an error message
1166
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1167
+ if ( 'edit' == $action ) {
1168
+ $action = 'update';
1169
+ }
1170
 
1171
  add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1172
+ } else {
1173
+ $vars = FrmAppHelper::json_to_array( $json_vars );
1174
+ $action = $vars[ $action ];
1175
  unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1176
  $_REQUEST = array_merge( $_REQUEST, $vars );
1177
+ $_POST = array_merge( $_POST, $_REQUEST );
1178
+ }
1179
+ } else {
1180
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1181
+ if ( isset( $_REQUEST['delete_all'] ) ) {
1182
+ // override the action for this page
1183
+ $action = 'delete_all';
1184
+ }
1185
+ }
1186
 
1187
  add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1188
+ FrmAppHelper::trigger_hook_load( 'form' );
1189
 
1190
+ switch ( $action ) {
1191
+ case 'new':
1192
  return self::new_form( $vars );
 
1193
  case 'add_new':
1194
  case 'list_templates':
1195
+ case 'create':
1196
+ case 'edit':
1197
+ case 'update':
1198
+ case 'duplicate':
1199
+ case 'trash':
1200
+ case 'untrash':
1201
+ case 'destroy':
1202
+ case 'delete_all':
1203
+ case 'settings':
1204
+ case 'update_settings':
1205
  return self::$action( $vars );
1206
+ default:
1207
  do_action( 'frm_form_action_' . $action );
1208
  if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1209
+ return;
1210
+ }
1211
 
1212
  $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1213
+ if ( $action == -1 ) {
1214
  $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1215
+ }
1216
 
1217
  if ( strpos( $action, 'bulk_' ) === 0 ) {
1218
+ FrmAppHelper::remove_get_action();
1219
+ return self::list_form();
1220
+ }
1221
 
1222
+ return self::display_forms_list();
1223
+ }
1224
+ }
 
 
 
1225
 
1226
+ public static function json_error( $errors ) {
1227
+ $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1228
+ return $errors;
1229
+ }
1230
 
 
 
1231
 
1232
+ /* FRONT-END FORMS */
1233
+ public static function admin_bar_css() {
1234
  if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1235
+ return;
1236
+ }
1237
 
1238
  add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1239
  FrmAppHelper::load_font_style();
1240
  }
1241
 
1242
  public static function admin_bar_configure() {
1243
+ global $frm_vars;
1244
  if ( empty( $frm_vars['forms_loaded'] ) ) {
1245
+ return;
1246
+ }
1247
 
1248
+ $actions = array();
1249
  foreach ( $frm_vars['forms_loaded'] as $form ) {
1250
  if ( is_object( $form ) ) {
1251
  $actions[ $form->id ] = $form->name;
1291
 
1292
  $wp_admin_bar->add_node(
1293
  array(
1294
+ 'parent' => 'frm-forms',
1295
+ 'id' => 'edit_form_' . $form_id,
1296
+ 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
1297
+ 'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ),
1298
  )
1299
  );
1300
  }
1301
  }
1302
 
1303
+ //formidable shortcode
 
 
 
 
1304
  public static function get_form_shortcode( $atts ) {
1305
+ global $frm_vars;
1306
  if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1307
+ $sc = '[formidable';
1308
  if ( ! empty( $atts ) ) {
1309
  foreach ( $atts as $k => $v ) {
1310
  $sc .= ' ' . $k . '="' . esc_attr( $v ) . '"';
1311
  }
1312
  }
 
1313
  return $sc . ']';
1314
+ }
1315
 
1316
  $shortcode_atts = shortcode_atts(
1317
  array(
1318
+ 'id' => '',
1319
+ 'key' => '',
1320
+ 'title' => false,
1321
+ 'description' => false,
1322
+ 'readonly' => false,
1323
+ 'entry_id' => false,
1324
+ 'fields' => array(),
1325
  'exclude_fields' => array(),
1326
+ 'minimize' => false,
1327
  ),
1328
  $atts
1329
  );
1330
  do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1331
 
1332
+ return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1333
+ }
1334
 
1335
+ public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1336
+ if ( empty( $id ) ) {
1337
+ $id = $key;
1338
+ }
1339
 
1340
+ $form = self::maybe_get_form_to_show( $id );
1341
+ if ( ! $form ) {
1342
+ return __( 'Please select a valid form', 'formidable' );
1343
+ }
1344
 
1345
  FrmAppController::maybe_update_styles();
1346
 
1347
  add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1348
+ FrmAppHelper::trigger_hook_load( 'form', $form );
1349
 
1350
+ $form = apply_filters( 'frm_pre_display_form', $form );
1351
 
1352
+ $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1353
 
1354
  if ( self::is_viewable_draft_form( $form ) ) {
1355
  // don't show a draft form on a page
1356
  $form = __( 'Please select a valid form', 'formidable' );
1357
+ } else if ( self::user_should_login( $form ) ) {
1358
  $form = do_shortcode( $frm_settings->login_msg );
1359
+ } else if ( self::user_has_permission_to_view( $form ) ) {
1360
  $form = do_shortcode( $frm_settings->login_msg );
1361
  } else {
1362
  do_action( 'frm_pre_get_form', $form );
1372
  }
1373
 
1374
  return $form;
1375
+ }
1376
 
1377
  private static function maybe_get_form_to_show( $id ) {
1378
  $form = false;
1390
  private static function is_viewable_draft_form( $form ) {
1391
  global $post;
1392
  $frm_settings = FrmAppHelper::get_settings();
 
1393
  return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1394
  }
1395
 
1401
  return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
1402
  }
1403
 
1404
+ public static function get_form( $form, $title, $description, $atts = array() ) {
1405
  ob_start();
1406
 
1407
  do_action( 'frm_before_get_form', $atts );
1408
 
1409
+ self::get_form_contents( $form, $title, $description, $atts );
1410
  self::enqueue_scripts( FrmForm::get_params( $form ) );
1411
 
1412
+ $contents = ob_get_contents();
1413
+ ob_end_clean();
1414
 
1415
  self::maybe_minimize_form( $atts, $contents );
1416
 
1417
+ return $contents;
1418
+ }
1419
 
1420
  public static function enqueue_scripts( $params ) {
1421
  do_action( 'frm_enqueue_form_scripts', $params );
1422
  }
1423
 
1424
  public static function get_form_contents( $form, $title, $description, $atts ) {
1425
+ $params = FrmForm::get_params( $form );
1426
+ $errors = self::get_saved_errors( $form, $params );
1427
+ $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1428
+ $reset = false;
1429
  $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1430
 
1431
  $handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1443
  do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1444
 
1445
  if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1446
+ $entry_id = self::just_created_entry( $form->id );
1447
+ $pass_args['entry_id'] = $entry_id;
1448
+ $pass_args['reset'] = true;
1449
  $pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1450
 
1451
  self::run_success_action( $pass_args );
1474
  } else {
1475
  $errors = array();
1476
  }
 
1477
  return $errors;
1478
  }
1479
 
1482
  */
1483
  public static function just_created_entry( $form_id ) {
1484
  global $frm_vars;
 
1485
  return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
1486
  }
1487
 
1489
  * @since 3.0
1490
  */
1491
  private static function get_confirmation_method( $atts ) {
1492
+ $opt = 'success_action';
1493
  $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1494
  $method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1495
 
1545
  do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1546
 
1547
  $opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
 
1548
  $args['success_opt'] = $opt;
1549
  if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1550
  self::load_page_after_submit( $args );
1562
  global $post;
1563
  $opt = $args['success_opt'];
1564
  if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1565
+ $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1566
  $old_post = $post;
1567
+ $post = $page;
1568
+ $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1569
  echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1570
  $post = $old_post;
1571
  }
1579
 
1580
  add_filter( 'frm_use_wpautop', '__return_false' );
1581
 
1582
+ $opt = $args['success_opt'];
1583
  $success_url = trim( $args['form']->options[ $opt . '_url' ] );
1584
  $success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1585
  $success_url = do_shortcode( $success_url );
1612
 
1613
  /**
1614
  * @since 3.0
 
1615
  * @param string $success_url
1616
  * @param string $success_msg
1617
  * @param array $args
1618
  */
1619
  private static function get_redirect_message( $success_url, $success_msg, $args ) {
1620
  $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' .
 
1621
  sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1622
  '</div></div>';
1623
 
1626
  'form_id' => $args['form']->id,
1627
  'form' => $args['form'],
1628
  );
 
1629
  return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1630
  }
1631
 
1652
  private static function show_form_after_submit( $args ) {
1653
  self::fill_atts_for_form_display( $args );
1654
 
1655
+ $errors = $args['errors'];
1656
+ $message = $args['message'];
1657
+ $form = $args['form'];
1658
+ $title = $args['title'];
1659
  $description = $args['description'];
1660
 
1661
  if ( empty( $args['fields'] ) ) {
1668
  $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1669
 
1670
  $frm_settings = FrmAppHelper::get_settings();
1671
+ $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1672
 
1673
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' );
1674
  }
1680
  */
1681
  private static function fill_atts_for_form_display( &$args ) {
1682
  $defaults = array(
1683
+ 'errors' => array(),
1684
+ 'message' => '',
1685
+ 'fields' => array(),
1686
+ 'form' => array(),
1687
+ 'title' => true,
1688
  'description' => false,
1689
+ 'reset' => false,
1690
  );
1691
+ $args = wp_parse_args( $args, $defaults );
1692
  }
1693
 
1694
  /**
1702
  self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
1703
 
1704
  $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
1705
+ $errors = array();
1706
+ $form = $atts['form'];
 
1707
  $message = $atts['message'];
1708
 
1709
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
1719
 
1720
  if ( $entry_id && is_numeric( $entry_id ) ) {
1721
  $message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
1722
+ $class = 'frm_message';
1723
  } else {
1724
  $message = $frm_settings->failed_msg;
1725
+ $class = FrmFormsHelper::form_error_class();
1726
  }
1727
 
1728
  $message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
 
1729
  return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
1730
  }
1731
 
1732
  public static function front_head() {
1733
  $version = FrmAppHelper::plugin_version();
1734
+ $suffix = FrmAppHelper::js_suffix();
1735
 
1736
  if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
1737
  wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
1768
  }
1769
 
1770
  public static function defer_script_loading( $tag, $handle ) {
1771
+ if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
1772
+ $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
1773
  }
1774
+ return $tag;
 
1775
  }
1776
 
1777
  public static function footer_js( $location = 'footer' ) {
1780
  FrmStylesController::enqueue_css();
1781
 
1782
  if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
1783
+ //load formidable js
1784
  wp_enqueue_script( 'formidable' );
1785
  }
1786
  }
1803
  return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
1804
  }
1805
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1806
  /**
1807
  * @deprecated 1.07.05
1808
  * @codeCoverageIgnore
classes/controllers/FrmHooksController.php CHANGED
@@ -2,217 +2,221 @@
2
 
3
  class FrmHooksController {
4
 
5
- /**
6
- * Trigger plugin-wide hook loading
7
- */
8
- public static function trigger_load_hook( $hooks = 'load_hooks' ) {
9
- $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) );
10
-
11
- $trigger_hooks = $hooks;
12
- $hooks = (array) $hooks;
13
-
14
- if ( 'load_hooks' == $trigger_hooks ) {
15
- if ( is_admin() ) {
16
- $hooks[] = 'load_admin_hooks';
17
- if ( defined( 'DOING_AJAX' ) ) {
18
- $hooks[] = 'load_ajax_hooks';
19
- $hooks[] = 'load_form_hooks';
20
- }
21
- }
22
-
23
- if ( is_multisite() ) {
24
- $hooks[] = 'load_multisite_hooks';
25
- }
26
- } else {
27
- // Make sure the hooks are only triggered once.
28
- add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' );
29
- }
30
- unset( $trigger_hooks );
31
-
32
- // Instansiate Controllers.
33
- foreach ( $controllers as $c ) {
34
- foreach ( $hooks as $hook ) {
35
  call_user_func( array( $c, $hook ) );
36
  unset( $hook );
37
- }
38
  unset( $c );
39
- }
40
 
41
- }
42
 
43
- public static function trigger_load_form_hooks() {
44
- self::trigger_load_hook( 'load_form_hooks' );
45
- }
46
 
47
  public static function load_hooks() {
48
  add_action( 'rest_api_init', 'FrmAppController::create_rest_routes', 0 );
49
- add_action( 'plugins_loaded', 'FrmAppController::load_lang' );
50
  add_filter( 'widget_text', 'do_shortcode' );
51
 
52
- // Entries controller.
53
- add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 );
54
- add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 );
55
 
56
- // Form Actions Controller.
57
- add_action( 'init', 'FrmFormActionsController::register_post_types', 1 );
58
  add_action( 'frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 3 );
59
 
60
- // Forms Controller.
61
- add_action( 'widgets_init', 'FrmFormsController::register_widgets' );
62
  add_action( 'init', 'FrmFormsController::front_head' );
63
- add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 );
64
- add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 );
65
- add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' );
66
  add_action( 'wp_footer', 'FrmFormsController::footer_js', 1, 0 );
67
 
68
  add_action( 'wp_scheduled_delete', 'FrmForm::scheduled_delete' );
69
 
70
- // Form Shortcodes.
71
- add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' );
72
 
73
- // Styles Controller.
74
- add_action( 'init', 'FrmStylesController::register_post_types', 0 );
75
- add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' );
76
- add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 );
77
- add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' );
78
 
79
- // Simple Blocks Controller.
80
  add_action( 'init', 'FrmSimpleBlocksController::register_simple_form_block' );
81
 
82
  add_filter( 'cron_schedules', 'FrmUsageController::add_schedules' );
83
  add_action( 'formidable_send_usage', 'FrmUsageController::send_snapshot' );
84
- }
85
 
86
  public static function load_admin_hooks() {
87
- add_action( 'admin_menu', 'FrmAppController::menu', 1 );
88
  add_filter( 'admin_body_class', 'FrmAppController::add_admin_class', 999 );
89
- add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
90
- add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' );
91
  add_action( 'admin_init', 'FrmAppController::admin_init', 11 );
92
  add_filter( 'plugin_action_links_' . FrmAppHelper::plugin_folder() . '/formidable.php', 'FrmAppController::settings_link' );
93
  add_filter( 'admin_footer_text', 'FrmAppController::set_footer_text' );
94
  add_action( 'wp_ajax_frm_dismiss_review', 'FrmAppController::dismiss_review' );
95
  add_action( 'wp_mail_smtp_core_recommendations_plugins', 'FrmAppController::remove_wpforms_nag' );
96
 
97
- // Addons Controller.
98
  add_action( 'admin_menu', 'FrmAddonsController::menu', 100 );
99
  add_filter( 'pre_set_site_transient_update_plugins', 'FrmAddonsController::check_update' );
100
 
101
- // Entries Controller.
102
- add_action( 'admin_menu', 'FrmEntriesController::menu', 12 );
103
- add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 );
104
- add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 );
105
- add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 );
106
-
107
- // Form Actions Controller.
108
- if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
109
- add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' );
110
- }
111
- add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 );
112
-
113
- // Forms Controller.
114
- add_action( 'admin_menu', 'FrmFormsController::menu', 10 );
115
- add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
116
-
117
- add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 );
118
- add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' );
 
119
  add_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
120
  add_action( 'et_pb_admin_excluded_shortcodes', 'FrmFormsController::prevent_divi_conflict' );
121
 
122
- // Forms Model.
123
- add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 );
124
 
125
- // Settings Controller.
126
- add_action( 'admin_menu', 'FrmSettingsController::menu', 45 );
127
- add_action( 'frm_before_settings', 'FrmSettingsController::license_box' );
128
  add_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' );
129
  add_action( 'wp_ajax_frm_settings_tab', 'FrmSettingsController::load_settings_tab' );
130
 
131
- // Styles Controller.
132
- add_action( 'admin_menu', 'FrmStylesController::menu', 14 );
133
- add_action( 'admin_init', 'FrmStylesController::admin_init' );
134
 
135
- // XML Controller.
136
- add_action( 'admin_menu', 'FrmXMLController::menu', 41 );
137
 
138
- // Simple Blocks Controller.
139
  add_action( 'enqueue_block_editor_assets', 'FrmSimpleBlocksController::block_editor_assets' );
140
 
141
  add_action( 'admin_init', 'FrmUsageController::schedule_send' );
142
- }
143
 
144
  public static function load_ajax_hooks() {
145
  add_action( 'wp_ajax_frm_install', 'FrmAppController::ajax_install' );
146
- add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
147
- add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
148
 
149
- // Addons.
150
  add_action( 'wp_ajax_frm_addon_activate', 'FrmAddon::activate' );
151
  add_action( 'wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' );
152
  add_action( 'wp_ajax_frm_install_addon', 'FrmAddonsController::ajax_install_addon' );
153
  add_action( 'wp_ajax_frm_activate_addon', 'FrmAddonsController::ajax_activate_addon' );
154
 
155
- // Fields Controller.
156
- add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' );
157
- add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' );
158
- add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' );
159
- add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' );
160
- add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' );
161
-
162
- // Form Actions Controller.
163
- add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' );
164
- add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' );
165
-
166
- // Forms Controller.
 
 
 
 
167
  add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' );
168
- add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' );
169
- add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' );
170
- add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' );
171
- add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' );
172
  add_action( 'wp_ajax_frm_forms_trash', 'FrmFormsController::ajax_trash' );
173
- add_action( 'wp_ajax_frm_install_form', 'FrmFormsController::build_new_form' );
174
  add_action( 'wp_ajax_frm_build_template', 'FrmFormsController::build_template' );
175
 
176
- // Settings.
177
  add_action( 'wp_ajax_frm_lite_settings_upgrade', 'FrmSettingsController::settings_cta_dismiss' );
178
 
179
- // Styles Controller.
180
- add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' );
181
- add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' );
182
- add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' );
183
- add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' );
184
  add_action( 'wp_ajax_frmpro_css', 'FrmStylesController::load_saved_css' );
185
  add_action( 'wp_ajax_nopriv_frmpro_css', 'FrmStylesController::load_saved_css' );
186
 
187
- // XML Controller.
188
  add_action( 'wp_ajax_frm_install_template', 'FrmXMLController::install_template' );
189
  add_action( 'wp_ajax_frm_entries_csv', 'FrmXMLController::csv' );
190
  add_action( 'wp_ajax_nopriv_frm_entries_csv', 'FrmXMLController::csv' );
191
- add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' );
192
- }
193
 
194
  public static function load_form_hooks() {
195
- // Fields Controller.
196
- add_filter( 'frm_field_type', 'FrmFieldsController::change_type' );
197
- add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' );
198
- add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 );
199
- add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' );
200
 
201
- // Forms Controller.
202
  add_filter( 'frm_form_classes', 'FrmFormsController::form_classes' );
203
 
204
- // Styles Controller.
205
- add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
206
- }
207
 
208
  public static function load_view_hooks() {
209
- // Hooks go here when a view is loaded.
210
- }
211
 
212
  public static function load_multisite_hooks() {
213
  add_action( 'wpmu_upgrade_site', 'FrmAppController::network_upgrade_site' );
214
 
215
- // Drop tables when mu site is deleted.
216
- add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
217
- }
218
  }
2
 
3
  class FrmHooksController {
4
 
5
+ /**
6
+ * Trigger plugin-wide hook loading
7
+ */
8
+ public static function trigger_load_hook( $hooks = 'load_hooks' ) {
9
+ $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) );
10
+
11
+ $trigger_hooks = $hooks;
12
+ $hooks = (array) $hooks;
13
+
14
+ if ( 'load_hooks' == $trigger_hooks ) {
15
+ if ( is_admin() ) {
16
+ $hooks[] = 'load_admin_hooks';
17
+ if ( defined( 'DOING_AJAX' ) ) {
18
+ $hooks[] = 'load_ajax_hooks';
19
+ $hooks[] = 'load_form_hooks';
20
+ }
21
+ }
22
+
23
+ if ( is_multisite() ) {
24
+ $hooks[] = 'load_multisite_hooks';
25
+ }
26
+ } else {
27
+ // Make sure the hooks are only triggered once
28
+ add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' );
29
+ }
30
+ unset( $trigger_hooks );
31
+
32
+ // Instansiate Controllers
33
+ foreach ( $controllers as $c ) {
34
+ foreach ( $hooks as $hook ) {
35
  call_user_func( array( $c, $hook ) );
36
  unset( $hook );
37
+ }
38
  unset( $c );
39
+ }
40
 
41
+ }
42
 
43
+ public static function trigger_load_form_hooks() {
44
+ self::trigger_load_hook( 'load_form_hooks' );
45
+ }
46
 
47
  public static function load_hooks() {
48
  add_action( 'rest_api_init', 'FrmAppController::create_rest_routes', 0 );
49
+ add_action( 'plugins_loaded', 'FrmAppController::load_lang' );
50
  add_filter( 'widget_text', 'do_shortcode' );
51
 
52
+ // Entries controller
53
+ add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 );
54
+ add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 );
55
 
56
+ // Form Actions Controller
57
+ add_action( 'init', 'FrmFormActionsController::register_post_types', 1 );
58
  add_action( 'frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 3 );
59
 
60
+ // Forms Controller
61
+ add_action( 'widgets_init', 'FrmFormsController::register_widgets' );
62
  add_action( 'init', 'FrmFormsController::front_head' );
63
+ add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 );
64
+ add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 );
65
+ add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' );
66
  add_action( 'wp_footer', 'FrmFormsController::footer_js', 1, 0 );
67
 
68
  add_action( 'wp_scheduled_delete', 'FrmForm::scheduled_delete' );
69
 
70
+ // Form Shortcodes
71
+ add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' );
72
 
73
+ // Styles Controller
74
+ add_action( 'init', 'FrmStylesController::register_post_types', 0 );
75
+ add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' );
76
+ add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 );
77
+ add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' );
78
 
79
+ //Simple Blocks Controller
80
  add_action( 'init', 'FrmSimpleBlocksController::register_simple_form_block' );
81
 
82
  add_filter( 'cron_schedules', 'FrmUsageController::add_schedules' );
83
  add_action( 'formidable_send_usage', 'FrmUsageController::send_snapshot' );
84
+ }
85
 
86
  public static function load_admin_hooks() {
87
+ add_action( 'admin_menu', 'FrmAppController::menu', 1 );
88
  add_filter( 'admin_body_class', 'FrmAppController::add_admin_class', 999 );
89
+ add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
90
+ add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' );
91
  add_action( 'admin_init', 'FrmAppController::admin_init', 11 );
92
  add_filter( 'plugin_action_links_' . FrmAppHelper::plugin_folder() . '/formidable.php', 'FrmAppController::settings_link' );
93
  add_filter( 'admin_footer_text', 'FrmAppController::set_footer_text' );
94
  add_action( 'wp_ajax_frm_dismiss_review', 'FrmAppController::dismiss_review' );
95
  add_action( 'wp_mail_smtp_core_recommendations_plugins', 'FrmAppController::remove_wpforms_nag' );
96
 
97
+ // Addons Controller
98
  add_action( 'admin_menu', 'FrmAddonsController::menu', 100 );
99
  add_filter( 'pre_set_site_transient_update_plugins', 'FrmAddonsController::check_update' );
100
 
101
+ // Entries Controller
102
+ add_action( 'admin_menu', 'FrmEntriesController::menu', 12 );
103
+ add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 );
104
+ add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 );
105
+ add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 );
106
+ add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 );
107
+
108
+ // Form Actions Controller
109
+ if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
110
+ add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' );
111
+ }
112
+ add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 );
113
+
114
+ // Forms Controller
115
+ add_action( 'admin_menu', 'FrmFormsController::menu', 10 );
116
+ add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
117
+
118
+ add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 );
119
+ add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' );
120
  add_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
121
  add_action( 'et_pb_admin_excluded_shortcodes', 'FrmFormsController::prevent_divi_conflict' );
122
 
123
+ // Forms Model
124
+ add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 );
125
 
126
+ // Settings Controller
127
+ add_action( 'admin_menu', 'FrmSettingsController::menu', 45 );
128
+ add_action( 'frm_before_settings', 'FrmSettingsController::license_box' );
129
  add_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' );
130
  add_action( 'wp_ajax_frm_settings_tab', 'FrmSettingsController::load_settings_tab' );
131
 
132
+ // Styles Controller
133
+ add_action( 'admin_menu', 'FrmStylesController::menu', 14 );
134
+ add_action( 'admin_init', 'FrmStylesController::admin_init' );
135
 
136
+ // XML Controller
137
+ add_action( 'admin_menu', 'FrmXMLController::menu', 41 );
138
 
139
+ // Simple Blocks Controller
140
  add_action( 'enqueue_block_editor_assets', 'FrmSimpleBlocksController::block_editor_assets' );
141
 
142
  add_action( 'admin_init', 'FrmUsageController::schedule_send' );
143
+ }
144
 
145
  public static function load_ajax_hooks() {
146
  add_action( 'wp_ajax_frm_install', 'FrmAppController::ajax_install' );
147
+ add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
148
+ add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
149
 
150
+ // Addons
151
  add_action( 'wp_ajax_frm_addon_activate', 'FrmAddon::activate' );
152
  add_action( 'wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' );
153
  add_action( 'wp_ajax_frm_install_addon', 'FrmAddonsController::ajax_install_addon' );
154
  add_action( 'wp_ajax_frm_activate_addon', 'FrmAddonsController::ajax_activate_addon' );
155
 
156
+ // Fields Controller
157
+ add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' );
158
+ add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' );
159
+ add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' );
160
+ add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' );
161
+ add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' );
162
+ add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' );
163
+ add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' );
164
+ add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' );
165
+ add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' );
166
+
167
+ // Form Actions Controller
168
+ add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' );
169
+ add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' );
170
+
171
+ // Forms Controller
172
  add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' );
173
+ add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' );
174
+ add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' );
175
+ add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' );
176
+ add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' );
177
  add_action( 'wp_ajax_frm_forms_trash', 'FrmFormsController::ajax_trash' );
 
178
  add_action( 'wp_ajax_frm_build_template', 'FrmFormsController::build_template' );
179
 
180
+ // Settings
181
  add_action( 'wp_ajax_frm_lite_settings_upgrade', 'FrmSettingsController::settings_cta_dismiss' );
182
 
183
+ // Styles Controller
184
+ add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' );
185
+ add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' );
186
+ add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' );
187
+ add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' );
188
  add_action( 'wp_ajax_frmpro_css', 'FrmStylesController::load_saved_css' );
189
  add_action( 'wp_ajax_nopriv_frmpro_css', 'FrmStylesController::load_saved_css' );
190
 
191
+ // XML Controller
192
  add_action( 'wp_ajax_frm_install_template', 'FrmXMLController::install_template' );
193
  add_action( 'wp_ajax_frm_entries_csv', 'FrmXMLController::csv' );
194
  add_action( 'wp_ajax_nopriv_frm_entries_csv', 'FrmXMLController::csv' );
195
+ add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' );
196
+ }
197
 
198
  public static function load_form_hooks() {
199
+ // Fields Controller
200
+ add_filter( 'frm_field_type', 'FrmFieldsController::change_type' );
201
+ add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' );
202
+ add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 );
203
+ add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' );
204
 
205
+ // Forms Controller
206
  add_filter( 'frm_form_classes', 'FrmFormsController::form_classes' );
207
 
208
+ // Styles Controller
209
+ add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
210
+ }
211
 
212
  public static function load_view_hooks() {
213
+ // Hooks go here when a view is loaded
214
+ }
215
 
216
  public static function load_multisite_hooks() {
217
  add_action( 'wpmu_upgrade_site', 'FrmAppController::network_upgrade_site' );
218
 
219
+ // drop tables when mu site is deleted
220
+ add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
221
+ }
222
  }
classes/controllers/FrmSettingsController.php CHANGED
@@ -2,71 +2,39 @@
2
 
3
  class FrmSettingsController {
4
 
5
- public static function menu() {
6
  // Make sure admins can see the menu items
7
  FrmAppHelper::force_capability( 'frm_change_settings' );
8
 
9
- add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' );
10
- }
11
 
12
- public static function license_box() {
13
  $a = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
14
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' );
15
- }
16
 
17
- public static function display_form( $errors = array(), $message = '' ) {
18
- global $frm_vars;
19
 
20
- $frm_settings = FrmAppHelper::get_settings();
 
21
 
22
- $uploads = wp_upload_dir();
23
- $target_path = $uploads['basedir'] . '/formidable/css';
24
 
25
  $sections = self::get_settings_tabs();
26
 
 
 
27
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' );
28
  }
29
 
30
  private static function get_settings_tabs() {
31
- $sections = array(
32
- 'general' => array(
33
- 'class' => __CLASS__,
34
- 'function' => 'general_settings',
35
- 'name' => __( 'General Settings', 'formidable' ),
36
- 'icon' => 'frm_icon_font frm_settings_icon',
37
- ),
38
- 'messages' => array(
39
- 'class' => __CLASS__,
40
- 'function' => 'message_settings',
41
- 'name' => __( 'Message Defaults', 'formidable' ),
42
- 'icon' => 'frm_icon_font frm_stamp_icon',
43
- ),
44
- 'permissions' => array(
45
- 'class' => __CLASS__,
46
- 'function' => 'permission_settings',
47
- 'name' => __( 'Permissions', 'formidable' ),
48
- 'icon' => 'frm_icon_font frm_lock_icon',
49
- ),
50
- 'recaptcha' => array(
51
- 'class' => __CLASS__,
52
- 'function' => 'recaptcha_settings',
53
- 'name' => __( 'reCaptcha', 'formidable' ),
54
- 'icon' => 'frm_icon_font frm_shield_check_icon',
55
- ),
56
- 'white_label' => array(
57
- 'name' => __( 'White Labeling', 'formidable' ),
58
- 'icon' => 'frm_icon_font frm_ghost_icon',
59
- 'html_class' => 'frm_show_upgrade frm_noallow',
60
- 'data' => array(
61
- 'medium' => 'white-label',
62
- 'upgrade' => __( 'White labeling options', 'formidable' ),
63
- ),
64
- ),
65
- );
66
-
67
  if ( apply_filters( 'frm_include_addon_page', false ) ) {
68
  // if no addons need a license, skip this page
69
- $show_licenses = false;
70
  $installed_addons = apply_filters( 'frm_installed_addons', array() );
71
  foreach ( $installed_addons as $installed_addon ) {
72
  if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' ) {
@@ -80,31 +48,12 @@ class FrmSettingsController {
80
  'class' => 'FrmAddonsController',
81
  'function' => 'license_settings',
82
  'name' => __( 'Plugin Licenses', 'formidable' ),
83
- 'icon' => 'frm_icon_font frm_keyalt_icon',
84
  'ajax' => true,
85
  );
86
  }
87
  }
88
  $sections = apply_filters( 'frm_add_settings_section', $sections );
89
 
90
- foreach ( $sections as $key => $section ) {
91
- $defaults = array(
92
- 'html_class' => '',
93
- 'name' => ucfirst( $key ),
94
- 'icon' => 'frm_icon_font frm_settings_icon',
95
- 'anchor' => $key . '_settings',
96
- 'data' => array(),
97
- );
98
-
99
- $section = array_merge( $defaults, $section );
100
-
101
- if ( isset( $section['ajax'] ) && ! isset( $section['data']['frmajax'] ) ) {
102
- $section['data']['frmajax'] = $section['ajax'];
103
- }
104
-
105
- $sections[ $key ] = $section;
106
- }
107
-
108
  return $sections;
109
  }
110
 
@@ -112,7 +61,7 @@ class FrmSettingsController {
112
  FrmAppHelper::permission_check( 'frm_change_settings' );
113
  check_ajax_referer( 'frm_ajax', 'nonce' );
114
 
115
- $section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' );
116
  $sections = self::get_settings_tabs();
117
  if ( ! isset( $sections[ $section ] ) ) {
118
  wp_die();
@@ -128,91 +77,49 @@ class FrmSettingsController {
128
  wp_die();
129
  }
130
 
131
- /**
132
- * @since 4.0
133
- */
134
- public static function general_settings() {
135
- $frm_settings = FrmAppHelper::get_settings();
136
-
137
- $uploads = wp_upload_dir();
138
- $target_path = $uploads['basedir'] . '/formidable/css';
139
-
140
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/general.php' );
141
- }
142
-
143
- /**
144
- * @since 4.0
145
- */
146
- public static function message_settings() {
147
- $frm_settings = FrmAppHelper::get_settings();
148
-
149
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/messages.php' );
150
- }
151
-
152
- /**
153
- * @since 4.0
154
- */
155
- public static function recaptcha_settings() {
156
- $frm_settings = FrmAppHelper::get_settings();
157
- $captcha_lang = FrmAppHelper::locales( 'captcha' );
158
-
159
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/recaptcha.php' );
160
- }
161
-
162
- /**
163
- * @since 4.0
164
- */
165
- public static function permission_settings() {
166
- $frm_settings = FrmAppHelper::get_settings();
167
- $frm_roles = FrmAppHelper::frm_capabilities();
168
-
169
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/permissions.php' );
170
- }
171
-
172
- public static function process_form( $stop_load = false ) {
173
- global $frm_vars;
174
 
175
- $frm_settings = FrmAppHelper::get_settings();
176
 
177
  $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
178
  if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
179
  wp_die( esc_html( $frm_settings->admin_permission ) );
180
- }
181
 
182
- $errors = array();
183
- $message = '';
184
 
185
- if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) {
186
- $errors = $frm_settings->validate( $_POST, array() );
187
 
188
- $frm_settings->update( stripslashes_deep( $_POST ) );
189
 
190
- if ( empty( $errors ) ) {
191
- $frm_settings->store();
192
- $message = __( 'Settings Saved', 'formidable' );
193
- }
194
- } else {
195
- $message = __( 'Settings Saved', 'formidable' );
196
- }
197
 
198
  if ( $stop_load == 'stop_load' ) {
199
- $frm_vars['settings_routed'] = true;
 
 
200
 
201
- return;
202
- }
203
-
204
- self::display_form( $errors, $message );
205
- }
206
 
207
- public static function route( $stop_load = false ) {
208
- $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
209
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
210
- if ( $action == 'process-form' ) {
211
  self::process_form( $stop_load );
212
- } elseif ( $stop_load != 'stop_load' ) {
213
  self::display_form();
214
- }
215
- }
216
 
217
  /**
218
  * Add CTA to the bottom on the plugin settings pages.
2
 
3
  class FrmSettingsController {
4
 
5
+ public static function menu() {
6
  // Make sure admins can see the menu items
7
  FrmAppHelper::force_capability( 'frm_change_settings' );
8
 
9
+ add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' );
10
+ }
11
 
12
+ public static function license_box() {
13
  $a = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
14
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' );
15
+ }
16
 
17
+ public static function display_form( $errors = array(), $message = '' ) {
18
+ global $frm_vars;
19
 
20
+ $frm_settings = FrmAppHelper::get_settings();
21
+ $frm_roles = FrmAppHelper::frm_capabilities();
22
 
23
+ $uploads = wp_upload_dir();
24
+ $target_path = $uploads['basedir'] . '/formidable/css';
25
 
26
  $sections = self::get_settings_tabs();
27
 
28
+ $captcha_lang = FrmAppHelper::locales( 'captcha' );
29
+
30
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' );
31
  }
32
 
33
  private static function get_settings_tabs() {
34
+ $sections = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  if ( apply_filters( 'frm_include_addon_page', false ) ) {
36
  // if no addons need a license, skip this page
37
+ $show_licenses = false;
38
  $installed_addons = apply_filters( 'frm_installed_addons', array() );
39
  foreach ( $installed_addons as $installed_addon ) {
40
  if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' ) {
48
  'class' => 'FrmAddonsController',
49
  'function' => 'license_settings',
50
  'name' => __( 'Plugin Licenses', 'formidable' ),
 
51
  'ajax' => true,
52
  );
53
  }
54
  }
55
  $sections = apply_filters( 'frm_add_settings_section', $sections );
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  return $sections;
58
  }
59
 
61
  FrmAppHelper::permission_check( 'frm_change_settings' );
62
  check_ajax_referer( 'frm_ajax', 'nonce' );
63
 
64
+ $section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' );
65
  $sections = self::get_settings_tabs();
66
  if ( ! isset( $sections[ $section ] ) ) {
67
  wp_die();
77
  wp_die();
78
  }
79
 
80
+ public static function process_form( $stop_load = false ) {
81
+ global $frm_vars;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
+ $frm_settings = FrmAppHelper::get_settings();
84
 
85
  $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
86
  if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
87
  wp_die( esc_html( $frm_settings->admin_permission ) );
88
+ }
89
 
90
+ $errors = array();
91
+ $message = '';
92
 
93
+ if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) {
94
+ $errors = $frm_settings->validate( $_POST, array() );
95
 
96
+ $frm_settings->update( stripslashes_deep( $_POST ) );
97
 
98
+ if ( empty( $errors ) ) {
99
+ $frm_settings->store();
100
+ $message = __( 'Settings Saved', 'formidable' );
101
+ }
102
+ } else {
103
+ $message = __( 'Settings Saved', 'formidable' );
104
+ }
105
 
106
  if ( $stop_load == 'stop_load' ) {
107
+ $frm_vars['settings_routed'] = true;
108
+ return;
109
+ }
110
 
111
+ self::display_form( $errors, $message );
112
+ }
 
 
 
113
 
114
+ public static function route( $stop_load = false ) {
115
+ $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
116
  $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
117
+ if ( $action == 'process-form' ) {
118
  self::process_form( $stop_load );
119
+ } else if ( $stop_load != 'stop_load' ) {
120
  self::display_form();
121
+ }
122
+ }
123
 
124
  /**
125
  * Add CTA to the bottom on the plugin settings pages.
classes/controllers/FrmSimpleBlocksController.php CHANGED
@@ -16,16 +16,16 @@ class FrmSimpleBlocksController {
16
  true
17
  );
18
 
19
- $icon = str_replace( 'dashicons-', '', apply_filters( 'frm_icon', 'svg' ) );
20
  $block_name = FrmAppHelper::get_menu_name();
21
  if ( $block_name === 'Formidable' ) {
22
  $block_name = 'Formidable Forms';
23
  }
24
 
25
  $script_vars = array(
26
- 'forms' => self::get_forms_options(),
27
- 'icon' => $icon,
28
- 'name' => $block_name,
29
  );
30
 
31
  wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars );
@@ -134,7 +134,6 @@ class FrmSimpleBlocksController {
134
  unset( $params['formId'] );
135
 
136
  $form = FrmFormsController::get_form_shortcode( $params );
137
-
138
  return str_replace( ' frm_logic_form ', ' ', $form ); // prevent the form from hiding
139
  }
140
  }
16
  true
17
  );
18
 
19
+ $icon = str_replace( 'dashicons-', '', apply_filters( 'frm_icon', 'svg' ) );
20
  $block_name = FrmAppHelper::get_menu_name();
21
  if ( $block_name === 'Formidable' ) {
22
  $block_name = 'Formidable Forms';
23
  }
24
 
25
  $script_vars = array(
26
+ 'forms' => self::get_forms_options(),
27
+ 'icon' => $icon,
28
+ 'name' => $block_name,
29
  );
30
 
31
  wp_localize_script( 'formidable-form-selector', 'formidable_form_selector', $script_vars );
134
  unset( $params['formId'] );
135
 
136
  $form = FrmFormsController::get_form_shortcode( $params );
 
137
  return str_replace( ' frm_logic_form ', ' ', $form ); // prevent the form from hiding
138
  }
139
  }
classes/controllers/FrmStylesController.php CHANGED
@@ -1,58 +1,58 @@
1
  <?php
2
 
3
  class FrmStylesController {
4
- public static $post_type = 'frm_styles';
5
- public static $screen = 'formidable_page_formidable-styles';
6
 
7
- public static function load_pro_hooks() {
8
- if ( FrmAppHelper::pro_is_installed() ) {
9
- FrmProStylesController::load_pro_hooks();
10
- }
11
- }
12
 
13
- public static function register_post_types() {
14
  register_post_type(
15
  self::$post_type,
16
  array(
17
- 'label' => __( 'Styles', 'formidable' ),
18
- 'public' => false,
19
- 'show_ui' => false,
20
  'capability_type' => 'page',
21
- 'capabilities' => array(
22
- 'edit_post' => 'frm_change_settings',
23
- 'edit_posts' => 'frm_change_settings',
24
- 'edit_others_posts' => 'frm_change_settings',
25
- 'publish_posts' => 'frm_change_settings',
26
- 'delete_post' => 'frm_change_settings',
27
- 'delete_posts' => 'frm_change_settings',
28
  'read_private_posts' => 'read_private_posts',
29
  ),
30
- 'supports' => array(
31
  'title',
32
  ),
33
- 'has_archive' => false,
34
- 'labels' => array(
35
- 'name' => __( 'Styles', 'formidable' ),
36
  'singular_name' => __( 'Style', 'formidable' ),
37
- 'menu_name' => __( 'Style', 'formidable' ),
38
- 'edit' => __( 'Edit', 'formidable' ),
39
- 'add_new_item' => __( 'Create a New Style', 'formidable' ),
40
- 'edit_item' => __( 'Edit Style', 'formidable' ),
41
  ),
42
  )
43
  );
44
- }
45
 
46
- public static function menu() {
47
  add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
48
- }
49
 
50
  public static function admin_init() {
51
  if ( ! FrmAppHelper::is_admin_page( 'formidable-styles' ) ) {
52
  return;
53
  }
54
 
55
- self::load_pro_hooks();
56
 
57
  $style_tab = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
58
  if ( $style_tab == 'manage' || $style_tab == 'custom_css' ) {
@@ -66,10 +66,10 @@ class FrmStylesController {
66
  wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
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 ), array(), $version );
71
- }
72
- }
73
 
74
  /**
75
  * @param string $register Either 'enqueue' or 'register'.
@@ -79,7 +79,7 @@ class FrmStylesController {
79
  global $frm_vars;
80
 
81
  $register_css = ( $register == 'register' );
82
- $should_load = $force || ( ( $frm_vars['load_css'] || $register_css ) && ! FrmAppHelper::is_admin() );
83
 
84
  if ( $should_load ) {
85
 
@@ -148,11 +148,10 @@ class FrmStylesController {
148
  public static function get_file_name() {
149
  if ( is_multisite() ) {
150
  $blog_id = get_current_blog_id();
151
- $name = 'formidableforms' . absint( $blog_id ) . '.css';
152
  } else {
153
  $name = 'formidableforms.css';
154
  }
155
-
156
  return $name;
157
  }
158
 
@@ -165,7 +164,6 @@ class FrmStylesController {
165
  } else {
166
  $this_version = $version;
167
  }
168
-
169
  return $this_version;
170
  }
171
 
@@ -176,7 +174,6 @@ class FrmStylesController {
176
  $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
177
  }
178
  }
179
-
180
  return $tag;
181
  }
182
 
@@ -200,17 +197,17 @@ class FrmStylesController {
200
  $style = 'default';
201
  } else {
202
  $frm_style = new FrmStyle( $style_id );
203
- $style = $frm_style->get_one();
204
- $style = $style->ID;
205
  }
206
 
207
  self::load_styler( $style, $message );
208
  }
209
 
210
  public static function save() {
211
- $frm_style = new FrmStyle();
212
- $message = '';
213
- $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
214
  $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
215
 
216
  if ( $post_id !== false && wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
@@ -228,10 +225,10 @@ class FrmStylesController {
228
  }
229
 
230
  public static function load_styler( $style, $message = '' ) {
231
- global $frm_settings;
232
 
233
- $frm_style = new FrmStyle();
234
- $styles = $frm_style->get_all();
235
 
236
  if ( is_numeric( $style ) ) {
237
  $style = $styles[ $style ];
@@ -239,18 +236,18 @@ class FrmStylesController {
239
  $style = $frm_style->get_default_style( $styles );
240
  }
241
 
242
- self::add_meta_boxes();
243
 
244
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/show.php' );
245
- }
246
 
247
  /**
248
  * @param string $message
249
  * @param array|object $forms
250
  */
251
  private static function manage( $message = '', $forms = array() ) {
252
- $frm_style = new FrmStyle();
253
- $styles = $frm_style->get_all();
254
  $default_style = $frm_style->get_default_style( $styles );
255
 
256
  if ( empty( $forms ) ) {
@@ -260,48 +257,45 @@ class FrmStylesController {
260
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php' );
261
  }
262
 
263
- private static function manage_styles() {
264
  $style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' );
265
  if ( ! $_POST || ! isset( $_POST['style'] ) || ! wp_verify_nonce( $style_nonce, 'frm_manage_style_nonce' ) ) {
266
- return self::manage();
267
- }
268
 
269
- global $wpdb;
270
 
271
  $forms = FrmForm::get_published_forms();
272
- foreach ( $forms as $form ) {
273
- $new_style = ( isset( $_POST['style'] ) && isset( $_POST['style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ) : '';
274
- $previous_style = ( isset( $_POST['prev_style'] ) && isset( $_POST['prev_style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['prev_style'][ $form->id ] ) ) : '';
275
- if ( $new_style == $previous_style ) {
276
- continue;
277
- }
278
 
279
- $form->options['custom_style'] = $new_style;
280
 
281
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
282
  unset( $form );
283
- }
284
-
285
- $message = __( 'Your form styles have been saved.', 'formidable' );
286
 
 
287
  return self::manage( $message, $forms );
288
- }
289
 
290
- public static function custom_css( $message = '', $style = null ) {
291
  if ( function_exists( 'wp_enqueue_code_editor' ) ) {
292
- $id = 'frm_codemirror_box';
293
  $settings = wp_enqueue_code_editor(
294
  array(
295
- 'type' => 'text/css',
296
  'codemirror' => array(
297
  'indentUnit' => 2,
298
- 'tabSize' => 2,
299
  ),
300
  )
301
  );
302
  } else {
303
- $id = 'frm_custom_css_box';
304
- $settings = array();
305
  $codemirror = '4.7';
306
  wp_enqueue_style( 'codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css', array(), $codemirror );
307
  wp_enqueue_script( 'codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), $codemirror );
@@ -310,7 +304,7 @@ class FrmStylesController {
310
 
311
  if ( ! isset( $style ) ) {
312
  $frm_style = new FrmStyle();
313
- $style = $frm_style->get_default_style();
314
  }
315
 
316
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php' );
@@ -321,7 +315,7 @@ class FrmStylesController {
321
 
322
  $message = '';
323
  $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_text_field' );
324
- $nonce = FrmAppHelper::get_post_param( 'frm_custom_css', '', 'sanitize_text_field' );
325
  if ( wp_verify_nonce( $nonce, 'frm_custom_css_nonce' ) ) {
326
  $frm_style->update( $post_id );
327
  $message = __( 'Your styling settings have been saved.', 'formidable' );
@@ -330,48 +324,48 @@ class FrmStylesController {
330
  return self::custom_css( $message );
331
  }
332
 
333
- public static function route() {
334
  $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
335
 
336
- switch ( $action ) {
337
- case 'edit':
338
- case 'save':
339
- case 'manage':
340
- case 'manage_styles':
341
- case 'custom_css':
342
- case 'save_css':
343
  return self::$action();
344
- default:
345
- do_action( 'frm_style_action_route', $action );
346
- if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
347
- return;
348
- }
349
 
350
- if ( 'new_style' == $action || 'duplicate' == $action ) {
351
- return self::$action();
352
- }
353
 
354
- return self::edit();
355
- }
356
- }
357
 
358
- public static function reset_styling() {
359
  FrmAppHelper::permission_check( 'frm_change_settings' );
360
- check_ajax_referer( 'frm_ajax', 'nonce' );
361
 
362
- $frm_style = new FrmStyle();
363
- $defaults = $frm_style->get_defaults();
364
 
365
- echo json_encode( $defaults );
366
- wp_die();
367
- }
368
 
369
  public static function change_styling() {
370
  check_ajax_referer( 'frm_ajax', 'nonce' );
371
 
372
  $frm_style = new FrmStyle();
373
- $defaults = $frm_style->get_defaults();
374
- $style = '';
375
 
376
  echo '<style type="text/css">';
377
  include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
@@ -379,21 +373,21 @@ class FrmStylesController {
379
  wp_die();
380
  }
381
 
382
- private static function add_meta_boxes() {
383
-
384
- // setup meta boxes
385
- $meta_boxes = array(
386
- 'general' => __( 'General', 'formidable' ),
387
- 'form-title' => __( 'Form Title', 'formidable' ),
388
- 'form-description' => __( 'Form Description', 'formidable' ),
389
- 'field-labels' => __( 'Field Labels', 'formidable' ),
390
- 'field-description' => __( 'Field Description', 'formidable' ),
391
- 'field-colors' => __( 'Field Colors', 'formidable' ),
392
- 'field-sizes' => __( 'Field Settings', 'formidable' ),
393
- 'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ),
394
- 'buttons' => __( 'Buttons', 'formidable' ),
395
- 'form-messages' => __( 'Form Messages', 'formidable' ),
396
- );
397
 
398
  /**
399
  * Add custom boxes to the styling settings
@@ -414,7 +408,7 @@ class FrmStylesController {
414
  FrmStylesHelper::prepare_color_output( $style->post_content, false );
415
 
416
  $current_tab = FrmAppHelper::simple_get( 'page-tab', 'sanitize_title', 'default' );
417
- $file_name = FrmAppHelper::plugin_path() . '/classes/views/styles/_' . $sec['args'] . '.php';
418
 
419
  /**
420
  * Set the location of custom styling settings right before
@@ -425,21 +419,19 @@ class FrmStylesController {
425
  */
426
  $file_name = apply_filters( 'frm_style_settings_' . $sec['args'], $file_name );
427
 
428
- echo '<div class="frm_grid_container">';
429
  include( $file_name );
430
- echo '</div>';
431
- }
432
 
433
- public static function load_css() {
434
  header( 'Content-type: text/css' );
435
 
436
- $frm_style = new FrmStyle();
437
- $defaults = $frm_style->get_defaults();
438
- $style = '';
439
 
440
  include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
441
- wp_die();
442
- }
443
 
444
  public static function load_saved_css() {
445
  $css = get_transient( 'frmpro_css' );
@@ -448,60 +440,57 @@ class FrmStylesController {
448
  wp_die();
449
  }
450
 
451
- /**
452
- * Check if the Formidable styling should be loaded,
453
- * then enqueue it for the footer
454
  *
455
- * @since 2.0
456
- */
457
- public static function enqueue_style() {
458
- global $frm_vars;
459
-
460
- if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
461
- // The CSS has already been loaded.
462
- return;
463
- }
464
-
465
- $frm_settings = FrmAppHelper::get_settings();
466
- if ( $frm_settings->load_style != 'none' ) {
467
- wp_enqueue_style( 'formidable' );
468
- $frm_vars['css_loaded'] = true;
469
- }
470
- }
471
-
472
- /**
473
- * Get the stylesheets for the form settings page
474
- */
475
- public static function get_style_opts() {
476
- $frm_style = new FrmStyle();
477
- $styles = $frm_style->get_all();
478
-
479
- return $styles;
480
- }
481
-
482
- public static function get_form_style( $form = 'default' ) {
483
- $style = FrmFormsHelper::get_form_style( $form );
484
-
485
- if ( empty( $style ) || 1 == $style ) {
486
- $style = 'default';
487
- }
488
-
489
- $frm_style = new FrmStyle( $style );
490
-
491
- return $frm_style->get_one();
492
- }
493
-
494
- /**
495
- * @param string $class
496
- * @param string $style
497
- */
498
  public static function get_form_style_class( $class, $style ) {
499
  if ( 1 == $style ) {
500
  $style = 'default';
501
  }
502
 
503
  $frm_style = new FrmStyle( $style );
504
- $style = $frm_style->get_one();
505
 
506
  if ( $style ) {
507
  $class .= ' frm_style_' . $style->post_name;
@@ -524,9 +513,9 @@ class FrmStylesController {
524
  }
525
  }
526
 
527
- /**
528
- * @param string $val
529
- */
530
  public static function get_style_val( $val, $form = 'default' ) {
531
  $style = self::get_form_style( $form );
532
  if ( $style && isset( $style->post_content[ $val ] ) ) {
@@ -536,33 +525,89 @@ class FrmStylesController {
536
 
537
  public static function show_entry_styles( $default_styles ) {
538
  $frm_style = new FrmStyle( 'default' );
539
- $style = $frm_style->get_one();
540
-
541
- if ( ! $style ) {
542
- return $default_styles;
543
- }
544
-
545
- foreach ( $default_styles as $name => $val ) {
546
- $setting = $name;
547
- if ( 'border_width' == $name ) {
548
- $setting = 'field_border_width';
549
- } elseif ( 'alt_bg_color' == $name ) {
550
- $setting = 'bg_color_active';
551
- }
552
- $default_styles[ $name ] = $style->post_content[ $setting ];
553
  unset( $name, $val );
554
- }
555
 
556
- return $default_styles;
557
- }
558
 
559
  public static function &important_style( $important, $field ) {
560
  $important = self::get_style_val( 'important_style', $field['form_id'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561
 
562
- return $important;
563
- }
564
-
565
- public static function do_accordion_sections( $screen, $context, $object ) {
566
- return do_accordion_sections( $screen, $context, $object );
567
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  }
1
  <?php
2
 
3
  class FrmStylesController {
4
+ public static $post_type = 'frm_styles';
5
+ public static $screen = 'formidable_page_formidable-styles';
6
 
7
+ public static function load_pro_hooks() {
8
+ if ( FrmAppHelper::pro_is_installed() ) {
9
+ FrmProStylesController::load_pro_hooks();
10
+ }
11
+ }
12
 
13
+ public static function register_post_types() {
14
  register_post_type(
15
  self::$post_type,
16
  array(
17
+ 'label' => __( 'Styles', 'formidable' ),
18
+ 'public' => false,
19
+ 'show_ui' => false,
20
  'capability_type' => 'page',
21
+ 'capabilities' => array(
22
+ 'edit_post' => 'frm_change_settings',
23
+ 'edit_posts' => 'frm_change_settings',
24
+ 'edit_others_posts' => 'frm_change_settings',
25
+ 'publish_posts' => 'frm_change_settings',
26
+ 'delete_post' => 'frm_change_settings',
27
+ 'delete_posts' => 'frm_change_settings',
28
  'read_private_posts' => 'read_private_posts',
29
  ),
30
+ 'supports' => array(
31
  'title',
32
  ),
33
+ 'has_archive' => false,
34
+ 'labels' => array(
35
+ 'name' => __( 'Styles', 'formidable' ),
36
  'singular_name' => __( 'Style', 'formidable' ),
37
+ 'menu_name' => __( 'Style', 'formidable' ),
38
+ 'edit' => __( 'Edit', 'formidable' ),
39
+ 'add_new_item' => __( 'Create a New Style', 'formidable' ),
40
+ 'edit_item' => __( 'Edit Style', 'formidable' ),
41
  ),
42
  )
43
  );
44
+ }
45
 
46
+ public static function menu() {
47
  add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
48
+ }
49
 
50
  public static function admin_init() {
51
  if ( ! FrmAppHelper::is_admin_page( 'formidable-styles' ) ) {
52
  return;
53
  }
54
 
55
+ self::load_pro_hooks();
56
 
57
  $style_tab = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
58
  if ( $style_tab == 'manage' || $style_tab == 'custom_css' ) {
66
  wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
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 ), array(), $version );
71
+ }
72
+ }
73
 
74
  /**
75
  * @param string $register Either 'enqueue' or 'register'.
79
  global $frm_vars;
80
 
81
  $register_css = ( $register == 'register' );
82
+ $should_load = $force || ( ( $frm_vars['load_css'] || $register_css ) && ! FrmAppHelper::is_admin() );
83
 
84
  if ( $should_load ) {
85
 
148
  public static function get_file_name() {
149
  if ( is_multisite() ) {
150
  $blog_id = get_current_blog_id();
151
+ $name = 'formidableforms' . absint( $blog_id ) . '.css';
152
  } else {
153
  $name = 'formidableforms.css';
154
  }
 
155
  return $name;
156
  }
157
 
164
  } else {
165
  $this_version = $version;
166
  }
 
167
  return $this_version;
168
  }
169
 
174
  $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
175
  }
176
  }
 
177
  return $tag;
178
  }
179
 
197
  $style = 'default';
198
  } else {
199
  $frm_style = new FrmStyle( $style_id );
200
+ $style = $frm_style->get_one();
201
+ $style = $style->ID;
202
  }
203
 
204
  self::load_styler( $style, $message );
205
  }
206
 
207
  public static function save() {
208
+ $frm_style = new FrmStyle();
209
+ $message = '';
210
+ $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
211
  $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
212
 
213
  if ( $post_id !== false && wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
225
  }
226
 
227
  public static function load_styler( $style, $message = '' ) {
228
+ global $frm_settings;
229
 
230
+ $frm_style = new FrmStyle();
231
+ $styles = $frm_style->get_all();
232
 
233
  if ( is_numeric( $style ) ) {
234
  $style = $styles[ $style ];
236
  $style = $frm_style->get_default_style( $styles );
237
  }
238
 
239
+ self::add_meta_boxes();
240
 
241
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/show.php' );
242
+ }
243
 
244
  /**
245
  * @param string $message
246
  * @param array|object $forms
247
  */
248
  private static function manage( $message = '', $forms = array() ) {
249
+ $frm_style = new FrmStyle();
250
+ $styles = $frm_style->get_all();
251
  $default_style = $frm_style->get_default_style( $styles );
252
 
253
  if ( empty( $forms ) ) {
257
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php' );
258
  }
259
 
260
+ private static function manage_styles() {
261
  $style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' );
262
  if ( ! $_POST || ! isset( $_POST['style'] ) || ! wp_verify_nonce( $style_nonce, 'frm_manage_style_nonce' ) ) {
263
+ return self::manage();
264
+ }
265
 
266
+ global $wpdb;
267
 
268
  $forms = FrmForm::get_published_forms();
269
+ foreach ( $forms as $form ) {
270
+ if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) {
271
+ continue;
272
+ }
 
 
273
 
274
+ $form->options['custom_style'] = $_POST['style'][ $form->id ];
275
 
276
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
277
  unset( $form );
278
+ }
 
 
279
 
280
+ $message = __( 'Your form styles have been saved.', 'formidable' );
281
  return self::manage( $message, $forms );
282
+ }
283
 
284
+ public static function custom_css( $message = '', $style = null ) {
285
  if ( function_exists( 'wp_enqueue_code_editor' ) ) {
286
+ $id = 'frm_codemirror_box';
287
  $settings = wp_enqueue_code_editor(
288
  array(
289
+ 'type' => 'text/css',
290
  'codemirror' => array(
291
  'indentUnit' => 2,
292
+ 'tabSize' => 2,
293
  ),
294
  )
295
  );
296
  } else {
297
+ $id = 'frm_custom_css_box';
298
+ $settings = array();
299
  $codemirror = '4.7';
300
  wp_enqueue_style( 'codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css', array(), $codemirror );
301
  wp_enqueue_script( 'codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), $codemirror );
304
 
305
  if ( ! isset( $style ) ) {
306
  $frm_style = new FrmStyle();
307
+ $style = $frm_style->get_default_style();
308
  }
309
 
310
  include( FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php' );
315
 
316
  $message = '';
317
  $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_text_field' );
318
+ $nonce = FrmAppHelper::get_post_param( 'frm_custom_css', '', 'sanitize_text_field' );
319
  if ( wp_verify_nonce( $nonce, 'frm_custom_css_nonce' ) ) {
320
  $frm_style->update( $post_id );
321
  $message = __( 'Your styling settings have been saved.', 'formidable' );
324
  return self::custom_css( $message );
325
  }
326
 
327
+ public static function route() {
328
  $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
329
 
330
+ switch ( $action ) {
331
+ case 'edit':
332
+ case 'save':
333
+ case 'manage':
334
+ case 'manage_styles':
335
+ case 'custom_css':
336
+ case 'save_css':
337
  return self::$action();
338
+ default:
339
+ do_action( 'frm_style_action_route', $action );
340
+ if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
341
+ return;
342
+ }
343
 
344
+ if ( 'new_style' == $action || 'duplicate' == $action ) {
345
+ return self::$action();
346
+ }
347
 
348
+ return self::edit();
349
+ }
350
+ }
351
 
352
+ public static function reset_styling() {
353
  FrmAppHelper::permission_check( 'frm_change_settings' );
354
+ check_ajax_referer( 'frm_ajax', 'nonce' );
355
 
356
+ $frm_style = new FrmStyle();
357
+ $defaults = $frm_style->get_defaults();
358
 
359
+ echo json_encode( $defaults );
360
+ wp_die();
361
+ }
362
 
363
  public static function change_styling() {
364
  check_ajax_referer( 'frm_ajax', 'nonce' );
365
 
366
  $frm_style = new FrmStyle();
367
+ $defaults = $frm_style->get_defaults();
368
+ $style = '';
369
 
370
  echo '<style type="text/css">';
371
  include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
373
  wp_die();
374
  }
375
 
376
+ private static function add_meta_boxes() {
377
+
378
+ // setup meta boxes
379
+ $meta_boxes = array(
380
+ 'general' => __( 'General', 'formidable' ),
381
+ 'form-title' => __( 'Form Title', 'formidable' ),
382
+ 'form-description' => __( 'Form Description', 'formidable' ),
383
+ 'field-labels' => __( 'Field Labels', 'formidable' ),
384
+ 'field-description' => __( 'Field Description', 'formidable' ),
385
+ 'field-colors' => __( 'Field Colors', 'formidable' ),
386
+ 'field-sizes' => __( 'Field Settings', 'formidable' ),
387
+ 'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ),
388
+ 'buttons' => __( 'Buttons', 'formidable' ),
389
+ 'form-messages' => __( 'Form Messages', 'formidable' ),
390
+ );
391
 
392
  /**
393
  * Add custom boxes to the styling settings
408
  FrmStylesHelper::prepare_color_output( $style->post_content, false );
409
 
410
  $current_tab = FrmAppHelper::simple_get( 'page-tab', 'sanitize_title', 'default' );
411
+ $file_name = FrmAppHelper::plugin_path() . '/classes/views/styles/_' . $sec['args'] . '.php';
412
 
413
  /**
414
  * Set the location of custom styling settings right before
419
  */
420
  $file_name = apply_filters( 'frm_style_settings_' . $sec['args'], $file_name );
421
 
 
422
  include( $file_name );
423
+ }
 
424
 
425
+ public static function load_css() {
426
  header( 'Content-type: text/css' );
427
 
428
+ $frm_style = new FrmStyle();
429
+ $defaults = $frm_style->get_defaults();
430
+ $style = '';
431
 
432
  include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
433
+ wp_die();
434
+ }
435
 
436
  public static function load_saved_css() {
437
  $css = get_transient( 'frmpro_css' );
440
  wp_die();
441
  }
442
 
443
+ /**
444
+ * Check if the Formidable styling should be loaded,
445
+ * then enqueue it for the footer
446
  *
447
+ * @since 2.0
448
+ */
449
+ public static function enqueue_style() {
450
+ global $frm_vars;
451
+
452
+ if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
453
+ // the CSS has already been loaded
454
+ return;
455
+ }
456
+
457
+ $frm_settings = FrmAppHelper::get_settings();
458
+ if ( $frm_settings->load_style != 'none' ) {
459
+ wp_enqueue_style( 'formidable' );
460
+ $frm_vars['css_loaded'] = true;
461
+ }
462
+ }
463
+
464
+ // Get the stylesheets for the form settings page
465
+ public static function get_style_opts() {
466
+ $frm_style = new FrmStyle();
467
+ $styles = $frm_style->get_all();
468
+
469
+ return $styles;
470
+ }
471
+
472
+ public static function get_form_style( $form = 'default' ) {
473
+ $style = FrmFormsHelper::get_form_style( $form );
474
+
475
+ if ( empty( $style ) || 1 == $style ) {
476
+ $style = 'default';
477
+ }
478
+
479
+ $frm_style = new FrmStyle( $style );
480
+ return $frm_style->get_one();
481
+ }
482
+
483
+ /**
484
+ * @param string $class
485
+ * @param string $style
486
+ */
 
 
 
487
  public static function get_form_style_class( $class, $style ) {
488
  if ( 1 == $style ) {
489
  $style = 'default';
490
  }
491
 
492
  $frm_style = new FrmStyle( $style );
493
+ $style = $frm_style->get_one();
494
 
495
  if ( $style ) {
496
  $class .= ' frm_style_' . $style->post_name;
513
  }
514
  }
515
 
516
+ /**
517
+ * @param string $val
518
+ */
519
  public static function get_style_val( $val, $form = 'default' ) {
520
  $style = self::get_form_style( $form );
521
  if ( $style && isset( $style->post_content[ $val ] ) ) {
525
 
526
  public static function show_entry_styles( $default_styles ) {
527
  $frm_style = new FrmStyle( 'default' );
528
+ $style = $frm_style->get_one();
529
+
530
+ if ( ! $style ) {
531
+ return $default_styles;
532
+ }
533
+
534
+ foreach ( $default_styles as $name => $val ) {
535
+ $setting = $name;
536
+ if ( 'border_width' == $name ) {
537
+ $setting = 'field_border_width';
538
+ } else if ( 'alt_bg_color' == $name ) {
539
+ $setting = 'bg_color_active';
540
+ }
541
+ $default_styles[ $name ] = $style->post_content[ $setting ];
542
  unset( $name, $val );
543
+ }
544
 
545
+ return $default_styles;
546
+ }
547
 
548
  public static function &important_style( $important, $field ) {
549
  $important = self::get_style_val( 'important_style', $field['form_id'] );
550
+ return $important;
551
+ }
552
+
553
+ /**
554
+ * Fallback for WP < 3.6
555
+ */
556
+ public static function do_accordion_sections( $screen, $context, $object ) {
557
+ if ( function_exists( 'do_accordion_sections' ) ) {
558
+ return do_accordion_sections( $screen, $context, $object );
559
+ }
560
+
561
+ global $wp_meta_boxes;
562
+
563
+ $screen = 'formidable_page_formidable-styles';
564
+ $screen = convert_to_screen( $screen );
565
+
566
+ $page = $screen->id;
567
+
568
+ $hidden = get_hidden_meta_boxes( $screen );
569
+ ?>
570
+ <div id="side-sortables" class="accordion-container">
571
+ <?php
572
+ $i = 0;
573
+ $first_open = false;
574
+ do {
575
+ if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[ $page ] ) || ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
576
+ break;
577
+ }
578
 
579
+ foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
580
+ if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
581
+ foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
582
+ if ( false == $box || ! $box['title'] ) {
583
+ continue;
584
+ }
585
+
586
+ $i++;
587
+ $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
588
+
589
+ if ( ! $first_open && empty( $hidden_class ) ) {
590
+ $first_open = true;
591
+ }
592
+
593
+ ?>
594
+ <div class="postbox <?php echo esc_attr( $box['id'] ); ?>">
595
+ <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ); ?>"><br/></div>
596
+ <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
597
+ <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
598
+ <div class="inside">
599
+ <?php call_user_func( $box['callback'], $object, $box ); ?>
600
+ </div><!-- .inside -->
601
+ </div><!-- .accordion-section-content -->
602
+ </div><!-- .postbox -->
603
+ <?php
604
+ }
605
+ }
606
+ }
607
+ } while ( 0 );
608
+ ?>
609
+ </div><!-- .accordion-container -->
610
+ <?php
611
+ return $i;
612
+ }
613
  }
classes/controllers/FrmXMLController.php CHANGED
@@ -13,7 +13,7 @@ class FrmXMLController {
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() );
19
 
@@ -28,6 +28,7 @@ class FrmXMLController {
28
  libxml_disable_entity_loader( $loader );
29
  }
30
 
 
31
  /**
32
  * Use the template link to install the XML template
33
  *
@@ -57,10 +58,10 @@ class FrmXMLController {
57
  if ( isset( $imported['form_status'] ) && ! empty( $imported['form_status'] ) ) {
58
  // Get the last form id in case there are child forms.
59
  end( $imported['form_status'] );
60
- $form_id = key( $imported['form_status'] );
61
  $response = array(
62
  'id' => $form_id,
63
- 'redirect' => FrmForm::get_edit_link( $form_id ),
64
  'success' => 1,
65
  );
66
  } else {
@@ -79,7 +80,6 @@ class FrmXMLController {
79
  * since we redirect to the last form.
80
  *
81
  * @since 3.06
82
- *
83
  * @param object $xml The values included in the XML.
84
  */
85
  private static function set_new_form_name( &$xml ) {
@@ -103,7 +103,7 @@ class FrmXMLController {
103
  }
104
 
105
  // Use a unique key to prevent editing existing form.
106
- $name = sanitize_title( $form->name );
107
  $form->form_key = FrmAppHelper::get_unique_key( $name, 'frm_forms', 'form_key' );
108
  }
109
  }
@@ -150,14 +150,13 @@ class FrmXMLController {
150
  }
151
 
152
  public static function import_xml() {
153
- $errors = array();
154
  $message = '';
155
 
156
  $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
157
  if ( false !== $permission_error ) {
158
  $errors[] = $permission_error;
159
  self::form( $errors );
160
-
161
  return;
162
  }
163
 
@@ -165,7 +164,6 @@ class FrmXMLController {
165
  if ( ! $has_file ) {
166
  $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
167
  self::form( $errors );
168
-
169
  return;
170
  }
171
 
@@ -175,7 +173,6 @@ class FrmXMLController {
175
  unset( $file );
176
  $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
177
  self::form( $errors );
178
-
179
  return;
180
  }
181
 
@@ -194,7 +191,6 @@ class FrmXMLController {
194
  if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) {
195
  // allow other file types to be imported
196
  do_action( 'frm_before_import_' . $file_type );
197
-
198
  return;
199
  }
200
  unset( $file_type );
@@ -202,12 +198,11 @@ class FrmXMLController {
202
  if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
203
  $errors[] = __( 'XML import is not enabled on your server with the libxml_disable_entity_loader function.', 'formidable' );
204
  self::form( $errors );
205
-
206
  return;
207
  }
208
 
209
  $set_err = libxml_use_internal_errors( true );
210
- $loader = libxml_disable_entity_loader( true );
211
 
212
  $result = FrmXMLHelper::import_xml( $file );
213
  FrmXMLHelper::parse_message( $result, $message, $errors );
@@ -226,8 +221,8 @@ class FrmXMLController {
226
  wp_die( esc_html( $error ) );
227
  }
228
 
229
- $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() );
230
- $type = FrmAppHelper::get_post_param( 'type', array() );
231
  $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
232
 
233
  if ( ! headers_sent() && ! $type ) {
@@ -252,17 +247,17 @@ class FrmXMLController {
252
  self::prepare_types_array( $type );
253
 
254
  $tables = array(
255
- 'items' => $wpdb->prefix . 'frm_items',
256
- 'forms' => $wpdb->prefix . 'frm_forms',
257
- 'posts' => $wpdb->posts,
258
- 'styles' => $wpdb->posts,
259
- 'actions' => $wpdb->posts,
260
  );
261
 
262
  $defaults = array(
263
  'ids' => false,
264
  );
265
- $args = wp_parse_args( $args, $defaults );
266
 
267
  // Make sure ids are numeric.
268
  if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
@@ -273,10 +268,10 @@ class FrmXMLController {
273
 
274
  foreach ( $type as $tb_type ) {
275
  $where = array();
276
- $join = '';
277
  $table = $tables[ $tb_type ];
278
 
279
- $select = $table . '.id';
280
  $query_vars = array();
281
 
282
  switch ( $tb_type ) {
@@ -284,8 +279,8 @@ class FrmXMLController {
284
  //add forms
285
  if ( $args['ids'] ) {
286
  $where[] = array(
287
- 'or' => 1,
288
- $table . '.id' => $args['ids'],
289
  $table . '.parent_form_id' => $args['ids'],
290
  );
291
  } else {
@@ -293,27 +288,27 @@ class FrmXMLController {
293
  }
294
  break;
295
  case 'actions':
296
- $select = $table . '.ID';
297
  $where['post_type'] = FrmFormActionsController::$action_post_type;
298
  if ( ! empty( $args['ids'] ) ) {
299
  $where['menu_order'] = $args['ids'];
300
  }
301
  break;
302
  case 'items':
303
- // $join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
304
  if ( $args['ids'] ) {
305
  $where[ $table . '.form_id' ] = $args['ids'];
306
  }
307
  break;
308
  case 'styles':
309
- // Loop through all exported forms and get their selected style IDs.
310
- $frm_style = new FrmStyle();
311
  $default_style = $frm_style->get_default_style();
312
- $form_ids = $args['ids'];
313
- $style_ids = array();
314
  foreach ( $form_ids as $form_id ) {
315
  $form_data = FrmForm::getOne( $form_id );
316
- // For forms that have not been updated while running 2.0, check if custom_style is set.
317
  if ( isset( $form_data->options['custom_style'] ) ) {
318
  if ( 1 === absint( $form_data->options['custom_style'] ) ) {
319
  $style_ids[] = $default_style->ID;
@@ -323,17 +318,17 @@ class FrmXMLController {
323
  }
324
  unset( $form_id, $form_data );
325
  }
326
- $select = $table . '.ID';
327
  $where['post_type'] = 'frm_styles';
328
 
329
- // Only export selected styles.
330
  if ( ! empty( $style_ids ) ) {
331
  $where['ID'] = $style_ids;
332
  }
333
  break;
334
  default:
335
- $select = $table . '.ID';
336
- $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
337
  $where['pm.meta_key'] = 'frm_form_id';
338
 
339
  if ( empty( $args['ids'] ) ) {
@@ -386,7 +381,7 @@ class FrmXMLController {
386
  foreach ( $records['forms'] as $form_id ) {
387
  $filename = 'form-' . $form_id . '.xml';
388
  if ( $selected_form_id === $form_id ) {
389
- $form = FrmForm::getOne( $form_id );
390
  $filename = sanitize_title( $form->name ) . '-form.xml';
391
  break;
392
  }
@@ -399,7 +394,6 @@ class FrmXMLController {
399
  }
400
  $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
401
  }
402
-
403
  return $filename;
404
  }
405
 
@@ -421,8 +415,8 @@ class FrmXMLController {
421
 
422
  if ( ! $form_id ) {
423
  $form_id = FrmAppHelper::get_param( 'form', '', 'get', 'sanitize_text_field' );
424
- $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
425
- $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
426
  }
427
 
428
  set_time_limit( 0 ); //Remove time limit to execute this function
@@ -433,7 +427,7 @@ class FrmXMLController {
433
 
434
  global $wpdb;
435
 
436
- $form = FrmForm::getOne( $form_id );
437
  $form_id = $form->id;
438
 
439
  $form_cols = self::get_fields_for_csv_export( $form_id, $form );
@@ -472,17 +466,16 @@ class FrmXMLController {
472
  }
473
 
474
  /**
475
- * Get the fields that should be included in the CSV export
476
- *
477
- * @since 2.0.19
478
- *
479
- * @param int $form_id
480
- * @param object $form
481
- *
482
- * @return array $csv_fields
483
- */
484
  private static function get_fields_for_csv_export( $form_id, $form ) {
485
- $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
486
  $no_export_fields = FrmField::no_save_fields();
487
  foreach ( $csv_fields as $k => $f ) {
488
  if ( in_array( $f->type, $no_export_fields ) ) {
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() );
19
 
28
  libxml_disable_entity_loader( $loader );
29
  }
30
 
31
+
32
  /**
33
  * Use the template link to install the XML template
34
  *
58
  if ( isset( $imported['form_status'] ) && ! empty( $imported['form_status'] ) ) {
59
  // Get the last form id in case there are child forms.
60
  end( $imported['form_status'] );
61
+ $form_id = key( $imported['form_status'] );
62
  $response = array(
63
  'id' => $form_id,
64
+ 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form_id ) ),
65
  'success' => 1,
66
  );
67
  } else {
80
  * since we redirect to the last form.
81
  *
82
  * @since 3.06
 
83
  * @param object $xml The values included in the XML.
84
  */
85
  private static function set_new_form_name( &$xml ) {
103
  }
104
 
105
  // Use a unique key to prevent editing existing form.
106
+ $name = sanitize_title( $form->name );
107
  $form->form_key = FrmAppHelper::get_unique_key( $name, 'frm_forms', 'form_key' );
108
  }
109
  }
150
  }
151
 
152
  public static function import_xml() {
153
+ $errors = array();
154
  $message = '';
155
 
156
  $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' );
157
  if ( false !== $permission_error ) {
158
  $errors[] = $permission_error;
159
  self::form( $errors );
 
160
  return;
161
  }
162
 
164
  if ( ! $has_file ) {
165
  $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
166
  self::form( $errors );
 
167
  return;
168
  }
169
 
173
  unset( $file );
174
  $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
175
  self::form( $errors );
 
176
  return;
177
  }
178
 
191
  if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) {
192
  // allow other file types to be imported
193
  do_action( 'frm_before_import_' . $file_type );
 
194
  return;
195
  }
196
  unset( $file_type );
198
  if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
199
  $errors[] = __( 'XML import is not enabled on your server with the libxml_disable_entity_loader function.', 'formidable' );
200
  self::form( $errors );
 
201
  return;
202
  }
203
 
204
  $set_err = libxml_use_internal_errors( true );
205
+ $loader = libxml_disable_entity_loader( true );
206
 
207
  $result = FrmXMLHelper::import_xml( $file );
208
  FrmXMLHelper::parse_message( $result, $message, $errors );
221
  wp_die( esc_html( $error ) );
222
  }
223
 
224
+ $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() );
225
+ $type = FrmAppHelper::get_post_param( 'type', array() );
226
  $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
227
 
228
  if ( ! headers_sent() && ! $type ) {
247
  self::prepare_types_array( $type );
248
 
249
  $tables = array(
250
+ 'items' => $wpdb->prefix . 'frm_items',
251
+ 'forms' => $wpdb->prefix . 'frm_forms',
252
+ 'posts' => $wpdb->posts,
253
+ 'styles' => $wpdb->posts,
254
+ 'actions' => $wpdb->posts,
255
  );
256
 
257
  $defaults = array(
258
  'ids' => false,
259
  );
260
+ $args = wp_parse_args( $args, $defaults );
261
 
262
  // Make sure ids are numeric.
263
  if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
268
 
269
  foreach ( $type as $tb_type ) {
270
  $where = array();
271
+ $join = '';
272
  $table = $tables[ $tb_type ];
273
 
274
+ $select = $table . '.id';
275
  $query_vars = array();
276
 
277
  switch ( $tb_type ) {
279
  //add forms
280
  if ( $args['ids'] ) {
281
  $where[] = array(
282
+ 'or' => 1,
283
+ $table . '.id' => $args['ids'],
284
  $table . '.parent_form_id' => $args['ids'],
285
  );
286
  } else {
288
  }
289
  break;
290
  case 'actions':
291
+ $select = $table . '.ID';
292
  $where['post_type'] = FrmFormActionsController::$action_post_type;
293
  if ( ! empty( $args['ids'] ) ) {
294
  $where['menu_order'] = $args['ids'];
295
  }
296
  break;
297
  case 'items':
298
+ //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
299
  if ( $args['ids'] ) {
300
  $where[ $table . '.form_id' ] = $args['ids'];
301
  }
302
  break;
303
  case 'styles':
304
+ // Loop through all exported forms and get their selected style IDs
305
+ $frm_style = new FrmStyle();
306
  $default_style = $frm_style->get_default_style();
307
+ $form_ids = $args['ids'];
308
+ $style_ids = array();
309
  foreach ( $form_ids as $form_id ) {
310
  $form_data = FrmForm::getOne( $form_id );
311
+ // For forms that have not been updated while running 2.0, check if custom_style is set
312
  if ( isset( $form_data->options['custom_style'] ) ) {
313
  if ( 1 === absint( $form_data->options['custom_style'] ) ) {
314
  $style_ids[] = $default_style->ID;
318
  }
319
  unset( $form_id, $form_data );
320
  }
321
+ $select = $table . '.ID';
322
  $where['post_type'] = 'frm_styles';
323
 
324
+ // Only export selected styles
325
  if ( ! empty( $style_ids ) ) {
326
  $where['ID'] = $style_ids;
327
  }
328
  break;
329
  default:
330
+ $select = $table . '.ID';
331
+ $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
332
  $where['pm.meta_key'] = 'frm_form_id';
333
 
334
  if ( empty( $args['ids'] ) ) {
381
  foreach ( $records['forms'] as $form_id ) {
382
  $filename = 'form-' . $form_id . '.xml';
383
  if ( $selected_form_id === $form_id ) {
384
+ $form = FrmForm::getOne( $form_id );
385
  $filename = sanitize_title( $form->name ) . '-form.xml';
386
  break;
387
  }
394
  }
395
  $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
396
  }
 
397
  return $filename;
398
  }
399
 
415
 
416
  if ( ! $form_id ) {
417
  $form_id = FrmAppHelper::get_param( 'form', '', 'get', 'sanitize_text_field' );
418
+ $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' );
419
+ $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' );
420
  }
421
 
422
  set_time_limit( 0 ); //Remove time limit to execute this function
427
 
428
  global $wpdb;
429
 
430
+ $form = FrmForm::getOne( $form_id );
431
  $form_id = $form->id;
432
 
433
  $form_cols = self::get_fields_for_csv_export( $form_id, $form );
466
  }
467
 
468
  /**
469
+ * Get the fields that should be included in the CSV export
470
+ *
471
+ * @since 2.0.19
472
+ *
473
+ * @param int $form_id
474
+ * @param object $form
475
+ * @return array $csv_fields
476
+ */
 
477
  private static function get_fields_for_csv_export( $form_id, $form ) {
478
+ $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' );
479
  $no_export_fields = FrmField::no_save_fields();
480
  foreach ( $csv_fields as $k => $f ) {
481
  if ( in_array( $f->type, $no_export_fields ) ) {
classes/factories/FrmFieldFactory.php CHANGED
@@ -31,7 +31,6 @@ class FrmFieldFactory {
31
 
32
  /**
33
  * @since 3.0
34
- *
35
  * @param object|array $field
36
  */
37
  public static function get_field_factory( $field ) {
@@ -42,7 +41,6 @@ class FrmFieldFactory {
42
  } else {
43
  $field_info = self::get_field_type( $field['type'], $field );
44
  }
45
-
46
  return $field_info;
47
  }
48
 
@@ -50,7 +48,6 @@ class FrmFieldFactory {
50
  if ( ! is_object( $field ) ) {
51
  $field = FrmField::getOne( $field );
52
  }
53
-
54
  return self::get_field_type( $field->type, $field );
55
  }
56
 
@@ -99,7 +96,6 @@ class FrmFieldFactory {
99
  );
100
 
101
  $class = isset( $type_classes[ $field_type ] ) ? $type_classes[ $field_type ] : '';
102
-
103
  return apply_filters( 'frm_get_field_type_class', $class, $field_type );
104
  }
105
 
@@ -118,7 +114,6 @@ class FrmFieldFactory {
118
  */
119
  public static function field_has_property( $type, $property ) {
120
  $field = self::get_field_type( $type );
121
-
122
  return $field->{$property};
123
  }
124
  }
31
 
32
  /**
33
  * @since 3.0
 
34
  * @param object|array $field
35
  */
36
  public static function get_field_factory( $field ) {
41
  } else {
42
  $field_info = self::get_field_type( $field['type'], $field );
43
  }
 
44
  return $field_info;
45
  }
46
 
48
  if ( ! is_object( $field ) ) {
49
  $field = FrmField::getOne( $field );
50
  }
 
51
  return self::get_field_type( $field->type, $field );
52
  }
53
 
96
  );
97
 
98
  $class = isset( $type_classes[ $field_type ] ) ? $type_classes[ $field_type ] : '';
 
99
  return apply_filters( 'frm_get_field_type_class', $class, $field_type );
100
  }
101
 
114
  */
115
  public static function field_has_property( $type, $property ) {
116
  $field = self::get_field_type( $type );
 
117
  return $field->{$property};
118
  }
119
  }
classes/helpers/FrmAppHelper.php CHANGED
@@ -4,25 +4,24 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  }
5
 
6
  class FrmAppHelper {
7
- public static $db_version = 97; //version of the database we are moving to
8
  public static $pro_db_version = 37; //deprecated
9
- public static $font_version = 4;
10
 
11
  /**
12
  * @since 2.0
13
  */
14
- public static $plug_version = '4.0b1';
15
 
16
- /**
17
- * @since 1.07.02
18
- *
19
- * @param none
20
- *
21
- * @return string The version of this plugin
22
- */
23
- public static function plugin_version() {
24
- return self::$plug_version;
25
- }
26
 
27
  public static function plugin_folder() {
28
  return basename( self::plugin_path() );
@@ -32,29 +31,29 @@ class FrmAppHelper {
32
  return dirname( dirname( dirname( __FILE__ ) ) );
33
  }
34
 
35
- public static function plugin_url() {
36
- // Prevously FRM_URL constant.
37
  return plugins_url( '', self::plugin_path() . '/formidable.php' );
38
- }
39
 
40
  public static function relative_plugin_url() {
41
  return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
42
  }
43
 
44
- /**
45
- * @return string Site URL
46
- */
47
- public static function site_url() {
48
- return site_url();
49
- }
50
-
51
- /**
52
- * Get the name of this site
53
- * Used for [sitename] shortcode
54
- *
55
- * @since 2.0
56
- * @return string
57
- */
58
  public static function site_name() {
59
  return get_option( 'blogname' );
60
  }
@@ -65,7 +64,6 @@ class FrmAppHelper {
65
  $url = str_replace( array( 'http://', 'https://' ), '', $url );
66
  $url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
67
  }
68
-
69
  return $url;
70
  }
71
 
@@ -109,14 +107,14 @@ class FrmAppHelper {
109
  return add_query_arg( $query_args, $page ) . $anchor;
110
  }
111
 
112
- /**
113
- * Get the Formidable settings
114
- *
115
- * @since 2.0
116
- *
117
- * @param array $args - May include the form id when values need translation.
118
- * @return FrmSettings $frm_setings
119
- */
120
  public static function get_settings( $args = array() ) {
121
  global $frm_settings;
122
  if ( empty( $frm_settings ) ) {
@@ -131,7 +129,6 @@ class FrmAppHelper {
131
 
132
  public static function get_menu_name() {
133
  $frm_settings = self::get_settings();
134
-
135
  return $frm_settings->menu;
136
  }
137
 
@@ -145,8 +142,7 @@ class FrmAppHelper {
145
  'fill' => '#4d4d4d',
146
  'orange' => '#f05a24',
147
  );
148
- $atts = array_merge( $defaults, $atts );
149
-
150
  return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 599.68 601.37" width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '">
151
  <defs />
152
  <rect fill="' . esc_attr( $atts['orange'] ) . '" x="289.64" y="383.96" width="140" height="76" />
@@ -156,19 +152,11 @@ class FrmAppHelper {
156
  </svg>';
157
  }
158
 
159
- /**
160
- * @since 4.0
161
- */
162
- public static function show_logo( $atts = array() ) {
163
- echo self::kses( self::svg_logo( $atts ), 'all' ); // WPCS: XSS ok.
164
- }
165
-
166
  /**
167
  * @since 2.02.04
168
  */
169
  public static function ips_saved() {
170
  $frm_settings = self::get_settings();
171
-
172
  return ! $frm_settings->no_ips;
173
  }
174
 
@@ -177,69 +165,64 @@ class FrmAppHelper {
177
  }
178
 
179
  public static function is_formidable_admin() {
180
- $page = self::simple_get( 'page', 'sanitize_title' );
181
  $is_formidable = strpos( $page, 'formidable' ) !== false;
182
  if ( empty( $page ) ) {
183
  global $pagenow;
184
- $post_type = self::simple_get( 'post_type', 'sanitize_title' );
185
  $is_formidable = ( $post_type == 'frm_display' );
186
  if ( empty( $post_type ) && $pagenow == 'post.php' ) {
187
  global $post;
188
  $is_formidable = ( $post && $post->post_type == 'frm_display' );
189
  }
190
  }
191
-
192
  return $is_formidable;
193
  }
194
 
195
- /**
196
- * Check for certain page in Formidable settings
197
- *
198
- * @since 2.0
199
- *
200
- * @param string $page The name of the page to check
201
- *
202
- * @return boolean
203
- */
204
  public static function is_admin_page( $page = 'formidable' ) {
205
- global $pagenow;
206
  $get_page = self::simple_get( 'page', 'sanitize_title' );
207
- if ( $pagenow ) {
208
  // allow this to be true during ajax load i.e. ajax form builder loading
209
  return ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
210
- }
211
 
212
  return is_admin() && $get_page == $page;
213
- }
214
-
215
- /**
216
- * Check for the form preview page
217
- *
218
- * @since 2.0
219
- *
220
- * @param None
221
- *
222
- * @return boolean
223
- */
224
- public static function is_preview_page() {
225
- global $pagenow;
226
  $action = self::simple_get( 'action', 'sanitize_title' );
227
-
228
  return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
229
- }
230
-
231
- /**
232
- * Check for ajax except the form preview page
233
- *
234
- * @since 2.0
235
- *
236
- * @param None
237
- *
238
- * @return boolean
239
- */
240
- public static function doing_ajax() {
241
- return self::wp_doing_ajax() && ! self::is_preview_page();
242
- }
243
 
244
  public static function js_suffix() {
245
  return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
@@ -256,7 +239,6 @@ class FrmAppHelper {
256
  } else {
257
  $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
258
  }
259
-
260
  return $doing_ajax;
261
  }
262
 
@@ -265,61 +247,55 @@ class FrmAppHelper {
265
  */
266
  public static function prevent_caching() {
267
  global $frm_vars;
268
-
269
  return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
270
  }
271
 
272
- /**
273
- * Check if on an admin page
274
- *
275
- * @since 2.0
276
- *
277
- * @param None
278
- *
279
- * @return boolean
280
- */
281
- public static function is_admin() {
282
- return is_admin() && ! self::wp_doing_ajax();
283
- }
284
-
285
- /**
286
- * Check if value contains blank value or empty array
287
- *
288
- * @since 2.0
289
- *
290
- * @param mixed $value - value to check
291
  * @param string
292
- *
293
- * @return boolean
294
- */
295
- public static function is_empty_value( $value, $empty = '' ) {
296
- return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
297
- }
298
-
299
- public static function is_not_empty_value( $value, $empty = '' ) {
300
- return ! self::is_empty_value( $value, $empty );
301
- }
302
-
303
- /**
304
- * Get any value from the $_SERVER
305
- *
306
- * @since 2.0
307
- *
308
- * @param string $value
309
- *
310
- * @return string
311
- */
312
  public static function get_server_value( $value ) {
313
- return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( wp_unslash( $_SERVER[ $value ] ) ) : '';
314
- }
315
-
316
- /**
317
- * Check for the IP address in several places
318
- * Used by [ip] shortcode
319
- *
320
- * @return string The IP address of the current user
321
- */
322
- public static function get_ip_address() {
323
  $ip_options = array(
324
  'HTTP_CLIENT_IP',
325
  'HTTP_CF_CONNECTING_IP',
@@ -333,34 +309,33 @@ class FrmAppHelper {
333
  );
334
  $ip = '';
335
  foreach ( $ip_options as $key ) {
336
- if ( ! isset( $_SERVER[ $key ] ) ) {
337
- continue;
338
- }
339
 
340
- $key = self::get_server_value( $key );
341
- foreach ( explode( ',', $key ) as $ip ) {
342
- $ip = trim( $ip ); // just to be safe.
343
 
344
  if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
345
- return sanitize_text_field( $ip );
346
- }
347
- }
348
- }
349
 
350
  return sanitize_text_field( $ip );
351
- }
352
 
353
- public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
354
  if ( strpos( $param, '[' ) ) {
355
  $params = explode( '[', $param );
356
- $param = $params[0];
357
- }
358
 
359
  if ( $src == 'get' ) {
360
- $value = isset( $_POST[ $param ] ) ? wp_unslash( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? wp_unslash( $_GET[ $param ] ) : $default );
361
- if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
362
- $value = htmlspecialchars_decode( wp_unslash( $_GET[ $param ] ) );
363
- }
364
  self::sanitize_value( $sanitize, $value );
365
  } else {
366
  $value = self::get_simple_request(
@@ -379,13 +354,13 @@ class FrmAppHelper {
379
  continue;
380
  }
381
 
382
- $p = trim( $p, ']' );
383
  $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
384
  }
385
  }
386
 
387
- return $value;
388
- }
389
 
390
  public static function get_post_param( $param, $default = '', $sanitize = '' ) {
391
  return self::get_simple_request(
@@ -404,7 +379,6 @@ class FrmAppHelper {
404
  * @param string $param
405
  * @param string $sanitize
406
  * @param string $default
407
- *
408
  * @return string|array
409
  */
410
  public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
@@ -422,9 +396,7 @@ class FrmAppHelper {
422
  * Get a GET/POST/REQUEST value and sanitize it
423
  *
424
  * @since 2.0.6
425
- *
426
  * @param array $args
427
- *
428
  * @return string|array
429
  */
430
  public static function get_simple_request( $args ) {
@@ -434,43 +406,39 @@ class FrmAppHelper {
434
  'type' => 'get',
435
  'sanitize' => 'sanitize_text_field',
436
  );
437
- $args = wp_parse_args( $args, $defaults );
438
 
439
  $value = $args['default'];
440
  if ( $args['type'] == 'get' ) {
441
  if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
442
- $value = wp_unslash( $_GET[ $args['param'] ] );
443
  }
444
- } elseif ( $args['type'] == 'post' ) {
445
  if ( isset( $_POST[ $args['param'] ] ) ) {
446
- $value = maybe_unserialize( wp_unslash( $_POST[ $args['param'] ] ) );
447
  }
448
  } else {
449
  if ( isset( $_REQUEST[ $args['param'] ] ) ) {
450
- $value = wp_unslash( $_REQUEST[ $args['param'] ] );
451
  }
452
  }
453
 
454
  self::sanitize_value( $args['sanitize'], $value );
455
-
456
  return $value;
457
  }
458
 
459
  /**
460
- * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
461
- *
462
- * @since 2.0.8
463
- *
464
- * @param string $value
465
- *
466
- * @return string $value
467
- */
468
  public static function preserve_backslashes( $value ) {
469
  // If backslashes have already been added, don't add them again
470
  if ( strpos( $value, '\\\\' ) === false ) {
471
  $value = addslashes( $value );
472
  }
473
-
474
  return $value;
475
  }
476
 
@@ -487,23 +455,21 @@ class FrmAppHelper {
487
  }
488
  }
489
 
490
- public static function sanitize_request( $sanitize_method, &$values ) {
491
- $temp_values = $values;
492
- foreach ( $temp_values as $k => $val ) {
493
- if ( isset( $sanitize_method[ $k ] ) ) {
494
  $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
495
- }
496
- }
497
- }
498
 
499
  /**
500
  * Sanitize the value, and allow some HTML
501
  *
502
  * @since 2.0
503
- *
504
  * @param string $value
505
  * @param array|string $allowed 'all' for everything included as defaults
506
- *
507
  * @return string
508
  */
509
  public static function kses( $value, $allowed = array() ) {
@@ -516,7 +482,7 @@ class FrmAppHelper {
516
  * @since 2.05.03
517
  */
518
  private static function allowed_html( $allowed ) {
519
- $html = self::safe_html();
520
  $allowed_html = array();
521
  if ( $allowed == 'all' ) {
522
  $allowed_html = $html;
@@ -539,7 +505,7 @@ class FrmAppHelper {
539
  );
540
 
541
  return array(
542
- 'a' => array(
543
  'class' => true,
544
  'href' => true,
545
  'id' => true,
@@ -547,46 +513,46 @@ class FrmAppHelper {
547
  'target' => true,
548
  'title' => true,
549
  ),
550
- 'abbr' => array(
551
  'title' => true,
552
  ),
553
- 'aside' => $allow_class,
554
- 'b' => array(),
555
  'blockquote' => array(
556
- 'cite' => true,
557
  ),
558
- 'br' => array(),
559
- 'cite' => array(
560
  'title' => true,
561
  ),
562
- 'code' => array(),
563
- 'defs' => array(),
564
- 'del' => array(
565
  'datetime' => true,
566
  'title' => true,
567
  ),
568
- 'dd' => array(),
569
- 'div' => array(
570
  'class' => true,
571
  'id' => true,
572
  'title' => true,
573
  'style' => true,
574
  ),
575
- 'dl' => array(),
576
- 'dt' => array(),
577
- 'em' => array(),
578
- 'h1' => $allow_class,
579
- 'h2' => $allow_class,
580
- 'h3' => $allow_class,
581
- 'h4' => $allow_class,
582
- 'h5' => $allow_class,
583
- 'h6' => $allow_class,
584
- 'i' => array(
585
  'class' => true,
586
  'id' => true,
587
  'icon' => true,
588
  ),
589
- 'img' => array(
590
  'alt' => true,
591
  'class' => true,
592
  'height' => true,
@@ -594,19 +560,19 @@ class FrmAppHelper {
594
  'src' => true,
595
  'width' => true,
596
  ),
597
- 'li' => $allow_class,
598
- 'ol' => $allow_class,
599
- 'p' => $allow_class,
600
- 'path' => array(
601
  'd' => true,
602
  'fill' => true,
603
  ),
604
- 'pre' => array(),
605
- 'q' => array(
606
  'cite' => true,
607
  'title' => true,
608
  ),
609
- 'rect' => array(
610
  'class' => true,
611
  'fill' => true,
612
  'height' => true,
@@ -614,74 +580,65 @@ class FrmAppHelper {
614
  'x' => true,
615
  'y' => true,
616
  ),
617
- 'section' => $allow_class,
618
- 'span' => array(
619
  'class' => true,
620
  'id' => true,
621
  'title' => true,
622
  'style' => true,
623
  ),
624
- 'strike' => array(),
625
- 'strong' => array(),
626
- 'svg' => array(
627
  'xmlns' => true,
628
  'viewbox' => true,
629
  'width' => true,
630
  'height' => true,
631
  ),
632
- 'ul' => $allow_class,
633
  );
634
  }
635
 
636
- /**
637
- * Used when switching the action for a bulk action
638
  *
639
- * @since 2.0
640
- */
641
  public static function remove_get_action() {
642
  if ( ! isset( $_GET ) ) {
643
  return;
644
  }
645
 
646
- $action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' );
647
- if ( empty( $action_name ) ) {
648
- return;
649
- }
650
-
651
- $new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' );
652
- if ( ! empty( $new_action ) ) {
653
  $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
654
- }
655
- }
656
 
657
- /**
658
- * Check the WP query for a parameter
659
- *
660
- * @since 2.0
661
- * @return string|array
662
- */
663
- public static function get_query_var( $value, $param ) {
664
- if ( $value != '' ) {
665
- return $value;
666
- }
667
 
668
- global $wp_query;
669
- if ( isset( $wp_query->query_vars[ $param ] ) ) {
670
- $value = $wp_query->query_vars[ $param ];
671
- }
672
 
673
- return $value;
674
- }
675
 
676
  /**
677
  * @since 3.0
678
  */
679
  public static function get_admin_header( $atts ) {
680
  $has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
681
- if ( ! isset( $atts['close'] ) || empty( $atts['close'] ) ) {
682
- $atts['close'] = '?page=formidable';
683
- }
684
-
685
  include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
686
  }
687
 
@@ -690,10 +647,8 @@ class FrmAppHelper {
690
  */
691
  public static function add_new_item_link( $atts ) {
692
  if ( isset( $atts['new_link'] ) && ! empty( $atts['new_link'] ) ) { ?>
693
- <a href="<?php echo esc_url( $atts['new_link'] ); ?>" class="button button-primary frm-button-primary frm-with-plus">
694
- <?php esc_html_e( 'Add New', 'formidable' ); ?>
695
- </a>
696
- <?php
697
  } elseif ( isset( $atts['link_hook'] ) ) {
698
  do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
699
  }
@@ -702,58 +657,43 @@ class FrmAppHelper {
702
  /**
703
  * @since 3.06
704
  */
705
- public static function show_search_box( $atts ) {
706
- $defaults = array(
707
- 'placeholder' => '',
708
- 'tosearch' => '',
709
- 'text' => __( 'Search', 'formidable' ),
710
- 'input_id' => '',
711
- );
712
- $atts = array_merge( $defaults, $atts );
713
-
714
- if ( $atts['input_id'] === 'template' && empty( $atts['tosearch'] ) ) {
715
- $atts['tosearch'] = 'frm-card';
716
- }
717
-
718
- $class = 'frm-search-input';
719
- if ( ! empty( $atts['tosearch'] ) ) {
720
  $class .= ' frm-auto-search';
721
  }
722
-
723
- $input_id = $atts['input_id'] . '-search-input';
724
-
 
725
  ?>
726
- <p class="frm-search">
727
- <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>">
728
- <?php echo esc_html( $atts['text'] ); ?>:
729
  </label>
730
- <span class="frmfont frm_search_icon"></span>
731
- <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s"
732
- value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $atts['placeholder'] ); ?>"
733
- class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $atts['tosearch'] ); ?>"
734
- <?php if ( ! empty( $atts['tosearch'] ) ) { ?>
735
- autocomplete="off"
736
- <?php } ?>
737
- />
738
  <?php
739
- if ( empty( $atts['tosearch'] ) ) {
740
- submit_button( $atts['text'], 'button-secondary', '', false, array( 'id' => 'search-submit' ) );
741
  }
742
  ?>
743
  </p>
744
  <?php
745
  }
746
 
747
- /**
748
- * @param string $type
749
- */
750
- public static function trigger_hook_load( $type, $object = null ) {
751
- // Only load the form hooks once.
752
  $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
753
- if ( ! $hooks_loaded ) {
754
  do_action( 'frm_load_' . $type . '_hooks' );
755
- }
756
- }
757
 
758
  /**
759
  * Save all front-end js scripts into a single file
@@ -764,11 +704,11 @@ class FrmAppHelper {
764
  $file_atts = apply_filters(
765
  'frm_js_location',
766
  array(
767
- 'file_name' => 'frm.min.js',
768
  'new_file_path' => self::plugin_path() . '/js',
769
  )
770
  );
771
- $new_file = new FrmCreateFile( $file_atts );
772
 
773
  $files = array(
774
  self::plugin_path() . '/js/jquery/jquery.placeholder.min.js',
@@ -778,177 +718,144 @@ class FrmAppHelper {
778
  $new_file->combine_files( $files );
779
  }
780
 
781
- /**
782
- * Check a value from a shortcode to see if true or false.
783
- * True when value is 1, true, 'true', 'yes'
784
- *
785
- * @since 1.07.10
786
- *
787
- * @param string $value The value to compare
788
- *
789
- * @return boolean True or False
790
- */
791
  public static function is_true( $value ) {
792
- return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
793
- }
794
 
795
  public static function get_pages() {
796
  $query = array(
797
  'post_type' => 'page',
798
  'post_status' => array( 'publish', 'private' ),
799
- 'numberposts' => - 1,
800
  'orderby' => 'title',
801
  'order' => 'ASC',
802
  );
803
-
804
  return get_posts( $query );
805
  }
806
 
807
- public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
808
- $pages = self::get_pages();
809
  $selected = self::get_post_param( $field_name, $page_id, 'absint' );
810
- ?>
811
  <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
812
- <option value=""> </option>
813
- <?php foreach ( $pages as $page ) { ?>
814
  <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>>
815
  <?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
816
  </option>
817
- <?php } ?>
818
- </select>
819
- <?php
820
- }
821
 
822
  public static function post_edit_link( $post_id ) {
823
  $post = get_post( $post_id );
824
- if ( $post ) {
825
  $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
826
- $post_url = self::maybe_full_screen_link( $post_url );
827
-
828
  return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
829
- }
830
-
831
- return '';
832
- }
833
-
834
- /**
835
- * Hide the WordPress menus on some pages.
836
- *
837
- * @since 4.0
838
- */
839
- public static function is_full_screen() {
840
- $action = self::simple_get( 'frm_action', 'sanitize_title' );
841
- $full_builder = self::is_admin_page( 'formidable' ) && ( $action === 'edit' || $action === 'settings' || $action === 'duplicate' );
842
- $styler = self::is_admin_page( 'formidable-styles' );
843
- $full_entries = self::simple_get( 'frm-full', 'absint' );
844
-
845
- return $full_builder || $full_entries || $styler;
846
- }
847
-
848
- /**
849
- * @since 4.0
850
- */
851
- public static function maybe_full_screen_link( $link ) {
852
- $is_full = self::simple_get( 'frm-full', 'absint' );
853
- if ( $is_full ) {
854
- $link .= '&frm-full=1';
855
- }
856
- return $link;
857
- }
858
 
859
  public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
860
  ?>
861
- <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>"
862
- <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?>
863
- class="frm_multiselect">
864
  <?php self::roles_options( $capability ); ?>
865
  </select>
866
  <?php
867
  }
868
 
869
  public static function roles_options( $capability ) {
870
- global $frm_vars;
871
  if ( isset( $frm_vars['editable_roles'] ) ) {
872
- $editable_roles = $frm_vars['editable_roles'];
873
- } else {
874
- $editable_roles = get_editable_roles();
875
- $frm_vars['editable_roles'] = $editable_roles;
876
- }
877
 
878
- foreach ( $editable_roles as $role => $details ) {
879
  $name = translate_user_role( $details['name'] );
880
  ?>
881
- <option value="<?php echo esc_attr( $role ); ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ); ?> </option>
882
- <?php
883
  unset( $role, $details );
884
- }
885
- }
886
 
887
  public static function frm_capabilities( $type = 'auto' ) {
888
- $cap = array(
889
- 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ),
890
- 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ),
891
- 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ),
892
- 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
893
- 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ),
894
- 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ),
895
- );
896
 
897
  if ( ! self::pro_is_installed() && 'pro' != $type ) {
898
- return $cap;
899
- }
900
 
901
- $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
902
- $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
903
- $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
904
- $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
905
 
906
- return $cap;
907
- }
908
 
909
  public static function user_has_permission( $needed_role ) {
910
- if ( $needed_role == '-1' ) {
911
- return false;
912
  }
913
 
914
- // $needed_role will be equal to blank if "Logged-in users" is selected.
915
- if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
916
- return true;
917
- }
918
 
919
- $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
920
- foreach ( $roles as $role ) {
921
  if ( current_user_can( $role ) ) {
922
- return true;
923
  }
924
- if ( $role == $needed_role ) {
925
- break;
926
  }
927
- }
928
-
929
- return false;
930
- }
931
-
932
- /**
933
- * Make sure administrators can see Formidable menu
934
- *
935
- * @since 2.0
936
- */
937
- public static function maybe_add_permissions() {
938
  self::force_capability( 'frm_view_entries' );
939
 
940
  if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
941
  return;
942
  }
943
 
944
- $user_id = get_current_user_id();
945
- $user = new WP_User( $user_id );
946
- $frm_roles = self::frm_capabilities();
947
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
948
  $user->add_cap( $frm_role );
949
  unset( $frm_role, $frm_role_description );
950
- }
951
- }
952
 
953
  /**
954
  * Make sure admins have permission to see the menu items
@@ -957,7 +864,7 @@ class FrmAppHelper {
957
  */
958
  public static function force_capability( $cap = 'frm_change_settings' ) {
959
  if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
960
- $role = get_role( 'administrator' );
961
  $frm_roles = self::frm_capabilities();
962
  foreach ( $frm_roles as $frm_role => $frm_role_description ) {
963
  $role->add_cap( $frm_role );
@@ -965,63 +872,58 @@ class FrmAppHelper {
965
  }
966
  }
967
 
968
- /**
969
- * Check if the user has permision for action.
970
- * Return permission message and stop the action if no permission
971
- *
972
- * @since 2.0
973
  *
974
- * @param string $permission
975
- */
 
976
  public static function permission_check( $permission, $show_message = 'show' ) {
977
  $permission_error = self::permission_nonce_error( $permission );
978
- if ( $permission_error !== false ) {
979
- if ( 'hide' == $show_message ) {
980
- $permission_error = '';
981
- }
982
  wp_die( esc_html( $permission_error ) );
983
- }
984
- }
985
 
986
- /**
987
- * Check user permission and nonce
988
- *
989
- * @since 2.0
990
- *
991
- * @param string $permission
992
  *
993
- * @return false|string The permission message or false if allowed
994
- */
 
 
995
  public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
996
  if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
997
  $frm_settings = self::get_settings();
998
-
999
  return $frm_settings->admin_permission;
1000
  }
1001
 
1002
  $error = false;
1003
  if ( empty( $nonce_name ) ) {
1004
- return $error;
1005
- }
1006
 
1007
- $nonce_value = ( $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
1008
- if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $nonce_value, $nonce ) ) ) {
1009
- $frm_settings = self::get_settings();
1010
- $error = $frm_settings->admin_permission;
1011
- }
1012
 
1013
- return $error;
1014
- }
1015
 
1016
- public static function checked( $values, $current ) {
1017
  if ( self::check_selected( $values, $current ) ) {
1018
- echo ' checked="checked"';
1019
  }
1020
- }
1021
 
1022
  public static function check_selected( $values, $current ) {
1023
- $values = self::recursive_function_map( $values, 'trim' );
1024
- $values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
1025
  $current = htmlspecialchars_decode( trim( $current ) );
1026
 
1027
  return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
@@ -1055,25 +957,24 @@ class FrmAppHelper {
1055
  return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
1056
  }
1057
 
1058
- /**
1059
- * Flatten a multi-dimensional array
1060
- */
1061
  public static function array_flatten( $array, $keys = 'keep' ) {
1062
- $return = array();
1063
- foreach ( $array as $key => $value ) {
1064
  if ( is_array( $value ) ) {
1065
  $return = array_merge( $return, self::array_flatten( $value, $keys ) );
1066
- } else {
1067
  if ( $keys == 'keep' ) {
1068
  $return[ $key ] = $value;
1069
  } else {
1070
  $return[] = $value;
1071
  }
1072
- }
1073
- }
1074
-
1075
- return $return;
1076
- }
1077
 
1078
  public static function esc_textarea( $text, $is_rich_text = false ) {
1079
  $safe_text = str_replace( '&quot;', '"', $text );
@@ -1081,47 +982,42 @@ class FrmAppHelper {
1081
  $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
1082
  }
1083
  $safe_text = str_replace( '&amp;', '&', $safe_text );
1084
-
1085
  return apply_filters( 'esc_textarea', $safe_text, $text );
1086
  }
1087
 
1088
- /**
1089
- * Add auto paragraphs to text areas
1090
  *
1091
- * @since 2.0
1092
- */
1093
  public static function use_wpautop( $content ) {
1094
  if ( apply_filters( 'frm_use_wpautop', true ) ) {
1095
  $content = wpautop( str_replace( '<br>', '<br />', $content ) );
1096
  }
1097
-
1098
  return $content;
1099
  }
1100
 
1101
  public static function replace_quotes( $val ) {
1102
- // Replace double quotes.
1103
  $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
1104
-
1105
- // Replace single quotes.
1106
- $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
1107
-
1108
- return $val;
1109
- }
1110
-
1111
- /**
1112
- * @since 2.0
1113
- * @return string The base Google APIS url for the current version of jQuery UI
1114
- */
1115
- public static function jquery_ui_base_url() {
1116
  $url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
1117
  $url = apply_filters( 'frm_jquery_ui_base_url', $url );
 
 
1118
 
1119
- return $url;
1120
- }
1121
-
1122
- /**
1123
- * @param string $handle
1124
- */
1125
  public static function script_version( $handle, $default = 0 ) {
1126
  global $wp_scripts;
1127
  if ( ! $wp_scripts ) {
@@ -1143,12 +1039,12 @@ class FrmAppHelper {
1143
 
1144
  public static function js_redirect( $url ) {
1145
  return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
1146
- }
1147
 
1148
  public static function get_user_id_param( $user_id ) {
1149
  if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
1150
- return $user_id;
1151
- }
1152
 
1153
  $user_id = sanitize_text_field( $user_id );
1154
  if ( $user_id == 'current' ) {
@@ -1160,14 +1056,14 @@ class FrmAppHelper {
1160
  $user = get_user_by( 'login', $user_id );
1161
  }
1162
 
1163
- if ( $user ) {
1164
- $user_id = $user->ID;
1165
- }
1166
  unset( $user );
1167
- }
1168
 
1169
- return $user_id;
1170
- }
1171
 
1172
  public static function get_file_contents( $filename, $atts = array() ) {
1173
  if ( ! is_file( $filename ) ) {
@@ -1179,42 +1075,31 @@ class FrmAppHelper {
1179
  include( $filename );
1180
  $contents = ob_get_contents();
1181
  ob_end_clean();
1182
-
1183
  return $contents;
1184
  }
1185
 
1186
- /**
1187
- * @param string $table_name
1188
- * @param string $column
1189
  * @param int $id
1190
  * @param int $num_chars
1191
- */
1192
- public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
1193
- $key = '';
1194
 
1195
- if ( ! empty( $name ) ) {
1196
  $key = sanitize_key( $name );
1197
- }
1198
 
1199
  if ( empty( $key ) ) {
1200
  $max_slug_value = pow( 36, $num_chars );
1201
- $min_slug_value = 37; // we want to have at least 2 characters in the slug
1202
- $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1203
- }
1204
-
1205
- $not_allowed = array(
1206
- 'id',
1207
- 'key',
1208
- 'created-at',
1209
- 'detaillink',
1210
- 'editlink',
1211
- 'siteurl',
1212
- 'evenodd',
1213
- );
1214
 
1215
- if ( is_numeric( $key ) || in_array( $key, $not_allowed ) ) {
1216
  $key = $key . 'a';
1217
- }
1218
 
1219
  $key_check = FrmDb::get_var(
1220
  $table_name,
@@ -1226,10 +1111,10 @@ class FrmAppHelper {
1226
  );
1227
 
1228
  if ( $key_check || is_numeric( $key_check ) ) {
1229
- $suffix = 2;
1230
  do {
1231
  $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
1232
- $key_check = FrmDb::get_var(
1233
  $table_name,
1234
  array(
1235
  $column => $alt_post_name,
@@ -1237,37 +1122,35 @@ class FrmAppHelper {
1237
  ),
1238
  $column
1239
  );
1240
- $suffix ++;
1241
  } while ( $key_check || is_numeric( $key_check ) );
1242
  $key = $alt_post_name;
1243
- }
 
 
1244
 
1245
- return $key;
1246
- }
1247
-
1248
- /**
1249
- * Editing a Form or Entry
1250
  *
1251
- * @param string $table
1252
- *
1253
- * @return bool|array
1254
- */
1255
- public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1256
- if ( ! $record ) {
1257
- return false;
1258
- }
1259
 
1260
  if ( empty( $post_values ) ) {
1261
- $post_values = wp_unslash( $_POST );
1262
  }
1263
 
1264
  $values = array(
1265
- 'id' => $record->id,
1266
  'fields' => array(),
1267
  );
1268
 
1269
  foreach ( array( 'name', 'description' ) as $var ) {
1270
- $default_val = isset( $record->{$var} ) ? $record->{$var} : '';
1271
  $values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
1272
  unset( $var, $default_val );
1273
  }
@@ -1278,19 +1161,19 @@ class FrmAppHelper {
1278
 
1279
  self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1280
 
1281
- if ( $table == 'entries' ) {
1282
- $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1283
- } elseif ( $table == 'forms' ) {
1284
- $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1285
- }
1286
 
1287
- return $values;
1288
- }
1289
 
1290
  private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1291
  if ( ! empty( $fields ) ) {
1292
  foreach ( (array) $fields as $field ) {
1293
- $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1294
  $args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1295
  self::fill_field_defaults( $field, $record, $values, $args );
1296
  }
@@ -1298,57 +1181,55 @@ class FrmAppHelper {
1298
  }
1299
 
1300
  private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1301
- $post_values = $args['post_values'];
1302
 
1303
- if ( $args['default'] ) {
1304
- $meta_value = $field->default_value;
1305
- } else {
1306
  if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1307
  if ( ! isset( $field->field_options['custom_field'] ) ) {
1308
- $field->field_options['custom_field'] = '';
1309
- }
1310
  $meta_value = FrmProEntryMetaHelper::get_post_value(
1311
  $record->post_id,
1312
  $field->field_options['post_field'],
1313
  $field->field_options['custom_field'],
1314
  array(
1315
  'truncate' => false,
1316
- 'type' => $field->type,
1317
- 'form_id' => $field->form_id,
1318
- 'field' => $field,
1319
  )
1320
  );
1321
- } else {
1322
  $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1323
- }
1324
- }
1325
 
1326
  $field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1327
- $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1328
 
1329
- $field_array = self::start_field_array( $field );
1330
- $field_array['value'] = $new_value;
1331
- $field_array['type'] = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1332
  $field_array['parent_form_id'] = $args['parent_form_id'];
1333
 
1334
- $args['field_type'] = $field_type;
1335
 
1336
  FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1337
 
1338
  if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1339
- $field_array['unique_msg'] = '';
1340
- }
1341
 
1342
- $field_array = array_merge( $field->field_options, $field_array );
1343
 
1344
- $values['fields'][ $field->id ] = $field_array;
1345
- }
1346
 
1347
  /**
1348
  * @since 3.0
1349
- *
1350
  * @param object $field
1351
- *
1352
  * @return array
1353
  */
1354
  public static function start_field_array( $field ) {
@@ -1365,48 +1246,48 @@ class FrmAppHelper {
1365
  );
1366
  }
1367
 
1368
- /**
1369
- * @param string $table
1370
- */
1371
  private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1372
- if ( $table == 'entries' ) {
1373
- $form = $record->form_id;
1374
  FrmForm::maybe_get_form( $form );
1375
- } else {
1376
- $form = $record;
1377
- }
1378
 
1379
- if ( ! $form ) {
1380
- return;
1381
- }
1382
 
1383
- $values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1384
  $values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1385
 
1386
  if ( ! is_array( $form->options ) ) {
1387
  return;
1388
  }
1389
 
1390
- foreach ( $form->options as $opt => $value ) {
1391
- $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1392
- }
1393
 
1394
  self::fill_form_defaults( $post_values, $values );
1395
- }
1396
 
1397
- /**
1398
- * Set to POST value or default
1399
- */
1400
  private static function fill_form_defaults( $post_values, array &$values ) {
1401
- $form_defaults = FrmFormsHelper::get_default_opts();
1402
 
1403
- foreach ( $form_defaults as $opt => $default ) {
1404
- if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1405
  $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1406
- }
1407
 
1408
  unset( $opt, $default );
1409
- }
1410
 
1411
  if ( ! isset( $values['custom_style'] ) ) {
1412
  $values['custom_style'] = self::custom_style_value( $post_values );
@@ -1415,16 +1296,14 @@ class FrmAppHelper {
1415
  foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1416
  if ( ! isset( $values[ $h . '_html' ] ) ) {
1417
  $values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1418
- }
1419
  unset( $h );
1420
- }
1421
- }
1422
 
1423
  /**
1424
  * @since 2.2.10
1425
- *
1426
  * @param array $post_values
1427
- *
1428
  * @return boolean|int
1429
  */
1430
  public static function custom_style_value( $post_values ) {
@@ -1434,75 +1313,87 @@ class FrmAppHelper {
1434
  $frm_settings = self::get_settings();
1435
  $custom_style = ( $frm_settings->load_style != 'none' );
1436
  }
1437
-
1438
  return $custom_style;
1439
  }
1440
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1441
  public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1442
- if ( is_array( $str ) ) {
1443
- return '';
1444
  }
1445
 
1446
- $length = (int) $length;
1447
- $str = wp_strip_all_tags( $str );
1448
  $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1449
 
1450
  if ( $length == 0 ) {
1451
- return '';
1452
- } elseif ( $length <= 10 ) {
1453
  $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1454
-
1455
  return $sub . ( ( $length < $original_len ) ? $continue : '' );
1456
- }
1457
 
1458
- $sub = '';
1459
- $len = 0;
1460
 
1461
  $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1462
 
1463
  foreach ( $words as $word ) {
1464
- $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1465
  $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1466
  if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
1467
- break;
1468
- }
1469
 
1470
- $sub .= $part;
1471
  $len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1472
 
1473
  if ( substr_count( $sub, ' ' ) > $minword && $total_len >= $length ) {
1474
- break;
1475
- }
1476
 
1477
  unset( $total_len, $word );
1478
- }
1479
 
1480
  return $sub . ( ( $len < $original_len ) ? $continue : '' );
1481
- }
1482
 
1483
  public static function mb_function( $function_names, $args ) {
1484
  $mb_function_name = $function_names[0];
1485
- $function_name = $function_names[1];
1486
  if ( function_exists( $mb_function_name ) ) {
1487
  $function_name = $mb_function_name;
1488
  }
1489
-
1490
  return call_user_func_array( $function_name, $args );
1491
  }
1492
 
1493
  public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1494
  if ( empty( $date ) ) {
1495
- return $date;
1496
- }
1497
 
1498
  if ( empty( $date_format ) ) {
1499
  $date_format = get_option( 'date_format' );
1500
  }
1501
 
1502
  if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1503
- $frmpro_settings = new FrmProSettings();
1504
- $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1505
- }
1506
 
1507
  $formatted = self::get_localized_date( $date_format, $date );
1508
 
@@ -1511,8 +1402,8 @@ class FrmAppHelper {
1511
  $formatted .= self::add_time_to_date( $time_format, $date );
1512
  }
1513
 
1514
- return $formatted;
1515
- }
1516
 
1517
  private static function add_time_to_date( $time_format, $date ) {
1518
  if ( empty( $time_format ) ) {
@@ -1520,7 +1411,7 @@ class FrmAppHelper {
1520
  }
1521
 
1522
  $trimmed_format = trim( $time_format );
1523
- $time = '';
1524
  if ( $time_format && ! empty( $trimmed_format ) ) {
1525
  $time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
1526
  }
@@ -1533,7 +1424,6 @@ class FrmAppHelper {
1533
  */
1534
  public static function get_localized_date( $date_format, $date ) {
1535
  $date = get_date_from_gmt( $date );
1536
-
1537
  return date_i18n( $date_format, strtotime( $date ) );
1538
  }
1539
 
@@ -1542,7 +1432,6 @@ class FrmAppHelper {
1542
  *
1543
  * @param int $from in seconds
1544
  * @param int|string $to in seconds
1545
- *
1546
  * @return string $time_ago
1547
  */
1548
  public static function human_time_diff( $from, $to = '', $levels = 1 ) {
@@ -1555,7 +1444,7 @@ class FrmAppHelper {
1555
 
1556
  // Get the time difference
1557
  $diff_object = $now->diff( $ago );
1558
- $diff = get_object_vars( $diff_object );
1559
 
1560
  // Add week amount and update day amount
1561
  $diff['w'] = floor( $diff['d'] / 7 );
@@ -1571,8 +1460,8 @@ class FrmAppHelper {
1571
  }
1572
  }
1573
 
1574
- $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
1575
- $time_strings = array_slice( $time_strings, 0, $levels_deep );
1576
  $time_ago_string = $time_strings ? implode( ' ', $time_strings ) : '0 ' . __( 'seconds', 'formidable' );
1577
 
1578
  return $time_ago_string;
@@ -1596,34 +1485,34 @@ class FrmAppHelper {
1596
  );
1597
  }
1598
 
1599
- // Pagination Methods.
1600
 
1601
- /**
1602
- * @param integer $current_p
1603
- */
1604
  public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1605
  return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1606
  }
1607
 
1608
- /**
1609
- * @param integer $current_p
1610
- */
1611
- public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1612
- if ( $current_p == 1 ) {
1613
- return 1;
1614
- } else {
1615
- return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1616
- }
1617
- }
1618
 
1619
  /**
1620
  * @return array
1621
  */
1622
  public static function json_to_array( $json_vars ) {
1623
- $vars = array();
1624
- foreach ( $json_vars as $jv ) {
1625
  $jv_name = explode( '[', $jv['name'] );
1626
- $last = count( $jv_name ) - 1;
1627
  foreach ( $jv_name as $p => $n ) {
1628
  $name = trim( $n, ']' );
1629
  if ( ! isset( $l1 ) ) {
@@ -1638,78 +1527,77 @@ class FrmAppHelper {
1638
  $l3 = $name;
1639
  }
1640
 
1641
- $this_val = ( $p == $last ) ? $jv['value'] : array();
1642
 
1643
- switch ( $p ) {
1644
- case 0:
1645
- $l1 = $name;
1646
- self::add_value_to_array( $name, $l1, $this_val, $vars );
1647
  break;
1648
 
1649
- case 1:
1650
- $l2 = $name;
1651
- self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1652
  break;
1653
 
1654
- case 2:
1655
- $l3 = $name;
1656
- self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1657
  break;
1658
 
1659
- case 3:
1660
- $l4 = $name;
1661
- self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1662
- }
1663
 
1664
  unset( $this_val, $n );
1665
- }
1666
 
1667
  unset( $last, $jv );
1668
- }
1669
-
1670
- return $vars;
1671
- }
1672
-
1673
- /**
1674
- * @param string $name
1675
- * @param string $l1
1676
- */
1677
- public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1678
- if ( $name == '' ) {
1679
- $vars[] = $val;
1680
- } elseif ( ! isset( $vars[ $l1 ] ) ) {
1681
- $vars[ $l1 ] = $val;
1682
- }
1683
- }
1684
 
1685
  public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1686
- $tooltips = array(
1687
- 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
1688
- 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
1689
- 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1690
- 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1691
- 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1692
- 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
1693
- /* translators: %1$s: Form name, %2$s: Date */
1694
- 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1695
- );
1696
-
1697
- if ( ! isset( $tooltips[ $name ] ) ) {
1698
- return;
1699
- }
1700
-
1701
- if ( 'open' == $class ) {
1702
- echo ' frm_help"';
1703
- } else {
1704
- echo ' class="frm_help"';
1705
- }
1706
 
1707
  echo ' title="' . esc_attr( $tooltips[ $name ] );
1708
 
1709
- if ( 'open' != $class ) {
1710
- echo '"';
1711
- }
1712
- }
1713
 
1714
  /**
1715
  * Add the current_page class to that page in the form nav
@@ -1725,36 +1613,35 @@ class FrmAppHelper {
1725
  }
1726
  }
1727
 
1728
- /**
1729
- * Prepare and json_encode post content
1730
- *
1731
- * @since 2.0
1732
- *
1733
- * @param array $post_content
1734
- *
1735
- * @return string $post_content ( json encoded array )
1736
- */
1737
- public static function prepare_and_encode( $post_content ) {
1738
- // Loop through array to strip slashes and add only the needed ones.
1739
  foreach ( $post_content as $key => $val ) {
1740
  // Replace problematic characters (like &quot;)
1741
  $val = str_replace( '&quot;', '"', $val );
1742
 
1743
  self::prepare_action_slashes( $val, $key, $post_content );
1744
- unset( $key, $val );
1745
- }
1746
 
1747
- // json_encode the array.
1748
- $post_content = json_encode( $post_content );
1749
 
1750
- // Add extra slashes for \r\n since WP strips them.
1751
  $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1752
 
1753
- // allow for &quot
1754
- $post_content = str_replace( '&quot;', '\\"', $post_content );
1755
 
1756
- return $post_content;
1757
- }
1758
 
1759
  private static function prepare_action_slashes( $val, $key, &$post_content ) {
1760
  if ( ! isset( $post_content[ $key ] ) ) {
@@ -1777,56 +1664,55 @@ class FrmAppHelper {
1777
 
1778
  public static function maybe_json_decode( $string ) {
1779
  if ( is_array( $string ) ) {
1780
- return $string;
1781
- }
1782
 
1783
  $new_string = json_decode( $string, true );
1784
  if ( function_exists( 'json_last_error' ) ) {
1785
  // php 5.3+
1786
- if ( json_last_error() == JSON_ERROR_NONE ) {
1787
- $string = $new_string;
1788
- }
1789
  } elseif ( isset( $new_string ) ) {
1790
  // php < 5.3 fallback
1791
- $string = $new_string;
1792
- }
1793
-
1794
- return $string;
1795
- }
1796
-
1797
- /**
1798
- * @since 1.07.10
1799
- *
1800
- * @param string $post_type The name of the post type that may need to be highlighted
1801
- * echo The javascript to open and highlight the Formidable menu
1802
- */
1803
  public static function maybe_highlight_menu( $post_type ) {
1804
- global $post;
1805
 
1806
  if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1807
- return;
1808
- }
1809
 
1810
  if ( is_object( $post ) && $post->post_type != $post_type ) {
1811
- return;
1812
- }
1813
 
1814
- self::load_admin_wide_js();
1815
- echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1816
- }
1817
 
1818
- /**
1819
- * Load the JS file on non-Formidable pages in the admin area
1820
  *
1821
- * @since 2.0
1822
- */
1823
  public static function load_admin_wide_js( $load = true ) {
1824
  $version = self::plugin_version();
1825
  wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1826
 
1827
  $global_strings = array(
1828
  'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1829
- 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1830
  'url' => self::plugin_url(),
1831
  'loading' => __( 'Loading&hellip;', 'formidable' ),
1832
  'nonce' => wp_create_nonce( 'frm_ajax' ),
@@ -1836,7 +1722,7 @@ class FrmAppHelper {
1836
  if ( $load ) {
1837
  wp_enqueue_script( 'formidable_admin_global' );
1838
  }
1839
- }
1840
 
1841
  /**
1842
  * @since 2.0.9
@@ -1845,30 +1731,30 @@ class FrmAppHelper {
1845
  wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1846
  }
1847
 
1848
- /**
1849
- * @param string $location
1850
- */
1851
  public static function localize_script( $location ) {
1852
  $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1853
  $ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
1854
 
1855
  $script_strings = array(
1856
- 'ajax_url' => $ajax_url,
1857
- 'images_url' => self::plugin_url() . '/images',
1858
- 'loading' => __( 'Loading&hellip;', 'formidable' ),
1859
- 'remove' => __( 'Remove', 'formidable' ),
1860
- 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
1861
- 'nonce' => wp_create_nonce( 'frm_ajax' ),
1862
- 'id' => __( 'ID', 'formidable' ),
1863
- 'no_results' => __( 'No results match', 'formidable' ),
1864
- 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
1865
- 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
1866
  'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
1867
  );
1868
  wp_localize_script( 'formidable', 'frm_js', $script_strings );
1869
 
1870
  if ( $location == 'admin' ) {
1871
- $frm_settings = self::get_settings();
1872
  $admin_script_strings = array(
1873
  'confirm_uninstall' => __( 'Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable' ),
1874
  'desc' => __( '(Click to add description)', 'formidable' ),
@@ -1912,92 +1798,92 @@ class FrmAppHelper {
1912
  }
1913
  }
1914
 
1915
- /**
1916
  * Echo the message on the plugins listing page
1917
  *
1918
- * @since 1.07.10
1919
- *
1920
- * @param float $min_version The version the add-on requires
1921
- */
1922
  public static function min_version_notice( $min_version ) {
1923
- $frm_version = self::plugin_version();
1924
 
1925
- // Check if Formidable meets minimum requirements.
1926
  if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1927
- return;
1928
- }
1929
 
1930
  $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1931
  echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
1932
- esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1933
- '</div></td></tr>';
1934
- }
1935
 
1936
- public static function locales( $type = 'date' ) {
1937
  $locales = array(
1938
- 'en' => __( 'English', 'formidable' ),
1939
- 'af' => __( 'Afrikaans', 'formidable' ),
1940
- 'sq' => __( 'Albanian', 'formidable' ),
1941
- 'ar' => __( 'Arabic', 'formidable' ),
1942
- 'hy' => __( 'Armenian', 'formidable' ),
1943
- 'az' => __( 'Azerbaijani', 'formidable' ),
1944
- 'eu' => __( 'Basque', 'formidable' ),
1945
- 'bs' => __( 'Bosnian', 'formidable' ),
1946
- 'bg' => __( 'Bulgarian', 'formidable' ),
1947
- 'ca' => __( 'Catalan', 'formidable' ),
1948
- 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1949
- 'zh-CN' => __( 'Chinese Simplified', 'formidable' ),
1950
- 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1951
- 'hr' => __( 'Croatian', 'formidable' ),
1952
- 'cs' => __( 'Czech', 'formidable' ),
1953
- 'da' => __( 'Danish', 'formidable' ),
1954
- 'nl' => __( 'Dutch', 'formidable' ),
1955
- 'en-GB' => __( 'English/UK', 'formidable' ),
1956
- 'eo' => __( 'Esperanto', 'formidable' ),
1957
- 'et' => __( 'Estonian', 'formidable' ),
1958
- 'fo' => __( 'Faroese', 'formidable' ),
1959
- 'fa' => __( 'Farsi/Persian', 'formidable' ),
1960
- 'fil' => __( 'Filipino', 'formidable' ),
1961
- 'fi' => __( 'Finnish', 'formidable' ),
1962
- 'fr' => __( 'French', 'formidable' ),
1963
- 'fr-CA' => __( 'French/Canadian', 'formidable' ),
1964
- 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1965
- 'de' => __( 'German', 'formidable' ),
1966
- 'de-AT' => __( 'German/Austria', 'formidable' ),
1967
- 'de-CH' => __( 'German/Switzerland', 'formidable' ),
1968
- 'el' => __( 'Greek', 'formidable' ),
1969
- 'he' => __( 'Hebrew', 'formidable' ),
1970
- 'iw' => __( 'Hebrew', 'formidable' ),
1971
- 'hi' => __( 'Hindi', 'formidable' ),
1972
- 'hu' => __( 'Hungarian', 'formidable' ),
1973
- 'is' => __( 'Icelandic', 'formidable' ),
1974
- 'id' => __( 'Indonesian', 'formidable' ),
1975
- 'it' => __( 'Italian', 'formidable' ),
1976
- 'ja' => __( 'Japanese', 'formidable' ),
1977
- 'ko' => __( 'Korean', 'formidable' ),
1978
- 'lv' => __( 'Latvian', 'formidable' ),
1979
- 'lt' => __( 'Lithuanian', 'formidable' ),
1980
- 'ms' => __( 'Malaysian', 'formidable' ),
1981
- 'no' => __( 'Norwegian', 'formidable' ),
1982
- 'pl' => __( 'Polish', 'formidable' ),
1983
- 'pt' => __( 'Portuguese', 'formidable' ),
1984
- 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1985
- 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ),
1986
- 'ro' => __( 'Romanian', 'formidable' ),
1987
- 'ru' => __( 'Russian', 'formidable' ),
1988
- 'sr' => __( 'Serbian', 'formidable' ),
1989
- 'sr-SR' => __( 'Serbian', 'formidable' ),
1990
- 'sk' => __( 'Slovak', 'formidable' ),
1991
- 'sl' => __( 'Slovenian', 'formidable' ),
1992
- 'es' => __( 'Spanish', 'formidable' ),
1993
  'es-419' => __( 'Spanish/Latin America', 'formidable' ),
1994
- 'sv' => __( 'Swedish', 'formidable' ),
1995
- 'ta' => __( 'Tamil', 'formidable' ),
1996
- 'th' => __( 'Thai', 'formidable' ),
1997
- 'tu' => __( 'Turkish', 'formidable' ),
1998
- 'tr' => __( 'Turkish', 'formidable' ),
1999
- 'uk' => __( 'Ukranian', 'formidable' ),
2000
- 'vi' => __( 'Vietnamese', 'formidable' ),
2001
  );
2002
 
2003
  if ( $type === 'captcha' ) {
@@ -2011,16 +1897,8 @@ class FrmAppHelper {
2011
  $locales = array_diff_key( $locales, array_flip( $unset ) );
2012
  $locales = apply_filters( 'frm_locales', $locales );
2013
 
2014
- return $locales;
2015
- }
2016
-
2017
- /**
2018
- * @deprecated 4.0
2019
- */
2020
- public static function insert_opt_html( $args ) {
2021
- _deprecated_function( __METHOD__, '4.0', 'FrmFormsHelper::insert_opt_html' );
2022
- FrmFormsHelper::insert_opt_html( $args );
2023
- }
2024
 
2025
  /**
2026
  * Used to filter shortcode in text widgets
@@ -2070,7 +1948,6 @@ class FrmAppHelper {
2070
  * @param string $group The name of the cache group
2071
  * @param string $query If blank, don't run a db call
2072
  * @param string $type The wpdb function to use with this query
2073
- *
2074
  * @return mixed $results The cache or query results
2075
  */
2076
  public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
@@ -2115,7 +1992,6 @@ class FrmAppHelper {
2115
  * @since 2.0
2116
  * @deprecated 2.05.06
2117
  * @codeCoverageIgnore
2118
- *
2119
  * @param string $cache_key
2120
  */
2121
  public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
@@ -2139,7 +2015,6 @@ class FrmAppHelper {
2139
  * @codeCoverageIgnore
2140
  *
2141
  * @param string $term The value to escape
2142
- *
2143
  * @return string The escaped value
2144
  */
2145
  public static function esc_like( $term ) {
@@ -2148,7 +2023,6 @@ class FrmAppHelper {
2148
 
2149
  /**
2150
  * @param string $order_query
2151
- *
2152
  * @deprecated 2.05.06
2153
  * @codeCoverageIgnore
2154
  */
@@ -2166,7 +2040,6 @@ class FrmAppHelper {
2166
 
2167
  /**
2168
  * @param string $limit
2169
- *
2170
  * @deprecated 2.05.06
2171
  * @codeCoverageIgnore
2172
  */
4
  }
5
 
6
  class FrmAppHelper {
7
+ public static $db_version = 90; //version of the database we are moving to
8
  public static $pro_db_version = 37; //deprecated
9
+ public static $font_version = 3;
10
 
11
  /**
12
  * @since 2.0
13
  */
14
+ public static $plug_version = '3.06.06';
15
 
16
+ /**
17
+ * @since 1.07.02
18
+ *
19
+ * @param none
20
+ * @return string The version of this plugin
21
+ */
22
+ public static function plugin_version() {
23
+ return self::$plug_version;
24
+ }
 
25
 
26
  public static function plugin_folder() {
27
  return basename( self::plugin_path() );
31
  return dirname( dirname( dirname( __FILE__ ) ) );
32
  }
33
 
34
+ public static function plugin_url() {
35
+ //prevously FRM_URL constant
36
  return plugins_url( '', self::plugin_path() . '/formidable.php' );
37
+ }
38
 
39
  public static function relative_plugin_url() {
40
  return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
41
  }
42
 
43
+ /**
44
+ * @return string Site URL
45
+ */
46
+ public static function site_url() {
47
+ return site_url();
48
+ }
49
+
50
+ /**
51
+ * Get the name of this site
52
+ * Used for [sitename] shortcode
53
+ *
54
+ * @since 2.0
55
+ * @return string
56
+ */
57
  public static function site_name() {
58
  return get_option( 'blogname' );
59
  }
64
  $url = str_replace( array( 'http://', 'https://' ), '', $url );
65
  $url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
66
  }
 
67
  return $url;
68
  }
69
 
107
  return add_query_arg( $query_args, $page ) . $anchor;
108
  }
109
 
110
+ /**
111
+ * Get the Formidable settings
112
+ *
113
+ * @since 2.0
114
+ *
115
+ * @param array $args - May include the form id when values need translation.
116
+ * @return FrmSettings $frm_setings
117
+ */
118
  public static function get_settings( $args = array() ) {
119
  global $frm_settings;
120
  if ( empty( $frm_settings ) ) {
129
 
130
  public static function get_menu_name() {
131
  $frm_settings = self::get_settings();
 
132
  return $frm_settings->menu;
133
  }
134
 
142
  'fill' => '#4d4d4d',
143
  'orange' => '#f05a24',
144
  );
145
+ $atts = array_merge( $defaults, $atts );
 
146
  return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 599.68 601.37" width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '">
147
  <defs />
148
  <rect fill="' . esc_attr( $atts['orange'] ) . '" x="289.64" y="383.96" width="140" height="76" />
152
  </svg>';
153
  }
154
 
 
 
 
 
 
 
 
155
  /**
156
  * @since 2.02.04
157
  */
158
  public static function ips_saved() {
159
  $frm_settings = self::get_settings();
 
160
  return ! $frm_settings->no_ips;
161
  }
162
 
165
  }
166
 
167
  public static function is_formidable_admin() {
168
+ $page = self::simple_get( 'page', 'sanitize_title' );
169
  $is_formidable = strpos( $page, 'formidable' ) !== false;
170
  if ( empty( $page ) ) {
171
  global $pagenow;
172
+ $post_type = self::simple_get( 'post_type', 'sanitize_title' );
173
  $is_formidable = ( $post_type == 'frm_display' );
174
  if ( empty( $post_type ) && $pagenow == 'post.php' ) {
175
  global $post;
176
  $is_formidable = ( $post && $post->post_type == 'frm_display' );
177
  }
178
  }
 
179
  return $is_formidable;
180
  }
181
 
182
+ /**
183
+ * Check for certain page in Formidable settings
184
+ *
185
+ * @since 2.0
186
+ *
187
+ * @param string $page The name of the page to check
188
+ * @return boolean
189
+ */
 
190
  public static function is_admin_page( $page = 'formidable' ) {
191
+ global $pagenow;
192
  $get_page = self::simple_get( 'page', 'sanitize_title' );
193
+ if ( $pagenow ) {
194
  // allow this to be true during ajax load i.e. ajax form builder loading
195
  return ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
196
+ }
197
 
198
  return is_admin() && $get_page == $page;
199
+ }
200
+
201
+ /**
202
+ * Check for the form preview page
203
+ *
204
+ * @since 2.0
205
+ *
206
+ * @param None
207
+ * @return boolean
208
+ */
209
+ public static function is_preview_page() {
210
+ global $pagenow;
 
211
  $action = self::simple_get( 'action', 'sanitize_title' );
 
212
  return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
213
+ }
214
+
215
+ /**
216
+ * Check for ajax except the form preview page
217
+ *
218
+ * @since 2.0
219
+ *
220
+ * @param None
221
+ * @return boolean
222
+ */
223
+ public static function doing_ajax() {
224
+ return self::wp_doing_ajax() && ! self::is_preview_page();
225
+ }
 
226
 
227
  public static function js_suffix() {
228
  return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
239
  } else {
240
  $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
241
  }
 
242
  return $doing_ajax;
243
  }
244
 
247
  */
248
  public static function prevent_caching() {
249
  global $frm_vars;
 
250
  return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
251
  }
252
 
253
+ /**
254
+ * Check if on an admin page
255
+ *
256
+ * @since 2.0
257
+ *
258
+ * @param None
259
+ * @return boolean
260
+ */
261
+ public static function is_admin() {
262
+ return is_admin() && ! self::wp_doing_ajax();
263
+ }
264
+
265
+ /**
266
+ * Check if value contains blank value or empty array
267
+ *
268
+ * @since 2.0
269
+ * @param mixed $value - value to check
 
 
270
  * @param string
271
+ * @return boolean
272
+ */
273
+ public static function is_empty_value( $value, $empty = '' ) {
274
+ return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
275
+ }
276
+
277
+ public static function is_not_empty_value( $value, $empty = '' ) {
278
+ return ! self::is_empty_value( $value, $empty );
279
+ }
280
+
281
+ /**
282
+ * Get any value from the $_SERVER
283
+ *
284
+ * @since 2.0
285
+ * @param string $value
286
+ * @return string
287
+ */
 
 
 
288
  public static function get_server_value( $value ) {
289
+ return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
290
+ }
291
+
292
+ /**
293
+ * Check for the IP address in several places
294
+ * Used by [ip] shortcode
295
+ *
296
+ * @return string The IP address of the current user
297
+ */
298
+ public static function get_ip_address() {
299
  $ip_options = array(
300
  'HTTP_CLIENT_IP',
301
  'HTTP_CF_CONNECTING_IP',
309
  );
310
  $ip = '';
311
  foreach ( $ip_options as $key ) {
312
+ if ( ! isset( $_SERVER[ $key ] ) ) {
313
+ continue;
314
+ }
315
 
316
+ foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
317
+ $ip = trim( $ip ); // just to be safe
 
318
 
319
  if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
320
+ return sanitize_text_field( $ip );
321
+ }
322
+ }
323
+ }
324
 
325
  return sanitize_text_field( $ip );
326
+ }
327
 
328
+ public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
329
  if ( strpos( $param, '[' ) ) {
330
  $params = explode( '[', $param );
331
+ $param = $params[0];
332
+ }
333
 
334
  if ( $src == 'get' ) {
335
+ $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
336
+ if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
337
+ $value = stripslashes_deep( htmlspecialchars_decode( $_GET[ $param ] ) );
338
+ }
339
  self::sanitize_value( $sanitize, $value );
340
  } else {
341
  $value = self::get_simple_request(
354
  continue;
355
  }
356
 
357
+ $p = trim( $p, ']' );
358
  $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
359
  }
360
  }
361
 
362
+ return $value;
363
+ }
364
 
365
  public static function get_post_param( $param, $default = '', $sanitize = '' ) {
366
  return self::get_simple_request(
379
  * @param string $param
380
  * @param string $sanitize
381
  * @param string $default
 
382
  * @return string|array
383
  */
384
  public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
396
  * Get a GET/POST/REQUEST value and sanitize it
397
  *
398
  * @since 2.0.6
 
399
  * @param array $args
 
400
  * @return string|array
401
  */
402
  public static function get_simple_request( $args ) {
406
  'type' => 'get',
407
  'sanitize' => 'sanitize_text_field',
408
  );
409
+ $args = wp_parse_args( $args, $defaults );
410
 
411
  $value = $args['default'];
412
  if ( $args['type'] == 'get' ) {
413
  if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
414
+ $value = $_GET[ $args['param'] ];
415
  }
416
+ } else if ( $args['type'] == 'post' ) {
417
  if ( isset( $_POST[ $args['param'] ] ) ) {
418
+ $value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) );
419
  }
420
  } else {
421
  if ( isset( $_REQUEST[ $args['param'] ] ) ) {
422
+ $value = $_REQUEST[ $args['param'] ];
423
  }
424
  }
425
 
426
  self::sanitize_value( $args['sanitize'], $value );
 
427
  return $value;
428
  }
429
 
430
  /**
431
+ * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
432
+ *
433
+ * @since 2.0.8
434
+ * @param string $value
435
+ * @return string $value
436
+ */
 
 
437
  public static function preserve_backslashes( $value ) {
438
  // If backslashes have already been added, don't add them again
439
  if ( strpos( $value, '\\\\' ) === false ) {
440
  $value = addslashes( $value );
441
  }
 
442
  return $value;
443
  }
444
 
455
  }
456
  }
457
 
458
+ public static function sanitize_request( $sanitize_method, &$values ) {
459
+ $temp_values = $values;
460
+ foreach ( $temp_values as $k => $val ) {
461
+ if ( isset( $sanitize_method[ $k ] ) ) {
462
  $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
463
+ }
464
+ }
465
+ }
466
 
467
  /**
468
  * Sanitize the value, and allow some HTML
469
  *
470
  * @since 2.0
 
471
  * @param string $value
472
  * @param array|string $allowed 'all' for everything included as defaults
 
473
  * @return string
474
  */
475
  public static function kses( $value, $allowed = array() ) {
482
  * @since 2.05.03
483
  */
484
  private static function allowed_html( $allowed ) {
485
+ $html = self::safe_html();
486
  $allowed_html = array();
487
  if ( $allowed == 'all' ) {
488
  $allowed_html = $html;
505
  );
506
 
507
  return array(
508
+ 'a' => array(
509
  'class' => true,
510
  'href' => true,
511
  'id' => true,
513
  'target' => true,
514
  'title' => true,
515
  ),
516
+ 'abbr' => array(
517
  'title' => true,
518
  ),
519
+ 'aside' => $allow_class,
520
+ 'b' => array(),
521
  'blockquote' => array(
522
+ 'cite' => true,
523
  ),
524
+ 'br' => array(),
525
+ 'cite' => array(
526
  'title' => true,
527
  ),
528
+ 'code' => array(),
529
+ 'defs' => array(),
530
+ 'del' => array(
531
  'datetime' => true,
532
  'title' => true,
533
  ),
534
+ 'dd' => array(),
535
+ 'div' => array(
536
  'class' => true,
537
  'id' => true,
538
  'title' => true,
539
  'style' => true,
540
  ),
541
+ 'dl' => array(),
542
+ 'dt' => array(),
543
+ 'em' => array(),
544
+ 'h1' => $allow_class,
545
+ 'h2' => $allow_class,
546
+ 'h3' => $allow_class,
547
+ 'h4' => $allow_class,
548
+ 'h5' => $allow_class,
549
+ 'h6' => $allow_class,
550
+ 'i' => array(
551
  'class' => true,
552
  'id' => true,
553
  'icon' => true,
554
  ),
555
+ 'img' => array(
556
  'alt' => true,
557
  'class' => true,
558
  'height' => true,
560
  'src' => true,
561
  'width' => true,
562
  ),
563
+ 'li' => $allow_class,
564
+ 'ol' => $allow_class,
565
+ 'p' => $allow_class,
566
+ 'path' => array(
567
  'd' => true,
568
  'fill' => true,
569
  ),
570
+ 'pre' => array(),
571
+ 'q' => array(
572
  'cite' => true,
573
  'title' => true,
574
  ),
575
+ 'rect' => array(
576
  'class' => true,
577
  'fill' => true,
578
  'height' => true,
580
  'x' => true,
581
  'y' => true,
582
  ),
583
+ 'section' => $allow_class,
584
+ 'span' => array(
585
  'class' => true,
586
  'id' => true,
587
  'title' => true,
588
  'style' => true,
589
  ),
590
+ 'strike' => array(),
591
+ 'strong' => array(),
592
+ 'svg' => array(
593
  'xmlns' => true,
594
  'viewbox' => true,
595
  'width' => true,
596
  'height' => true,
597
  ),
598
+ 'ul' => $allow_class,
599
  );
600
  }
601
 
602
+ /**
603
+ * Used when switching the action for a bulk action
604
  *
605
+ * @since 2.0
606
+ */
607
  public static function remove_get_action() {
608
  if ( ! isset( $_GET ) ) {
609
  return;
610
  }
611
 
612
+ $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
613
+ if ( ! empty( $new_action ) ) {
 
 
 
 
 
614
  $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
615
+ }
616
+ }
617
 
618
+ /**
619
+ * Check the WP query for a parameter
620
+ *
621
+ * @since 2.0
622
+ * @return string|array
623
+ */
624
+ public static function get_query_var( $value, $param ) {
625
+ if ( $value != '' ) {
626
+ return $value;
627
+ }
628
 
629
+ global $wp_query;
630
+ if ( isset( $wp_query->query_vars[ $param ] ) ) {
631
+ $value = $wp_query->query_vars[ $param ];
632
+ }
633
 
634
+ return $value;
635
+ }
636
 
637
  /**
638
  * @since 3.0
639
  */
640
  public static function get_admin_header( $atts ) {
641
  $has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
 
 
 
 
642
  include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
643
  }
644
 
647
  */
648
  public static function add_new_item_link( $atts ) {
649
  if ( isset( $atts['new_link'] ) && ! empty( $atts['new_link'] ) ) { ?>
650
+ <a href="<?php echo esc_url( $atts['new_link'] ) ?>" class="add-new-h2 frm_animate_bg"><?php esc_html_e( 'Add New', 'formidable' ); ?></a>
651
+ <?php
 
 
652
  } elseif ( isset( $atts['link_hook'] ) ) {
653
  do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
654
  }
657
  /**
658
  * @since 3.06
659
  */
660
+ public static function show_search_box( $text, $input_id, $placeholder = '' ) {
661
+ $tosearch = '';
662
+ $class = 'frm-search-input';
663
+ if ( $input_id === 'template' ) {
664
+ $tosearch = 'frm-card';
 
 
 
 
 
 
 
 
 
 
665
  $class .= ' frm-auto-search';
666
  }
667
+ $input_id = $input_id . '-search-input';
668
+ if ( empty( $text ) ) {
669
+ $text = __( 'Search', 'formidable' );
670
+ }
671
  ?>
672
+ <p class="search-box frm-search">
673
+ <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ) ?>">
674
+ <?php echo wp_kses( $text, array() ); ?>:
675
  </label>
676
+ <span class="dashicons dashicons-search"></span>
677
+ <input type="search" id="<?php echo esc_attr( $input_id ) ?>" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $tosearch ); ?>" />
 
 
 
 
 
 
678
  <?php
679
+ if ( empty( $tosearch ) ) {
680
+ submit_button( $text, 'button-secondary', '', false, array( 'id' => 'search-submit' ) );
681
  }
682
  ?>
683
  </p>
684
  <?php
685
  }
686
 
687
+ /**
688
+ * @param string $type
689
+ */
690
+ public static function trigger_hook_load( $type, $object = null ) {
691
+ // only load the form hooks once
692
  $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
693
+ if ( ! $hooks_loaded ) {
694
  do_action( 'frm_load_' . $type . '_hooks' );
695
+ }
696
+ }
697
 
698
  /**
699
  * Save all front-end js scripts into a single file
704
  $file_atts = apply_filters(
705
  'frm_js_location',
706
  array(
707
+ 'file_name' => 'frm.min.js',
708
  'new_file_path' => self::plugin_path() . '/js',
709
  )
710
  );
711
+ $new_file = new FrmCreateFile( $file_atts );
712
 
713
  $files = array(
714
  self::plugin_path() . '/js/jquery/jquery.placeholder.min.js',
718
  $new_file->combine_files( $files );
719
  }
720
 
721
+ /**
722
+ * Check a value from a shortcode to see if true or false.
723
+ * True when value is 1, true, 'true', 'yes'
724
+ *
725
+ * @since 1.07.10
726
+ *
727
+ * @param string $value The value to compare
728
+ * @return boolean True or False
729
+ */
 
730
  public static function is_true( $value ) {
731
+ return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
732
+ }
733
 
734
  public static function get_pages() {
735
  $query = array(
736
  'post_type' => 'page',
737
  'post_status' => array( 'publish', 'private' ),
738
+ 'numberposts' => -1,
739
  'orderby' => 'title',
740
  'order' => 'ASC',
741
  );
 
742
  return get_posts( $query );
743
  }
744
 
745
+ public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
746
+ $pages = self::get_pages();
747
  $selected = self::get_post_param( $field_name, $page_id, 'absint' );
748
+ ?>
749
  <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
750
+ <option value=""> </option>
751
+ <?php foreach ( $pages as $page ) { ?>
752
  <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>>
753
  <?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
754
  </option>
755
+ <?php } ?>
756
+ </select>
757
+ <?php
758
+ }
759
 
760
  public static function post_edit_link( $post_id ) {
761
  $post = get_post( $post_id );
762
+ if ( $post ) {
763
  $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
 
 
764
  return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
765
+ }
766
+ return '';
767
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
768
 
769
  public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
770
  ?>
771
+ <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?> class="frm_multiselect">
 
 
772
  <?php self::roles_options( $capability ); ?>
773
  </select>
774
  <?php
775
  }
776
 
777
  public static function roles_options( $capability ) {
778
+ global $frm_vars;
779
  if ( isset( $frm_vars['editable_roles'] ) ) {
780
+ $editable_roles = $frm_vars['editable_roles'];
781
+ } else {
782
+ $editable_roles = get_editable_roles();
783
+ $frm_vars['editable_roles'] = $editable_roles;
784
+ }
785
 
786
+ foreach ( $editable_roles as $role => $details ) {
787
  $name = translate_user_role( $details['name'] );
788
  ?>
789
+ <option value="<?php echo esc_attr( $role ); ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ); ?> </option>
790
+ <?php
791
  unset( $role, $details );
792
+ }
793
+ }
794
 
795
  public static function frm_capabilities( $type = 'auto' ) {
796
+ $cap = array(
797
+ 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ),
798
+ 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ),
799
+ 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ),
800
+ 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
801
+ 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ),
802
+ 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ),
803
+ );
804
 
805
  if ( ! self::pro_is_installed() && 'pro' != $type ) {
806
+ return $cap;
807
+ }
808
 
809
+ $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
810
+ $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
811
+ $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
812
+ $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
813
 
814
+ return $cap;
815
+ }
816
 
817
  public static function user_has_permission( $needed_role ) {
818
+ if ( $needed_role == '-1' ) {
819
+ return false;
820
  }
821
 
822
+ // $needed_role will be equal to blank if "Logged-in users" is selected
823
+ if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
824
+ return true;
825
+ }
826
 
827
+ $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
828
+ foreach ( $roles as $role ) {
829
  if ( current_user_can( $role ) ) {
830
+ return true;
831
  }
832
+ if ( $role == $needed_role ) {
833
+ break;
834
  }
835
+ }
836
+ return false;
837
+ }
838
+
839
+ /**
840
+ * Make sure administrators can see Formidable menu
841
+ *
842
+ * @since 2.0
843
+ */
844
+ public static function maybe_add_permissions() {
 
845
  self::force_capability( 'frm_view_entries' );
846
 
847
  if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
848
  return;
849
  }
850
 
851
+ $user_id = get_current_user_id();
852
+ $user = new WP_User( $user_id );
853
+ $frm_roles = self::frm_capabilities();
854
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
855
  $user->add_cap( $frm_role );
856
  unset( $frm_role, $frm_role_description );
857
+ }
858
+ }
859
 
860
  /**
861
  * Make sure admins have permission to see the menu items
864
  */
865
  public static function force_capability( $cap = 'frm_change_settings' ) {
866
  if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
867
+ $role = get_role( 'administrator' );
868
  $frm_roles = self::frm_capabilities();
869
  foreach ( $frm_roles as $frm_role => $frm_role_description ) {
870
  $role->add_cap( $frm_role );
872
  }
873
  }
874
 
875
+ /**
876
+ * Check if the user has permision for action.
877
+ * Return permission message and stop the action if no permission
 
 
878
  *
879
+ * @since 2.0
880
+ * @param string $permission
881
+ */
882
  public static function permission_check( $permission, $show_message = 'show' ) {
883
  $permission_error = self::permission_nonce_error( $permission );
884
+ if ( $permission_error !== false ) {
885
+ if ( 'hide' == $show_message ) {
886
+ $permission_error = '';
887
+ }
888
  wp_die( esc_html( $permission_error ) );
889
+ }
890
+ }
891
 
892
+ /**
893
+ * Check user permission and nonce
 
 
 
 
894
  *
895
+ * @since 2.0
896
+ * @param string $permission
897
+ * @return false|string The permission message or false if allowed
898
+ */
899
  public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
900
  if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
901
  $frm_settings = self::get_settings();
 
902
  return $frm_settings->admin_permission;
903
  }
904
 
905
  $error = false;
906
  if ( empty( $nonce_name ) ) {
907
+ return $error;
908
+ }
909
 
910
+ if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
911
+ $frm_settings = self::get_settings();
912
+ $error = $frm_settings->admin_permission;
913
+ }
 
914
 
915
+ return $error;
916
+ }
917
 
918
+ public static function checked( $values, $current ) {
919
  if ( self::check_selected( $values, $current ) ) {
920
+ echo ' checked="checked"';
921
  }
922
+ }
923
 
924
  public static function check_selected( $values, $current ) {
925
+ $values = self::recursive_function_map( $values, 'trim' );
926
+ $values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
927
  $current = htmlspecialchars_decode( trim( $current ) );
928
 
929
  return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
957
  return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
958
  }
959
 
960
+ /**
961
+ * Flatten a multi-dimensional array
962
+ */
963
  public static function array_flatten( $array, $keys = 'keep' ) {
964
+ $return = array();
965
+ foreach ( $array as $key => $value ) {
966
  if ( is_array( $value ) ) {
967
  $return = array_merge( $return, self::array_flatten( $value, $keys ) );
968
+ } else {
969
  if ( $keys == 'keep' ) {
970
  $return[ $key ] = $value;
971
  } else {
972
  $return[] = $value;
973
  }
974
+ }
975
+ }
976
+ return $return;
977
+ }
 
978
 
979
  public static function esc_textarea( $text, $is_rich_text = false ) {
980
  $safe_text = str_replace( '&quot;', '"', $text );
982
  $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
983
  }
984
  $safe_text = str_replace( '&amp;', '&', $safe_text );
 
985
  return apply_filters( 'esc_textarea', $safe_text, $text );
986
  }
987
 
988
+ /**
989
+ * Add auto paragraphs to text areas
990
  *
991
+ * @since 2.0
992
+ */
993
  public static function use_wpautop( $content ) {
994
  if ( apply_filters( 'frm_use_wpautop', true ) ) {
995
  $content = wpautop( str_replace( '<br>', '<br />', $content ) );
996
  }
 
997
  return $content;
998
  }
999
 
1000
  public static function replace_quotes( $val ) {
1001
+ //Replace double quotes
1002
  $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
1003
+ //Replace single quotes
1004
+ $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
1005
+ return $val;
1006
+ }
1007
+
1008
+ /**
1009
+ * @since 2.0
1010
+ * @return string The base Google APIS url for the current version of jQuery UI
1011
+ */
1012
+ public static function jquery_ui_base_url() {
 
 
1013
  $url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core', '1.11.4' );
1014
  $url = apply_filters( 'frm_jquery_ui_base_url', $url );
1015
+ return $url;
1016
+ }
1017
 
1018
+ /**
1019
+ * @param string $handle
1020
+ */
 
 
 
1021
  public static function script_version( $handle, $default = 0 ) {
1022
  global $wp_scripts;
1023
  if ( ! $wp_scripts ) {
1039
 
1040
  public static function js_redirect( $url ) {
1041
  return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
1042
+ }
1043
 
1044
  public static function get_user_id_param( $user_id ) {
1045
  if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
1046
+ return $user_id;
1047
+ }
1048
 
1049
  $user_id = sanitize_text_field( $user_id );
1050
  if ( $user_id == 'current' ) {
1056
  $user = get_user_by( 'login', $user_id );
1057
  }
1058
 
1059
+ if ( $user ) {
1060
+ $user_id = $user->ID;
1061
+ }
1062
  unset( $user );
1063
+ }
1064
 
1065
+ return $user_id;
1066
+ }
1067
 
1068
  public static function get_file_contents( $filename, $atts = array() ) {
1069
  if ( ! is_file( $filename ) ) {
1075
  include( $filename );
1076
  $contents = ob_get_contents();
1077
  ob_end_clean();
 
1078
  return $contents;
1079
  }
1080
 
1081
+ /**
1082
+ * @param string $table_name
1083
+ * @param string $column
1084
  * @param int $id
1085
  * @param int $num_chars
1086
+ */
1087
+ public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
1088
+ $key = '';
1089
 
1090
+ if ( ! empty( $name ) ) {
1091
  $key = sanitize_key( $name );
1092
+ }
1093
 
1094
  if ( empty( $key ) ) {
1095
  $max_slug_value = pow( 36, $num_chars );
1096
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
1097
+ $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
1098
+ }
 
 
 
 
 
 
 
 
 
 
1099
 
1100
+ if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
1101
  $key = $key . 'a';
1102
+ }
1103
 
1104
  $key_check = FrmDb::get_var(
1105
  $table_name,
1111
  );
1112
 
1113
  if ( $key_check || is_numeric( $key_check ) ) {
1114
+ $suffix = 2;
1115
  do {
1116
  $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
1117
+ $key_check = FrmDb::get_var(
1118
  $table_name,
1119
  array(
1120
  $column => $alt_post_name,
1122
  ),
1123
  $column
1124
  );
1125
+ $suffix++;
1126
  } while ( $key_check || is_numeric( $key_check ) );
1127
  $key = $alt_post_name;
1128
+ }
1129
+ return $key;
1130
+ }
1131
 
1132
+ /**
1133
+ * Editing a Form or Entry
 
 
 
1134
  *
1135
+ * @param string $table
1136
+ * @return bool|array
1137
+ */
1138
+ public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
1139
+ if ( ! $record ) {
1140
+ return false;
1141
+ }
 
1142
 
1143
  if ( empty( $post_values ) ) {
1144
+ $post_values = stripslashes_deep( $_POST );
1145
  }
1146
 
1147
  $values = array(
1148
+ 'id' => $record->id,
1149
  'fields' => array(),
1150
  );
1151
 
1152
  foreach ( array( 'name', 'description' ) as $var ) {
1153
+ $default_val = isset( $record->{$var} ) ? $record->{$var} : '';
1154
  $values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
1155
  unset( $var, $default_val );
1156
  }
1161
 
1162
  self::prepare_field_arrays( $fields, $record, $values, array_merge( $args, compact( 'default', 'post_values' ) ) );
1163
 
1164
+ if ( $table == 'entries' ) {
1165
+ $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1166
+ } else if ( $table == 'forms' ) {
1167
+ $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1168
+ }
1169
 
1170
+ return $values;
1171
+ }
1172
 
1173
  private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
1174
  if ( ! empty( $fields ) ) {
1175
  foreach ( (array) $fields as $field ) {
1176
+ $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1177
  $args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1178
  self::fill_field_defaults( $field, $record, $values, $args );
1179
  }
1181
  }
1182
 
1183
  private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1184
+ $post_values = $args['post_values'];
1185
 
1186
+ if ( $args['default'] ) {
1187
+ $meta_value = $field->default_value;
1188
+ } else {
1189
  if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1190
  if ( ! isset( $field->field_options['custom_field'] ) ) {
1191
+ $field->field_options['custom_field'] = '';
1192
+ }
1193
  $meta_value = FrmProEntryMetaHelper::get_post_value(
1194
  $record->post_id,
1195
  $field->field_options['post_field'],
1196
  $field->field_options['custom_field'],
1197
  array(
1198
  'truncate' => false,
1199
+ 'type' => $field->type,
1200
+ 'form_id' => $field->form_id,
1201
+ 'field' => $field,
1202
  )
1203
  );
1204
+ } else {
1205
  $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1206
+ }
1207
+ }
1208
 
1209
  $field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1210
+ $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1211
 
1212
+ $field_array = self::start_field_array( $field );
1213
+ $field_array['value'] = $new_value;
1214
+ $field_array['type'] = apply_filters( 'frm_field_type', $field_type, $field, $new_value );
1215
  $field_array['parent_form_id'] = $args['parent_form_id'];
1216
 
1217
+ $args['field_type'] = $field_type;
1218
 
1219
  FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
1220
 
1221
  if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1222
+ $field_array['unique_msg'] = '';
1223
+ }
1224
 
1225
+ $field_array = array_merge( $field->field_options, $field_array );
1226
 
1227
+ $values['fields'][ $field->id ] = $field_array;
1228
+ }
1229
 
1230
  /**
1231
  * @since 3.0
 
1232
  * @param object $field
 
1233
  * @return array
1234
  */
1235
  public static function start_field_array( $field ) {
1246
  );
1247
  }
1248
 
1249
+ /**
1250
+ * @param string $table
1251
+ */
1252
  private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1253
+ if ( $table == 'entries' ) {
1254
+ $form = $record->form_id;
1255
  FrmForm::maybe_get_form( $form );
1256
+ } else {
1257
+ $form = $record;
1258
+ }
1259
 
1260
+ if ( ! $form ) {
1261
+ return;
1262
+ }
1263
 
1264
+ $values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1265
  $values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1266
 
1267
  if ( ! is_array( $form->options ) ) {
1268
  return;
1269
  }
1270
 
1271
+ foreach ( $form->options as $opt => $value ) {
1272
+ $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1273
+ }
1274
 
1275
  self::fill_form_defaults( $post_values, $values );
1276
+ }
1277
 
1278
+ /**
1279
+ * Set to POST value or default
1280
+ */
1281
  private static function fill_form_defaults( $post_values, array &$values ) {
1282
+ $form_defaults = FrmFormsHelper::get_default_opts();
1283
 
1284
+ foreach ( $form_defaults as $opt => $default ) {
1285
+ if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1286
  $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1287
+ }
1288
 
1289
  unset( $opt, $default );
1290
+ }
1291
 
1292
  if ( ! isset( $values['custom_style'] ) ) {
1293
  $values['custom_style'] = self::custom_style_value( $post_values );
1296
  foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1297
  if ( ! isset( $values[ $h . '_html' ] ) ) {
1298
  $values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1299
+ }
1300
  unset( $h );
1301
+ }
1302
+ }
1303
 
1304
  /**
1305
  * @since 2.2.10
 
1306
  * @param array $post_values
 
1307
  * @return boolean|int
1308
  */
1309
  public static function custom_style_value( $post_values ) {
1313
  $frm_settings = self::get_settings();
1314
  $custom_style = ( $frm_settings->load_style != 'none' );
1315
  }
 
1316
  return $custom_style;
1317
  }
1318
 
1319
+ public static function insert_opt_html( $args ) {
1320
+ $class = '';
1321
+ $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
1322
+ if ( $possible_email_field ) {
1323
+ $class .= 'show_frm_not_email_to';
1324
+ }
1325
+ ?>
1326
+ <li>
1327
+ <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" >[<?php echo esc_attr( $args['id'] ); ?>]</a>
1328
+ <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['key'] ); ?>" >[<?php echo esc_attr( self::truncate( $args['key'], 10 ) ); ?>]</a>
1329
+ <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ); ?>" data-code="<?php echo esc_attr( $args['id'] ); ?>" ><?php echo esc_attr( self::truncate( $args['name'], 60 ) ); ?></a>
1330
+ </li>
1331
+ <?php
1332
+ }
1333
+
1334
  public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1335
+ if ( is_array( $str ) ) {
1336
+ return '';
1337
  }
1338
 
1339
+ $length = (int) $length;
1340
+ $str = wp_strip_all_tags( $str );
1341
  $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1342
 
1343
  if ( $length == 0 ) {
1344
+ return '';
1345
+ } else if ( $length <= 10 ) {
1346
  $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
 
1347
  return $sub . ( ( $length < $original_len ) ? $continue : '' );
1348
+ }
1349
 
1350
+ $sub = '';
1351
+ $len = 0;
1352
 
1353
  $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1354
 
1355
  foreach ( $words as $word ) {
1356
+ $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1357
  $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1358
  if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
1359
+ break;
1360
+ }
1361
 
1362
+ $sub .= $part;
1363
  $len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1364
 
1365
  if ( substr_count( $sub, ' ' ) > $minword && $total_len >= $length ) {
1366
+ break;
1367
+ }
1368
 
1369
  unset( $total_len, $word );
1370
+ }
1371
 
1372
  return $sub . ( ( $len < $original_len ) ? $continue : '' );
1373
+ }
1374
 
1375
  public static function mb_function( $function_names, $args ) {
1376
  $mb_function_name = $function_names[0];
1377
+ $function_name = $function_names[1];
1378
  if ( function_exists( $mb_function_name ) ) {
1379
  $function_name = $mb_function_name;
1380
  }
 
1381
  return call_user_func_array( $function_name, $args );
1382
  }
1383
 
1384
  public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1385
  if ( empty( $date ) ) {
1386
+ return $date;
1387
+ }
1388
 
1389
  if ( empty( $date_format ) ) {
1390
  $date_format = get_option( 'date_format' );
1391
  }
1392
 
1393
  if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1394
+ $frmpro_settings = new FrmProSettings();
1395
+ $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1396
+ }
1397
 
1398
  $formatted = self::get_localized_date( $date_format, $date );
1399
 
1402
  $formatted .= self::add_time_to_date( $time_format, $date );
1403
  }
1404
 
1405
+ return $formatted;
1406
+ }
1407
 
1408
  private static function add_time_to_date( $time_format, $date ) {
1409
  if ( empty( $time_format ) ) {
1411
  }
1412
 
1413
  $trimmed_format = trim( $time_format );
1414
+ $time = '';
1415
  if ( $time_format && ! empty( $trimmed_format ) ) {
1416
  $time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
1417
  }
1424
  */
1425
  public static function get_localized_date( $date_format, $date ) {
1426
  $date = get_date_from_gmt( $date );
 
1427
  return date_i18n( $date_format, strtotime( $date ) );
1428
  }
1429
 
1432
  *
1433
  * @param int $from in seconds
1434
  * @param int|string $to in seconds
 
1435
  * @return string $time_ago
1436
  */
1437
  public static function human_time_diff( $from, $to = '', $levels = 1 ) {
1444
 
1445
  // Get the time difference
1446
  $diff_object = $now->diff( $ago );
1447
+ $diff = get_object_vars( $diff_object );
1448
 
1449
  // Add week amount and update day amount
1450
  $diff['w'] = floor( $diff['d'] / 7 );
1460
  }
1461
  }
1462
 
1463
+ $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
1464
+ $time_strings = array_slice( $time_strings, 0, $levels_deep );
1465
  $time_ago_string = $time_strings ? implode( ' ', $time_strings ) : '0 ' . __( 'seconds', 'formidable' );
1466
 
1467
  return $time_ago_string;
1485
  );
1486
  }
1487
 
1488
+ // Pagination Methods
1489
 
1490
+ /**
1491
+ * @param integer $current_p
1492
+ */
1493
  public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1494
  return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1495
  }
1496
 
1497
+ /**
1498
+ * @param integer $current_p
1499
+ */
1500
+ public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1501
+ if ( $current_p == 1 ) {
1502
+ return 1;
1503
+ } else {
1504
+ return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1505
+ }
1506
+ }
1507
 
1508
  /**
1509
  * @return array
1510
  */
1511
  public static function json_to_array( $json_vars ) {
1512
+ $vars = array();
1513
+ foreach ( $json_vars as $jv ) {
1514
  $jv_name = explode( '[', $jv['name'] );
1515
+ $last = count( $jv_name ) - 1;
1516
  foreach ( $jv_name as $p => $n ) {
1517
  $name = trim( $n, ']' );
1518
  if ( ! isset( $l1 ) ) {
1527
  $l3 = $name;
1528
  }
1529
 
1530
+ $this_val = ( $p == $last ) ? $jv['value'] : array();
1531
 
1532
+ switch ( $p ) {
1533
+ case 0:
1534
+ $l1 = $name;
1535
+ self::add_value_to_array( $name, $l1, $this_val, $vars );
1536
  break;
1537
 
1538
+ case 1:
1539
+ $l2 = $name;
1540
+ self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1541
  break;
1542
 
1543
+ case 2:
1544
+ $l3 = $name;
1545
+ self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1546
  break;
1547
 
1548
+ case 3:
1549
+ $l4 = $name;
1550
+ self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1551
+ }
1552
 
1553
  unset( $this_val, $n );
1554
+ }
1555
 
1556
  unset( $last, $jv );
1557
+ }
1558
+
1559
+ return $vars;
1560
+ }
1561
+
1562
+ /**
1563
+ * @param string $name
1564
+ * @param string $l1
1565
+ */
1566
+ public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1567
+ if ( $name == '' ) {
1568
+ $vars[] = $val;
1569
+ } else if ( ! isset( $vars[ $l1 ] ) ) {
1570
+ $vars[ $l1 ] = $val;
1571
+ }
1572
+ }
1573
 
1574
  public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1575
+ $tooltips = array(
1576
+ 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
1577
+ 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
1578
+ 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1579
+ 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1580
+ 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1581
+ 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
1582
+ 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1583
+ );
1584
+
1585
+ if ( ! isset( $tooltips[ $name ] ) ) {
1586
+ return;
1587
+ }
1588
+
1589
+ if ( 'open' == $class ) {
1590
+ echo ' frm_help"';
1591
+ } else {
1592
+ echo ' class="frm_help"';
1593
+ }
 
1594
 
1595
  echo ' title="' . esc_attr( $tooltips[ $name ] );
1596
 
1597
+ if ( 'open' != $class ) {
1598
+ echo '"';
1599
+ }
1600
+ }
1601
 
1602
  /**
1603
  * Add the current_page class to that page in the form nav
1613
  }
1614
  }
1615
 
1616
+ /**
1617
+ * Prepare and json_encode post content
1618
+ *
1619
+ * @since 2.0
1620
+ *
1621
+ * @param array $post_content
1622
+ * @return string $post_content ( json encoded array )
1623
+ */
1624
+ public static function prepare_and_encode( $post_content ) {
1625
+ //Loop through array to strip slashes and add only the needed ones
 
1626
  foreach ( $post_content as $key => $val ) {
1627
  // Replace problematic characters (like &quot;)
1628
  $val = str_replace( '&quot;', '"', $val );
1629
 
1630
  self::prepare_action_slashes( $val, $key, $post_content );
1631
+ unset( $key, $val );
1632
+ }
1633
 
1634
+ // json_encode the array
1635
+ $post_content = json_encode( $post_content );
1636
 
1637
+ // add extra slashes for \r\n since WP strips them
1638
  $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1639
 
1640
+ // allow for &quot
1641
+ $post_content = str_replace( '&quot;', '\\"', $post_content );
1642
 
1643
+ return $post_content;
1644
+ }
1645
 
1646
  private static function prepare_action_slashes( $val, $key, &$post_content ) {
1647
  if ( ! isset( $post_content[ $key ] ) ) {
1664
 
1665
  public static function maybe_json_decode( $string ) {
1666
  if ( is_array( $string ) ) {
1667
+ return $string;
1668
+ }
1669
 
1670
  $new_string = json_decode( $string, true );
1671
  if ( function_exists( 'json_last_error' ) ) {
1672
  // php 5.3+
1673
+ if ( json_last_error() == JSON_ERROR_NONE ) {
1674
+ $string = $new_string;
1675
+ }
1676
  } elseif ( isset( $new_string ) ) {
1677
  // php < 5.3 fallback
1678
+ $string = $new_string;
1679
+ }
1680
+ return $string;
1681
+ }
1682
+
1683
+ /**
1684
+ * @since 1.07.10
1685
+ *
1686
+ * @param string $post_type The name of the post type that may need to be highlighted
1687
+ * echo The javascript to open and highlight the Formidable menu
1688
+ */
 
1689
  public static function maybe_highlight_menu( $post_type ) {
1690
+ global $post;
1691
 
1692
  if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1693
+ return;
1694
+ }
1695
 
1696
  if ( is_object( $post ) && $post->post_type != $post_type ) {
1697
+ return;
1698
+ }
1699
 
1700
+ self::load_admin_wide_js();
1701
+ echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1702
+ }
1703
 
1704
+ /**
1705
+ * Load the JS file on non-Formidable pages in the admin area
1706
  *
1707
+ * @since 2.0
1708
+ */
1709
  public static function load_admin_wide_js( $load = true ) {
1710
  $version = self::plugin_version();
1711
  wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1712
 
1713
  $global_strings = array(
1714
  'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1715
+ 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1716
  'url' => self::plugin_url(),
1717
  'loading' => __( 'Loading&hellip;', 'formidable' ),
1718
  'nonce' => wp_create_nonce( 'frm_ajax' ),
1722
  if ( $load ) {
1723
  wp_enqueue_script( 'formidable_admin_global' );
1724
  }
1725
+ }
1726
 
1727
  /**
1728
  * @since 2.0.9
1731
  wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1732
  }
1733
 
1734
+ /**
1735
+ * @param string $location
1736
+ */
1737
  public static function localize_script( $location ) {
1738
  $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1739
  $ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
1740
 
1741
  $script_strings = array(
1742
+ 'ajax_url' => $ajax_url,
1743
+ 'images_url' => self::plugin_url() . '/images',
1744
+ 'loading' => __( 'Loading&hellip;', 'formidable' ),
1745
+ 'remove' => __( 'Remove', 'formidable' ),
1746
+ 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
1747
+ 'nonce' => wp_create_nonce( 'frm_ajax' ),
1748
+ 'id' => __( 'ID', 'formidable' ),
1749
+ 'no_results' => __( 'No results match', 'formidable' ),
1750
+ 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
1751
+ 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
1752
  'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
1753
  );
1754
  wp_localize_script( 'formidable', 'frm_js', $script_strings );
1755
 
1756
  if ( $location == 'admin' ) {
1757
+ $frm_settings = self::get_settings();
1758
  $admin_script_strings = array(
1759
  'confirm_uninstall' => __( 'Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable' ),
1760
  'desc' => __( '(Click to add description)', 'formidable' ),
1798
  }
1799
  }
1800
 
1801
+ /**
1802
  * Echo the message on the plugins listing page
1803
  *
1804
+ * @since 1.07.10
1805
+ *
1806
+ * @param float $min_version The version the add-on requires
1807
+ */
1808
  public static function min_version_notice( $min_version ) {
1809
+ $frm_version = self::plugin_version();
1810
 
1811
+ // check if Formidable meets minimum requirements
1812
  if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1813
+ return;
1814
+ }
1815
 
1816
  $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1817
  echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
1818
+ esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1819
+ '</div></td></tr>';
1820
+ }
1821
 
1822
+ public static function locales( $type = 'date' ) {
1823
  $locales = array(
1824
+ 'en' => __( 'English', 'formidable' ),
1825
+ 'af' => __( 'Afrikaans', 'formidable' ),
1826
+ 'sq' => __( 'Albanian', 'formidable' ),
1827
+ 'ar' => __( 'Arabic', 'formidable' ),
1828
+ 'hy' => __( 'Armenian', 'formidable' ),
1829
+ 'az' => __( 'Azerbaijani', 'formidable' ),
1830
+ 'eu' => __( 'Basque', 'formidable' ),
1831
+ 'bs' => __( 'Bosnian', 'formidable' ),
1832
+ 'bg' => __( 'Bulgarian', 'formidable' ),
1833
+ 'ca' => __( 'Catalan', 'formidable' ),
1834
+ 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1835
+ 'zh-CN' => __( 'Chinese Simplified', 'formidable' ),
1836
+ 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1837
+ 'hr' => __( 'Croatian', 'formidable' ),
1838
+ 'cs' => __( 'Czech', 'formidable' ),
1839
+ 'da' => __( 'Danish', 'formidable' ),
1840
+ 'nl' => __( 'Dutch', 'formidable' ),
1841
+ 'en-GB' => __( 'English/UK', 'formidable' ),
1842
+ 'eo' => __( 'Esperanto', 'formidable' ),
1843
+ 'et' => __( 'Estonian', 'formidable' ),
1844
+ 'fo' => __( 'Faroese', 'formidable' ),
1845
+ 'fa' => __( 'Farsi/Persian', 'formidable' ),
1846
+ 'fil' => __( 'Filipino', 'formidable' ),
1847
+ 'fi' => __( 'Finnish', 'formidable' ),
1848
+ 'fr' => __( 'French', 'formidable' ),
1849
+ 'fr-CA' => __( 'French/Canadian', 'formidable' ),
1850
+ 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1851
+ 'de' => __( 'German', 'formidable' ),
1852
+ 'de-AT' => __( 'German/Austria', 'formidable' ),
1853
+ 'de-CH' => __( 'German/Switzerland', 'formidable' ),
1854
+ 'el' => __( 'Greek', 'formidable' ),
1855
+ 'he' => __( 'Hebrew', 'formidable' ),
1856
+ 'iw' => __( 'Hebrew', 'formidable' ),
1857
+ 'hi' => __( 'Hindi', 'formidable' ),
1858
+ 'hu' => __( 'Hungarian', 'formidable' ),
1859
+ 'is' => __( 'Icelandic', 'formidable' ),
1860
+ 'id' => __( 'Indonesian', 'formidable' ),
1861
+ 'it' => __( 'Italian', 'formidable' ),
1862
+ 'ja' => __( 'Japanese', 'formidable' ),
1863
+ 'ko' => __( 'Korean', 'formidable' ),
1864
+ 'lv' => __( 'Latvian', 'formidable' ),
1865
+ 'lt' => __( 'Lithuanian', 'formidable' ),
1866
+ 'ms' => __( 'Malaysian', 'formidable' ),
1867
+ 'no' => __( 'Norwegian', 'formidable' ),
1868
+ 'pl' => __( 'Polish', 'formidable' ),
1869
+ 'pt' => __( 'Portuguese', 'formidable' ),
1870
+ 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1871
+ 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ),
1872
+ 'ro' => __( 'Romanian', 'formidable' ),
1873
+ 'ru' => __( 'Russian', 'formidable' ),
1874
+ 'sr' => __( 'Serbian', 'formidable' ),
1875
+ 'sr-SR' => __( 'Serbian', 'formidable' ),
1876
+ 'sk' => __( 'Slovak', 'formidable' ),
1877
+ 'sl' => __( 'Slovenian', 'formidable' ),
1878
+ 'es' => __( 'Spanish', 'formidable' ),
1879
  'es-419' => __( 'Spanish/Latin America', 'formidable' ),
1880
+ 'sv' => __( 'Swedish', 'formidable' ),
1881
+ 'ta' => __( 'Tamil', 'formidable' ),
1882
+ 'th' => __( 'Thai', 'formidable' ),
1883
+ 'tu' => __( 'Turkish', 'formidable' ),
1884
+ 'tr' => __( 'Turkish', 'formidable' ),
1885
+ 'uk' => __( 'Ukranian', 'formidable' ),
1886
+ 'vi' => __( 'Vietnamese', 'formidable' ),
1887
  );
1888
 
1889
  if ( $type === 'captcha' ) {
1897
  $locales = array_diff_key( $locales, array_flip( $unset ) );
1898
  $locales = apply_filters( 'frm_locales', $locales );
1899
 
1900
+ return $locales;
1901
+ }
 
 
 
 
 
 
 
 
1902
 
1903
  /**
1904
  * Used to filter shortcode in text widgets
1948
  * @param string $group The name of the cache group
1949
  * @param string $query If blank, don't run a db call
1950
  * @param string $type The wpdb function to use with this query
 
1951
  * @return mixed $results The cache or query results
1952
  */
1953
  public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
1992
  * @since 2.0
1993
  * @deprecated 2.05.06
1994
  * @codeCoverageIgnore
 
1995
  * @param string $cache_key
1996
  */
1997
  public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
2015
  * @codeCoverageIgnore
2016
  *
2017
  * @param string $term The value to escape
 
2018
  * @return string The escaped value
2019
  */
2020
  public static function esc_like( $term ) {
2023
 
2024
  /**
2025
  * @param string $order_query
 
2026
  * @deprecated 2.05.06
2027
  * @codeCoverageIgnore
2028
  */
2040
 
2041
  /**
2042
  * @param string $limit
 
2043
  * @deprecated 2.05.06
2044
  * @codeCoverageIgnore
2045
  */
classes/helpers/FrmCSVExportHelper.php CHANGED
@@ -2,23 +2,22 @@
2
 
3
  class FrmCSVExportHelper {
4
 
5
- protected static $separator = ', ';
6
  protected static $column_separator = ',';
7
- protected static $line_break = 'return';
8
- protected static $charset = 'UTF-8';
9
- protected static $to_encoding = 'UTF-8';
10
- protected static $wp_date_format = 'Y-m-d H:i:s';
11
- protected static $comment_count = 0;
12
- protected static $form_id = 0;
13
- protected static $headings = array();
14
- protected static $fields = array();
15
  protected static $entry;
16
  protected static $has_parent_id;
17
 
18
  public static function csv_format_options() {
19
  $formats = array( 'UTF-8', 'ISO-8859-1', 'windows-1256', 'windows-1251', 'macintosh' );
20
  $formats = apply_filters( 'frm_csv_format_options', $formats );
21
-
22
  return $formats;
23
  }
24
 
@@ -26,7 +25,7 @@ class FrmCSVExportHelper {
26
  global $frm_vars;
27
  $frm_vars['prevent_caching'] = true;
28
 
29
- self::$fields = $atts['form_cols'];
30
  self::$form_id = $atts['form']->id;
31
  self::set_class_paramters();
32
  self::set_has_parent_id( $atts['form'] );
@@ -37,11 +36,11 @@ class FrmCSVExportHelper {
37
  self::print_file_headers( $filename );
38
  unset( $filename );
39
 
40
- $comment_count = FrmDb::get_count(
41
  'frm_item_metas',
42
  array(
43
- 'item_id' => $atts['entry_ids'],
44
- 'field_id' => 0,
45
  'meta_value like' => '{',
46
  ),
47
  array(
@@ -61,14 +60,13 @@ class FrmCSVExportHelper {
61
  }
62
 
63
  private static function set_class_paramters() {
64
- self::$separator = apply_filters( 'frm_csv_sep', self::$separator );
65
- self::$line_break = apply_filters( 'frm_csv_line_break', self::$line_break );
66
  self::$wp_date_format = apply_filters( 'frm_csv_date_format', self::$wp_date_format );
67
  self::get_csv_format();
68
  self::$charset = get_option( 'blog_charset' );
69
 
70
- $col_sep = ( isset( $_POST['csv_col_sep'] ) && ! empty( $_POST['csv_col_sep'] ) ) ? sanitize_text_field( wp_unslash( $_POST['csv_col_sep'] ) ) : self::$column_separator;
71
-
72
  self::$column_separator = apply_filters( 'frm_csv_column_sep', $col_sep );
73
  }
74
 
@@ -95,15 +93,15 @@ class FrmCSVExportHelper {
95
  }
96
 
97
  public static function get_csv_format() {
98
- $csv_format = FrmAppHelper::get_post_param( 'csv_format', 'UTF-8', 'sanitize_text_field' );
99
- $csv_format = apply_filters( 'frm_csv_format', $csv_format );
100
  self::$to_encoding = $csv_format;
101
  }
102
 
103
  private static function prepare_csv_headings() {
104
  $headings = array();
105
  self::csv_headings( $headings );
106
- $headings = apply_filters(
107
  'frm_csv_columns',
108
  $headings,
109
  self::$form_id,
@@ -119,27 +117,25 @@ class FrmCSVExportHelper {
119
  private static function csv_headings( &$headings ) {
120
  foreach ( self::$fields as $col ) {
121
  $field_headings = array();
122
- $separate_values = array( 'user_id', 'file', 'data', 'date' );
123
- if ( isset( $col->field_options['separate_value'] ) && $col->field_options['separate_value'] && ! in_array( $col->type, $separate_values, true ) ) {
124
  $field_headings[ $col->id . '_label' ] = strip_tags( $col->name . ' ' . __( '(label)', 'formidable' ) );
125
  }
126
 
127
  $field_headings[ $col->id ] = strip_tags( $col->name );
128
- $field_headings = apply_filters(
129
  'frm_csv_field_columns',
130
  $field_headings,
131
  array(
132
  'field' => $col,
133
  )
134
  );
135
-
136
  $headings += $field_headings;
137
  }
138
 
139
  if ( self::$comment_count ) {
140
- for ( $i = 0; $i < self::$comment_count; $i ++ ) {
141
- $headings[ 'comment' . $i ] = __( 'Comment', 'formidable' );
142
- $headings[ 'comment_user_id' . $i ] = __( 'Comment User', 'formidable' );
143
  $headings[ 'comment_created_at' . $i ] = __( 'Comment Date', 'formidable' );
144
  }
145
  unset( $i );
@@ -147,12 +143,12 @@ class FrmCSVExportHelper {
147
 
148
  $headings['created_at'] = __( 'Timestamp', 'formidable' );
149
  $headings['updated_at'] = __( 'Last Updated', 'formidable' );
150
- $headings['user_id'] = __( 'Created By', 'formidable' );
151
  $headings['updated_by'] = __( 'Updated By', 'formidable' );
152
- $headings['is_draft'] = __( 'Draft', 'formidable' );
153
- $headings['ip'] = __( 'IP', 'formidable' );
154
- $headings['id'] = __( 'ID', 'formidable' );
155
- $headings['item_key'] = __( 'Key', 'formidable' );
156
  if ( self::has_parent_id() ) {
157
  $headings['parent_id'] = __( 'Parent ID', 'formidable' );
158
  }
@@ -164,9 +160,9 @@ class FrmCSVExportHelper {
164
 
165
  private static function prepare_next_csv_rows( $next_set ) {
166
  // order by parent_item_id so children will be first
167
- $where = array(
168
- 'or' => 1,
169
- 'id' => $next_set,
170
  'parent_item_id' => $next_set,
171
  );
172
  $entries = FrmEntry::getAll( $where, ' ORDER BY parent_item_id DESC', '', true, false );
@@ -252,15 +248,14 @@ class FrmCSVExportHelper {
252
  $field_value,
253
  $col,
254
  array(
255
- 'type' => $col->type,
256
- 'post_id' => self::$entry->post_id,
257
- 'show_icon' => false,
258
- 'entry_id' => self::$entry->id,
259
- 'sep' => self::$separator,
260
  'embedded_field_id' => ( isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0,
261
  )
262
  );
263
-
264
  $row[ $col->id . '_label' ] = $sep_value;
265
  unset( $sep_value );
266
  }
@@ -288,12 +283,12 @@ class FrmCSVExportHelper {
288
  private static function add_entry_data_to_csv( &$row ) {
289
  $row['created_at'] = FrmAppHelper::get_formatted_time( self::$entry->created_at, self::$wp_date_format, ' ' );
290
  $row['updated_at'] = FrmAppHelper::get_formatted_time( self::$entry->updated_at, self::$wp_date_format, ' ' );
291
- $row['user_id'] = self::$entry->user_id;
292
  $row['updated_by'] = self::$entry->updated_by;
293
- $row['is_draft'] = self::$entry->is_draft ? '1' : '0';
294
- $row['ip'] = self::$entry->ip;
295
- $row['id'] = self::$entry->id;
296
- $row['item_key'] = self::$entry->item_key;
297
  if ( self::has_parent_id() ) {
298
  $row['parent_id'] = self::$entry->parent_item_id;
299
  }
@@ -349,7 +344,7 @@ class FrmCSVExportHelper {
349
  }
350
 
351
  return self::escape_csv( $line );
352
- }
353
 
354
  /**
355
  * Escape a " in a csv with another "
@@ -362,7 +357,6 @@ class FrmCSVExportHelper {
362
  $value = "'" . $value;
363
  }
364
  $value = str_replace( '"', '""', $value );
365
-
366
  return $value;
367
  }
368
  }
2
 
3
  class FrmCSVExportHelper {
4
 
5
+ protected static $separator = ', ';
6
  protected static $column_separator = ',';
7
+ protected static $line_break = 'return';
8
+ protected static $charset = 'UTF-8';
9
+ protected static $to_encoding = 'UTF-8';
10
+ protected static $wp_date_format = 'Y-m-d H:i:s';
11
+ protected static $comment_count = 0;
12
+ protected static $form_id = 0;
13
+ protected static $headings = array();
14
+ protected static $fields = array();
15
  protected static $entry;
16
  protected static $has_parent_id;
17
 
18
  public static function csv_format_options() {
19
  $formats = array( 'UTF-8', 'ISO-8859-1', 'windows-1256', 'windows-1251', 'macintosh' );
20
  $formats = apply_filters( 'frm_csv_format_options', $formats );
 
21
  return $formats;
22
  }
23
 
25
  global $frm_vars;
26
  $frm_vars['prevent_caching'] = true;
27
 
28
+ self::$fields = $atts['form_cols'];
29
  self::$form_id = $atts['form']->id;
30
  self::set_class_paramters();
31
  self::set_has_parent_id( $atts['form'] );
36
  self::print_file_headers( $filename );
37
  unset( $filename );
38
 
39
+ $comment_count = FrmDb::get_count(
40
  'frm_item_metas',
41
  array(
42
+ 'item_id' => $atts['entry_ids'],
43
+ 'field_id' => 0,
44
  'meta_value like' => '{',
45
  ),
46
  array(
60
  }
61
 
62
  private static function set_class_paramters() {
63
+ self::$separator = apply_filters( 'frm_csv_sep', self::$separator );
64
+ self::$line_break = apply_filters( 'frm_csv_line_break', self::$line_break );
65
  self::$wp_date_format = apply_filters( 'frm_csv_date_format', self::$wp_date_format );
66
  self::get_csv_format();
67
  self::$charset = get_option( 'blog_charset' );
68
 
69
+ $col_sep = ( isset( $_POST['csv_col_sep'] ) && ! empty( $_POST['csv_col_sep'] ) ) ? sanitize_text_field( $_POST['csv_col_sep'] ) : self::$column_separator;
 
70
  self::$column_separator = apply_filters( 'frm_csv_column_sep', $col_sep );
71
  }
72
 
93
  }
94
 
95
  public static function get_csv_format() {
96
+ $csv_format = FrmAppHelper::get_post_param( 'csv_format', 'UTF-8', 'sanitize_text_field' );
97
+ $csv_format = apply_filters( 'frm_csv_format', $csv_format );
98
  self::$to_encoding = $csv_format;
99
  }
100
 
101
  private static function prepare_csv_headings() {
102
  $headings = array();
103
  self::csv_headings( $headings );
104
+ $headings = apply_filters(
105
  'frm_csv_columns',
106
  $headings,
107
  self::$form_id,
117
  private static function csv_headings( &$headings ) {
118
  foreach ( self::$fields as $col ) {
119
  $field_headings = array();
120
+ if ( isset( $col->field_options['separate_value'] ) && $col->field_options['separate_value'] && ! in_array( $col->type, array( 'user_id', 'file', 'data', 'date' ), true ) ) {
 
121
  $field_headings[ $col->id . '_label' ] = strip_tags( $col->name . ' ' . __( '(label)', 'formidable' ) );
122
  }
123
 
124
  $field_headings[ $col->id ] = strip_tags( $col->name );
125
+ $field_headings = apply_filters(
126
  'frm_csv_field_columns',
127
  $field_headings,
128
  array(
129
  'field' => $col,
130
  )
131
  );
 
132
  $headings += $field_headings;
133
  }
134
 
135
  if ( self::$comment_count ) {
136
+ for ( $i = 0; $i < self::$comment_count; $i++ ) {
137
+ $headings[ 'comment' . $i ] = __( 'Comment', 'formidable' );
138
+ $headings[ 'comment_user_id' . $i ] = __( 'Comment User', 'formidable' );
139
  $headings[ 'comment_created_at' . $i ] = __( 'Comment Date', 'formidable' );
140
  }
141
  unset( $i );
143
 
144
  $headings['created_at'] = __( 'Timestamp', 'formidable' );
145
  $headings['updated_at'] = __( 'Last Updated', 'formidable' );
146
+ $headings['user_id'] = __( 'Created By', 'formidable' );
147
  $headings['updated_by'] = __( 'Updated By', 'formidable' );
148
+ $headings['is_draft'] = __( 'Draft', 'formidable' );
149
+ $headings['ip'] = __( 'IP', 'formidable' );
150
+ $headings['id'] = __( 'ID', 'formidable' );
151
+ $headings['item_key'] = __( 'Key', 'formidable' );
152
  if ( self::has_parent_id() ) {
153
  $headings['parent_id'] = __( 'Parent ID', 'formidable' );
154
  }
160
 
161
  private static function prepare_next_csv_rows( $next_set ) {
162
  // order by parent_item_id so children will be first
163
+ $where = array(
164
+ 'or' => 1,
165
+ 'id' => $next_set,
166
  'parent_item_id' => $next_set,
167
  );
168
  $entries = FrmEntry::getAll( $where, ' ORDER BY parent_item_id DESC', '', true, false );
248
  $field_value,
249
  $col,
250
  array(
251
+ 'type' => $col->type,
252
+ 'post_id' => self::$entry->post_id,
253
+ 'show_icon' => false,
254
+ 'entry_id' => self::$entry->id,
255
+ 'sep' => self::$separator,
256
  'embedded_field_id' => ( isset( self::$entry->embedded_fields ) && isset( self::$entry->embedded_fields[ self::$entry->id ] ) ) ? 'form' . self::$entry->embedded_fields[ self::$entry->id ] : 0,
257
  )
258
  );
 
259
  $row[ $col->id . '_label' ] = $sep_value;
260
  unset( $sep_value );
261
  }
283
  private static function add_entry_data_to_csv( &$row ) {
284
  $row['created_at'] = FrmAppHelper::get_formatted_time( self::$entry->created_at, self::$wp_date_format, ' ' );
285
  $row['updated_at'] = FrmAppHelper::get_formatted_time( self::$entry->updated_at, self::$wp_date_format, ' ' );
286
+ $row['user_id'] = self::$entry->user_id;
287
  $row['updated_by'] = self::$entry->updated_by;
288
+ $row['is_draft'] = self::$entry->is_draft ? '1' : '0';
289
+ $row['ip'] = self::$entry->ip;
290
+ $row['id'] = self::$entry->id;
291
+ $row['item_key'] = self::$entry->item_key;
292
  if ( self::has_parent_id() ) {
293
  $row['parent_id'] = self::$entry->parent_item_id;
294
  }
344
  }
345
 
346
  return self::escape_csv( $line );
347
+ }
348
 
349
  /**
350
  * Escape a " in a csv with another "
357
  $value = "'" . $value;
358
  }
359
  $value = str_replace( '"', '""', $value );
 
360
  return $value;
361
  }
362
  }
classes/helpers/FrmEmailHelper.php CHANGED
@@ -12,15 +12,13 @@ class FrmEmailHelper {
12
  * @since 2.03.04
13
  *
14
  * @param int $form_id
15
- *
16
  * @return int
17
  */
18
  public static function get_user_id_field_for_form( $form_id ) {
19
  $where = array(
20
- 'type' => 'user_id',
21
  'form_id' => $form_id,
22
  );
23
-
24
  $user_id_field = FrmDb::get_var( 'frm_fields', $where, 'id' );
25
 
26
  return (int) $user_id_field;
12
  * @since 2.03.04
13
  *
14
  * @param int $form_id
 
15
  * @return int
16
  */
17
  public static function get_user_id_field_for_form( $form_id ) {
18
  $where = array(
19
+ 'type' => 'user_id',
20
  'form_id' => $form_id,
21
  );
 
22
  $user_id_field = FrmDb::get_var( 'frm_fields', $where, 'id' );
23
 
24
  return (int) $user_id_field;
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -5,41 +5,41 @@ if ( ! defined( 'ABSPATH' ) ) {
5
 
6
  class FrmEntriesHelper {
7
 
8
- public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
9
  $values = array(
10
  'name' => '',
11
  'description' => '',
12
  'item_key' => '',
13
  );
14
 
15
- $values['fields'] = array();
16
  if ( empty( $fields ) ) {
17
  return apply_filters( 'frm_setup_new_entry', $values );
18
  }
19
 
20
- foreach ( (array) $fields as $field ) {
21
  $original_default = $field->default_value;
22
  self::prepare_field_default_value( $field );
23
  $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
24
 
25
- $field_array = FrmAppHelper::start_field_array( $field );
26
- $field_array['value'] = $new_value;
27
- $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
28
- $field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
29
- $field_array['reset_value'] = $reset;
30
- $field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0';
31
  $field_array['original_default'] = $original_default;
32
 
33
  FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
34
 
35
- $field_array = array_merge( $field->field_options, $field_array );
36
 
37
- $values['fields'][] = $field_array;
38
 
39
  if ( ! $form || ! isset( $form->id ) ) {
40
  $form = FrmForm::getOne( $field->form_id );
41
  }
42
- }
43
 
44
  $form->options = maybe_unserialize( $form->options );
45
  if ( is_array( $form->options ) ) {
@@ -47,14 +47,14 @@ class FrmEntriesHelper {
47
  }
48
 
49
  $form_defaults = FrmFormsHelper::get_default_opts();
50
- $frm_settings = FrmAppHelper::get_settings();
51
 
52
- $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' );
 
53
 
54
  $values = array_merge( $form_defaults, $values );
55
 
56
  return apply_filters( 'frm_setup_new_entry', $values );
57
- }
58
 
59
  /**
60
  * @since 2.05
@@ -71,24 +71,23 @@ class FrmEntriesHelper {
71
  }
72
 
73
  /**
74
- * Set the value for each field
75
- * This function is used when the form is first loaded and on all page turns *for a new entry*
76
- *
77
- * @since 2.0.13
78
- *
79
- * @param object $field - this is passed by reference since it is an object
80
- * @param boolean $reset
81
- * @param array $args
82
- *
83
- * @return string|array $new_value
84
- */
85
  private static function get_field_value_for_new_entry( $field, $reset, $args ) {
86
  $new_value = $field->default_value;
87
 
88
  if ( ! $reset && self::value_is_posted( $field, $args ) ) {
89
  self::get_posted_value( $field, $new_value, $args );
90
- } elseif ( ! FrmField::is_option_empty( $field, 'placeholder' ) ) {
91
- // If placeholder is selected, the value should be blank (unless it was posted, of course).
92
 
93
  // TODO: move to Pro
94
  if ( 'address' == $field->type && isset( $new_value['country'] ) ) {
@@ -106,15 +105,13 @@ class FrmEntriesHelper {
106
  }
107
 
108
  /**
109
- * Check if a field has a posted value
110
- *
111
- * @since 2.01.0
112
- *
113
- * @param object $field
114
- * @param array $args
115
- *
116
- * @return boolean $value_is_posted
117
- */
118
  public static function value_is_posted( $field, $args ) {
119
  $value_is_posted = false;
120
  if ( $_POST ) {
@@ -123,105 +120,102 @@ class FrmEntriesHelper {
123
  if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) {
124
  $value_is_posted = true;
125
  }
126
- } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) {
127
  $value_is_posted = true;
128
  }
129
  }
130
-
131
  return $value_is_posted;
132
  }
133
 
134
  public static function setup_edit_vars( $values, $record ) {
135
  $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
136
- $values['form_id'] = $record->form_id;
137
- $values['is_draft'] = $record->is_draft;
138
-
139
  return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
140
- }
141
 
142
  public static function replace_default_message( $message, $atts ) {
143
  if ( strpos( $message, '[default-message' ) === false &&
144
  strpos( $message, '[default_message' ) === false &&
145
- ! empty( $message ) ) {
146
- return $message;
147
- }
148
 
149
  if ( empty( $message ) ) {
150
- $message = '[default-message]';
151
- }
152
 
153
  preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
154
 
155
- foreach ( $shortcodes[0] as $short_key => $tag ) {
156
  $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
157
  if ( ! empty( $add_atts ) ) {
158
  $this_atts = array_merge( $atts, $add_atts );
159
- } else {
160
- $this_atts = $atts;
161
- }
162
 
163
  $default = FrmEntriesController::show_entry_shortcode( $this_atts );
164
 
165
- // Add the default message.
166
- $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
167
- }
168
 
169
- return $message;
170
- }
171
 
172
  public static function prepare_display_value( $entry, $field, $atts ) {
173
  $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
174
 
175
- if ( FrmAppHelper::pro_is_installed() ) {
176
  FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
177
- }
178
 
179
  if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
180
  return self::display_value( $field_value, $field, $atts );
181
  }
182
 
183
- // This is an embeded form.
184
- $val = '';
185
 
186
  if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
187
- // This is a repeating section.
188
  $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
189
- } else {
190
- // Get all values for this field.
191
- $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
192
 
193
- if ( $child_values ) {
194
- $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
195
- }
196
- }
197
 
198
- $field_value = array();
199
 
200
  if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
201
- return $val;
202
- }
203
 
204
- foreach ( $child_entries as $child_entry ) {
205
- $atts['item_id'] = $child_entry->id;
206
- $atts['post_id'] = $child_entry->post_id;
207
 
208
- // Fet the value for this field -- check for post values as well.
209
  $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
210
 
211
- if ( $entry_val ) {
212
- // foreach entry get display_value.
213
  $field_value[] = self::display_value( $entry_val, $field, $atts );
214
- }
215
 
216
  unset( $child_entry );
217
- }
218
 
219
  $val = implode( ', ', (array) $field_value );
220
-
221
  return FrmAppHelper::kses( $val, 'all' );
222
- }
223
 
224
- /**
225
  * Prepare the saved value for display
226
  *
227
  * @param array|string $value
@@ -233,50 +227,49 @@ class FrmEntriesHelper {
233
  public static function display_value( $value, $field, $atts = array() ) {
234
 
235
  $defaults = array(
236
- 'type' => '',
237
- 'html' => false,
238
  'show_filename' => true,
239
- 'truncate' => false,
240
- 'sep' => ', ',
241
- 'post_id' => 0,
242
- 'form_id' => $field->form_id,
243
- 'field' => $field,
244
- 'keepjs' => 0,
245
- 'return_array' => false,
246
  );
247
 
248
- $atts = wp_parse_args( $atts, $defaults );
249
 
250
  if ( FrmField::is_image( $field ) || $field->type == 'star' ) {
251
  $atts['truncate'] = false;
252
- $atts['html'] = true;
253
  }
254
 
255
  $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
256
 
257
  if ( ! isset( $field->field_options['post_field'] ) ) {
258
- $field->field_options['post_field'] = '';
259
- }
260
 
261
  if ( ! isset( $field->field_options['custom_field'] ) ) {
262
- $field->field_options['custom_field'] = '';
263
- }
264
 
265
- if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
266
- $atts['pre_truncate'] = $atts['truncate'];
267
- $atts['truncate'] = true;
268
- $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
269
 
270
- $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
271
- $atts['truncate'] = $atts['pre_truncate'];
272
- }
273
 
274
- if ( $value == '' ) {
275
- return $value;
276
- }
277
 
278
  $unfiltered_value = maybe_unserialize( $value );
279
-
280
  $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
281
  $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
282
 
@@ -284,160 +277,156 @@ class FrmEntriesHelper {
284
  $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
285
  }
286
 
287
- if ( $atts['truncate'] && $atts['type'] != 'url' ) {
288
  $value = FrmAppHelper::truncate( $value, 50 );
289
- }
290
 
291
  if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
292
  $value = FrmAppHelper::kses( $value, 'all' );
293
  }
294
 
295
  return apply_filters( 'frm_display_value', $value, $field, $atts );
296
- }
297
 
298
  public static function set_posted_value( $field, $value, $args ) {
299
- // If validating a field with "other" opt, set back to prev value now.
300
- if ( isset( $args['other'] ) && $args['other'] ) {
301
- $value = $args['temp_value'];
302
- }
303
  if ( empty( $args['parent_field_id'] ) ) {
304
- $_POST['item_meta'][ $field->id ] = $value;
305
- } else {
306
- $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
307
- }
308
- }
309
 
310
  public static function get_posted_value( $field, &$value, $args ) {
311
  $field_id = is_object( $field ) ? $field->id : $field;
312
 
313
  if ( empty( $args['parent_field_id'] ) ) {
314
- $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : '';
315
- } else {
316
- $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : '';
317
- }
318
- $value = wp_unslash( $value );
319
  FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
320
- }
321
-
322
- /**
323
- * Check if field has an "Other" option and if any other values are posted
324
- *
325
- * @since 2.0
326
- *
327
- * @param object $field
328
- * @param string|array $value
329
- * @param array $args
330
- */
331
- public static function maybe_set_other_validation( $field, &$value, &$args ) {
332
- $args['other'] = false;
333
- if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) {
334
- return;
335
- }
336
-
337
- // Get other value for fields in repeating section.
338
- self::set_other_repeating_vals( $field, $value, $args );
339
-
340
- // Check if there are any posted "Other" values.
 
341
  if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
342
 
343
- // Save original value.
344
- $args['temp_value'] = $value;
345
- $args['other'] = true;
346
- $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] );
347
-
348
- // Set the validation value now
349
- self::set_other_validation_val( $value, $other_vals, $field, $args );
350
- }
351
- }
352
-
353
- /**
354
- * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
355
- *
356
- * @since 2.0
357
- *
358
- * @param object $field
359
- * @param string|array $value
360
- * @param array $args
361
- */
362
- public static function set_other_repeating_vals( $field, &$value, &$args ) {
363
- if ( ! $args['parent_field_id'] ) {
364
- return;
365
- }
366
-
367
- // Check if there are any other posted "other" values for this field.
368
  if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) {
369
- // Save original value
370
- $args['temp_value'] = $value;
371
- $args['other'] = true;
372
-
373
- $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] );
374
-
375
- // Set the validation value now.
376
- self::set_other_validation_val( $value, $other_vals, $field, $args );
377
- }
378
- }
379
-
380
- /**
381
- * Modify value used for validation
382
- * This function essentially removes the "Other" radio or checkbox value from the $value being validated.
383
- * It also adds any text from the free text fields to the value
384
- *
385
- * Needs to accommodate for times when other opt is selected, but no other free text is entered
386
- *
387
- * @since 2.0
388
- *
389
- * @param string|array $value
390
- * @param string|array $other_vals (usually of posted values)
391
- * @param object $field
392
- * @param array $args
393
- */
394
- public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
395
- // Checkboxes and multi-select dropdowns.
396
- if ( is_array( $value ) && $field->type == 'checkbox' ) {
397
- // Combine "Other" values with checked values. "Other" values will override checked box values.
398
- $value = array_merge( $value, $other_vals );
399
- $value = array_filter( $value );
400
- if ( count( $value ) == 0 ) {
401
- $value = '';
402
- }
403
- } else {
404
- // Radio and dropdowns.
405
  $other_key = array_filter( array_keys( $field->options ), 'is_string' );
406
- $other_key = reset( $other_key );
407
 
408
- // Multi-select dropdown.
409
- if ( is_array( $value ) ) {
410
- $o_key = array_search( $field->options[ $other_key ], $value );
411
 
412
  if ( $o_key !== false ) {
413
- // Modify the original value so other key will be preserved.
414
  $value[ $other_key ] = $value[ $o_key ];
415
 
416
- // By default, the array keys will be numeric for multi-select dropdowns.
417
- // If going backwards and forwards between pages, the array key will match the other key.
418
  if ( $o_key !== $other_key ) {
419
  unset( $value[ $o_key ] );
420
  }
421
 
422
- $args['temp_value'] = $value;
423
  $value[ $other_key ] = reset( $other_vals );
424
  if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
425
  unset( $value[ $other_key ] );
426
  }
427
  }
428
- } elseif ( $field->options[ $other_key ] == $value ) {
429
- $value = $other_vals;
430
- }
431
- }
432
- }
433
 
434
- /**
435
- * Add submitted values to a string for spam checking.
436
- *
437
- * @param array $values
438
- */
439
  public static function entry_array_to_string( $values ) {
440
- $content = '';
441
  foreach ( $values['item_meta'] as $val ) {
442
  if ( $content != '' ) {
443
  $content .= "\n\n";
@@ -452,7 +441,7 @@ class FrmEntriesHelper {
452
  }
453
 
454
  return $content;
455
- }
456
 
457
  /**
458
  * Get the browser from the user agent
@@ -464,18 +453,18 @@ class FrmEntriesHelper {
464
  * @return string
465
  */
466
  public static function get_browser( $u_agent ) {
467
- $bname = __( 'Unknown', 'formidable' );
468
  $platform = __( 'Unknown', 'formidable' );
469
- $ub = '';
470
 
471
  // Get the operating system
472
  if ( preg_match( '/windows|win32/i', $u_agent ) ) {
473
  $platform = 'Windows';
474
- } elseif ( preg_match( '/android/i', $u_agent ) ) {
475
  $platform = 'Android';
476
- } elseif ( preg_match( '/linux/i', $u_agent ) ) {
477
  $platform = 'Linux';
478
- } elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
479
  $platform = 'OS X';
480
  }
481
 
@@ -490,19 +479,19 @@ class FrmEntriesHelper {
490
  // Next get the name of the useragent yes seperately and for good reason
491
  if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
492
  $bname = 'Internet Explorer';
493
- $ub = 'MSIE';
494
  } else {
495
  foreach ( $agent_options as $agent_key => $agent_name ) {
496
  if ( strpos( $u_agent, $agent_key ) !== false ) {
497
  $bname = $agent_name;
498
- $ub = $agent_key;
499
  break;
500
  }
501
  }
502
  }
503
 
504
  // finally get the correct version number
505
- $known = array( 'Version', $ub, 'other' );
506
  $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
507
  preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
508
 
@@ -517,7 +506,7 @@ class FrmEntriesHelper {
517
  } else {
518
  $version = $matches['version'][1];
519
  }
520
- } elseif ( $i === 1 ) {
521
  $version = $matches['version'][0];
522
  } else {
523
  $version = '';
@@ -535,93 +524,26 @@ class FrmEntriesHelper {
535
  * @since 3.0
536
  */
537
  public static function actions_dropdown( $atts ) {
538
- $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
539
  $links = self::get_action_links( $id, $atts['entry'] );
540
-
541
- foreach ( $links as $link ) {
542
- ?>
543
- <div class="misc-pub-section">
544
- <a href="<?php echo esc_url( FrmAppHelper::maybe_full_screen_link( $link['url'] ) ); ?>"
545
- <?php
546
- if ( isset( $link['data'] ) ) {
547
- foreach ( $link['data'] as $data => $value ) {
548
- echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
549
- }
550
- }
551
- if ( isset( $link['class'] ) ) {
552
- echo 'class="' . esc_attr( $link['class'] ) . '" ';
553
- }
554
- ?>
555
- >
556
- <i class="<?php echo esc_attr( $link['icon'] ); ?>" aria-hidden="true"></i>
557
- <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
558
- </a>
559
- </div>
560
- <?php
561
- }
562
  }
563
 
564
  /**
565
  * @since 3.0
566
  */
567
  private static function get_action_links( $id, $entry ) {
568
- $page = FrmAppHelper::get_param( 'frm_action' );
569
  $actions = array();
570
 
571
- if ( $page != 'show' ) {
572
- $actions['frm_view'] = array(
573
- 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
574
- 'label' => __( 'View Entry', 'formidable' ),
575
- 'icon' => 'frm_icon_font frm_save_icon',
576
- );
577
- }
578
-
579
  if ( current_user_can( 'frm_delete_entries' ) ) {
580
  $actions['frm_delete'] = array(
581
  'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ),
582
- 'label' => __( 'Delete Entry', 'formidable' ),
583
  'icon' => 'frm_icon_font frm_delete_icon',
584
- 'data' => array(
585
- 'frmverify' => __( 'Really delete?', 'formidable' ),
586
- ),
587
- );
588
- }
589
-
590
- if ( $page == 'show' ) {
591
- $actions['frm_print'] = array(
592
- 'url' => '#',
593
- 'label' => __( 'Print Entry', 'formidable' ),
594
- 'data' => array(
595
- 'frmprint' => '1',
596
- ),
597
- 'icon' => 'frm_icon_font frm_printer_icon',
598
  );
599
  }
600
 
601
- $actions['frm_resend'] = array(
602
- 'url' => '#',
603
- 'label' => __( 'Resend Emails', 'formidable' ),
604
- 'class' => 'frm_noallow',
605
- 'data' => array(
606
- 'upgrade' => __( 'Resend Emails', 'formidable' ),
607
- 'medium' => 'resend-email',
608
- 'content' => 'entry',
609
- ),
610
- 'icon' => 'frm_icon_font frm_email_icon',
611
- );
612
-
613
- $actions['frm_edit'] = array(
614
- 'url' => '#',
615
- 'label' => __( 'Edit Entry', 'formidable' ),
616
- 'class' => 'frm_noallow',
617
- 'data' => array(
618
- 'upgrade' => __( 'Entry edits', 'formidable' ),
619
- 'medium' => 'edit-entries',
620
- 'content' => 'entry',
621
- ),
622
- 'icon' => 'frm_icon_font frm_pencil_icon',
623
- );
624
-
625
  return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
626
  }
627
  }
5
 
6
  class FrmEntriesHelper {
7
 
8
+ public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
9
  $values = array(
10
  'name' => '',
11
  'description' => '',
12
  'item_key' => '',
13
  );
14
 
15
+ $values['fields'] = array();
16
  if ( empty( $fields ) ) {
17
  return apply_filters( 'frm_setup_new_entry', $values );
18
  }
19
 
20
+ foreach ( (array) $fields as $field ) {
21
  $original_default = $field->default_value;
22
  self::prepare_field_default_value( $field );
23
  $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
24
 
25
+ $field_array = FrmAppHelper::start_field_array( $field );
26
+ $field_array['value'] = $new_value;
27
+ $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
28
+ $field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
29
+ $field_array['reset_value'] = $reset;
30
+ $field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0';
31
  $field_array['original_default'] = $original_default;
32
 
33
  FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
34
 
35
+ $field_array = array_merge( $field->field_options, $field_array );
36
 
37
+ $values['fields'][] = $field_array;
38
 
39
  if ( ! $form || ! isset( $form->id ) ) {
40
  $form = FrmForm::getOne( $field->form_id );
41
  }
42
+ }
43
 
44
  $form->options = maybe_unserialize( $form->options );
45
  if ( is_array( $form->options ) ) {
47
  }
48
 
49
  $form_defaults = FrmFormsHelper::get_default_opts();
 
50
 
51
+ $frm_settings = FrmAppHelper::get_settings();
52
+ $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' );
53
 
54
  $values = array_merge( $form_defaults, $values );
55
 
56
  return apply_filters( 'frm_setup_new_entry', $values );
57
+ }
58
 
59
  /**
60
  * @since 2.05
71
  }
72
 
73
  /**
74
+ * Set the value for each field
75
+ * This function is used when the form is first loaded and on all page turns *for a new entry*
76
+ *
77
+ * @since 2.0.13
78
+ *
79
+ * @param object $field - this is passed by reference since it is an object
80
+ * @param boolean $reset
81
+ * @param array $args
82
+ * @return string|array $new_value
83
+ */
 
84
  private static function get_field_value_for_new_entry( $field, $reset, $args ) {
85
  $new_value = $field->default_value;
86
 
87
  if ( ! $reset && self::value_is_posted( $field, $args ) ) {
88
  self::get_posted_value( $field, $new_value, $args );
89
+ } else if ( FrmField::is_option_true( $field, 'clear_on_focus' ) ) {
90
+ // If clear on focus is selected, the value should be blank (unless it was posted, of course)
91
 
92
  // TODO: move to Pro
93
  if ( 'address' == $field->type && isset( $new_value['country'] ) ) {
105
  }
106
 
107
  /**
108
+ * Check if a field has a posted value
109
+ *
110
+ * @since 2.01.0
111
+ * @param object $field
112
+ * @param array $args
113
+ * @return boolean $value_is_posted
114
+ */
 
 
115
  public static function value_is_posted( $field, $args ) {
116
  $value_is_posted = false;
117
  if ( $_POST ) {
120
  if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) {
121
  $value_is_posted = true;
122
  }
123
+ } else if ( isset( $_POST['item_meta'][ $field->id ] ) ) {
124
  $value_is_posted = true;
125
  }
126
  }
 
127
  return $value_is_posted;
128
  }
129
 
130
  public static function setup_edit_vars( $values, $record ) {
131
  $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
132
+ $values['form_id'] = $record->form_id;
133
+ $values['is_draft'] = $record->is_draft;
 
134
  return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
135
+ }
136
 
137
  public static function replace_default_message( $message, $atts ) {
138
  if ( strpos( $message, '[default-message' ) === false &&
139
  strpos( $message, '[default_message' ) === false &&
140
+ ! empty( $message ) ) {
141
+ return $message;
142
+ }
143
 
144
  if ( empty( $message ) ) {
145
+ $message = '[default-message]';
146
+ }
147
 
148
  preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
149
 
150
+ foreach ( $shortcodes[0] as $short_key => $tag ) {
151
  $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
152
  if ( ! empty( $add_atts ) ) {
153
  $this_atts = array_merge( $atts, $add_atts );
154
+ } else {
155
+ $this_atts = $atts;
156
+ }
157
 
158
  $default = FrmEntriesController::show_entry_shortcode( $this_atts );
159
 
160
+ // Add the default message
161
+ $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
162
+ }
163
 
164
+ return $message;
165
+ }
166
 
167
  public static function prepare_display_value( $entry, $field, $atts ) {
168
  $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
169
 
170
+ if ( FrmAppHelper::pro_is_installed() ) {
171
  FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
172
+ }
173
 
174
  if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
175
  return self::display_value( $field_value, $field, $atts );
176
  }
177
 
178
+ // this is an embeded form
179
+ $val = '';
180
 
181
  if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
182
+ //this is a repeating section
183
  $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
184
+ } else {
185
+ // get all values for this field
186
+ $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
187
 
188
+ if ( $child_values ) {
189
+ $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
190
+ }
191
+ }
192
 
193
+ $field_value = array();
194
 
195
  if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
196
+ return $val;
197
+ }
198
 
199
+ foreach ( $child_entries as $child_entry ) {
200
+ $atts['item_id'] = $child_entry->id;
201
+ $atts['post_id'] = $child_entry->post_id;
202
 
203
+ // get the value for this field -- check for post values as well
204
  $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
205
 
206
+ if ( $entry_val ) {
207
+ // foreach entry get display_value
208
  $field_value[] = self::display_value( $entry_val, $field, $atts );
209
+ }
210
 
211
  unset( $child_entry );
212
+ }
213
 
214
  $val = implode( ', ', (array) $field_value );
 
215
  return FrmAppHelper::kses( $val, 'all' );
216
+ }
217
 
218
+ /**
219
  * Prepare the saved value for display
220
  *
221
  * @param array|string $value
227
  public static function display_value( $value, $field, $atts = array() ) {
228
 
229
  $defaults = array(
230
+ 'type' => '',
231
+ 'html' => false,
232
  'show_filename' => true,
233
+ 'truncate' => false,
234
+ 'sep' => ', ',
235
+ 'post_id' => 0,
236
+ 'form_id' => $field->form_id,
237
+ 'field' => $field,
238
+ 'keepjs' => 0,
239
+ 'return_array' => false,
240
  );
241
 
242
+ $atts = wp_parse_args( $atts, $defaults );
243
 
244
  if ( FrmField::is_image( $field ) || $field->type == 'star' ) {
245
  $atts['truncate'] = false;
246
+ $atts['html'] = true;
247
  }
248
 
249
  $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
250
 
251
  if ( ! isset( $field->field_options['post_field'] ) ) {
252
+ $field->field_options['post_field'] = '';
253
+ }
254
 
255
  if ( ! isset( $field->field_options['custom_field'] ) ) {
256
+ $field->field_options['custom_field'] = '';
257
+ }
258
 
259
+ if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
260
+ $atts['pre_truncate'] = $atts['truncate'];
261
+ $atts['truncate'] = true;
262
+ $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
263
 
264
+ $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
265
+ $atts['truncate'] = $atts['pre_truncate'];
266
+ }
267
 
268
+ if ( $value == '' ) {
269
+ return $value;
270
+ }
271
 
272
  $unfiltered_value = maybe_unserialize( $value );
 
273
  $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
274
  $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
275
 
277
  $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
278
  }
279
 
280
+ if ( $atts['truncate'] && $atts['type'] != 'url' ) {
281
  $value = FrmAppHelper::truncate( $value, 50 );
282
+ }
283
 
284
  if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
285
  $value = FrmAppHelper::kses( $value, 'all' );
286
  }
287
 
288
  return apply_filters( 'frm_display_value', $value, $field, $atts );
289
+ }
290
 
291
  public static function set_posted_value( $field, $value, $args ) {
292
+ // If validating a field with "other" opt, set back to prev value now
293
+ if ( isset( $args['other'] ) && $args['other'] ) {
294
+ $value = $args['temp_value'];
295
+ }
296
  if ( empty( $args['parent_field_id'] ) ) {
297
+ $_POST['item_meta'][ $field->id ] = $value;
298
+ } else {
299
+ $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
300
+ }
301
+ }
302
 
303
  public static function get_posted_value( $field, &$value, $args ) {
304
  $field_id = is_object( $field ) ? $field->id : $field;
305
 
306
  if ( empty( $args['parent_field_id'] ) ) {
307
+ $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : '';
308
+ } else {
309
+ $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : '';
310
+ }
 
311
  FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
312
+ $value = stripslashes_deep( $value );
313
+ }
314
+
315
+ /**
316
+ * Check if field has an "Other" option and if any other values are posted
317
+ *
318
+ * @since 2.0
319
+ *
320
+ * @param object $field
321
+ * @param string|array $value
322
+ * @param array $args
323
+ */
324
+ public static function maybe_set_other_validation( $field, &$value, &$args ) {
325
+ $args['other'] = false;
326
+ if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) {
327
+ return;
328
+ }
329
+
330
+ // Get other value for fields in repeating section
331
+ self::set_other_repeating_vals( $field, $value, $args );
332
+
333
+ // Check if there are any posted "Other" values
334
  if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
335
 
336
+ // Save original value
337
+ $args['temp_value'] = $value;
338
+ $args['other'] = true;
339
+ $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] );
340
+
341
+ // Set the validation value now
342
+ self::set_other_validation_val( $value, $other_vals, $field, $args );
343
+ }
344
+ }
345
+
346
+ /**
347
+ * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
348
+ *
349
+ * @since 2.0
350
+ *
351
+ * @param object $field
352
+ * @param string|array $value
353
+ * @param array $args
354
+ */
355
+ public static function set_other_repeating_vals( $field, &$value, &$args ) {
356
+ if ( ! $args['parent_field_id'] ) {
357
+ return;
358
+ }
359
+
360
+ // Check if there are any other posted "other" values for this field
361
  if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) {
362
+ // Save original value
363
+ $args['temp_value'] = $value;
364
+ $args['other'] = true;
365
+
366
+ $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ];
367
+
368
+ // Set the validation value now
369
+ self::set_other_validation_val( $value, $other_vals, $field, $args );
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Modify value used for validation
375
+ * This function essentially removes the "Other" radio or checkbox value from the $value being validated.
376
+ * It also adds any text from the free text fields to the value
377
+ *
378
+ * Needs to accommodate for times when other opt is selected, but no other free text is entered
379
+ *
380
+ * @since 2.0
381
+ *
382
+ * @param string|array $value
383
+ * @param string|array $other_vals (usually of posted values)
384
+ * @param object $field
385
+ * @param array $args
386
+ */
387
+ public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
388
+ // Checkboxes and multi-select dropdowns
389
+ if ( is_array( $value ) && $field->type == 'checkbox' ) {
390
+ // Combine "Other" values with checked values. "Other" values will override checked box values.
391
+ $value = array_merge( $value, $other_vals );
392
+ $value = array_filter( $value );
393
+ if ( count( $value ) == 0 ) {
394
+ $value = '';
395
+ }
396
+ } else {
397
+ // Radio and dropdowns
398
  $other_key = array_filter( array_keys( $field->options ), 'is_string' );
399
+ $other_key = reset( $other_key );
400
 
401
+ // Multi-select dropdown
402
+ if ( is_array( $value ) ) {
403
+ $o_key = array_search( $field->options[ $other_key ], $value );
404
 
405
  if ( $o_key !== false ) {
406
+ // Modify the original value so other key will be preserved
407
  $value[ $other_key ] = $value[ $o_key ];
408
 
409
+ // By default, the array keys will be numeric for multi-select dropdowns
410
+ // If going backwards and forwards between pages, the array key will match the other key
411
  if ( $o_key !== $other_key ) {
412
  unset( $value[ $o_key ] );
413
  }
414
 
415
+ $args['temp_value'] = $value;
416
  $value[ $other_key ] = reset( $other_vals );
417
  if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
418
  unset( $value[ $other_key ] );
419
  }
420
  }
421
+ } else if ( $field->options[ $other_key ] == $value ) {
422
+ $value = $other_vals;
423
+ }
424
+ }
425
+ }
426
 
427
+ // Add submitted values to a string for spam checking
 
 
 
 
428
  public static function entry_array_to_string( $values ) {
429
+ $content = '';
430
  foreach ( $values['item_meta'] as $val ) {
431
  if ( $content != '' ) {
432
  $content .= "\n\n";
441
  }
442
 
443
  return $content;
444
+ }
445
 
446
  /**
447
  * Get the browser from the user agent
453
  * @return string
454
  */
455
  public static function get_browser( $u_agent ) {
456
+ $bname = __( 'Unknown', 'formidable' );
457
  $platform = __( 'Unknown', 'formidable' );
458
+ $ub = '';
459
 
460
  // Get the operating system
461
  if ( preg_match( '/windows|win32/i', $u_agent ) ) {
462
  $platform = 'Windows';
463
+ } else if ( preg_match( '/android/i', $u_agent ) ) {
464
  $platform = 'Android';
465
+ } else if ( preg_match( '/linux/i', $u_agent ) ) {
466
  $platform = 'Linux';
467
+ } else if ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
468
  $platform = 'OS X';
469
  }
470
 
479
  // Next get the name of the useragent yes seperately and for good reason
480
  if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
481
  $bname = 'Internet Explorer';
482
+ $ub = 'MSIE';
483
  } else {
484
  foreach ( $agent_options as $agent_key => $agent_name ) {
485
  if ( strpos( $u_agent, $agent_key ) !== false ) {
486
  $bname = $agent_name;
487
+ $ub = $agent_key;
488
  break;
489
  }
490
  }
491
  }
492
 
493
  // finally get the correct version number
494
+ $known = array( 'Version', $ub, 'other' );
495
  $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
496
  preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
497
 
506
  } else {
507
  $version = $matches['version'][1];
508
  }
509
+ } else if ( $i === 1 ) {
510
  $version = $matches['version'][0];
511
  } else {
512
  $version = '';
524
  * @since 3.0
525
  */
526
  public static function actions_dropdown( $atts ) {
527
+ $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
528
  $links = self::get_action_links( $id, $atts['entry'] );
529
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  }
531
 
532
  /**
533
  * @since 3.0
534
  */
535
  private static function get_action_links( $id, $entry ) {
 
536
  $actions = array();
537
 
 
 
 
 
 
 
 
 
538
  if ( current_user_can( 'frm_delete_entries' ) ) {
539
  $actions['frm_delete'] = array(
540
  'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ),
541
+ 'label' => __( 'Delete', 'formidable' ),
542
  'icon' => 'frm_icon_font frm_delete_icon',
543
+ 'data' => array( 'frmverify' => __( 'Really delete?', 'formidable' ) ),
 
 
 
 
 
 
 
 
 
 
 
 
 
544
  );
545
  }
546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
548
  }
549
  }
classes/helpers/FrmEntriesListHelper.php CHANGED
@@ -6,20 +6,20 @@ class FrmEntriesListHelper extends FrmListHelper {
6
  protected $field;
7
 
8
  public function prepare_items() {
9
- global $per_page;
10
 
11
  $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
12
- $form_id = $this->params['form'];
13
 
14
  $s_query = array();
15
 
16
  if ( $form_id ) {
17
  $s_query['it.form_id'] = $form_id;
18
- $join_form_in_query = false;
19
  } else {
20
- $s_query[] = array(
21
- 'or' => 1,
22
- 'parent_form_id' => null,
23
  'parent_form_id <' => 1,
24
  );
25
  $join_form_in_query = true;
@@ -33,7 +33,7 @@ class FrmEntriesListHelper extends FrmListHelper {
33
  );
34
 
35
  if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
36
- $fid = self::get_param( array( 'param' => 'fid' ) );
37
  $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
38
  }
39
 
@@ -41,14 +41,14 @@ class FrmEntriesListHelper extends FrmListHelper {
41
 
42
  $orderby = self::get_param(
43
  array(
44
- 'param' => 'orderby',
45
  'default' => 'id',
46
  )
47
  );
48
 
49
  if ( strpos( $orderby, 'meta' ) !== false ) {
50
  $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
51
- $orderby .= in_array( $order_field_type, array( 'number', 'scale', 'star' ) ) ? '+0' : '';
52
  }
53
 
54
  $order = self::get_param(
@@ -59,7 +59,7 @@ class FrmEntriesListHelper extends FrmListHelper {
59
  );
60
  $order = FrmDb::esc_order( $orderby . ' ' . $order );
61
 
62
- $page = $this->get_pagenum();
63
  $start = (int) self::get_param(
64
  array(
65
  'param' => 'start',
@@ -67,14 +67,14 @@ class FrmEntriesListHelper extends FrmListHelper {
67
  )
68
  );
69
 
70
- $limit = FrmDb::esc_limit( $start . ',' . $per_page );
71
  $this->items = FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
72
  $total_items = FrmEntry::getRecordCount( $s_query );
73
 
74
  $this->set_pagination_args(
75
  array(
76
  'total_items' => $total_items,
77
- 'per_page' => $per_page,
78
  )
79
  );
80
  }
@@ -82,23 +82,22 @@ class FrmEntriesListHelper extends FrmListHelper {
82
  public function no_items() {
83
  $s = self::get_param(
84
  array(
85
- 'param' => 's',
86
  'sanitize' => 'sanitize_text_field',
87
  )
88
  );
89
  if ( ! empty( $s ) ) {
90
  esc_html_e( 'No Entries Found', 'formidable' );
91
-
92
- return;
93
- }
94
 
95
  $form_id = $this->params['form'];
96
- $form = $this->params['form'];
97
 
98
- if ( $form_id ) {
99
  $form = FrmForm::getOne( $form_id );
100
- }
101
- $colspan = $this->get_column_count();
102
 
103
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
104
  }
@@ -116,21 +115,21 @@ class FrmEntriesListHelper extends FrmListHelper {
116
  echo '<input type="hidden" name="_wp_http_referer" value="" />';
117
 
118
  echo FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) ); // WPCS: XSS ok.
119
- submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) );
120
  echo '</div>';
121
  }
122
  }
123
 
124
  /**
125
- * Gets the name of the primary column in the Entries screen
126
- *
127
- * @since 2.0.14
128
- *
129
- * @return string $primary_column
130
- */
131
  protected function get_primary_column_name() {
132
  $columns = get_column_headers( $this->screen );
133
- $hidden = get_hidden_columns( $this->screen );
134
 
135
  $primary_column = '';
136
 
@@ -146,12 +145,12 @@ class FrmEntriesListHelper extends FrmListHelper {
146
 
147
  public function single_row( $item, $style = '' ) {
148
  // Set up the hover actions for this user
149
- $actions = array();
150
  $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id;
151
 
152
  $this->get_actions( $actions, $item, $view_link );
153
 
154
- $action_links = $this->row_actions( $actions );
155
 
156
  // Set up the checkbox ( because the user is editable, otherwise its empty )
157
  $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
@@ -159,7 +158,7 @@ class FrmEntriesListHelper extends FrmListHelper {
159
  $r = "<tr id='item-action-{$item->id}'$style>";
160
 
161
  list( $columns, $hidden, , $primary ) = $this->get_column_info();
162
- $action_col = false;
163
 
164
  foreach ( $columns as $column_name => $column_display_name ) {
165
  $class = $column_name . ' column-' . $column_name;
@@ -170,15 +169,15 @@ class FrmEntriesListHelper extends FrmListHelper {
170
 
171
  if ( in_array( $column_name, $hidden ) ) {
172
  $class .= ' frm_hidden';
173
- } elseif ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) {
174
- $action_col = $column_name;
175
- }
176
 
177
  $attributes = 'class="' . esc_attr( $class ) . '"';
178
  unset( $class );
179
  $attributes .= ' data-colname="' . $column_display_name . '"';
180
 
181
- $form_id = $this->params['form'] ? $this->params['form'] : 0;
182
  $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
183
 
184
  if ( $this->column_name == 'cb' ) {
@@ -190,15 +189,15 @@ class FrmEntriesListHelper extends FrmListHelper {
190
  $val = $this->column_value( $item );
191
  }
192
 
193
- $r .= "<td $attributes>";
194
  if ( $column_name == $action_col ) {
195
- $edit_link = FrmAppHelper::maybe_full_screen_link( '?page=formidable-entries&frm_action=edit&id=' . $item->id );
196
- $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
197
- $r .= $action_links;
198
  } else {
199
- $r .= $val;
200
- }
201
- $r .= '</td>';
202
  }
203
  unset( $val );
204
  }
@@ -223,7 +222,7 @@ class FrmEntriesListHelper extends FrmListHelper {
223
  case 'created_at':
224
  case 'updated_at':
225
  $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
226
- $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
227
  break;
228
  case 'is_draft':
229
  $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' );
@@ -236,7 +235,7 @@ class FrmEntriesListHelper extends FrmListHelper {
236
  break;
237
  case 'user_id':
238
  $user = get_userdata( $item->user_id );
239
- $val = $user ? $user->user_login : '';
240
  break;
241
  case 'parent_item_id':
242
  $val = $item->parent_item_id;
@@ -251,27 +250,25 @@ class FrmEntriesListHelper extends FrmListHelper {
251
  return $val;
252
  }
253
 
254
- /**
255
- * @param string $view_link
256
- */
257
- private function get_actions( &$actions, $item, $view_link ) {
258
- $view_link = FrmAppHelper::maybe_full_screen_link( $view_link );
259
  $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
260
 
261
  if ( current_user_can( 'frm_delete_entries' ) ) {
262
- $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
263
- $delete_link = FrmAppHelper::maybe_full_screen_link( $delete_link );
264
  $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" data-frmverify="' . esc_attr__( 'Are you sure?', 'formidable' ) . '">' . __( 'Delete', 'formidable' ) . '</a>';
265
- }
266
 
267
  $actions = apply_filters( 'frm_row_actions', $actions, $item );
268
- }
269
 
270
  private function get_column_value( $item, &$val ) {
271
  $col_name = $this->column_name;
272
 
273
  if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
274
- $sep_val = true;
275
  $col_name = str_replace( 'frmsep_', '', $col_name );
276
  } else {
277
  $sep_val = false;
@@ -287,10 +284,10 @@ class FrmEntriesListHelper extends FrmListHelper {
287
  }
288
 
289
  $atts = array(
290
- 'type' => $field->type,
291
- 'truncate' => true,
292
- 'post_id' => $item->post_id,
293
- 'entry_id' => $item->id,
294
  'embedded_field_id' => 0,
295
  );
296
 
6
  protected $field;
7
 
8
  public function prepare_items() {
9
+ global $per_page;
10
 
11
  $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
12
+ $form_id = $this->params['form'];
13
 
14
  $s_query = array();
15
 
16
  if ( $form_id ) {
17
  $s_query['it.form_id'] = $form_id;
18
+ $join_form_in_query = false;
19
  } else {
20
+ $s_query[] = array(
21
+ 'or' => 1,
22
+ 'parent_form_id' => null,
23
  'parent_form_id <' => 1,
24
  );
25
  $join_form_in_query = true;
33
  );
34
 
35
  if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
36
+ $fid = self::get_param( array( 'param' => 'fid' ) );
37
  $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
38
  }
39
 
41
 
42
  $orderby = self::get_param(
43
  array(
44
+ 'param' => 'orderby',
45
  'default' => 'id',
46
  )
47
  );
48
 
49
  if ( strpos( $orderby, 'meta' ) !== false ) {
50
  $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
51
+ $orderby .= in_array( $order_field_type, array( 'number', 'scale', 'star' ) ) ? '+0' : '';
52
  }
53
 
54
  $order = self::get_param(
59
  );
60
  $order = FrmDb::esc_order( $orderby . ' ' . $order );
61
 
62
+ $page = $this->get_pagenum();
63
  $start = (int) self::get_param(
64
  array(
65
  'param' => 'start',
67
  )
68
  );
69
 
70
+ $limit = FrmDb::esc_limit( $start . ',' . $per_page );
71
  $this->items = FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
72
  $total_items = FrmEntry::getRecordCount( $s_query );
73
 
74
  $this->set_pagination_args(
75
  array(
76
  'total_items' => $total_items,
77
+ 'per_page' => $per_page,
78
  )
79
  );
80
  }
82
  public function no_items() {
83
  $s = self::get_param(
84
  array(
85
+ 'param' => 's',
86
  'sanitize' => 'sanitize_text_field',
87
  )
88
  );
89
  if ( ! empty( $s ) ) {
90
  esc_html_e( 'No Entries Found', 'formidable' );
91
+ return;
92
+ }
 
93
 
94
  $form_id = $this->params['form'];
95
+ $form = $this->params['form'];
96
 
97
+ if ( $form_id ) {
98
  $form = FrmForm::getOne( $form_id );
99
+ }
100
+ $colspan = $this->get_column_count();
101
 
102
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
103
  }
115
  echo '<input type="hidden" name="_wp_http_referer" value="" />';
116
 
117
  echo FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) ); // WPCS: XSS ok.
118
+ submit_button( __( 'Filter', 'formidable' ), 'filter_action', '', false, array( 'id' => 'post-query-submit' ) );
119
  echo '</div>';
120
  }
121
  }
122
 
123
  /**
124
+ * Gets the name of the primary column in the Entries screen
125
+ *
126
+ * @since 2.0.14
127
+ *
128
+ * @return string $primary_column
129
+ */
130
  protected function get_primary_column_name() {
131
  $columns = get_column_headers( $this->screen );
132
+ $hidden = get_hidden_columns( $this->screen );
133
 
134
  $primary_column = '';
135
 
145
 
146
  public function single_row( $item, $style = '' ) {
147
  // Set up the hover actions for this user
148
+ $actions = array();
149
  $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id;
150
 
151
  $this->get_actions( $actions, $item, $view_link );
152
 
153
+ $action_links = $this->row_actions( $actions );
154
 
155
  // Set up the checkbox ( because the user is editable, otherwise its empty )
156
  $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
158
  $r = "<tr id='item-action-{$item->id}'$style>";
159
 
160
  list( $columns, $hidden, , $primary ) = $this->get_column_info();
161
+ $action_col = false;
162
 
163
  foreach ( $columns as $column_name => $column_display_name ) {
164
  $class = $column_name . ' column-' . $column_name;
169
 
170
  if ( in_array( $column_name, $hidden ) ) {
171
  $class .= ' frm_hidden';
172
+ } else if ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) {
173
+ $action_col = $column_name;
174
+ }
175
 
176
  $attributes = 'class="' . esc_attr( $class ) . '"';
177
  unset( $class );
178
  $attributes .= ' data-colname="' . $column_display_name . '"';
179
 
180
+ $form_id = $this->params['form'] ? $this->params['form'] : 0;
181
  $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
182
 
183
  if ( $this->column_name == 'cb' ) {
189
  $val = $this->column_value( $item );
190
  }
191
 
192
+ $r .= "<td $attributes>";
193
  if ( $column_name == $action_col ) {
194
+ $edit_link = '?page=formidable-entries&frm_action=edit&id=' . $item->id;
195
+ $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
196
+ $r .= $action_links;
197
  } else {
198
+ $r .= $val;
199
+ }
200
+ $r .= '</td>';
201
  }
202
  unset( $val );
203
  }
222
  case 'created_at':
223
  case 'updated_at':
224
  $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
225
+ $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
226
  break;
227
  case 'is_draft':
228
  $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' );
235
  break;
236
  case 'user_id':
237
  $user = get_userdata( $item->user_id );
238
+ $val = $user ? $user->user_login : '';
239
  break;
240
  case 'parent_item_id':
241
  $val = $item->parent_item_id;
250
  return $val;
251
  }
252
 
253
+ /**
254
+ * @param string $view_link
255
+ */
256
+ private function get_actions( &$actions, $item, $view_link ) {
 
257
  $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
258
 
259
  if ( current_user_can( 'frm_delete_entries' ) ) {
260
+ $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
 
261
  $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" data-frmverify="' . esc_attr__( 'Are you sure?', 'formidable' ) . '">' . __( 'Delete', 'formidable' ) . '</a>';
262
+ }
263
 
264
  $actions = apply_filters( 'frm_row_actions', $actions, $item );
265
+ }
266
 
267
  private function get_column_value( $item, &$val ) {
268
  $col_name = $this->column_name;
269
 
270
  if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
271
+ $sep_val = true;
272
  $col_name = str_replace( 'frmsep_', '', $col_name );
273
  } else {
274
  $sep_val = false;
284
  }
285
 
286
  $atts = array(
287
+ 'type' => $field->type,
288
+ 'truncate' => true,
289
+ 'post_id' => $item->post_id,
290
+ 'entry_id' => $item->id,
291
  'embedded_field_id' => 0,
292
  );
293
 
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -16,10 +16,9 @@ class FrmFieldsHelper {
16
  global $wpdb;
17
  $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
18
 
19
- $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
20
- $values['form_id'] = $form_id;
21
  $values['field_order'] = $field_count + 1;
22
-
23
  $values['field_options']['custom_html'] = self::get_default_html( $type );
24
 
25
  if ( isset( $setting ) && ! empty( $setting ) ) {
@@ -30,18 +29,17 @@ class FrmFieldsHelper {
30
  }
31
  }
32
 
33
- return $values;
34
- }
35
 
36
  public static function get_html_id( $field, $plus = '' ) {
37
  return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
38
- }
39
 
40
- public static function setup_edit_vars( $field, $doing_ajax = false ) {
41
  $values = self::field_object_to_array( $field );
42
-
43
  return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
44
- }
45
 
46
  public static function field_object_to_array( $field ) {
47
  $values = (array) $field;
@@ -55,7 +53,7 @@ class FrmFieldsHelper {
55
 
56
  private static function fill_field_array( $field, array &$field_array ) {
57
  $field_array['options'] = $field->options;
58
- $field_array['value'] = $field->default_value;
59
 
60
  self::prepare_edit_front_field( $field_array, $field );
61
 
@@ -113,7 +111,6 @@ class FrmFieldsHelper {
113
  */
114
  public static function get_default_field_options( $type ) {
115
  $field_type = FrmFieldFactory::get_field_type( $type );
116
-
117
  return $field_type->get_default_field_options();
118
  }
119
 
@@ -163,7 +160,6 @@ class FrmFieldsHelper {
163
  if ( 'captcha' === $field->type ) {
164
  $field_array['invalid'] = $frm_settings->re_msg;
165
  } else {
166
- /* translators: %s: Field name */
167
  $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
168
  }
169
  }
@@ -199,7 +195,7 @@ class FrmFieldsHelper {
199
  */
200
  public static function get_default_field_options_from_field( $field, $values = array() ) {
201
  $field_type = self::get_original_field( $field );
202
- $opts = $field_type->get_default_field_options();
203
 
204
  $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
205
  $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
@@ -219,7 +215,6 @@ class FrmFieldsHelper {
219
  if ( ! empty( $original_type ) && $field->type != $original_type ) {
220
  $field->type = $original_type;
221
  }
222
-
223
  return FrmFieldFactory::get_field_object( $field );
224
  }
225
 
@@ -231,7 +226,7 @@ class FrmFieldsHelper {
231
  * @param array $atts
232
  */
233
  private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
234
- $field_obj = FrmFieldFactory::get_field_object( $field );
235
  $field_array = $field_obj->prepare_front_field( $field_array, $atts );
236
  }
237
 
@@ -244,22 +239,21 @@ class FrmFieldsHelper {
244
  */
245
  public static function get_default_field( $type ) {
246
  $field_type = FrmFieldFactory::get_field_type( $type );
247
-
248
  return $field_type->get_new_field_defaults();
249
  }
250
 
251
- public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
252
- global $wpdb;
253
 
254
- $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
255
- $values['form_id'] = $form_id;
256
- $values['options'] = maybe_serialize( $field->options );
257
  $values['default_value'] = maybe_serialize( $field->default_value );
258
 
259
- foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
260
- $values[ $col ] = $field->{$col};
261
- }
262
- }
263
 
264
  /**
265
  * @since 2.0
@@ -270,27 +264,25 @@ class FrmFieldsHelper {
270
  * @return string
271
  */
272
  public static function get_error_msg( $field, $error ) {
273
- $frm_settings = FrmAppHelper::get_settings();
274
  $default_settings = $frm_settings->default_options();
275
- $field_name = is_array( $field ) ? $field['name'] : $field->name;
276
 
277
  $conf_msg = __( 'The entered values do not match', 'formidable' );
278
  $defaults = array(
279
  'unique_msg' => array(
280
  'full' => $default_settings['unique_msg'],
281
- /* translators: %s: Field name */
282
  'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
283
  ),
284
- 'invalid' => array(
285
  'full' => __( 'This field is invalid', 'formidable' ),
286
- /* translators: %s: Field name */
287
  'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
288
  ),
289
- 'blank' => array(
290
  'full' => $frm_settings->blank_msg,
291
  'part' => $frm_settings->blank_msg,
292
  ),
293
- 'conf_msg' => array(
294
  'full' => $conf_msg,
295
  'part' => $conf_msg,
296
  ),
@@ -299,18 +291,16 @@ class FrmFieldsHelper {
299
  $msg = FrmField::get_option( $field, $error );
300
  $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
301
  $msg = do_shortcode( $msg );
302
-
303
  return $msg;
304
  }
305
 
306
  public static function get_form_fields( $form_id, $error = array() ) {
307
  $fields = FrmField::get_all_for_form( $form_id );
308
-
309
  return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
310
  }
311
 
312
  public static function get_default_html( $type = 'text' ) {
313
- $field = FrmFieldFactory::get_field_type( $type );
314
  $default_html = $field->default_html();
315
 
316
  // these hooks are here for reverse compatibility since 3.0
@@ -360,7 +350,6 @@ class FrmFieldsHelper {
360
  if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
361
  $position = 'top';
362
  }
363
-
364
  return $position;
365
  }
366
 
@@ -393,140 +382,49 @@ class FrmFieldsHelper {
393
  if ( isset( $field['in_section'] ) && $field['in_section'] ) {
394
  $id .= '-' . $field['in_section'];
395
  }
396
-
397
  return 'frm_checkbox_' . $id . '-' . $opt_key;
398
  }
399
 
400
  public static function show_single_option( $field ) {
401
- self::hidden_field_option( $field );
402
-
403
  if ( ! is_array( $field['options'] ) ) {
404
  return;
405
  }
406
 
407
- $base_name = 'default_value_' . $field['id'];
408
- $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
409
-
410
- $default_type = self::get_default_value_type( $field );
411
 
412
  foreach ( $field['options'] as $opt_key => $opt ) {
413
- $field_val = self::get_value_from_array( $opt, $opt_key, $field );
414
- $opt = self::get_label_from_array( $opt, $opt_key, $field );
415
 
416
- $field_name = $base_name . ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
 
417
 
418
- $checked = ( isset( $field['default_value'] ) && ( ( ! is_array( $field['default_value'] ) && $field['default_value'] == $field_val ) || ( is_array( $field['default_value'] ) && in_array( $field_val, $field['default_value'] ) ) ) );
419
 
420
- // If this is an "Other" option, get the HTML for it.
421
  if ( self::is_other_opt( $opt_key ) ) {
422
  if ( FrmAppHelper::pro_is_installed() ) {
423
  require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
424
  }
425
- } else {
426
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
427
- }
428
 
429
- unset( $checked );
430
  }
431
- }
432
-
433
- /**
434
- * Include hidden row for javascript to duplicate.
435
- *
436
- * @since 4.0
437
- * @param array $field
438
- */
439
- private static function hidden_field_option( $field ) {
440
- // Don't duplicate during an ajax add option.
441
- $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
442
- if ( $ajax_action === 'frm_add_field_option' ) {
443
- return;
444
- }
445
-
446
- $opt_key = '000';
447
- $field_val = '';
448
- $opt = '';
449
- $checked = false;
450
- $field_name = 'default_value_' . $field['id'];
451
- $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
452
-
453
- $default_type = self::get_default_value_type( $field );
454
- $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
455
-
456
- require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
457
- }
458
-
459
- /**
460
- * @since 4.0
461
- *
462
- * @param array $field
463
- * @return string radio or checkbox
464
- */
465
- private static function get_default_value_type( $field ) {
466
- $default_type = $field['type'];
467
- if ( $field['type'] === 'select' ) {
468
- $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
469
- }
470
- return $default_type;
471
- }
472
 
473
  public static function get_value_from_array( $opt, $opt_key, $field ) {
474
  $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
475
-
476
  return FrmFieldsController::check_value( $opt, $opt_key, $field );
477
  }
478
 
479
  public static function get_label_from_array( $opt, $opt_key, $field ) {
480
  $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
481
-
482
  return FrmFieldsController::check_label( $opt );
483
  }
484
 
485
- /**
486
- * @since 4.0
487
- */
488
- public static function inline_modal( $args ) {
489
- $defaults = array(
490
- 'id' => '',
491
- 'class' => '',
492
- 'show' => 0,
493
- 'callback' => array(),
494
- 'args' => array(),
495
- 'title' => '',
496
- );
497
- $args = array_merge( $defaults, $args );
498
-
499
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php' );
500
- }
501
-
502
- /**
503
- * @since 4.0
504
- */
505
- public static function smart_values() {
506
- $continue = apply_filters( 'frm_smart_values_box', true );
507
- if ( $continue === true ) {
508
- $upgrade_link = array(
509
- 'medium' => 'builder',
510
- 'content' => 'smart-tags',
511
- );
512
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' );
513
- }
514
- }
515
-
516
- /**
517
- * @since 4.0
518
- */
519
- public static function input_mask() {
520
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php' );
521
- }
522
-
523
- /**
524
- * @since 4.0
525
- */
526
- public static function layout_classes() {
527
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php' );
528
- }
529
-
530
  /**
531
  * @param int $tax_id
532
  *
@@ -534,32 +432,28 @@ class FrmFieldsHelper {
534
  */
535
  public static function get_term_link( $tax_id ) {
536
  $tax = get_taxonomy( $tax_id );
537
- if ( ! $tax ) {
538
- return '';
539
- }
540
 
541
  $link = sprintf(
542
- /* translators: %1$s: Start HTML link, %2$s: Content type label, %3$s: Content type, %4$s: End HTML link */
543
- esc_html__( 'Options are dynamically created from your %1$s%2$s: %3$s%4$s', 'formidable' ),
544
- '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">',
545
- esc_html__( 'taxonomy', 'formidable' ),
546
- empty( $tax->labels->name ) ? esc_html__( 'Categories', 'formidable' ) : $tax->labels->name,
547
- '</a>'
548
  );
549
  unset( $tax );
550
 
551
- return $link;
552
- }
553
 
554
  public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
555
- $hide_opt = self::get_value_for_comparision( $hide_opt );
556
  $observed_value = self::get_value_for_comparision( $observed_value );
557
 
558
  if ( is_array( $observed_value ) ) {
559
  return self::array_value_condition( $observed_value, $cond, $hide_opt );
560
- }
561
 
562
- $m = false;
563
  if ( $cond == '==' ) {
564
  $m = $observed_value == $hide_opt;
565
  } elseif ( $cond == '!=' ) {
@@ -580,9 +474,8 @@ class FrmFieldsHelper {
580
  $m = ( $m === false ) ? false : true;
581
  }
582
  }
583
-
584
- return $m;
585
- }
586
 
587
  /**
588
  * Trim and sanitize the values
@@ -599,8 +492,8 @@ class FrmFieldsHelper {
599
  }
600
 
601
  public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
602
- $m = false;
603
- if ( $cond == '==' ) {
604
  if ( is_array( $hide_opt ) ) {
605
  $m = array_intersect( $hide_opt, $observed_value );
606
  $m = empty( $m ) ? false : true;
@@ -611,10 +504,10 @@ class FrmFieldsHelper {
611
  $m = ! in_array( $hide_opt, $observed_value );
612
  } elseif ( $cond == '>' ) {
613
  $min = min( $observed_value );
614
- $m = $min > $hide_opt;
615
  } elseif ( $cond == '<' ) {
616
  $max = max( $observed_value );
617
- $m = $max < $hide_opt;
618
  } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
619
  foreach ( $observed_value as $ob ) {
620
  $m = strpos( $ob, $hide_opt );
@@ -624,36 +517,36 @@ class FrmFieldsHelper {
624
  }
625
  }
626
 
627
- if ( $cond == 'not LIKE' ) {
628
- $m = ( $m === false ) ? true : false;
629
- }
630
- }
631
 
632
- return $m;
633
- }
634
 
635
- /**
636
- * Replace a few basic shortcodes and field ids
637
  *
638
- * @since 2.0
639
- * @return string
640
- */
641
  public static function basic_replace_shortcodes( $value, $form, $entry ) {
642
  if ( strpos( $value, '[sitename]' ) !== false ) {
643
- $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
644
- $value = str_replace( '[sitename]', $new_value, $value );
645
- }
646
 
647
  $value = apply_filters( 'frm_content', $value, $form, $entry );
648
  $value = do_shortcode( $value );
649
 
650
- return $value;
651
- }
652
 
653
  public static function get_shortcodes( $content, $form_id ) {
654
- if ( FrmAppHelper::pro_is_installed() ) {
655
  return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
656
- }
657
 
658
  $fields = FrmField::getAll(
659
  array(
@@ -666,37 +559,23 @@ class FrmFieldsHelper {
666
 
667
  preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER );
668
 
669
- return $matches;
670
- }
671
 
672
  public static function allowed_shortcodes( $fields = array() ) {
673
- $tagregexp = array(
674
- 'editlink',
675
- 'id',
676
- 'key',
677
- 'ip',
678
- 'siteurl',
679
- 'sitename',
680
- 'admin_email',
681
- 'post[-|_]id',
682
- 'created[-|_]at',
683
- 'updated[-|_]at',
684
- 'updated[-|_]by',
685
- 'parent[-|_]id',
686
- );
687
 
688
- foreach ( $fields as $field ) {
689
- $tagregexp[] = $field->id;
690
- $tagregexp[] = $field->field_key;
691
- }
692
 
693
  $tagregexp = implode( '|', $tagregexp );
694
-
695
- return $tagregexp;
696
- }
697
 
698
  public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
699
- foreach ( $shortcodes[0] as $short_key => $tag ) {
700
  if ( empty( $tag ) ) {
701
  continue;
702
  }
@@ -705,8 +584,8 @@ class FrmFieldsHelper {
705
  $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
706
 
707
  $atts['entry'] = $entry;
708
- $atts['tag'] = $tag;
709
- $replace_with = self::get_value_for_shortcode( $atts );
710
 
711
  if ( $replace_with !== null ) {
712
  self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with );
@@ -717,7 +596,7 @@ class FrmFieldsHelper {
717
  }
718
 
719
  return $content;
720
- }
721
 
722
  /**
723
  * Prevent shortcodes in fields from being processed
@@ -728,7 +607,7 @@ class FrmFieldsHelper {
728
  * @param string $value
729
  */
730
  public static function sanitize_embedded_shortcodes( $atts, &$value ) {
731
- $atts['value'] = $value;
732
  $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
733
  if ( $should_sanitize ) {
734
  $value = str_replace( '[', '&#91;', $value );
@@ -746,9 +625,9 @@ class FrmFieldsHelper {
746
  $clean_tag = str_replace( '-', '_', $atts['tag'] );
747
 
748
  $shortcode_values = array(
749
- 'id' => $atts['entry']->id,
750
- 'key' => $atts['entry']->item_key,
751
- 'ip' => $atts['entry']->ip,
752
  );
753
 
754
  $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
@@ -758,10 +637,10 @@ class FrmFieldsHelper {
758
  } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
759
  $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
760
  } elseif ( $clean_tag == 'user_agent' ) {
761
- $description = maybe_unserialize( $atts['entry']->description );
762
  $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
763
  } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
764
- $atts['tag'] = $clean_tag;
765
  $replace_with = self::get_entry_timestamp( $atts );
766
  } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
767
  $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
@@ -784,7 +663,7 @@ class FrmFieldsHelper {
784
  $time_format = ' ';
785
  } else {
786
  $atts['format'] = get_option( 'date_format' );
787
- $time_format = '';
788
  }
789
 
790
  return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
@@ -811,7 +690,7 @@ class FrmFieldsHelper {
811
  $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
812
  $string_value = $replace_with;
813
  if ( is_array( $replace_with ) ) {
814
- $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
815
  $string_value = implode( $sep, $replace_with );
816
  }
817
 
@@ -820,51 +699,51 @@ class FrmFieldsHelper {
820
  } else {
821
  $atts['entry_id'] = $atts['entry']->id;
822
  $atts['entry_key'] = $atts['entry']->item_key;
823
- $replace_with = self::get_display_value( $replace_with, $field, $atts );
824
  }
825
  }
826
 
827
  return $replace_with;
828
  }
829
 
830
- /**
831
- * Get the value to replace a few standard shortcodes
832
- *
833
- * @since 2.0
834
- * @return string
835
- */
836
- public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
837
- $new_value = '';
838
- switch ( $tag ) {
839
- case 'admin_email':
840
  $new_value = get_option( 'admin_email' );
841
- break;
842
- case 'siteurl':
843
- $new_value = FrmAppHelper::site_url();
844
- break;
845
- case 'frmurl':
846
- $new_value = FrmAppHelper::plugin_url();
847
- break;
848
- case 'sitename':
849
- $new_value = FrmAppHelper::site_name();
850
- break;
851
- case 'get':
852
- $new_value = self::process_get_shortcode( $atts, $return_array );
853
- }
854
-
855
- return $new_value;
856
- }
857
-
858
- /**
859
- * Process the [get] shortcode
860
- *
861
- * @since 2.0
862
- * @return string|array
863
- */
864
- public static function process_get_shortcode( $atts, $return_array = false ) {
865
  if ( ! isset( $atts['param'] ) ) {
866
- return '';
867
- }
868
 
869
  if ( strpos( $atts['param'], '&#91;' ) ) {
870
  $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
@@ -872,22 +751,22 @@ class FrmFieldsHelper {
872
  }
873
 
874
  $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
875
- $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
876
 
877
- if ( $new_value == '' ) {
878
  if ( ! isset( $atts['prev_val'] ) ) {
879
- $atts['prev_val'] = '';
880
- }
881
 
882
  $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
883
- }
884
 
885
  if ( is_array( $new_value ) && ! $return_array ) {
886
  $new_value = implode( ', ', $new_value );
887
  }
888
 
889
- return $new_value;
890
- }
891
 
892
  public static function get_display_value( $value, $field, $atts = array() ) {
893
 
@@ -903,14 +782,13 @@ class FrmFieldsHelper {
903
  public static function get_unfiltered_display_value( $atts ) {
904
  $value = $atts['value'];
905
  $field = $atts['field'];
906
- $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
907
 
908
  if ( is_array( $field ) ) {
909
  $field = $field['id'];
910
  }
911
 
912
  $field_obj = FrmFieldFactory::get_field_object( $field );
913
-
914
  return $field_obj->get_display_value( $value, $atts );
915
  }
916
 
@@ -953,54 +831,33 @@ class FrmFieldsHelper {
953
  }
954
 
955
  public static function get_field_types( $type ) {
956
- $single_input = self::single_input_fields();
957
  $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
 
958
 
959
- $field_selection = FrmField::all_field_selection();
960
 
961
- $field_types = array();
962
  if ( in_array( $type, $single_input ) ) {
963
- self::field_types_for_input( $single_input, $field_selection, $field_types );
964
  } elseif ( in_array( $type, $multiple_input ) ) {
965
- self::field_types_for_input( $multiple_input, $field_selection, $field_types );
 
 
966
  } elseif ( isset( $field_selection[ $type ] ) ) {
967
- $field_types[ $type ] = $field_selection[ $type ];
968
- }
969
 
970
  $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
 
 
971
 
972
- return $field_types;
973
- }
974
-
975
- /**
976
- * Get a list of all fields that use a single value input.
977
- *
978
- * @since 4.0
979
- */
980
- public static function single_input_fields() {
981
- $fields = array(
982
- 'text',
983
- 'textarea',
984
- 'rte',
985
- 'number',
986
- 'email',
987
- 'url',
988
- 'date',
989
- 'phone',
990
- 'hidden',
991
- 'time',
992
- 'tag',
993
- 'password',
994
- );
995
- return apply_filters( 'frm_single_input_fields', $fields );
996
- }
997
-
998
- private static function field_types_for_input( $inputs, $fields, &$field_types ) {
999
- foreach ( $inputs as $input ) {
1000
- $field_types[ $input ] = $fields[ $input ];
1001
  unset( $input );
1002
- }
1003
- }
1004
 
1005
  /**
1006
  * Check if current field option is an "other" option
@@ -1008,33 +865,32 @@ class FrmFieldsHelper {
1008
  * @since 2.0.6
1009
  *
1010
  * @param string $opt_key
1011
- *
1012
  * @return boolean Returns true if current field option is an "Other" option
1013
  */
1014
  public static function is_other_opt( $opt_key ) {
1015
  return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1016
  }
1017
 
1018
- /**
1019
- * Get value that belongs in "Other" text box
1020
- *
1021
- * @since 2.0.6
1022
- *
1023
- * @param array $args
1024
- */
1025
- public static function get_other_val( $args ) {
1026
  $defaults = array(
1027
  'opt_key' => 0,
1028
  'field' => array(),
1029
  'parent' => false,
1030
  'pointer' => false,
1031
  );
1032
- $args = wp_parse_args( $args, $defaults );
1033
 
1034
- $opt_key = $args['opt_key'];
1035
- $field = $args['field'];
1036
- $parent = $args['parent'];
1037
- $pointer = $args['pointer'];
1038
  $other_val = '';
1039
 
1040
  // If option is an "other" option and there is a value set for this field,
@@ -1052,10 +908,9 @@ class FrmFieldsHelper {
1052
  } else {
1053
  $other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] );
1054
  }
1055
-
1056
  return $other_val;
1057
 
1058
- } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
1059
  // For normal fields
1060
 
1061
  if ( FrmField::is_field_with_multiple_values( $field ) ) {
@@ -1063,7 +918,6 @@ class FrmFieldsHelper {
1063
  } else {
1064
  $other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] );
1065
  }
1066
-
1067
  return $other_val;
1068
  }
1069
 
@@ -1087,7 +941,7 @@ class FrmFieldsHelper {
1087
  if ( isset( $field['value'][ $o_key ] ) ) {
1088
  unset( $field['value'][ $o_key ], $o_key );
1089
  }
1090
- } elseif ( $temp_val == $field['value'] ) {
1091
  // For radio and regular dropdowns
1092
  return '';
1093
  } else {
@@ -1102,27 +956,26 @@ class FrmFieldsHelper {
1102
  }
1103
 
1104
  return $other_val;
1105
- }
1106
-
1107
- /**
1108
- * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
1109
- * Intended for front-end use
1110
- *
1111
- * @since 2.0.6
1112
- *
1113
- * @param array $args should include field, opt_key and field name
1114
- * @param boolean $other_opt
1115
- * @param string $checked
1116
- *
1117
- * @return array $other_args
1118
- */
1119
- public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1120
  //Check if this is an "Other" option
1121
  if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1122
  return;
1123
  }
1124
 
1125
- $other_opt = true;
1126
  $other_args = array();
1127
 
1128
  self::set_other_name( $args, $other_args );
@@ -1132,13 +985,12 @@ class FrmFieldsHelper {
1132
  $checked = 'checked="checked" ';
1133
  }
1134
 
1135
- return $other_args;
1136
- }
1137
 
1138
  /**
1139
  * @param array $args
1140
  * @param array $other_args
1141
- *
1142
  * @since 2.0.6
1143
  */
1144
  private static function set_other_name( $args, &$other_args ) {
@@ -1163,7 +1015,7 @@ class FrmFieldsHelper {
1163
  * @since 2.0.6
1164
  */
1165
  private static function set_other_value( $args, &$other_args ) {
1166
- $parent = '';
1167
  $pointer = '';
1168
 
1169
  // Check for parent ID and pointer
@@ -1171,7 +1023,7 @@ class FrmFieldsHelper {
1171
 
1172
  // Count should only be greater than 3 if inside of a repeating section
1173
  if ( count( $temp_array ) > 3 ) {
1174
- $parent = str_replace( ']', '', $temp_array[1] );
1175
  $pointer = str_replace( ']', '', $temp_array[2] );
1176
  }
1177
 
@@ -1190,12 +1042,11 @@ class FrmFieldsHelper {
1190
  * If this field includes an other option, show it
1191
  *
1192
  * @param $args array
1193
- *
1194
  * @since 2.0.6
1195
  */
1196
  public static function include_other_input( $args ) {
1197
- if ( ! $args['other_opt'] ) {
1198
- return;
1199
  }
1200
 
1201
  $classes = array( 'frm_other_input' );
@@ -1212,26 +1063,23 @@ class FrmFieldsHelper {
1212
 
1213
  $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1214
 
1215
- echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1216
- esc_html( $label ) .
1217
- '</label>' .
1218
- '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1219
- ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1220
- ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1221
  }
1222
 
1223
  /**
1224
- * Get the HTML id for an "Other" text field
1225
- * Note: This does not affect fields in repeating sections
1226
- *
1227
- * @since 2.0.08
1228
- *
1229
- * @param string $type - field type
1230
- * @param string $html_id
1231
- * @param string|boolean $opt_key
1232
- *
1233
- * @return string $other_id
1234
- */
1235
  public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1236
  $other_id = $html_id;
1237
 
@@ -1249,48 +1097,83 @@ class FrmFieldsHelper {
1249
  return $other_id;
1250
  }
1251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1252
  public static function switch_field_ids( $val ) {
1253
- global $frm_duplicate_ids;
1254
- $replace = array();
1255
- $replace_with = array();
1256
- foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1257
- $replace[] = '[if ' . $old . ']';
1258
  $replace_with[] = '[if ' . $new . ']';
1259
- $replace[] = '[if ' . $old . ' ';
1260
  $replace_with[] = '[if ' . $new . ' ';
1261
- $replace[] = '[/if ' . $old . ']';
1262
  $replace_with[] = '[/if ' . $new . ']';
1263
- $replace[] = '[foreach ' . $old . ']';
1264
  $replace_with[] = '[foreach ' . $new . ']';
1265
- $replace[] = '[/foreach ' . $old . ']';
1266
  $replace_with[] = '[/foreach ' . $new . ']';
1267
- $replace[] = '[' . $old . ']';
1268
  $replace_with[] = '[' . $new . ']';
1269
- $replace[] = '[' . $old . ' ';
1270
  $replace_with[] = '[' . $new . ' ';
1271
  unset( $old, $new );
1272
- }
1273
  if ( is_array( $val ) ) {
1274
  foreach ( $val as $k => $v ) {
1275
- $val[ $k ] = str_replace( $replace, $replace_with, $v );
1276
  unset( $k, $v );
1277
- }
1278
- } else {
1279
  $val = str_replace( $replace, $replace_with, $val );
1280
- }
1281
-
1282
- return $val;
1283
- }
1284
 
1285
- /**
1286
- * @since 4.0
1287
- */
1288
- public static function bulk_options_overlay() {
1289
- $prepop = array();
1290
- self::get_bulk_prefilled_opts( $prepop );
1291
-
1292
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1293
- }
1294
 
1295
  public static function get_us_states() {
1296
  $states = array(
@@ -1346,233 +1229,17 @@ class FrmFieldsHelper {
1346
  'WI' => 'Wisconsin',
1347
  'WY' => 'Wyoming',
1348
  );
1349
-
1350
  return apply_filters( 'frm_us_states', $states );
1351
  }
1352
 
1353
  public static function get_countries() {
1354
- $countries = array(
1355
- __( 'Afghanistan', 'formidable' ),
1356
- __( 'Albania', 'formidable' ),
1357
- __( 'Algeria', 'formidable' ),
1358
- __( 'American Samoa', 'formidable' ),
1359
- __( 'Andorra', 'formidable' ),
1360
- __( 'Angola', 'formidable' ),
1361
- __( 'Anguilla', 'formidable' ),
1362
- __( 'Antarctica', 'formidable' ),
1363
- __( 'Antigua and Barbuda', 'formidable' ),
1364
- __( 'Argentina', 'formidable' ),
1365
- __( 'Armenia', 'formidable' ),
1366
- __( 'Aruba', 'formidable' ),
1367
- __( 'Australia', 'formidable' ),
1368
- __( 'Austria', 'formidable' ),
1369
- __( 'Azerbaijan', 'formidable' ),
1370
- __( 'Bahamas', 'formidable' ),
1371
- __( 'Bahrain', 'formidable' ),
1372
- __( 'Bangladesh', 'formidable' ),
1373
- __( 'Barbados', 'formidable' ),
1374
- __( 'Belarus', 'formidable' ),
1375
- __( 'Belgium', 'formidable' ),
1376
- __( 'Belize', 'formidable' ),
1377
- __( 'Benin', 'formidable' ),
1378
- __( 'Bermuda', 'formidable' ),
1379
- __( 'Bhutan', 'formidable' ),
1380
- __( 'Bolivia', 'formidable' ),
1381
- __( 'Bosnia and Herzegovina', 'formidable' ),
1382
- __( 'Botswana', 'formidable' ),
1383
- __( 'Brazil', 'formidable' ),
1384
- __( 'Brunei', 'formidable' ),
1385
- __( 'Bulgaria', 'formidable' ),
1386
- __( 'Burkina Faso', 'formidable' ),
1387
- __( 'Burundi', 'formidable' ),
1388
- __( 'Cambodia', 'formidable' ),
1389
- __( 'Cameroon', 'formidable' ),
1390
- __( 'Canada', 'formidable' ),
1391
- __( 'Cape Verde', 'formidable' ),
1392
- __( 'Cayman Islands', 'formidable' ),
1393
- __( 'Central African Republic', 'formidable' ),
1394
- __( 'Chad', 'formidable' ),
1395
- __( 'Chile', 'formidable' ),
1396
- __( 'China', 'formidable' ),
1397
- __( 'Colombia', 'formidable' ),
1398
- __( 'Comoros', 'formidable' ),
1399
- __( 'Congo', 'formidable' ),
1400
- __( 'Costa Rica', 'formidable' ),
1401
- __( 'C&ocirc;te d\'Ivoire', 'formidable' ),
1402
- __( 'Croatia', 'formidable' ),
1403
- __( 'Cuba', 'formidable' ),
1404
- __( 'Cyprus', 'formidable' ),
1405
- __( 'Czech Republic', 'formidable' ),
1406
- __( 'Denmark', 'formidable' ),
1407
- __( 'Djibouti', 'formidable' ),
1408
- __( 'Dominica', 'formidable' ),
1409
- __( 'Dominican Republic', 'formidable' ),
1410
- __( 'East Timor', 'formidable' ),
1411
- __( 'Ecuador', 'formidable' ),
1412
- __( 'Egypt', 'formidable' ),
1413
- __( 'El Salvador', 'formidable' ),
1414
- __( 'Equatorial Guinea', 'formidable' ),
1415
- __( 'Eritrea', 'formidable' ),
1416
- __( 'Estonia', 'formidable' ),
1417
- __( 'Ethiopia', 'formidable' ),
1418
- __( 'Fiji', 'formidable' ),
1419
- __( 'Finland', 'formidable' ),
1420
- __( 'France', 'formidable' ),
1421
- __( 'French Guiana', 'formidable' ),
1422
- __( 'French Polynesia', 'formidable' ),
1423
- __( 'Gabon', 'formidable' ),
1424
- __( 'Gambia', 'formidable' ),
1425
- __( 'Georgia', 'formidable' ),
1426
- __( 'Germany', 'formidable' ),
1427
- __( 'Ghana', 'formidable' ),
1428
- __( 'Gibraltar', 'formidable' ),
1429
- __( 'Greece', 'formidable' ),
1430
- __( 'Greenland', 'formidable' ),
1431
- __( 'Grenada', 'formidable' ),
1432
- __( 'Guam', 'formidable' ),
1433
- __( 'Guatemala', 'formidable' ),
1434
- __( 'Guinea', 'formidable' ),
1435
- __( 'Guinea-Bissau', 'formidable' ),
1436
- __( 'Guyana', 'formidable' ),
1437
- __( 'Haiti', 'formidable' ),
1438
- __( 'Honduras', 'formidable' ),
1439
- __( 'Hong Kong', 'formidable' ),
1440
- __( 'Hungary', 'formidable' ),
1441
- __( 'Iceland', 'formidable' ),
1442
- __( 'India', 'formidable' ),
1443
- __( 'Indonesia', 'formidable' ),
1444
- __( 'Iran', 'formidable' ),
1445
- __( 'Iraq', 'formidable' ),
1446
- __( 'Ireland', 'formidable' ),
1447
- __( 'Israel', 'formidable' ),
1448
- __( 'Italy', 'formidable' ),
1449
- __( 'Jamaica', 'formidable' ),
1450
- __( 'Japan', 'formidable' ),
1451
- __( 'Jordan', 'formidable' ),
1452
- __( 'Kazakhstan', 'formidable' ),
1453
- __( 'Kenya', 'formidable' ),
1454
- __( 'Kiribati', 'formidable' ),
1455
- __( 'North Korea', 'formidable' ),
1456
- __( 'South Korea', 'formidable' ),
1457
- __( 'Kuwait', 'formidable' ),
1458
- __( 'Kyrgyzstan', 'formidable' ),
1459
- __( 'Laos', 'formidable' ),
1460
- __( 'Latvia', 'formidable' ),
1461
- __( 'Lebanon', 'formidable' ),
1462
- __( 'Lesotho', 'formidable' ),
1463
- __( 'Liberia', 'formidable' ),
1464
- __( 'Libya', 'formidable' ),
1465
- __( 'Liechtenstein', 'formidable' ),
1466
- __( 'Lithuania', 'formidable' ),
1467
- __( 'Luxembourg', 'formidable' ),
1468
- __( 'Macedonia', 'formidable' ),
1469
- __( 'Madagascar', 'formidable' ),
1470
- __( 'Malawi', 'formidable' ),
1471
- __( 'Malaysia', 'formidable' ),
1472
- __( 'Maldives', 'formidable' ),
1473
- __( 'Mali', 'formidable' ),
1474
- __( 'Malta', 'formidable' ),
1475
- __( 'Marshall Islands', 'formidable' ),
1476
- __( 'Mauritania', 'formidable' ),
1477
- __( 'Mauritius', 'formidable' ),
1478
- __( 'Mexico', 'formidable' ),
1479
- __( 'Micronesia', 'formidable' ),
1480
- __( 'Moldova', 'formidable' ),
1481
- __( 'Monaco', 'formidable' ),
1482
- __( 'Mongolia', 'formidable' ),
1483
- __( 'Montenegro', 'formidable' ),
1484
- __( 'Montserrat', 'formidable' ),
1485
- __( 'Morocco', 'formidable' ),
1486
- __( 'Mozambique', 'formidable' ),
1487
- __( 'Myanmar', 'formidable' ),
1488
- __( 'Namibia', 'formidable' ),
1489
- __( 'Nauru', 'formidable' ),
1490
- __( 'Nepal', 'formidable' ),
1491
- __( 'Netherlands', 'formidable' ),
1492
- __( 'New Zealand', 'formidable' ),
1493
- __( 'Nicaragua', 'formidable' ),
1494
- __( 'Niger', 'formidable' ),
1495
- __( 'Nigeria', 'formidable' ),
1496
- __( 'Norway', 'formidable' ),
1497
- __( 'Northern Mariana Islands', 'formidable' ),
1498
- __( 'Oman', 'formidable' ),
1499
- __( 'Pakistan', 'formidable' ),
1500
- __( 'Palau', 'formidable' ),
1501
- __( 'Palestine', 'formidable' ),
1502
- __( 'Panama', 'formidable' ),
1503
- __( 'Papua New Guinea', 'formidable' ),
1504
- __( 'Paraguay', 'formidable' ),
1505
- __( 'Peru', 'formidable' ),
1506
- __( 'Philippines', 'formidable' ),
1507
- __( 'Poland', 'formidable' ),
1508
- __( 'Portugal', 'formidable' ),
1509
- __( 'Puerto Rico', 'formidable' ),
1510
- __( 'Qatar', 'formidable' ),
1511
- __( 'Romania', 'formidable' ),
1512
- __( 'Russia', 'formidable' ),
1513
- __( 'Rwanda', 'formidable' ),
1514
- __( 'Saint Kitts and Nevis', 'formidable' ),
1515
- __( 'Saint Lucia', 'formidable' ),
1516
- __( 'Saint Vincent and the Grenadines', 'formidable' ),
1517
- __( 'Samoa', 'formidable' ),
1518
- __( 'San Marino', 'formidable' ),
1519
- __( 'Sao Tome and Principe', 'formidable' ),
1520
- __( 'Saudi Arabia', 'formidable' ),
1521
- __( 'Senegal', 'formidable' ),
1522
- __( 'Serbia and Montenegro', 'formidable' ),
1523
- __( 'Seychelles', 'formidable' ),
1524
- __( 'Sierra Leone', 'formidable' ),
1525
- __( 'Singapore', 'formidable' ),
1526
- __( 'Slovakia', 'formidable' ),
1527
- __( 'Slovenia', 'formidable' ),
1528
- __( 'Solomon Islands', 'formidable' ),
1529
- __( 'Somalia', 'formidable' ),
1530
- __( 'South Africa', 'formidable' ),
1531
- __( 'South Sudan', 'formidable' ),
1532
- __( 'Spain', 'formidable' ),
1533
- __( 'Sri Lanka', 'formidable' ),
1534
- __( 'Sudan', 'formidable' ),
1535
- __( 'Suriname', 'formidable' ),
1536
- __( 'Swaziland', 'formidable' ),
1537
- __( 'Sweden', 'formidable' ),
1538
- __( 'Switzerland', 'formidable' ),
1539
- __( 'Syria', 'formidable' ),
1540
- __( 'Taiwan', 'formidable' ),
1541
- __( 'Tajikistan', 'formidable' ),
1542
- __( 'Tanzania', 'formidable' ),
1543
- __( 'Thailand', 'formidable' ),
1544
- __( 'Togo', 'formidable' ),
1545
- __( 'Tonga', 'formidable' ),
1546
- __( 'Trinidad and Tobago', 'formidable' ),
1547
- __( 'Tunisia', 'formidable' ),
1548
- __( 'Turkey', 'formidable' ),
1549
- __( 'Turkmenistan', 'formidable' ),
1550
- __( 'Tuvalu', 'formidable' ),
1551
- __( 'Uganda', 'formidable' ),
1552
- __( 'Ukraine', 'formidable' ),
1553
- __( 'United Arab Emirates', 'formidable' ),
1554
- __( 'United Kingdom', 'formidable' ),
1555
- __( 'United States', 'formidable' ),
1556
- __( 'Uruguay', 'formidable' ),
1557
- __( 'Uzbekistan', 'formidable' ),
1558
- __( 'Vanuatu', 'formidable' ),
1559
- __( 'Vatican City', 'formidable' ),
1560
- __( 'Venezuela', 'formidable' ),
1561
- __( 'Vietnam', 'formidable' ),
1562
- __( 'Virgin Islands, British', 'formidable' ),
1563
- __( 'Virgin Islands, U.S.', 'formidable' ),
1564
- __( 'Yemen', 'formidable' ),
1565
- __( 'Zambia', 'formidable' ),
1566
- __( 'Zimbabwe', 'formidable' ),
1567
- );
1568
-
1569
- return apply_filters( 'frm_countries', $countries );
1570
  }
1571
 
1572
  public static function get_bulk_prefilled_opts( array &$prepop ) {
1573
  $prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries();
1574
 
1575
- $states = self::get_us_states();
1576
  $state_abv = array_keys( $states );
1577
  sort( $state_abv );
1578
  $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
@@ -1621,7 +1288,7 @@ class FrmFieldsHelper {
1621
  );
1622
 
1623
  $prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1624
- }
1625
 
1626
  /**
1627
  * Display a field value selector
@@ -1631,10 +1298,10 @@ class FrmFieldsHelper {
1631
  * @param int $selector_field_id
1632
  * @param array $selector_args
1633
  */
1634
- public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1635
- $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1636
- $field_value_selector->display();
1637
- }
1638
 
1639
  /**
1640
  * Convert a field object to a flat array
@@ -1647,45 +1314,11 @@ class FrmFieldsHelper {
1647
  */
1648
  public static function convert_field_object_to_flat_array( $field ) {
1649
  $field_options = $field->field_options;
1650
- $field_array = get_object_vars( $field );
1651
  unset( $field_array['field_options'] );
1652
-
1653
  return $field_array + $field_options;
1654
  }
1655
 
1656
- /**
1657
- * @deprecated 4.0
1658
- */
1659
- public static function show_icon_link_js( $atts ) {
1660
- _deprecated_function( __METHOD__, '4.0' );
1661
- $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1662
- if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1663
- $atts['icon'] .= 'frm_hidden ';
1664
- }
1665
- echo '<a href="javascript:void(0)" class="frm_bstooltip ' . esc_attr( $atts['icon'] ) . 'frm_default_val_icons frm_action_icon frm_icon_font" title="' . esc_attr( $atts['message'] ) . '"></a>';
1666
- }
1667
-
1668
- /**
1669
- * @deprecated 4.0
1670
- */
1671
- public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
1672
- _deprecated_function( __METHOD__, '4.0' );
1673
- }
1674
-
1675
- /**
1676
- * @deprecated 4.0
1677
- */
1678
- public static function clear_on_focus_html( $field, $display, $id = '' ) {
1679
- _deprecated_function( __METHOD__, '4.0' );
1680
- }
1681
-
1682
- /**
1683
- * @deprecated 4.0
1684
- */
1685
- public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
1686
- _deprecated_function( __METHOD__, '4.0' );
1687
- }
1688
-
1689
  /**
1690
  * @deprecated 3.0
1691
  * @codeCoverageIgnore
@@ -1708,7 +1341,7 @@ class FrmFieldsHelper {
1708
  */
1709
  public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
1710
  return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
1711
- }
1712
 
1713
  /**
1714
  * @deprecated 3.0
16
  global $wpdb;
17
  $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
18
 
19
+ $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
20
+ $values['form_id'] = $form_id;
21
  $values['field_order'] = $field_count + 1;
 
22
  $values['field_options']['custom_html'] = self::get_default_html( $type );
23
 
24
  if ( isset( $setting ) && ! empty( $setting ) ) {
29
  }
30
  }
31
 
32
+ return $values;
33
+ }
34
 
35
  public static function get_html_id( $field, $plus = '' ) {
36
  return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
37
+ }
38
 
39
+ public static function setup_edit_vars( $field, $doing_ajax = false ) {
40
  $values = self::field_object_to_array( $field );
 
41
  return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
42
+ }
43
 
44
  public static function field_object_to_array( $field ) {
45
  $values = (array) $field;
53
 
54
  private static function fill_field_array( $field, array &$field_array ) {
55
  $field_array['options'] = $field->options;
56
+ $field_array['value'] = $field->default_value;
57
 
58
  self::prepare_edit_front_field( $field_array, $field );
59
 
111
  */
112
  public static function get_default_field_options( $type ) {
113
  $field_type = FrmFieldFactory::get_field_type( $type );
 
114
  return $field_type->get_default_field_options();
115
  }
116
 
160
  if ( 'captcha' === $field->type ) {
161
  $field_array['invalid'] = $frm_settings->re_msg;
162
  } else {
 
163
  $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
164
  }
165
  }
195
  */
196
  public static function get_default_field_options_from_field( $field, $values = array() ) {
197
  $field_type = self::get_original_field( $field );
198
+ $opts = $field_type->get_default_field_options();
199
 
200
  $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
201
  $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
215
  if ( ! empty( $original_type ) && $field->type != $original_type ) {
216
  $field->type = $original_type;
217
  }
 
218
  return FrmFieldFactory::get_field_object( $field );
219
  }
220
 
226
  * @param array $atts
227
  */
228
  private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
229
+ $field_obj = FrmFieldFactory::get_field_object( $field );
230
  $field_array = $field_obj->prepare_front_field( $field_array, $atts );
231
  }
232
 
239
  */
240
  public static function get_default_field( $type ) {
241
  $field_type = FrmFieldFactory::get_field_type( $type );
 
242
  return $field_type->get_new_field_defaults();
243
  }
244
 
245
+ public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
246
+ global $wpdb;
247
 
248
+ $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
249
+ $values['form_id'] = $form_id;
250
+ $values['options'] = maybe_serialize( $field->options );
251
  $values['default_value'] = maybe_serialize( $field->default_value );
252
 
253
+ foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
254
+ $values[ $col ] = $field->{$col};
255
+ }
256
+ }
257
 
258
  /**
259
  * @since 2.0
264
  * @return string
265
  */
266
  public static function get_error_msg( $field, $error ) {
267
+ $frm_settings = FrmAppHelper::get_settings();
268
  $default_settings = $frm_settings->default_options();
269
+ $field_name = is_array( $field ) ? $field['name'] : $field->name;
270
 
271
  $conf_msg = __( 'The entered values do not match', 'formidable' );
272
  $defaults = array(
273
  'unique_msg' => array(
274
  'full' => $default_settings['unique_msg'],
 
275
  'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
276
  ),
277
+ 'invalid' => array(
278
  'full' => __( 'This field is invalid', 'formidable' ),
 
279
  'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
280
  ),
281
+ 'blank' => array(
282
  'full' => $frm_settings->blank_msg,
283
  'part' => $frm_settings->blank_msg,
284
  ),
285
+ 'conf_msg' => array(
286
  'full' => $conf_msg,
287
  'part' => $conf_msg,
288
  ),
291
  $msg = FrmField::get_option( $field, $error );
292
  $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
293
  $msg = do_shortcode( $msg );
 
294
  return $msg;
295
  }
296
 
297
  public static function get_form_fields( $form_id, $error = array() ) {
298
  $fields = FrmField::get_all_for_form( $form_id );
 
299
  return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
300
  }
301
 
302
  public static function get_default_html( $type = 'text' ) {
303
+ $field = FrmFieldFactory::get_field_type( $type );
304
  $default_html = $field->default_html();
305
 
306
  // these hooks are here for reverse compatibility since 3.0
350
  if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
351
  $position = 'top';
352
  }
 
353
  return $position;
354
  }
355
 
382
  if ( isset( $field['in_section'] ) && $field['in_section'] ) {
383
  $id .= '-' . $field['in_section'];
384
  }
 
385
  return 'frm_checkbox_' . $id . '-' . $opt_key;
386
  }
387
 
388
  public static function show_single_option( $field ) {
 
 
389
  if ( ! is_array( $field['options'] ) ) {
390
  return;
391
  }
392
 
393
+ $field_name = isset( $field['html_name'] ) ? $field['html_name'] : $field['name'];
394
+ $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
 
 
395
 
396
  foreach ( $field['options'] as $opt_key => $opt ) {
397
+ $field_val = self::get_value_from_array( $opt, $opt_key, $field );
398
+ $opt = self::get_label_from_array( $opt, $opt_key, $field );
399
 
400
+ // Get string for Other text field, if needed
401
+ $other_val = self::get_other_val( compact( 'opt_key', 'field' ) );
402
 
403
+ $checked = ( $other_val || isset( $field['value'] ) && ( ( ! is_array( $field['value'] ) && $field['value'] == $field_val ) || ( is_array( $field['value'] ) && in_array( $field_val, $field['value'] ) ) ) ) ? ' checked="checked"' : '';
404
 
405
+ // If this is an "Other" option, get the HTML for it
406
  if ( self::is_other_opt( $opt_key ) ) {
407
  if ( FrmAppHelper::pro_is_installed() ) {
408
  require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
409
  }
410
+ } else {
411
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
412
+ }
413
 
414
+ unset( $checked, $other_val );
415
  }
416
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
 
418
  public static function get_value_from_array( $opt, $opt_key, $field ) {
419
  $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
 
420
  return FrmFieldsController::check_value( $opt, $opt_key, $field );
421
  }
422
 
423
  public static function get_label_from_array( $opt, $opt_key, $field ) {
424
  $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
 
425
  return FrmFieldsController::check_label( $opt );
426
  }
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  /**
429
  * @param int $tax_id
430
  *
432
  */
433
  public static function get_term_link( $tax_id ) {
434
  $tax = get_taxonomy( $tax_id );
435
+ if ( ! $tax ) {
436
+ return '';
437
+ }
438
 
439
  $link = sprintf(
440
+ esc_html__( 'Please add options from the WordPress "%1$s" page', 'formidable' ),
441
+ '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? esc_html__( 'Categories', 'formidable' ) : $tax->labels->name ) . '</a>'
 
 
 
 
442
  );
443
  unset( $tax );
444
 
445
+ return $link;
446
+ }
447
 
448
  public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
449
+ $hide_opt = self::get_value_for_comparision( $hide_opt );
450
  $observed_value = self::get_value_for_comparision( $observed_value );
451
 
452
  if ( is_array( $observed_value ) ) {
453
  return self::array_value_condition( $observed_value, $cond, $hide_opt );
454
+ }
455
 
456
+ $m = false;
457
  if ( $cond == '==' ) {
458
  $m = $observed_value == $hide_opt;
459
  } elseif ( $cond == '!=' ) {
474
  $m = ( $m === false ) ? false : true;
475
  }
476
  }
477
+ return $m;
478
+ }
 
479
 
480
  /**
481
  * Trim and sanitize the values
492
  }
493
 
494
  public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
495
+ $m = false;
496
+ if ( $cond == '==' ) {
497
  if ( is_array( $hide_opt ) ) {
498
  $m = array_intersect( $hide_opt, $observed_value );
499
  $m = empty( $m ) ? false : true;
504
  $m = ! in_array( $hide_opt, $observed_value );
505
  } elseif ( $cond == '>' ) {
506
  $min = min( $observed_value );
507
+ $m = $min > $hide_opt;
508
  } elseif ( $cond == '<' ) {
509
  $max = max( $observed_value );
510
+ $m = $max < $hide_opt;
511
  } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
512
  foreach ( $observed_value as $ob ) {
513
  $m = strpos( $ob, $hide_opt );
517
  }
518
  }
519
 
520
+ if ( $cond == 'not LIKE' ) {
521
+ $m = ( $m === false ) ? true : false;
522
+ }
523
+ }
524
 
525
+ return $m;
526
+ }
527
 
528
+ /**
529
+ * Replace a few basic shortcodes and field ids
530
  *
531
+ * @since 2.0
532
+ * @return string
533
+ */
534
  public static function basic_replace_shortcodes( $value, $form, $entry ) {
535
  if ( strpos( $value, '[sitename]' ) !== false ) {
536
+ $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
537
+ $value = str_replace( '[sitename]', $new_value, $value );
538
+ }
539
 
540
  $value = apply_filters( 'frm_content', $value, $form, $entry );
541
  $value = do_shortcode( $value );
542
 
543
+ return $value;
544
+ }
545
 
546
  public static function get_shortcodes( $content, $form_id ) {
547
+ if ( FrmAppHelper::pro_is_installed() ) {
548
  return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
549
+ }
550
 
551
  $fields = FrmField::getAll(
552
  array(
559
 
560
  preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER );
561
 
562
+ return $matches;
563
+ }
564
 
565
  public static function allowed_shortcodes( $fields = array() ) {
566
+ $tagregexp = array( 'editlink', 'id', 'key', 'ip', 'siteurl', 'sitename', 'admin_email', 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', 'parent[-|_]id' );
 
 
 
 
 
 
 
 
 
 
 
 
 
567
 
568
+ foreach ( $fields as $field ) {
569
+ $tagregexp[] = $field->id;
570
+ $tagregexp[] = $field->field_key;
571
+ }
572
 
573
  $tagregexp = implode( '|', $tagregexp );
574
+ return $tagregexp;
575
+ }
 
576
 
577
  public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
578
+ foreach ( $shortcodes[0] as $short_key => $tag ) {
579
  if ( empty( $tag ) ) {
580
  continue;
581
  }
584
  $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
585
 
586
  $atts['entry'] = $entry;
587
+ $atts['tag'] = $tag;
588
+ $replace_with = self::get_value_for_shortcode( $atts );
589
 
590
  if ( $replace_with !== null ) {
591
  self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with );
596
  }
597
 
598
  return $content;
599
+ }
600
 
601
  /**
602
  * Prevent shortcodes in fields from being processed
607
  * @param string $value
608
  */
609
  public static function sanitize_embedded_shortcodes( $atts, &$value ) {
610
+ $atts['value'] = $value;
611
  $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
612
  if ( $should_sanitize ) {
613
  $value = str_replace( '[', '&#91;', $value );
625
  $clean_tag = str_replace( '-', '_', $atts['tag'] );
626
 
627
  $shortcode_values = array(
628
+ 'id' => $atts['entry']->id,
629
+ 'key' => $atts['entry']->item_key,
630
+ 'ip' => $atts['entry']->ip,
631
  );
632
 
633
  $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
637
  } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
638
  $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
639
  } elseif ( $clean_tag == 'user_agent' ) {
640
+ $description = maybe_unserialize( $atts['entry']->description );
641
  $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
642
  } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
643
+ $atts['tag'] = $clean_tag;
644
  $replace_with = self::get_entry_timestamp( $atts );
645
  } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
646
  $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
663
  $time_format = ' ';
664
  } else {
665
  $atts['format'] = get_option( 'date_format' );
666
+ $time_format = '';
667
  }
668
 
669
  return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
690
  $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
691
  $string_value = $replace_with;
692
  if ( is_array( $replace_with ) ) {
693
+ $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
694
  $string_value = implode( $sep, $replace_with );
695
  }
696
 
699
  } else {
700
  $atts['entry_id'] = $atts['entry']->id;
701
  $atts['entry_key'] = $atts['entry']->item_key;
702
+ $replace_with = self::get_display_value( $replace_with, $field, $atts );
703
  }
704
  }
705
 
706
  return $replace_with;
707
  }
708
 
709
+ /**
710
+ * Get the value to replace a few standard shortcodes
711
+ *
712
+ * @since 2.0
713
+ * @return string
714
+ */
715
+ public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
716
+ $new_value = '';
717
+ switch ( $tag ) {
718
+ case 'admin_email':
719
  $new_value = get_option( 'admin_email' );
720
+ break;
721
+ case 'siteurl':
722
+ $new_value = FrmAppHelper::site_url();
723
+ break;
724
+ case 'frmurl':
725
+ $new_value = FrmAppHelper::plugin_url();
726
+ break;
727
+ case 'sitename':
728
+ $new_value = FrmAppHelper::site_name();
729
+ break;
730
+ case 'get':
731
+ $new_value = self::process_get_shortcode( $atts, $return_array );
732
+ }
733
+
734
+ return $new_value;
735
+ }
736
+
737
+ /**
738
+ * Process the [get] shortcode
739
+ *
740
+ * @since 2.0
741
+ * @return string|array
742
+ */
743
+ public static function process_get_shortcode( $atts, $return_array = false ) {
744
  if ( ! isset( $atts['param'] ) ) {
745
+ return '';
746
+ }
747
 
748
  if ( strpos( $atts['param'], '&#91;' ) ) {
749
  $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
751
  }
752
 
753
  $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
754
+ $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
755
 
756
+ if ( $new_value == '' ) {
757
  if ( ! isset( $atts['prev_val'] ) ) {
758
+ $atts['prev_val'] = '';
759
+ }
760
 
761
  $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
762
+ }
763
 
764
  if ( is_array( $new_value ) && ! $return_array ) {
765
  $new_value = implode( ', ', $new_value );
766
  }
767
 
768
+ return $new_value;
769
+ }
770
 
771
  public static function get_display_value( $value, $field, $atts = array() ) {
772
 
782
  public static function get_unfiltered_display_value( $atts ) {
783
  $value = $atts['value'];
784
  $field = $atts['field'];
785
+ $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
786
 
787
  if ( is_array( $field ) ) {
788
  $field = $field['id'];
789
  }
790
 
791
  $field_obj = FrmFieldFactory::get_field_object( $field );
 
792
  return $field_obj->get_display_value( $value, $atts );
793
  }
794
 
831
  }
832
 
833
  public static function get_field_types( $type ) {
834
+ $single_input = array( 'text', 'textarea', 'rte', 'number', 'email', 'url', 'file', 'date', 'phone', 'hidden', 'time', 'user_id', 'tag', 'password' );
835
  $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
836
+ $other_type = array( 'html', 'break' );
837
 
838
+ $field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() );
839
 
840
+ $field_types = array();
841
  if ( in_array( $type, $single_input ) ) {
842
+ self::field_types_for_input( $single_input, $field_selection, $field_types );
843
  } elseif ( in_array( $type, $multiple_input ) ) {
844
+ self::field_types_for_input( $multiple_input, $field_selection, $field_types );
845
+ } elseif ( in_array( $type, $other_type ) ) {
846
+ self::field_types_for_input( $other_type, $field_selection, $field_types );
847
  } elseif ( isset( $field_selection[ $type ] ) ) {
848
+ $field_types[ $type ] = $field_selection[ $type ];
849
+ }
850
 
851
  $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
852
+ return $field_types;
853
+ }
854
 
855
+ private static function field_types_for_input( $inputs, $fields, &$field_types ) {
856
+ foreach ( $inputs as $input ) {
857
+ $field_types[ $input ] = $fields[ $input ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
858
  unset( $input );
859
+ }
860
+ }
861
 
862
  /**
863
  * Check if current field option is an "other" option
865
  * @since 2.0.6
866
  *
867
  * @param string $opt_key
 
868
  * @return boolean Returns true if current field option is an "Other" option
869
  */
870
  public static function is_other_opt( $opt_key ) {
871
  return $opt_key && strpos( $opt_key, 'other_' ) === 0;
872
  }
873
 
874
+ /**
875
+ * Get value that belongs in "Other" text box
876
+ *
877
+ * @since 2.0.6
878
+ *
879
+ * @param array $args
880
+ */
881
+ public static function get_other_val( $args ) {
882
  $defaults = array(
883
  'opt_key' => 0,
884
  'field' => array(),
885
  'parent' => false,
886
  'pointer' => false,
887
  );
888
+ $args = wp_parse_args( $args, $defaults );
889
 
890
+ $opt_key = $args['opt_key'];
891
+ $field = $args['field'];
892
+ $parent = $args['parent'];
893
+ $pointer = $args['pointer'];
894
  $other_val = '';
895
 
896
  // If option is an "other" option and there is a value set for this field,
908
  } else {
909
  $other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] );
910
  }
 
911
  return $other_val;
912
 
913
+ } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
914
  // For normal fields
915
 
916
  if ( FrmField::is_field_with_multiple_values( $field ) ) {
918
  } else {
919
  $other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] );
920
  }
 
921
  return $other_val;
922
  }
923
 
941
  if ( isset( $field['value'][ $o_key ] ) ) {
942
  unset( $field['value'][ $o_key ], $o_key );
943
  }
944
+ } else if ( $temp_val == $field['value'] ) {
945
  // For radio and regular dropdowns
946
  return '';
947
  } else {
956
  }
957
 
958
  return $other_val;
959
+ }
960
+
961
+ /**
962
+ * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
963
+ * Intended for front-end use
964
+ *
965
+ * @since 2.0.6
966
+ *
967
+ * @param array $args should include field, opt_key and field name
968
+ * @param boolean $other_opt
969
+ * @param string $checked
970
+ * @return array $other_args
971
+ */
972
+ public static function prepare_other_input( $args, &$other_opt, &$checked ) {
 
973
  //Check if this is an "Other" option
974
  if ( ! self::is_other_opt( $args['opt_key'] ) ) {
975
  return;
976
  }
977
 
978
+ $other_opt = true;
979
  $other_args = array();
980
 
981
  self::set_other_name( $args, $other_args );
985
  $checked = 'checked="checked" ';
986
  }
987
 
988
+ return $other_args;
989
+ }
990
 
991
  /**
992
  * @param array $args
993
  * @param array $other_args
 
994
  * @since 2.0.6
995
  */
996
  private static function set_other_name( $args, &$other_args ) {
1015
  * @since 2.0.6
1016
  */
1017
  private static function set_other_value( $args, &$other_args ) {
1018
+ $parent = '';
1019
  $pointer = '';
1020
 
1021
  // Check for parent ID and pointer
1023
 
1024
  // Count should only be greater than 3 if inside of a repeating section
1025
  if ( count( $temp_array ) > 3 ) {
1026
+ $parent = str_replace( ']', '', $temp_array[1] );
1027
  $pointer = str_replace( ']', '', $temp_array[2] );
1028
  }
1029
 
1042
  * If this field includes an other option, show it
1043
  *
1044
  * @param $args array
 
1045
  * @since 2.0.6
1046
  */
1047
  public static function include_other_input( $args ) {
1048
+ if ( ! $args['other_opt'] ) {
1049
+ return;
1050
  }
1051
 
1052
  $classes = array( 'frm_other_input' );
1063
 
1064
  $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1065
 
1066
+ ?><label for="<?php echo esc_attr( $other_id ) ?>" class="frm_screen_reader frm_hidden"><?php
1067
+ echo esc_html( $label );
1068
+ ?></label><input type="text" id="<?php echo esc_attr( $other_id ) ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ) ?>" <?php
1069
+ echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' );
1070
+ ?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>" /><?php
 
1071
  }
1072
 
1073
  /**
1074
+ * Get the HTML id for an "Other" text field
1075
+ * Note: This does not affect fields in repeating sections
1076
+ *
1077
+ * @since 2.0.08
1078
+ * @param string $type - field type
1079
+ * @param string $html_id
1080
+ * @param string|boolean $opt_key
1081
+ * @return string $other_id
1082
+ */
 
 
1083
  public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1084
  $other_id = $html_id;
1085
 
1097
  return $other_id;
1098
  }
1099
 
1100
+ public static function clear_on_focus_html( $field, $display, $id = '' ) {
1101
+ if ( $display['clear_on_focus'] ) {
1102
+ $has_default_value = ! empty( $field['default_value'] );
1103
+ echo '<span id="frm_clear_on_focus_' . esc_attr( $field['id'] . $id ) . '" class="frm-show-click">';
1104
+
1105
+ if ( $display['default_blank'] ) {
1106
+ self::show_default_blank_js( $field['default_blank'], $has_default_value );
1107
+ echo '<input type="hidden" name="field_options[default_blank_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['default_blank'] ) . '" />';
1108
+ }
1109
+
1110
+ self::show_onfocus_js( $field['clear_on_focus'], $has_default_value );
1111
+ echo '<input type="hidden" name="field_options[clear_on_focus_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['clear_on_focus'] ) . '" />';
1112
+
1113
+ echo '</span>';
1114
+ }
1115
+ }
1116
+
1117
+ public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
1118
+ $atts = array(
1119
+ 'icon' => 'frm_reload_icon',
1120
+ 'message' => $is_selected ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' ),
1121
+ 'is_selected' => $is_selected,
1122
+ 'has_default' => $has_default_value,
1123
+ );
1124
+ self::show_icon_link_js( $atts );
1125
+ }
1126
+
1127
+ public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
1128
+ $atts = array(
1129
+ 'icon' => 'frm_error_icon',
1130
+ 'message' => $is_selected ? __( 'Default value will NOT pass form validation', 'formidable' ) : __( 'Default value will pass form validation', 'formidable' ),
1131
+ 'is_selected' => $is_selected,
1132
+ 'has_default' => $has_default_value,
1133
+ );
1134
+ self::show_icon_link_js( $atts );
1135
+ }
1136
+
1137
+ public static function show_icon_link_js( $atts ) {
1138
+ $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1139
+ if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1140
+ $atts['icon'] .= 'frm_hidden ';
1141
+ }
1142
+ echo '<a href="javascript:void(0)" class="frm_bstooltip ' . esc_attr( $atts['icon'] ) . 'frm_default_val_icons frm_action_icon frm_icon_font" title="' . esc_attr( $atts['message'] ) . '"></a>';
1143
+ }
1144
+
1145
  public static function switch_field_ids( $val ) {
1146
+ global $frm_duplicate_ids;
1147
+ $replace = array();
1148
+ $replace_with = array();
1149
+ foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1150
+ $replace[] = '[if ' . $old . ']';
1151
  $replace_with[] = '[if ' . $new . ']';
1152
+ $replace[] = '[if ' . $old . ' ';
1153
  $replace_with[] = '[if ' . $new . ' ';
1154
+ $replace[] = '[/if ' . $old . ']';
1155
  $replace_with[] = '[/if ' . $new . ']';
1156
+ $replace[] = '[foreach ' . $old . ']';
1157
  $replace_with[] = '[foreach ' . $new . ']';
1158
+ $replace[] = '[/foreach ' . $old . ']';
1159
  $replace_with[] = '[/foreach ' . $new . ']';
1160
+ $replace[] = '[' . $old . ']';
1161
  $replace_with[] = '[' . $new . ']';
1162
+ $replace[] = '[' . $old . ' ';
1163
  $replace_with[] = '[' . $new . ' ';
1164
  unset( $old, $new );
1165
+ }
1166
  if ( is_array( $val ) ) {
1167
  foreach ( $val as $k => $v ) {
1168
+ $val[ $k ] = str_replace( $replace, $replace_with, $v );
1169
  unset( $k, $v );
1170
+ }
1171
+ } else {
1172
  $val = str_replace( $replace, $replace_with, $val );
1173
+ }
 
 
 
1174
 
1175
+ return $val;
1176
+ }
 
 
 
 
 
 
 
1177
 
1178
  public static function get_us_states() {
1179
  $states = array(
1229
  'WI' => 'Wisconsin',
1230
  'WY' => 'Wyoming',
1231
  );
 
1232
  return apply_filters( 'frm_us_states', $states );
1233
  }
1234
 
1235
  public static function get_countries() {
1236
+ return apply_filters( 'frm_countries', array( __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ), __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ), __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ), __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ), __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ), __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ), __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ), __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ), __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ), __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ), __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ), __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ), __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ), __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ), __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ), __( 'Costa Rica', 'formidable' ), __( 'C&ocirc;te d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ), __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ), __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ), __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ), __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ), __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ), __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ), __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ), __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ), __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ), __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ), __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ), __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ), __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ), __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ), __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ), __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ), __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ), __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ), __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ), __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ), __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ), __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ), __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ), __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ), __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ), __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ), __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ), __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ), __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ), __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ), __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ), __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ), __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ), __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ), __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ), __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ), __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ), __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ), __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ), __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ), __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ), __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ), __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ), __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ), __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ), __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ), __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ), __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ), __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ), __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ), __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ), __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ), __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ), __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ), __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ), __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ), __( 'Zimbabwe', 'formidable' ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1237
  }
1238
 
1239
  public static function get_bulk_prefilled_opts( array &$prepop ) {
1240
  $prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries();
1241
 
1242
+ $states = self::get_us_states();
1243
  $state_abv = array_keys( $states );
1244
  sort( $state_abv );
1245
  $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1288
  );
1289
 
1290
  $prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1291
+ }
1292
 
1293
  /**
1294
  * Display a field value selector
1298
  * @param int $selector_field_id
1299
  * @param array $selector_args
1300
  */
1301
+ public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1302
+ $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1303
+ $field_value_selector->display();
1304
+ }
1305
 
1306
  /**
1307
  * Convert a field object to a flat array
1314
  */
1315
  public static function convert_field_object_to_flat_array( $field ) {
1316
  $field_options = $field->field_options;
1317
+ $field_array = get_object_vars( $field );
1318
  unset( $field_array['field_options'] );
 
1319
  return $field_array + $field_options;
1320
  }
1321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1322
  /**
1323
  * @deprecated 3.0
1324
  * @codeCoverageIgnore
1341
  */
1342
  public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
1343
  return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
1344
+ }
1345
 
1346
  /**
1347
  * @deprecated 3.0
classes/helpers/FrmFormsHelper.php CHANGED
@@ -16,50 +16,48 @@ class FrmFormsHelper {
16
  $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) );
17
  $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form );
18
 
19
- return $target_url;
20
- }
21
-
22
- public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) {
23
- $defaults = array(
24
- 'blank' => true,
25
- 'field_id' => false,
26
- 'onchange' => false,
27
- 'exclude' => false,
28
- 'class' => '',
29
  'inc_children' => 'exclude',
30
- );
31
- $args = wp_parse_args( $args, $defaults );
32
 
33
- if ( ! $args['field_id'] ) {
34
- $args['field_id'] = $field_name;
35
- }
36
 
37
  $query = array();
38
- if ( $args['exclude'] ) {
39
  $query['id !'] = $args['exclude'];
40
- }
41
 
42
- $where = apply_filters( 'frm_forms_dropdown', $query, $field_name );
43
- $forms = FrmForm::get_published_forms( $where, 999, $args['inc_children'] );
44
  $add_html = array();
45
  self::add_html_attr( $args['onchange'], 'onchange', $add_html );
46
  self::add_html_attr( $args['class'], 'class', $add_html );
47
 
48
- ?>
49
- <select name="<?php echo esc_attr( $field_name ); ?>"
50
- id="<?php echo esc_attr( $args['field_id'] ); ?>"
51
- <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // WPCS: XSS ok. ?>>
52
- <?php if ( $args['blank'] ) { ?>
53
- <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
54
- <?php } ?>
55
- <?php foreach ( $forms as $form ) { ?>
56
- <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>>
57
- <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?>
58
- </option>
59
- <?php } ?>
60
- </select>
61
- <?php
62
- }
63
 
64
  /**
65
  * @param string $class
@@ -74,7 +72,7 @@ class FrmFormsHelper {
74
  }
75
  }
76
 
77
- public static function form_switcher( $selected = false ) {
78
  $where = apply_filters( 'frm_forms_dropdown', array(), '' );
79
  $forms = FrmForm::get_published_forms( $where );
80
 
@@ -86,77 +84,59 @@ class FrmFormsHelper {
86
  unset( $args['form'] );
87
  } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) {
88
  unset( $args['id'] );
89
- }
90
 
91
  $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
92
  if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy_all' ) ) ) {
93
- $args['frm_action'] = 'list';
94
- $args['form'] = 0;
95
  } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
96
- $args['frm_action'] = 'edit';
97
- } elseif ( isset( $_GET['post'] ) ) {
98
- $args['form'] = 0;
99
- $base = admin_url( 'edit.php?post_type=frm_display' );
100
- }
101
-
102
- $name = ( $selected === false ) ? __( 'Switch Form', 'formidable' ) : $selected;
103
- $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name );
104
- $name = FrmAppHelper::truncate( $name, 20 );
105
-
106
- ?>
107
- <div id="frm_bs_dropdown" class="dropdown <?php echo esc_attr( is_rtl() ? 'pull-right' : 'pull-left' ); ?>">
108
- <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown">
109
- <h1>
110
- <?php echo esc_html( $name ); ?>
111
- <b class="frm_icon_font frm_arrowdown4_icon"></b>
112
- </h1>
113
- </a>
114
- <ul class="frm-dropdown-menu frm-on-top frm-inline-modal frm_code_list frm-full-hover" role="menu" aria-labelledby="frm-navbarDrop">
115
- <?php if ( count( $forms ) > 8 ) { ?>
116
- <li class="frm-with-search">
117
- <?php
118
- FrmAppHelper::show_search_box(
119
- array(
120
- 'input_id' => 'dropform',
121
- 'placeholder' => __( 'Search Forms', 'formidable' ),
122
- 'tosearch' => 'frm-dropdown-form',
123
- )
124
- );
125
- ?>
126
- </li>
127
- <?php } ?>
128
- <?php
129
- foreach ( $forms as $form ) {
130
- if ( isset( $args['id'] ) ) {
131
- $args['id'] = $form->id;
132
- }
133
- if ( isset( $args['form'] ) ) {
134
- $args['form'] = $form->id;
135
- }
136
-
137
- $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args );
138
- $form_name = empty( $form->name ) ? __( '(no title)', 'formidable' ) : $form->name;
139
- ?>
140
- <li class="frm-dropdown-form">
141
- <a href="<?php echo esc_url( $url ); ?>" tabindex="-1"><?php echo esc_html( $form_name ); ?></a>
142
- </li>
143
- <?php
144
- unset( $form );
145
  }
146
- ?>
 
 
 
 
 
147
  </ul>
148
- </div>
149
- <?php
150
- }
151
 
152
  /**
153
  * @since 3.05
154
- * @deprecated 4.0
155
- *
156
  * @param array $values - The form array
157
  */
158
  public static function builder_submit_button( $values ) {
159
- FrmDeprecated::builder_submit_button( $values );
 
 
 
 
 
 
 
 
 
 
 
160
  }
161
 
162
  public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
@@ -173,7 +153,6 @@ class FrmFormsHelper {
173
  } else {
174
  $field_label = $field_type;
175
  }
176
-
177
  return $field_label;
178
  }
179
 
@@ -186,7 +165,6 @@ class FrmFormsHelper {
186
  } else {
187
  $icon = 'frm_icon_font frm_pencil_icon';
188
  }
189
-
190
  return $icon;
191
  }
192
 
@@ -194,9 +172,7 @@ class FrmFormsHelper {
194
  * Get the invalid form error message
195
  *
196
  * @since 2.02.07
197
- *
198
  * @param array $args
199
- *
200
  * @return string
201
  */
202
  public static function get_invalid_error_message( $args ) {
@@ -214,32 +190,31 @@ class FrmFormsHelper {
214
  $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] );
215
  $message = FrmAppHelper::use_wpautop( do_shortcode( $message ) );
216
  $message = '<div class="' . esc_attr( $atts['class'] ) . '">' . $message . '</div>';
217
-
218
  return $message;
219
  }
220
 
221
- /**
222
- * Used when a form is created
223
- */
224
- public static function setup_new_vars( $values = array() ) {
225
- global $wpdb;
226
 
227
- if ( ! empty( $values ) ) {
228
- $post_values = $values;
229
- } else {
230
- $values = array();
231
  $post_values = isset( $_POST ) ? $_POST : array();
232
- }
233
 
234
  $defaults = array(
235
- 'name' => '',
236
  'description' => '',
237
  );
238
  foreach ( $defaults as $var => $default ) {
239
  if ( ! isset( $values[ $var ] ) ) {
240
  $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
241
- }
242
- }
243
 
244
  $values['description'] = FrmAppHelper::use_wpautop( $values['description'] );
245
 
@@ -248,7 +223,7 @@ class FrmFormsHelper {
248
  'logged_in' => '',
249
  'editable' => '',
250
  'is_template' => 0,
251
- 'status' => 'published',
252
  'parent_form_id' => 0,
253
  );
254
  foreach ( $defaults as $var => $default ) {
@@ -258,63 +233,63 @@ class FrmFormsHelper {
258
  }
259
  unset( $defaults );
260
 
261
- if ( ! isset( $values['form_key'] ) ) {
262
  $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
263
- }
264
 
265
- $values = self::fill_default_opts( $values, false, $post_values );
266
  $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
267
 
268
  return apply_filters( 'frm_setup_new_form_vars', $values );
269
- }
270
 
271
- /**
272
- * Used when editing a form
273
- */
274
- public static function setup_edit_vars( $values, $record, $post_values = array() ) {
275
  if ( empty( $post_values ) ) {
276
  $post_values = stripslashes_deep( $_POST );
277
  }
278
 
279
- $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key;
280
  $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template;
281
- $values['status'] = $record->status;
282
 
283
  $values = self::fill_default_opts( $values, $record, $post_values );
284
 
285
  return apply_filters( 'frm_setup_edit_form_vars', $values );
286
- }
287
 
288
  public static function fill_default_opts( $values, $record, $post_values ) {
289
 
290
- $defaults = self::get_default_opts();
291
  foreach ( $defaults as $var => $default ) {
292
  if ( is_array( $default ) ) {
293
- if ( ! isset( $values[ $var ] ) ) {
294
  $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
295
- }
296
 
297
- foreach ( $default as $k => $v ) {
298
  $values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v );
299
 
300
- if ( is_array( $v ) ) {
301
- foreach ( $v as $k1 => $v1 ) {
302
  $values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
303
- unset( $k1, $v1 );
304
- }
305
- }
306
 
307
  unset( $k, $v );
308
- }
309
- } else {
310
  $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
311
- }
312
 
313
  unset( $var, $default );
314
- }
315
 
316
- return $values;
317
- }
318
 
319
  public static function get_default_opts() {
320
  $frm_settings = FrmAppHelper::get_settings();
@@ -339,7 +314,6 @@ class FrmFormsHelper {
339
  /**
340
  * @param array $options
341
  * @param array $values
342
- *
343
  * @since 2.0.6
344
  */
345
  public static function fill_form_options( &$options, $values ) {
@@ -350,43 +324,41 @@ class FrmFormsHelper {
350
  }
351
  }
352
 
353
- /**
354
- * @param string $loc
355
- */
356
  public static function get_default_html( $loc ) {
357
  if ( $loc == 'submit' ) {
358
- $draft_link = self::get_draft_link();
359
- $default_html = <<<SUBMIT_HTML
360
  <div class="frm_submit">
361
  [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button]
362
  <button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
363
  $draft_link
364
  </div>
365
  SUBMIT_HTML;
366
- } elseif ( $loc == 'before' ) {
367
- $default_html = <<<BEFORE_HTML
368
  <legend class="frm_screen_reader">[form_name]</legend>
369
  [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
370
  [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
371
  BEFORE_HTML;
372
  } else {
373
- $default_html = '';
374
- }
375
-
376
- return $default_html;
377
- }
378
 
379
- public static function get_draft_link() {
380
- $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
381
 
382
- return $link;
383
- }
 
 
384
 
385
  public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) {
386
  $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values );
387
  if ( ! strpos( $button, '[button_action]' ) ) {
388
  echo $button; // WPCS: XSS ok.
389
-
390
  return;
391
  }
392
 
@@ -394,7 +366,7 @@ BEFORE_HTML;
394
 
395
  $classes = apply_filters( 'frm_submit_button_class', array(), $form );
396
  if ( ! empty( $classes ) ) {
397
- $classes = implode( ' ', $classes );
398
  $button_class = ' class="frm_button_submit';
399
  if ( strpos( $button_parts[0], $button_class ) !== false ) {
400
  $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
@@ -408,261 +380,92 @@ BEFORE_HTML;
408
  echo $button_parts[1]; // WPCS: XSS ok.
409
  }
410
 
411
- /**
412
- * @since 4.0
413
- */
414
- public static function html_shortcodes() {
415
- $codes = array(
416
- 'id' => array(
417
- 'label' => __( 'Field ID', 'formidable' ),
418
- 'class' => 'show_field_custom_html',
419
- ),
420
- 'key' => array(
421
- 'label' => __( 'Field Key', 'formidable' ),
422
- 'class' => 'show_field_custom_html',
423
- ),
424
- 'field_name' => array(
425
- 'label' => __( 'Field Name', 'formidable' ),
426
- 'class' => 'show_field_custom_html',
427
- ),
428
- 'description' => array(
429
- 'label' => __( 'Field Description', 'formidable' ),
430
- 'class' => 'show_field_custom_html',
431
- ),
432
- 'label_position' => array(
433
- 'label' => __( 'Label Position', 'formidable' ),
434
- 'class' => 'show_field_custom_html',
435
- ),
436
- 'required_label' => array(
437
- 'label' => __( 'Required Label', 'formidable' ),
438
- 'class' => 'show_field_custom_html',
439
- ),
440
- 'input' => array(
441
- 'label' => __( 'Input Field', 'formidable' ),
442
- 'class' => 'show_field_custom_html',
443
- ),
444
- 'input opt=1' => array(
445
- 'label' => __( 'Single Option', 'formidable' ),
446
- 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ),
447
- 'class' => 'show_field_custom_html',
448
- ),
449
- 'input label=0' => array(
450
- 'label' => __( 'Hide Option Label', 'formidable' ),
451
- 'class' => 'show_field_custom_html',
452
- ),
453
- 'required_class' => array(
454
- 'label' => __( 'Required Class', 'formidable' ),
455
- 'title' => __( 'Add class name if field is required', 'formidable' ),
456
- 'class' => 'show_field_custom_html',
457
- ),
458
- 'error_class' => array(
459
- 'label' => __( 'Error Class', 'formidable' ),
460
- 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ),
461
- 'class' => 'show_field_custom_html',
462
- ),
463
-
464
- 'form_name' => array(
465
- 'label' => __( 'Form Name', 'formidable' ),
466
- 'class' => 'show_before_html show_after_html',
467
- ),
468
- 'form_description' => array(
469
- 'label' => __( 'Form Description', 'formidable' ),
470
- 'class' => 'show_before_html show_after_html',
471
- ),
472
- 'form_key' => array(
473
- 'label' => __( 'Form Key', 'formidable' ),
474
- 'class' => 'show_before_html show_after_html',
475
- ),
476
- 'deletelink' => array(
477
- 'label' => __( 'Delete Entry Link', 'formidable' ),
478
- 'class' => 'show_before_html show_after_html',
479
- ),
480
-
481
- 'button_label' => array(
482
- 'label' => __( 'Button Label', 'formidable' ),
483
- 'class' => 'show_submit_html',
484
- ),
485
- 'button_action' => array(
486
- 'label' => __( 'Button Hook', 'formidable' ),
487
- 'class' => 'show_submit_html',
488
- ),
489
- );
490
-
491
- /**
492
- * @since 4.0
493
- */
494
- return apply_filters( 'frm_html_codes', $codes );
495
- }
496
-
497
- /**
498
- * @since 4.0
499
- * @param array $args
500
- */
501
- public static function insert_opt_html( $args ) {
502
- $class = isset( $args['class'] ) ? $args['class'] : '';
503
- $fields = FrmField::all_field_selection();
504
- $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
505
-
506
- self::prepare_field_type( $field );
507
-
508
- if ( ! isset( $field['icon'] ) ) {
509
- $field['icon'] = 'frmfont frm_pencil_icon';
510
- }
511
-
512
- $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
513
- if ( $possible_email_field ) {
514
- $class .= ' show_frm_not_email_to';
515
- }
516
- ?>
517
- <li class="<?php echo esc_attr( $class ); ?>">
518
- <a href="javascript:void(0)" class="frmids frm_insert_code"
519
- data-code="<?php echo esc_attr( $args['id'] ); ?>">
520
- <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
521
- <i class="<?php echo esc_attr( $field['icon'] ); ?>" aria-hidden="true"></i>
522
- <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
523
- </a>
524
- <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden"
525
- data-code="<?php echo esc_attr( $args['key'] ); ?>">
526
- <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
527
- <?php if ( isset( $field['icon'] ) ) { ?>
528
- <i class="<?php echo esc_attr( $field['icon'] ); ?>" aria-hidden="true"></i>
529
- <?php } ?>
530
- <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
531
- </a>
532
- </li>
533
- <?php
534
- }
535
-
536
- /**
537
- * @since 4.0
538
- * @param array $args
539
- */
540
- public static function insert_code_html( $args ) {
541
- $defaults = array(
542
- 'class' => '',
543
- 'code' => '',
544
- 'label' => '',
545
- 'title' => '',
546
- );
547
-
548
- $args = array_merge( $defaults, $args );
549
- $has_tooltip = ! empty( $args['title'] );
550
-
551
- ?>
552
- <li class="<?php echo esc_attr( $args['class'] ); ?>">
553
- <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>"
554
- <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?>
555
- data-code="<?php echo esc_attr( $args['code'] ); ?>">
556
- <span>
557
- [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>]
558
- </span>
559
- <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?>
560
- </a>
561
- </li>
562
- <?php
563
- }
564
-
565
- /**
566
- * Some field types in add-ons may have been added with only
567
- * a field type and name.
568
- *
569
- * @since 4.0
570
- */
571
- public static function prepare_field_type( &$field ) {
572
- if ( ! is_array( $field ) ) {
573
- $field = array(
574
- 'name' => $field,
575
- 'icon' => 'frm_icon_font frm_pencil_icon',
576
- );
577
- }
578
- }
579
-
580
- /**
581
- * Automatically add end section fields if they don't exist (2.0 migration)
582
- *
583
- * @since 2.0
584
  *
585
- * @param boolean $reset_fields
586
- */
587
- public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
 
 
588
  if ( empty( $fields ) ) {
589
  return;
590
  }
591
 
592
  $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) );
593
- $open = false;
594
- $prev_order = false;
595
- $add_order = 0;
596
- $last_field = false;
597
- foreach ( $fields as $field ) {
598
  if ( $prev_order === $field->field_order ) {
599
- $add_order ++;
600
  }
601
 
602
  if ( $add_order ) {
603
- $reset_fields = true;
604
  $field->field_order = $field->field_order + $add_order;
605
  FrmField::update( $field->id, array( 'field_order' => $field->field_order ) );
606
  }
607
 
608
- switch ( $field->type ) {
609
- case 'divider':
610
- // Create an end section if open.
611
  self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field, 'move' );
612
 
613
- // Mark it open for the next end section.
614
- $open = true;
615
  break;
616
- case 'break':
617
  self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field, 'move' );
618
  break;
619
- case 'end_divider':
620
- if ( ! $open ) {
621
- // The section isn't open, so this is an extra field that needs to be removed.
622
- FrmField::destroy( $field->id );
623
- $reset_fields = true;
624
- }
625
-
626
- // There is already an end section here, so there is no need to create one.
627
- $open = false;
628
- }
629
  $prev_order = $field->field_order;
630
 
631
  $last_field = $field;
632
  unset( $field );
633
- }
634
 
635
  self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
636
- }
637
 
638
  /**
639
  * Create end section field if it doesn't exist. This is for migration from < 2.0
640
  * Fix any ordering that may be messed up
641
  */
642
  public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) {
643
- if ( ! $open ) {
644
- return;
645
- }
646
 
647
  $end_section_values['field_order'] = $field->field_order + 1;
648
 
649
- FrmField::create( $end_section_values );
650
 
651
  if ( $move == 'move' ) {
652
  // bump the order of current field unless we're at the end of the form
653
  FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
654
  }
655
 
656
- $add_order += 2;
657
- $open = false;
658
- $reset_fields = true;
659
- }
660
 
661
  public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
662
  $codes = array(
663
- 'form_name' => $title,
664
  'form_description' => $description,
665
- 'entry_key' => true,
666
  );
667
  foreach ( $codes as $code => $show ) {
668
  if ( $code == 'form_name' ) {
@@ -676,7 +479,7 @@ BEFORE_HTML;
676
  }
677
 
678
  FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
679
- }
680
 
681
  //replace [form_key]
682
  $html = str_replace( '[form_key]', $form->form_key, $html );
@@ -688,8 +491,8 @@ BEFORE_HTML;
688
  add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
689
  $submit_label = apply_filters( 'frm_submit_button', $title, $form );
690
  $submit_label = esc_attr( do_shortcode( $submit_label ) );
691
- $html = str_replace( '[button_label]', $submit_label, $html );
692
- }
693
 
694
  $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values );
695
 
@@ -705,17 +508,17 @@ BEFORE_HTML;
705
  $html = do_shortcode( $html );
706
  }
707
 
708
- return $html;
709
- }
710
 
711
  public static function submit_button_label( $submit ) {
712
  if ( ! $submit || empty( $submit ) ) {
713
- $frm_settings = FrmAppHelper::get_settings();
714
- $submit = $frm_settings->submit_value;
715
- }
716
 
717
- return $submit;
718
- }
719
 
720
  /**
721
  * If the Formidable styling isn't being loaded,
@@ -744,7 +547,7 @@ BEFORE_HTML;
744
  }
745
  }
746
 
747
- // If submit button needs to be inline or centered.
748
  if ( is_object( $form ) ) {
749
  $form = $form->options;
750
  }
@@ -760,8 +563,8 @@ BEFORE_HTML;
760
 
761
  $class = apply_filters( 'frm_add_form_style_class', $class, $style );
762
 
763
- return $class;
764
- }
765
 
766
  /**
767
  * Returns appropriate class if form has top labels
@@ -793,7 +596,7 @@ BEFORE_HTML;
793
 
794
  $fields = array_reverse( $fields ); // start from the fields closest to the submit button
795
  foreach ( $fields as $field ) {
796
- $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
797
  $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
798
  if ( $has_input ) {
799
  return self::field_has_top_label( $field, $form );
@@ -813,25 +616,24 @@ BEFORE_HTML;
813
  */
814
  private static function field_has_top_label( $field, $form ) {
815
  $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form );
816
-
817
  return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
818
  }
819
 
820
- /**
821
- * @param object|string|boolean $form
822
- *
823
- * @return string
824
- */
825
- public static function get_form_style( $form ) {
826
  $style = 1;
827
  if ( empty( $form ) || 'default' == 'form' ) {
828
  return $style;
829
- } elseif ( is_object( $form ) && $form->parent_form_id ) {
830
  // get the parent form if this is a child
831
  $form = $form->parent_form_id;
832
- } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
833
  $form = $form['parent_form_id'];
834
- } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
835
  $style = $form['custom_style'];
836
  }
837
 
@@ -842,13 +644,12 @@ BEFORE_HTML;
842
  $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
843
 
844
  return $style;
845
- }
846
 
847
  /**
848
  * Display the validation error messages when an entry is submitted
849
  *
850
  * @param array $args - includes img, errors
851
- *
852
  * @since 2.0.6
853
  */
854
  public static function show_errors( $args ) {
@@ -876,7 +677,6 @@ BEFORE_HTML;
876
  * If the message in the global settings is empty, show every validation message in the error box
877
  *
878
  * @param array $args - includes img, errors, and show_img
879
- *
880
  * @since 2.0.6
881
  */
882
  public static function show_error( $args ) {
@@ -906,24 +706,24 @@ BEFORE_HTML;
906
 
907
  public static function maybe_get_scroll_js( $id ) {
908
  $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) );
909
- if ( $offset != - 1 ) {
910
  self::get_scroll_js( $id );
911
  }
912
  }
913
 
914
  public static function get_scroll_js( $form_id ) {
915
- echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>';
916
- }
917
 
918
  /**
919
  * @since 3.0
920
  */
921
  public static function actions_dropdown( $atts ) {
922
  if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
923
- $status = $atts['status'];
924
- $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
925
  $trash_link = self::delete_trash_info( $form_id, $status );
926
- $links = self::get_action_links( $form_id, $status );
927
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
928
  }
929
  }
@@ -936,7 +736,7 @@ BEFORE_HTML;
936
  $form = FrmForm::getOne( $form_id );
937
  }
938
 
939
- $actions = array();
940
  $trash_links = self::delete_trash_links( $form_id );
941
  if ( 'trash' == $form->status ) {
942
  $actions['restore'] = $trash_links['restore'];
@@ -950,13 +750,13 @@ BEFORE_HTML;
950
  $actions['frm_duplicate'] = array(
951
  'url' => wp_nonce_url( $duplicate_link ),
952
  'label' => __( 'Create Form from Template', 'formidable' ),
953
- 'icon' => 'frm_icon_font frm_clone_icon',
954
  );
955
  } else {
956
  $actions['duplicate'] = array(
957
  'url' => wp_nonce_url( $duplicate_link ),
958
  'label' => __( 'Duplicate Form', 'formidable' ),
959
- 'icon' => 'frm_icon_font frm_clone_icon',
960
  );
961
  }
962
 
@@ -968,20 +768,20 @@ BEFORE_HTML;
968
 
969
  public static function edit_form_link( $form_id ) {
970
  if ( is_object( $form_id ) ) {
971
- $form = $form_id;
972
- $name = $form->name;
973
- $form_id = $form->id;
974
- } else {
975
  $name = FrmForm::getName( $form_id );
976
- }
977
 
978
- if ( $form_id ) {
979
- $val = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . ( '' == $name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $name, 40 ) ) . '</a>';
980
- } else {
981
- $val = '';
982
- }
983
 
984
- return $val;
985
  }
986
 
987
  public static function delete_trash_link( $id, $status, $length = 'label' ) {
@@ -996,7 +796,7 @@ BEFORE_HTML;
996
  public static function format_link_html( $link_details, $length = 'label' ) {
997
  $link = '';
998
  if ( ! empty( $link_details ) ) {
999
- $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"';
1000
  if ( isset( $link_details['data'] ) ) {
1001
  foreach ( $link_details['data'] as $data => $value ) {
1002
  $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"';
@@ -1004,16 +804,9 @@ BEFORE_HTML;
1004
  } elseif ( isset( $link_details['confirm'] ) ) {
1005
  $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1006
  }
1007
-
1008
  $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1009
- if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
1010
- $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1011
- $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1012
- }
1013
-
1014
  $link .= '>' . $label . '</a>';
1015
  }
1016
-
1017
  return $link;
1018
  }
1019
 
@@ -1043,7 +836,7 @@ BEFORE_HTML;
1043
  */
1044
  private static function delete_trash_links( $id ) {
1045
  $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1046
- $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
1047
 
1048
  return array(
1049
  'restore' => array(
@@ -1051,20 +844,20 @@ BEFORE_HTML;
1051
  'short' => __( 'Restore', 'formidable' ),
1052
  'url' => wp_nonce_url( $base_url . '&frm_action=untrash', 'untrash_form_' . absint( $id ) ),
1053
  ),
1054
- 'trash' => array(
1055
  'label' => __( 'Move Form to Trash', 'formidable' ),
1056
  'short' => __( 'Trash', 'formidable' ),
1057
  'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ),
1058
  'icon' => 'frm_icon_font frm_delete_icon',
1059
  'data' => array( 'frmverify' => __( 'Are you sure?', 'formidable' ) ),
1060
  ),
1061
- 'delete' => array(
1062
- 'label' => __( 'Delete Permanently', 'formidable' ),
1063
- 'short' => __( 'Delete', 'formidable' ),
1064
- 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ),
1065
  'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ),
1066
- 'icon' => 'frm_icon_font frm_delete_icon',
1067
- 'data' => array( 'frmverify' => __( 'Delete form & entries?', 'formidable' ) ),
1068
  ),
1069
  );
1070
  }
@@ -1074,25 +867,37 @@ BEFORE_HTML;
1074
  */
1075
  public static function css_classes() {
1076
  $classes = array(
1077
- 'frm_total' => array(
1078
- 'label' => __( 'Total', 'formidable' ),
1079
- 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
1080
- ),
1081
- 'frm_scroll_box' => array(
1082
- 'label' => __( 'Scroll Box', 'formidable' ),
1083
- 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ),
1084
- ),
1085
  'frm_first' => array(
1086
- 'label' => __( 'First', 'formidable' ),
1087
- 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
1088
  ),
1089
  'frm_alignright' => __( 'Right', 'formidable' ),
 
 
 
 
1090
  'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1091
  'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1092
  'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1093
  'frm_capitalize' => array(
1094
- 'label' => __( 'Capitalize', 'formidable' ),
1095
- 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
1096
  ),
1097
  );
1098
 
@@ -1101,10 +906,10 @@ BEFORE_HTML;
1101
 
1102
  public static function grid_classes() {
1103
  $base = array(
1104
- 'frm_half' => '1/2',
1105
 
1106
- 'frm_third' => '1/3',
1107
- 'frm_two_thirds' => '2/3',
1108
 
1109
  'frm_fourth' => '1/4',
1110
  'frm_three_fourths' => '3/4',
@@ -1113,16 +918,28 @@ BEFORE_HTML;
1113
  $frm_settings = FrmAppHelper::get_settings();
1114
  if ( $frm_settings->old_css ) {
1115
  $classes = array(
1116
- 'frm_sixth' => '1/6',
1117
- 'frm10' => '5/6',
 
 
 
 
 
1118
 
1119
- 'frm_full' => '100%',
1120
  );
1121
  } else {
1122
  $classes = array(
1123
- 'frm_sixth' => '1/6',
1124
- 'frm10' => '5/6',
1125
- 'frm12' => '100%',
 
 
 
 
 
 
 
1126
  );
1127
  }
1128
 
@@ -1138,68 +955,25 @@ BEFORE_HTML;
1138
  $label = $class;
1139
  } elseif ( ! is_array( $style ) ) {
1140
  $label = $style;
1141
- } elseif ( isset( $style['label'] ) ) {
1142
  $label = $style['label'];
1143
  }
1144
-
1145
  return $label;
1146
  }
1147
 
1148
  public static function status_nice_name( $status ) {
1149
- $nice_names = array(
1150
- 'draft' => __( 'Draft', 'formidable' ),
1151
- 'trash' => __( 'Trash', 'formidable' ),
1152
- 'publish' => __( 'Published', 'formidable' ),
1153
- );
1154
 
1155
  if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
1156
- $status = 'publish';
1157
- }
1158
 
1159
  $name = $nice_names[ $status ];
1160
 
1161
- return $name;
1162
- }
1163
-
1164
- /**
1165
- * If a template or add-on cannot be installed, show a message
1166
- * about which plan is required.
1167
- *
1168
- * @since 4.0
1169
- */
1170
- public static function show_plan_required( &$item, $link ) {
1171
- $requires = self::get_plan_required( $item );
1172
- if ( empty( $requires ) ) {
1173
- return;
1174
- }
1175
-
1176
- ?>
1177
- <p>
1178
- <?php esc_html_e( 'License plan required:', 'formidable' ); ?>
1179
- <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener">
1180
- <?php echo esc_html( $requires ); ?>
1181
- </a>
1182
- </p>
1183
- <?php
1184
- }
1185
-
1186
- /**
1187
- * @since 4.0
1188
- */
1189
- public static function get_plan_required( &$item ) {
1190
- if ( ! isset( $item['categories'] ) || ( isset( $item['url'] ) && ! empty( $item['url'] ) ) ) {
1191
- return false;
1192
- }
1193
-
1194
- $plans = array( 'free', 'Personal', 'Business', 'Elite' );
1195
-
1196
- foreach ( $item['categories'] as $k => $category ) {
1197
- if ( in_array( $category, $plans ) ) {
1198
- unset( $item['categories'][ $k ] );
1199
- return $category;
1200
- }
1201
- }
1202
-
1203
- return false;
1204
- }
1205
  }
16
  $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) );
17
  $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form );
18
 
19
+ return $target_url;
20
+ }
21
+
22
+ public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) {
23
+ $defaults = array(
24
+ 'blank' => true,
25
+ 'field_id' => false,
26
+ 'onchange' => false,
27
+ 'exclude' => false,
28
+ 'class' => '',
29
  'inc_children' => 'exclude',
30
+ );
31
+ $args = wp_parse_args( $args, $defaults );
32
 
33
+ if ( ! $args['field_id'] ) {
34
+ $args['field_id'] = $field_name;
35
+ }
36
 
37
  $query = array();
38
+ if ( $args['exclude'] ) {
39
  $query['id !'] = $args['exclude'];
40
+ }
41
 
42
+ $where = apply_filters( 'frm_forms_dropdown', $query, $field_name );
43
+ $forms = FrmForm::get_published_forms( $where, 999, $args['inc_children'] );
44
  $add_html = array();
45
  self::add_html_attr( $args['onchange'], 'onchange', $add_html );
46
  self::add_html_attr( $args['class'], 'class', $add_html );
47
 
48
+ ?>
49
+ <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $args['field_id'] ) ?>" <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // WPCS: XSS ok. ?>>
50
+ <?php if ( $args['blank'] ) { ?>
51
+ <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
52
+ <?php } ?>
53
+ <?php foreach ( $forms as $form ) { ?>
54
+ <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>>
55
+ <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?>
56
+ </option>
57
+ <?php } ?>
58
+ </select>
59
+ <?php
60
+ }
 
 
61
 
62
  /**
63
  * @param string $class
72
  }
73
  }
74
 
75
+ public static function form_switcher() {
76
  $where = apply_filters( 'frm_forms_dropdown', array(), '' );
77
  $forms = FrmForm::get_published_forms( $where );
78
 
84
  unset( $args['form'] );
85
  } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) {
86
  unset( $args['id'] );
87
+ }
88
 
89
  $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
90
  if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy_all' ) ) ) {
91
+ $args['frm_action'] = 'list';
92
+ $args['form'] = 0;
93
  } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
94
+ $args['frm_action'] = 'edit';
95
+ } else if ( isset( $_GET['post'] ) ) {
96
+ $args['form'] = 0;
97
+ $base = admin_url( 'edit.php?post_type=frm_display' );
98
+ }
99
+
100
+ ?>
101
+ <li id="frm_bs_dropdown" class="dropdown <?php echo esc_attr( is_rtl() ? 'pull-right' : 'pull-left' ) ?>">
102
+ <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php esc_html_e( 'Switch Form', 'formidable' ) ?> <b class="caret"></b></a>
103
+ <ul class="frm-dropdown-menu frm-on-top" role="menu" aria-labelledby="frm-navbarDrop">
104
+ <?php
105
+ foreach ( $forms as $form ) {
106
+ if ( isset( $args['id'] ) ) {
107
+ $args['id'] = $form->id;
108
+ }
109
+ if ( isset( $args['form'] ) ) {
110
+ $args['form'] = $form->id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  }
112
+ ?>
113
+ <li><a href="<?php echo esc_url( isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 60 ) ); ?></a></li>
114
+ <?php
115
+ unset( $form );
116
+ }
117
+ ?>
118
  </ul>
119
+ </li>
120
+ <?php
121
+ }
122
 
123
  /**
124
  * @since 3.05
 
 
125
  * @param array $values - The form array
126
  */
127
  public static function builder_submit_button( $values ) {
128
+ $page_action = FrmAppHelper::get_param( 'frm_action' );
129
+ $label = ( $page_action == 'edit' || $page_action == 'update' ) ? __( 'Update', 'formidable' ) : __( 'Create', 'formidable' );
130
+
131
+ ?>
132
+ <div class="postbox">
133
+ <p class="inside">
134
+ <button class="frm_submit_<?php echo esc_attr( ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_' ); ?>ajax button-primary frm_button_submit" type="button">
135
+ <?php echo esc_html( $label ); ?>
136
+ </button>
137
+ </p>
138
+ </div>
139
+ <?php
140
  }
141
 
142
  public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
153
  } else {
154
  $field_label = $field_type;
155
  }
 
156
  return $field_label;
157
  }
158
 
165
  } else {
166
  $icon = 'frm_icon_font frm_pencil_icon';
167
  }
 
168
  return $icon;
169
  }
170
 
172
  * Get the invalid form error message
173
  *
174
  * @since 2.02.07
 
175
  * @param array $args
 
176
  * @return string
177
  */
178
  public static function get_invalid_error_message( $args ) {
190
  $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] );
191
  $message = FrmAppHelper::use_wpautop( do_shortcode( $message ) );
192
  $message = '<div class="' . esc_attr( $atts['class'] ) . '">' . $message . '</div>';
 
193
  return $message;
194
  }
195
 
196
+ /**
197
+ * Used when a form is created
198
+ */
199
+ public static function setup_new_vars( $values = array() ) {
200
+ global $wpdb;
201
 
202
+ if ( ! empty( $values ) ) {
203
+ $post_values = $values;
204
+ } else {
205
+ $values = array();
206
  $post_values = isset( $_POST ) ? $_POST : array();
207
+ }
208
 
209
  $defaults = array(
210
+ 'name' => '',
211
  'description' => '',
212
  );
213
  foreach ( $defaults as $var => $default ) {
214
  if ( ! isset( $values[ $var ] ) ) {
215
  $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
216
+ }
217
+ }
218
 
219
  $values['description'] = FrmAppHelper::use_wpautop( $values['description'] );
220
 
223
  'logged_in' => '',
224
  'editable' => '',
225
  'is_template' => 0,
226
+ 'status' => 'draft',
227
  'parent_form_id' => 0,
228
  );
229
  foreach ( $defaults as $var => $default ) {
233
  }
234
  unset( $defaults );
235
 
236
+ if ( ! isset( $values['form_key'] ) ) {
237
  $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
238
+ }
239
 
240
+ $values = self::fill_default_opts( $values, false, $post_values );
241
  $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
242
 
243
  return apply_filters( 'frm_setup_new_form_vars', $values );
244
+ }
245
 
246
+ /**
247
+ * Used when editing a form
248
+ */
249
+ public static function setup_edit_vars( $values, $record, $post_values = array() ) {
250
  if ( empty( $post_values ) ) {
251
  $post_values = stripslashes_deep( $_POST );
252
  }
253
 
254
+ $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key;
255
  $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template;
256
+ $values['status'] = $record->status;
257
 
258
  $values = self::fill_default_opts( $values, $record, $post_values );
259
 
260
  return apply_filters( 'frm_setup_edit_form_vars', $values );
261
+ }
262
 
263
  public static function fill_default_opts( $values, $record, $post_values ) {
264
 
265
+ $defaults = self::get_default_opts();
266
  foreach ( $defaults as $var => $default ) {
267
  if ( is_array( $default ) ) {
268
+ if ( ! isset( $values[ $var ] ) ) {
269
  $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
270
+ }
271
 
272
+ foreach ( $default as $k => $v ) {
273
  $values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v );
274
 
275
+ if ( is_array( $v ) ) {
276
+ foreach ( $v as $k1 => $v1 ) {
277
  $values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
278
+ unset( $k1, $v1 );
279
+ }
280
+ }
281
 
282
  unset( $k, $v );
283
+ }
284
+ } else {
285
  $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
286
+ }
287
 
288
  unset( $var, $default );
289
+ }
290
 
291
+ return $values;
292
+ }
293
 
294
  public static function get_default_opts() {
295
  $frm_settings = FrmAppHelper::get_settings();
314
  /**
315
  * @param array $options
316
  * @param array $values
 
317
  * @since 2.0.6
318
  */
319
  public static function fill_form_options( &$options, $values ) {
324
  }
325
  }
326
 
327
+ /**
328
+ * @param string $loc
329
+ */
330
  public static function get_default_html( $loc ) {
331
  if ( $loc == 'submit' ) {
332
+ $draft_link = self::get_draft_link();
333
+ $default_html = <<<SUBMIT_HTML
334
  <div class="frm_submit">
335
  [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button]
336
  <button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
337
  $draft_link
338
  </div>
339
  SUBMIT_HTML;
340
+ } else if ( $loc == 'before' ) {
341
+ $default_html = <<<BEFORE_HTML
342
  <legend class="frm_screen_reader">[form_name]</legend>
343
  [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
344
  [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
345
  BEFORE_HTML;
346
  } else {
347
+ $default_html = '';
348
+ }
 
 
 
349
 
350
+ return $default_html;
351
+ }
352
 
353
+ public static function get_draft_link() {
354
+ $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
355
+ return $link;
356
+ }
357
 
358
  public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) {
359
  $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values );
360
  if ( ! strpos( $button, '[button_action]' ) ) {
361
  echo $button; // WPCS: XSS ok.
 
362
  return;
363
  }
364
 
366
 
367
  $classes = apply_filters( 'frm_submit_button_class', array(), $form );
368
  if ( ! empty( $classes ) ) {
369
+ $classes = implode( ' ', $classes );
370
  $button_class = ' class="frm_button_submit';
371
  if ( strpos( $button_parts[0], $button_class ) !== false ) {
372
  $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
380
  echo $button_parts[1]; // WPCS: XSS ok.
381
  }
382
 
383
+ /**
384
+ * Automatically add end section fields if they don't exist (2.0 migration)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  *
386
+ * @since 2.0
387
+ *
388
+ * @param boolean $reset_fields
389
+ */
390
+ public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
391
  if ( empty( $fields ) ) {
392
  return;
393
  }
394
 
395
  $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) );
396
+ $open = false;
397
+ $prev_order = false;
398
+ $add_order = 0;
399
+ $last_field = false;
400
+ foreach ( $fields as $field ) {
401
  if ( $prev_order === $field->field_order ) {
402
+ $add_order++;
403
  }
404
 
405
  if ( $add_order ) {
406
+ $reset_fields = true;
407
  $field->field_order = $field->field_order + $add_order;
408
  FrmField::update( $field->id, array( 'field_order' => $field->field_order ) );
409
  }
410
 
411
+ switch ( $field->type ) {
412
+ case 'divider':
413
+ // create an end section if open
414
  self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field, 'move' );
415
 
416
+ // mark it open for the next end section
417
+ $open = true;
418
  break;
419
+ case 'break':
420
  self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field, 'move' );
421
  break;
422
+ case 'end_divider':
423
+ if ( ! $open ) {
424
+ // the section isn't open, so this is an extra field that needs to be removed
425
+ FrmField::destroy( $field->id );
426
+ $reset_fields = true;
427
+ }
428
+
429
+ // There is already an end section here, so there is no need to create one
430
+ $open = false;
431
+ }
432
  $prev_order = $field->field_order;
433
 
434
  $last_field = $field;
435
  unset( $field );
436
+ }
437
 
438
  self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
439
+ }
440
 
441
  /**
442
  * Create end section field if it doesn't exist. This is for migration from < 2.0
443
  * Fix any ordering that may be messed up
444
  */
445
  public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) {
446
+ if ( ! $open ) {
447
+ return;
448
+ }
449
 
450
  $end_section_values['field_order'] = $field->field_order + 1;
451
 
452
+ FrmField::create( $end_section_values );
453
 
454
  if ( $move == 'move' ) {
455
  // bump the order of current field unless we're at the end of the form
456
  FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
457
  }
458
 
459
+ $add_order += 2;
460
+ $open = false;
461
+ $reset_fields = true;
462
+ }
463
 
464
  public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
465
  $codes = array(
466
+ 'form_name' => $title,
467
  'form_description' => $description,
468
+ 'entry_key' => true,
469
  );
470
  foreach ( $codes as $code => $show ) {
471
  if ( $code == 'form_name' ) {
479
  }
480
 
481
  FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
482
+ }
483
 
484
  //replace [form_key]
485
  $html = str_replace( '[form_key]', $form->form_key, $html );
491
  add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
492
  $submit_label = apply_filters( 'frm_submit_button', $title, $form );
493
  $submit_label = esc_attr( do_shortcode( $submit_label ) );
494
+ $html = str_replace( '[button_label]', $submit_label, $html );
495
+ }
496
 
497
  $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values );
498
 
508
  $html = do_shortcode( $html );
509
  }
510
 
511
+ return $html;
512
+ }
513
 
514
  public static function submit_button_label( $submit ) {
515
  if ( ! $submit || empty( $submit ) ) {
516
+ $frm_settings = FrmAppHelper::get_settings();
517
+ $submit = $frm_settings->submit_value;
518
+ }
519
 
520
+ return $submit;
521
+ }
522
 
523
  /**
524
  * If the Formidable styling isn't being loaded,
547
  }
548
  }
549
 
550
+ //If submit button needs to be inline or centered
551
  if ( is_object( $form ) ) {
552
  $form = $form->options;
553
  }
563
 
564
  $class = apply_filters( 'frm_add_form_style_class', $class, $style );
565
 
566
+ return $class;
567
+ }
568
 
569
  /**
570
  * Returns appropriate class if form has top labels
596
 
597
  $fields = array_reverse( $fields ); // start from the fields closest to the submit button
598
  foreach ( $fields as $field ) {
599
+ $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
600
  $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
601
  if ( $has_input ) {
602
  return self::field_has_top_label( $field, $form );
616
  */
617
  private static function field_has_top_label( $field, $form ) {
618
  $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form );
 
619
  return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
620
  }
621
 
622
+ /**
623
+ * @param string|boolean $form
624
+ *
625
+ * @return string
626
+ */
627
+ public static function get_form_style( $form ) {
628
  $style = 1;
629
  if ( empty( $form ) || 'default' == 'form' ) {
630
  return $style;
631
+ } else if ( is_object( $form ) && $form->parent_form_id ) {
632
  // get the parent form if this is a child
633
  $form = $form->parent_form_id;
634
+ } else if ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
635
  $form = $form['parent_form_id'];
636
+ } else if ( is_array( $form ) && isset( $form['custom_style'] ) ) {
637
  $style = $form['custom_style'];
638
  }
639
 
644
  $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
645
 
646
  return $style;
647
+ }
648
 
649
  /**
650
  * Display the validation error messages when an entry is submitted
651
  *
652
  * @param array $args - includes img, errors
 
653
  * @since 2.0.6
654
  */
655
  public static function show_errors( $args ) {
677
  * If the message in the global settings is empty, show every validation message in the error box
678
  *
679
  * @param array $args - includes img, errors, and show_img
 
680
  * @since 2.0.6
681
  */
682
  public static function show_error( $args ) {
706
 
707
  public static function maybe_get_scroll_js( $id ) {
708
  $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) );
709
+ if ( $offset != -1 ) {
710
  self::get_scroll_js( $id );
711
  }
712
  }
713
 
714
  public static function get_scroll_js( $form_id ) {
715
+ echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>';
716
+ }
717
 
718
  /**
719
  * @since 3.0
720
  */
721
  public static function actions_dropdown( $atts ) {
722
  if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
723
+ $status = $atts['status'];
724
+ $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
725
  $trash_link = self::delete_trash_info( $form_id, $status );
726
+ $links = self::get_action_links( $form_id, $status );
727
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
728
  }
729
  }
736
  $form = FrmForm::getOne( $form_id );
737
  }
738
 
739
+ $actions = array();
740
  $trash_links = self::delete_trash_links( $form_id );
741
  if ( 'trash' == $form->status ) {
742
  $actions['restore'] = $trash_links['restore'];
750
  $actions['frm_duplicate'] = array(
751
  'url' => wp_nonce_url( $duplicate_link ),
752
  'label' => __( 'Create Form from Template', 'formidable' ),
753
+ 'icon' => 'frm_icon_font frm_duplicate_icon',
754
  );
755
  } else {
756
  $actions['duplicate'] = array(
757
  'url' => wp_nonce_url( $duplicate_link ),
758
  'label' => __( 'Duplicate Form', 'formidable' ),
759
+ 'icon' => 'frm_icon_font frm_duplicate_icon',
760
  );
761
  }
762
 
768
 
769
  public static function edit_form_link( $form_id ) {
770
  if ( is_object( $form_id ) ) {
771
+ $form = $form_id;
772
+ $name = $form->name;
773
+ $form_id = $form->id;
774
+ } else {
775
  $name = FrmForm::getName( $form_id );
776
+ }
777
 
778
+ if ( $form_id ) {
779
+ $val = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ) ) . '">' . ( '' == $name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $name, 40 ) ) . '</a>';
780
+ } else {
781
+ $val = '';
782
+ }
783
 
784
+ return $val;
785
  }
786
 
787
  public static function delete_trash_link( $id, $status, $length = 'label' ) {
796
  public static function format_link_html( $link_details, $length = 'label' ) {
797
  $link = '';
798
  if ( ! empty( $link_details ) ) {
799
+ $link = '<a href="' . esc_url( $link_details['url'] ) . '"';
800
  if ( isset( $link_details['data'] ) ) {
801
  foreach ( $link_details['data'] as $data => $value ) {
802
  $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"';
804
  } elseif ( isset( $link_details['confirm'] ) ) {
805
  $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
806
  }
 
807
  $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
 
 
 
 
 
808
  $link .= '>' . $label . '</a>';
809
  }
 
810
  return $link;
811
  }
812
 
836
  */
837
  private static function delete_trash_links( $id ) {
838
  $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
839
+ $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
840
 
841
  return array(
842
  'restore' => array(
844
  'short' => __( 'Restore', 'formidable' ),
845
  'url' => wp_nonce_url( $base_url . '&frm_action=untrash', 'untrash_form_' . absint( $id ) ),
846
  ),
847
+ 'trash' => array(
848
  'label' => __( 'Move Form to Trash', 'formidable' ),
849
  'short' => __( 'Trash', 'formidable' ),
850
  'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ),
851
  'icon' => 'frm_icon_font frm_delete_icon',
852
  'data' => array( 'frmverify' => __( 'Are you sure?', 'formidable' ) ),
853
  ),
854
+ 'delete' => array(
855
+ 'label' => __( 'Delete Permanently', 'formidable' ),
856
+ 'short' => __( 'Delete', 'formidable' ),
857
+ 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ),
858
  'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ),
859
+ 'icon' => 'frm_icon_font frm_delete_icon',
860
+ 'data' => array( 'frmverify' => __( 'Delete form & entries?', 'formidable' ) ),
861
  ),
862
  );
863
  }
867
  */
868
  public static function css_classes() {
869
  $classes = array(
 
 
 
 
 
 
 
 
870
  'frm_first' => array(
871
+ 'label' => __( 'First', 'formidable' ),
872
+ 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
873
  ),
874
  'frm_alignright' => __( 'Right', 'formidable' ),
875
+ 'frm_total' => array(
876
+ 'label' => __( 'Total', 'formidable' ),
877
+ 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
878
+ ),
879
  'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
880
  'frm_grid' => __( 'Even Grid Row', 'formidable' ),
881
  'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
882
+ 'frm_two_col' => array(
883
+ 'label' => __( '2 Col Options', 'formidable' ),
884
+ 'title' => __( 'Put your radio button or checkbox options into two columns.', 'formidable' ),
885
+ ),
886
+ 'frm_three_col' => array(
887
+ 'label' => __( '3 Col Options', 'formidable' ),
888
+ 'title' => __( 'Put your radio button or checkbox options into three columns.', 'formidable' ),
889
+ ),
890
+ 'frm_four_col' => array(
891
+ 'label' => __( '4 Col Options', 'formidable' ),
892
+ 'title' => __( 'Put your radio button or checkbox options into four columns.', 'formidable' ),
893
+ ),
894
+ 'frm_scroll_box' => array(
895
+ 'label' => __( 'Scroll Box', 'formidable' ),
896
+ 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ),
897
+ ),
898
  'frm_capitalize' => array(
899
+ 'label' => __( 'Capitalize', 'formidable' ),
900
+ 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
901
  ),
902
  );
903
 
906
 
907
  public static function grid_classes() {
908
  $base = array(
909
+ 'frm_half' => '1/2',
910
 
911
+ 'frm_third' => '1/3',
912
+ 'frm_two_thirds' => '2/3',
913
 
914
  'frm_fourth' => '1/4',
915
  'frm_three_fourths' => '3/4',
918
  $frm_settings = FrmAppHelper::get_settings();
919
  if ( $frm_settings->old_css ) {
920
  $classes = array(
921
+ 'frm_fifth' => '1/5',
922
+ 'frm_four_fifths' => '4/5',
923
+
924
+ 'frm_two_fifths' => '2/5',
925
+ 'frm_three_fifths' => '3/5',
926
+
927
+ 'frm_sixth' => '1/6',
928
 
929
+ 'frm_full' => '100%',
930
  );
931
  } else {
932
  $classes = array(
933
+ 'frm_sixth' => '1/6',
934
+ 'frm10' => '5/6',
935
+
936
+ 'frm11' => '11/12',
937
+ 'frm1' => '1/12',
938
+
939
+ 'frm5' => '5/12',
940
+ 'frm7' => '7/12',
941
+
942
+ 'frm12' => '100%',
943
  );
944
  }
945
 
955
  $label = $class;
956
  } elseif ( ! is_array( $style ) ) {
957
  $label = $style;
958
+ } else if ( isset( $style['label'] ) ) {
959
  $label = $style['label'];
960
  }
 
961
  return $label;
962
  }
963
 
964
  public static function status_nice_name( $status ) {
965
+ $nice_names = array(
966
+ 'draft' => __( 'Draft', 'formidable' ),
967
+ 'trash' => __( 'Trash', 'formidable' ),
968
+ 'publish' => __( 'Published', 'formidable' ),
969
+ );
970
 
971
  if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
972
+ $status = 'publish';
973
+ }
974
 
975
  $name = $nice_names[ $status ];
976
 
977
+ return $name;
978
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979
  }
classes/helpers/FrmFormsListHelper.php CHANGED
@@ -15,7 +15,7 @@ class FrmFormsListHelper extends FrmListHelper {
15
  public function prepare_items() {
16
  global $wpdb, $per_page, $mode;
17
 
18
- $page = $this->get_pagenum();
19
  $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
20
 
21
  $mode = self::get_param(
@@ -45,23 +45,23 @@ class FrmFormsListHelper extends FrmListHelper {
45
 
46
  $s_query = array(
47
  array(
48
- 'or' => 1,
49
- 'parent_form_id' => null,
50
  'parent_form_id <' => 1,
51
  ),
52
  );
53
  switch ( $this->status ) {
54
- case 'draft':
55
- $s_query['is_template'] = 0;
56
- $s_query['status'] = 'draft';
57
- break;
58
- case 'trash':
59
- $s_query['status'] = 'trash';
60
- break;
61
- default:
62
- $s_query['is_template'] = 0;
63
- $s_query['status !'] = 'trash';
64
- break;
65
  }
66
 
67
  $s = self::get_param(
@@ -70,7 +70,7 @@ class FrmFormsListHelper extends FrmListHelper {
70
  'sanitize' => 'sanitize_text_field',
71
  )
72
  );
73
- if ( $s != '' ) {
74
  preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
75
  $search_terms = array_map( 'trim', $matches[0] );
76
  foreach ( (array) $search_terms as $term ) {
@@ -82,10 +82,10 @@ class FrmFormsListHelper extends FrmListHelper {
82
  );
83
  unset( $term );
84
  }
85
- }
86
 
87
  $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
88
- $total_items = FrmDb::get_count( 'frm_forms', $s_query );
89
 
90
  $this->set_pagination_args(
91
  array(
@@ -96,92 +96,79 @@ class FrmFormsListHelper extends FrmListHelper {
96
  }
97
 
98
  public function no_items() {
99
- echo '<p>';
100
- if ( $this->status === 'trash' ) {
101
- esc_html_e( 'No forms found in the trash.', 'formidable' );
102
- ?>
103
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
104
- <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
105
- </a>
106
- <?php
107
- } else {
108
-
109
- esc_html_e( 'No Forms Found.', 'formidable' );
110
- ?>
111
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=add_new' ) ); ?>">
112
- <?php esc_html_e( 'Add New', 'formidable' ); ?>
113
- </a>
114
- <?php
115
- }
116
- echo '</p>';
117
  }
118
 
119
  public function get_bulk_actions() {
120
- $actions = array();
121
 
122
- if ( 'trash' == $this->status ) {
123
  if ( current_user_can( 'frm_edit_forms' ) ) {
124
- $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
125
- }
126
 
127
  if ( current_user_can( 'frm_delete_forms' ) ) {
128
- $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
129
- }
130
  } elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
131
- $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
132
  } elseif ( current_user_can( 'frm_delete_forms' ) ) {
133
  $actions['bulk_delete'] = __( 'Delete', 'formidable' );
134
- }
135
 
136
- return $actions;
137
- }
138
 
139
  public function extra_tablenav( $which ) {
140
- if ( 'top' != $which ) {
141
- return;
142
- }
143
 
144
  if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
145
- ?>
146
- <div class="alignleft actions frm_visible_overflow">
147
- <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
148
- </div>
149
- <?php
150
- }
151
  }
152
 
153
  public function get_views() {
154
 
155
  $statuses = array(
156
- 'published' => __( 'My Forms', 'formidable' ),
157
- 'draft' => __( 'Drafts', 'formidable' ),
158
- 'trash' => __( 'Trash', 'formidable' ),
159
  );
160
 
161
- $links = array();
162
- $counts = FrmForm::get_count();
163
  $form_type = self::get_param(
164
  array(
165
- 'param' => 'form_type',
166
  'default' => 'published',
167
  )
168
  );
169
 
170
- foreach ( $statuses as $status => $name ) {
171
 
172
- if ( $status == $form_type ) {
173
- $class = ' class="current"';
174
- } else {
175
- $class = '';
176
- }
177
 
178
- if ( $counts->{$status} || 'draft' !== $status ) {
179
- /* translators: %1$s: Status, %2$s: Number of items */
180
  $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
181
- }
182
 
183
  unset( $status, $name );
184
- }
185
 
186
  return $links;
187
  }
@@ -197,15 +184,15 @@ class FrmFormsListHelper extends FrmListHelper {
197
  }
198
 
199
  public function single_row( $item, $style = '' ) {
200
- global $frm_vars, $mode;
201
 
202
  // Set up the hover actions for this user
203
- $actions = array();
204
- $edit_link = FrmForm::get_edit_link( $item->id );
205
 
206
  $this->get_actions( $actions, $item, $edit_link );
207
 
208
- $action_links = $this->row_actions( $actions );
209
 
210
  // Set up the checkbox ( because the user is editable, otherwise its empty )
211
  $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
@@ -214,9 +201,9 @@ class FrmFormsListHelper extends FrmListHelper {
214
 
215
  list( $columns, $hidden ) = $this->get_column_info();
216
 
217
- $format = 'Y/m/d';
218
- if ( 'list' != $mode ) {
219
- $format .= ' \<\b\r \/\> g:i:s a';
220
  }
221
 
222
  foreach ( $columns as $column_name => $column_display_name ) {
@@ -224,12 +211,12 @@ class FrmFormsListHelper extends FrmListHelper {
224
 
225
  $style = '';
226
  if ( in_array( $column_name, $hidden ) ) {
227
- $class .= ' frm_hidden';
228
  }
229
 
230
- $class = 'class="' . esc_attr( $class ) . '"';
231
  $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
232
- $attributes = $class . $style . $data_colname;
233
 
234
  switch ( $column_name ) {
235
  case 'cb':
@@ -237,37 +224,37 @@ class FrmFormsListHelper extends FrmListHelper {
237
  break;
238
  case 'id':
239
  case 'form_key':
240
- $val = $item->{$column_name};
241
- break;
242
  case 'name':
243
- $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
244
- $val .= $action_links;
245
 
246
- break;
247
  case 'created_at':
248
  $date = date( $format, strtotime( $item->created_at ) );
249
- $val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
250
  break;
251
  case 'shortcode':
252
  $val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>';
253
- if ( 'excerpt' == $mode ) {
254
  $val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
255
- }
256
- break;
257
- case 'entries':
258
  if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
259
  $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr( 'Saving entries is disabled for this form', 'formidable' ) . '"></i>';
260
  } else {
261
  $text = FrmEntry::getRecordCount( $item->id );
262
- $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
263
  unset( $text );
264
  }
265
  }
266
 
267
  if ( isset( $val ) ) {
268
- $r .= "<td $attributes>";
269
- $r .= $val;
270
- $r .= '</td>';
271
  }
272
  unset( $val );
273
  }
@@ -276,9 +263,9 @@ class FrmFormsListHelper extends FrmListHelper {
276
  return $r;
277
  }
278
 
279
- /**
280
- * @param string $edit_link
281
- */
282
  private function get_actions( &$actions, $item, $edit_link ) {
283
  $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
284
  foreach ( $new_actions as $link => $action ) {
@@ -287,24 +274,23 @@ class FrmFormsListHelper extends FrmListHelper {
287
 
288
  if ( 'trash' == $this->status ) {
289
  $actions = $new_actions;
290
-
291
  return;
292
  }
293
 
294
  if ( current_user_can( 'frm_edit_forms' ) ) {
295
- $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
296
  $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
297
  }
298
 
299
- $actions = array_merge( $actions, $new_actions );
300
  $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
301
- }
302
 
303
- /**
304
- * @param string $edit_link
305
- */
306
  private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
307
- $form_name = $item->name;
308
  if ( trim( $form_name ) == '' ) {
309
  $form_name = __( '(no title)', 'formidable' );
310
  }
@@ -313,37 +299,37 @@ class FrmFormsListHelper extends FrmListHelper {
313
  $form_name = FrmAppHelper::truncate( $form_name, 50 );
314
  }
315
 
316
- $val = '<strong>';
317
- if ( 'trash' == $this->status ) {
318
- $val .= $form_name;
319
- } else {
320
  $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
321
- }
322
 
323
- $this->add_draft_label( $item, $val );
324
- $val .= '</strong>';
325
 
326
- $this->add_form_description( $item, $val );
327
 
328
- return $val;
329
- }
330
 
331
- /**
332
- * @param string $val
333
- */
334
- private function add_draft_label( $item, &$val ) {
335
- if ( 'draft' == $item->status && 'draft' != $this->status ) {
336
  $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
337
- }
338
- }
339
-
340
- /**
341
- * @param string $val
342
- */
343
- private function add_form_description( $item, &$val ) {
344
- global $mode;
345
- if ( 'excerpt' == $mode ) {
346
  $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
347
- }
348
- }
349
  }
15
  public function prepare_items() {
16
  global $wpdb, $per_page, $mode;
17
 
18
+ $page = $this->get_pagenum();
19
  $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
20
 
21
  $mode = self::get_param(
45
 
46
  $s_query = array(
47
  array(
48
+ 'or' => 1,
49
+ 'parent_form_id' => null,
50
  'parent_form_id <' => 1,
51
  ),
52
  );
53
  switch ( $this->status ) {
54
+ case 'draft':
55
+ $s_query['is_template'] = 0;
56
+ $s_query['status'] = 'draft';
57
+ break;
58
+ case 'trash':
59
+ $s_query['status'] = 'trash';
60
+ break;
61
+ default:
62
+ $s_query['is_template'] = 0;
63
+ $s_query['status !'] = 'trash';
64
+ break;
65
  }
66
 
67
  $s = self::get_param(
70
  'sanitize' => 'sanitize_text_field',
71
  )
72
  );
73
+ if ( $s != '' ) {
74
  preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
75
  $search_terms = array_map( 'trim', $matches[0] );
76
  foreach ( (array) $search_terms as $term ) {
82
  );
83
  unset( $term );
84
  }
85
+ }
86
 
87
  $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
88
+ $total_items = FrmDb::get_count( 'frm_forms', $s_query );
89
 
90
  $this->set_pagination_args(
91
  array(
96
  }
97
 
98
  public function no_items() {
99
+ esc_html_e( 'No Forms Found.', 'formidable' );
100
+ ?>
101
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) ?>">
102
+ <?php esc_html_e( 'Add New', 'formidable' ); ?>
103
+ </a>
104
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  public function get_bulk_actions() {
108
+ $actions = array();
109
 
110
+ if ( 'trash' == $this->status ) {
111
  if ( current_user_can( 'frm_edit_forms' ) ) {
112
+ $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
113
+ }
114
 
115
  if ( current_user_can( 'frm_delete_forms' ) ) {
116
+ $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
117
+ }
118
  } elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
119
+ $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
120
  } elseif ( current_user_can( 'frm_delete_forms' ) ) {
121
  $actions['bulk_delete'] = __( 'Delete', 'formidable' );
122
+ }
123
 
124
+ return $actions;
125
+ }
126
 
127
  public function extra_tablenav( $which ) {
128
+ if ( 'top' != $which ) {
129
+ return;
130
+ }
131
 
132
  if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
133
+ ?>
134
+ <div class="alignleft actions frm_visible_overflow">
135
+ <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
136
+ </div>
137
+ <?php
138
+ }
139
  }
140
 
141
  public function get_views() {
142
 
143
  $statuses = array(
144
+ 'published' => __( 'My Forms', 'formidable' ),
145
+ 'draft' => __( 'Drafts', 'formidable' ),
146
+ 'trash' => __( 'Trash', 'formidable' ),
147
  );
148
 
149
+ $links = array();
150
+ $counts = FrmForm::get_count();
151
  $form_type = self::get_param(
152
  array(
153
+ 'param' => 'form_type',
154
  'default' => 'published',
155
  )
156
  );
157
 
158
+ foreach ( $statuses as $status => $name ) {
159
 
160
+ if ( $status == $form_type ) {
161
+ $class = ' class="current"';
162
+ } else {
163
+ $class = '';
164
+ }
165
 
166
+ if ( $counts->{$status} || 'published' == $status ) {
 
167
  $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
168
+ }
169
 
170
  unset( $status, $name );
171
+ }
172
 
173
  return $links;
174
  }
184
  }
185
 
186
  public function single_row( $item, $style = '' ) {
187
+ global $frm_vars, $mode;
188
 
189
  // Set up the hover actions for this user
190
+ $actions = array();
191
+ $edit_link = '?page=formidable&frm_action=edit&id=' . $item->id;
192
 
193
  $this->get_actions( $actions, $item, $edit_link );
194
 
195
+ $action_links = $this->row_actions( $actions );
196
 
197
  // Set up the checkbox ( because the user is editable, otherwise its empty )
198
  $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
201
 
202
  list( $columns, $hidden ) = $this->get_column_info();
203
 
204
+ $format = 'Y/m/d';
205
+ if ( 'list' != $mode ) {
206
+ $format .= ' \<\b\r \/\> g:i:s a';
207
  }
208
 
209
  foreach ( $columns as $column_name => $column_display_name ) {
211
 
212
  $style = '';
213
  if ( in_array( $column_name, $hidden ) ) {
214
+ $class .= ' frm_hidden';
215
  }
216
 
217
+ $class = 'class="' . esc_attr( $class ) . '"';
218
  $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
219
+ $attributes = $class . $style . $data_colname;
220
 
221
  switch ( $column_name ) {
222
  case 'cb':
224
  break;
225
  case 'id':
226
  case 'form_key':
227
+ $val = $item->{$column_name};
228
+ break;
229
  case 'name':
230
+ $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
231
+ $val .= $action_links;
232
 
233
+ break;
234
  case 'created_at':
235
  $date = date( $format, strtotime( $item->created_at ) );
236
+ $val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
237
  break;
238
  case 'shortcode':
239
  $val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>';
240
+ if ( 'excerpt' == $mode ) {
241
  $val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
242
+ }
243
+ break;
244
+ case 'entries':
245
  if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
246
  $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr( 'Saving entries is disabled for this form', 'formidable' ) . '"></i>';
247
  } else {
248
  $text = FrmEntry::getRecordCount( $item->id );
249
+ $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
250
  unset( $text );
251
  }
252
  }
253
 
254
  if ( isset( $val ) ) {
255
+ $r .= "<td $attributes>";
256
+ $r .= $val;
257
+ $r .= '</td>';
258
  }
259
  unset( $val );
260
  }
263
  return $r;
264
  }
265
 
266
+ /**
267
+ * @param string $edit_link
268
+ */
269
  private function get_actions( &$actions, $item, $edit_link ) {
270
  $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
271
  foreach ( $new_actions as $link => $action ) {
274
 
275
  if ( 'trash' == $this->status ) {
276
  $actions = $new_actions;
 
277
  return;
278
  }
279
 
280
  if ( current_user_can( 'frm_edit_forms' ) ) {
281
+ $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
282
  $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
283
  }
284
 
285
+ $actions = array_merge( $actions, $new_actions );
286
  $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
287
+ }
288
 
289
+ /**
290
+ * @param string $edit_link
291
+ */
292
  private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
293
+ $form_name = $item->name;
294
  if ( trim( $form_name ) == '' ) {
295
  $form_name = __( '(no title)', 'formidable' );
296
  }
299
  $form_name = FrmAppHelper::truncate( $form_name, 50 );
300
  }
301
 
302
+ $val = '<strong>';
303
+ if ( 'trash' == $this->status ) {
304
+ $val .= $form_name;
305
+ } else {
306
  $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
307
+ }
308
 
309
+ $this->add_draft_label( $item, $val );
310
+ $val .= '</strong>';
311
 
312
+ $this->add_form_description( $item, $val );
313
 
314
+ return $val;
315
+ }
316
 
317
+ /**
318
+ * @param string $val
319
+ */
320
+ private function add_draft_label( $item, &$val ) {
321
+ if ( 'draft' == $item->status && 'draft' != $this->status ) {
322
  $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
323
+ }
324
+ }
325
+
326
+ /**
327
+ * @param string $val
328
+ */
329
+ private function add_form_description( $item, &$val ) {
330
+ global $mode;
331
+ if ( 'excerpt' == $mode ) {
332
  $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
333
+ }
334
+ }
335
  }
classes/helpers/FrmListHelper.php CHANGED
@@ -67,10 +67,10 @@ class FrmListHelper {
67
  protected $modes = array();
68
 
69
  /**
70
- *
71
- * @var array
72
- */
73
- protected $params;
74
 
75
  /**
76
  * Stores the value returned by ->get_column_info()
@@ -81,35 +81,20 @@ class FrmListHelper {
81
 
82
  protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
83
 
84
- protected $compat_methods = array(
85
- 'set_pagination_args',
86
- 'get_views',
87
- 'get_bulk_actions',
88
- 'bulk_actions',
89
- 'row_actions',
90
- 'view_switcher',
91
- 'get_items_per_page',
92
- 'pagination',
93
- 'get_sortable_columns',
94
- 'get_column_info',
95
- 'get_table_classes',
96
- 'display_tablenav',
97
- 'extra_tablenav',
98
- 'single_row_columns',
99
- );
100
 
101
  /**
102
- * Construct the table object
103
- */
104
  public function __construct( $args ) {
105
  $args = wp_parse_args(
106
  $args,
107
  array(
108
- 'params' => array(),
109
- 'plural' => '',
110
  'singular' => '',
111
- 'ajax' => false,
112
- 'screen' => null,
113
  )
114
  );
115
 
@@ -123,7 +108,7 @@ class FrmListHelper {
123
  $args['plural'] = $this->screen->base;
124
  }
125
 
126
- $args['plural'] = sanitize_key( $args['plural'] );
127
  $args['singular'] = sanitize_key( $args['singular'] );
128
 
129
  $this->_args = $args;
@@ -186,7 +171,6 @@ class FrmListHelper {
186
  * An internal method that sets all the necessary pagination arguments
187
  *
188
  * @param array $args An associative array with information about the pagination
189
- *
190
  * @access protected
191
  *
192
  * @param array|string $args
@@ -197,7 +181,7 @@ class FrmListHelper {
197
  array(
198
  'total_items' => 0,
199
  'total_pages' => 0,
200
- 'per_page' => 0,
201
  )
202
  );
203
 
@@ -222,7 +206,6 @@ class FrmListHelper {
222
  *
223
  * @param string $key Pagination argument to retrieve. Common values include 'total_items',
224
  * 'total_pages', 'per_page', or 'infinite_scroll'.
225
- *
226
  * @return int Number of items that correspond to the given pagination argument.
227
  */
228
  public function get_pagination_arg( $key ) {
@@ -275,13 +258,12 @@ class FrmListHelper {
275
  $this->hidden_search_inputs( $search_params );
276
  }
277
 
278
- FrmAppHelper::show_search_box( compact( 'text', 'input_id' ) );
279
  }
280
 
281
  private function hidden_search_inputs( $param_name ) {
282
  if ( ! empty( $_REQUEST[ $param_name ] ) ) {
283
- $value = sanitize_text_field( wp_unslash( $_REQUEST[ $param_name ] ) );
284
- echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $value ) . '" />';
285
  }
286
  }
287
 
@@ -371,7 +353,6 @@ class FrmListHelper {
371
  */
372
  $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
373
  $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
374
-
375
  $two = '';
376
  } else {
377
  $two = '2';
@@ -419,17 +400,16 @@ class FrmListHelper {
419
  }
420
 
421
  private static function get_bulk_action( $action_name ) {
422
- $action = false;
423
  $action_param = self::get_param(
424
  array(
425
- 'param' => $action_name,
426
  'sanitize' => 'sanitize_text_field',
427
  )
428
  );
429
- if ( $action_param && - 1 != $action_param ) {
430
  $action = $action_param;
431
  }
432
-
433
  return $action;
434
  }
435
 
@@ -441,12 +421,10 @@ class FrmListHelper {
441
  *
442
  * @param array $actions The list of actions
443
  * @param bool $always_visible Whether the actions should be always visible
444
- *
445
  * @return string
446
  */
447
  protected function row_actions( $actions, $always_visible = false ) {
448
  $action_count = count( $actions );
449
-
450
  $i = 0;
451
 
452
  if ( ! $action_count ) {
@@ -455,7 +433,7 @@ class FrmListHelper {
455
 
456
  $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
457
  foreach ( $actions as $action => $link ) {
458
- ++ $i;
459
  ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
460
  $out .= "<span class='$action'>$link$sep</span>";
461
  }
@@ -475,10 +453,10 @@ class FrmListHelper {
475
  * @param string $current_mode
476
  */
477
  protected function view_switcher( $current_mode ) {
478
- ?>
479
- <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>"/>
480
  <div class="view-switch">
481
- <?php
482
  foreach ( $this->modes as $mode => $title ) {
483
  $classes = array( 'view-' . $mode );
484
  if ( $current_mode == $mode ) {
@@ -492,9 +470,9 @@ class FrmListHelper {
492
  esc_html( $title )
493
  );
494
  }
495
- ?>
496
  </div>
497
- <?php
498
  }
499
 
500
  /**
@@ -522,8 +500,7 @@ class FrmListHelper {
522
  * @access protected
523
  *
524
  * @param string $option
525
- * @param int $default
526
- *
527
  * @return int
528
  */
529
  protected function get_items_per_page( $option, $default = 20 ) {
@@ -561,14 +538,13 @@ class FrmListHelper {
561
  return;
562
  }
563
 
564
- $total_items = $this->_pagination_args['total_items'];
565
- $total_pages = $this->_pagination_args['total_pages'];
566
  $infinite_scroll = false;
567
  if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
568
  $infinite_scroll = $this->_pagination_args['infinite_scroll'];
569
  }
570
 
571
- /* translators: %s: Number of items */
572
  $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>';
573
 
574
  $current = $this->get_pagenum();
@@ -610,8 +586,6 @@ class FrmListHelper {
610
  );
611
  }
612
  $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
613
-
614
- /* translators: %1$s: Current page number, %2$s: Total pages */
615
  $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after;
616
 
617
  $page_links[] = $this->add_page_link(
@@ -657,17 +631,17 @@ class FrmListHelper {
657
  'next' => false,
658
  );
659
 
660
- if ( $current == 1 ) {
661
  $disable['first'] = true;
662
  $disable['prev'] = true;
663
- } elseif ( $current == 2 ) {
664
  $disable['first'] = true;
665
  }
666
 
667
- if ( $current == $total_pages ) {
668
  $disable['last'] = true;
669
  $disable['next'] = true;
670
- } elseif ( $current == $total_pages - 1 ) {
671
  $disable['last'] = true;
672
  }
673
 
@@ -681,7 +655,6 @@ class FrmListHelper {
681
  'prev' => __( 'Previous page', 'formidable' ),
682
  'next' => __( 'Next page', 'formidable' ),
683
  );
684
-
685
  return $labels[ $link ];
686
  }
687
 
@@ -697,7 +670,6 @@ class FrmListHelper {
697
  } else {
698
  $link = $this->add_active_link( $atts );
699
  }
700
-
701
  return $link;
702
  }
703
 
@@ -706,9 +678,8 @@ class FrmListHelper {
706
  }
707
 
708
  private function add_active_link( $atts ) {
709
- $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
710
  $label = $this->link_label( $atts['page'] );
711
-
712
  return sprintf(
713
  "<a class='button %s-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
714
  $atts['page'],
@@ -745,7 +716,7 @@ class FrmListHelper {
745
  */
746
  protected function get_default_primary_column_name() {
747
  $columns = $this->get_columns();
748
- $column = '';
749
 
750
  // We need a primary defined so responsive views show something,
751
  // so let's fall back to the first non-checkbox column.
@@ -787,7 +758,7 @@ class FrmListHelper {
787
  * @param string $default Column name default for the specific list table, e.g. 'name'.
788
  * @param string $context Screen ID for specific list table, e.g. 'plugins'.
789
  */
790
- $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
791
 
792
  if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
793
  $column = $default;
@@ -818,7 +789,7 @@ class FrmListHelper {
818
  }
819
 
820
  $columns = get_column_headers( $this->screen );
821
- $hidden = get_hidden_columns( $this->screen );
822
 
823
  $sortable_columns = $this->get_sortable_columns();
824
  /**
@@ -848,7 +819,6 @@ class FrmListHelper {
848
  }
849
 
850
  $primary = $this->get_primary_column_name();
851
-
852
  $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
853
 
854
  return $this->_column_headers;
@@ -865,7 +835,6 @@ class FrmListHelper {
865
  public function get_column_count() {
866
  list ( $columns, $hidden ) = $this->get_column_info();
867
  $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
868
-
869
  return count( $columns ) - count( $hidden );
870
  }
871
 
@@ -886,7 +855,7 @@ class FrmListHelper {
886
  $current_url = remove_query_arg( 'paged', $current_url );
887
 
888
  if ( isset( $_GET['orderby'] ) ) {
889
- $current_orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
890
  } else {
891
  $current_orderby = '';
892
  }
@@ -899,9 +868,9 @@ class FrmListHelper {
899
 
900
  if ( ! empty( $columns['cb'] ) ) {
901
  static $cb_counter = 1;
902
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>';
903
- $columns['cb'] .= '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />';
904
- $cb_counter ++;
905
  }
906
 
907
  foreach ( $columns as $column_key => $column_display_name ) {
@@ -913,7 +882,7 @@ class FrmListHelper {
913
 
914
  if ( 'cb' == $column_key ) {
915
  $class[] = 'check-column';
916
- } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
917
  $class[] = 'num';
918
  }
919
 
@@ -925,11 +894,11 @@ class FrmListHelper {
925
  list( $orderby, $desc_first ) = $sortable[ $column_key ];
926
 
927
  if ( $current_orderby == $orderby ) {
928
- $order = 'asc' == $current_order ? 'desc' : 'asc';
929
  $class[] = 'sorted';
930
  $class[] = $current_order;
931
  } else {
932
- $order = $desc_first ? 'desc' : 'asc';
933
  $class[] = 'sortable';
934
  $class[] = $desc_first ? 'asc' : 'desc';
935
  }
@@ -937,9 +906,9 @@ class FrmListHelper {
937
  $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . esc_html( $column_display_name ) . '</span><span class="sorting-indicator"></span></a>';
938
  }
939
 
940
- $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
941
  $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
942
- $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : '';
943
 
944
  if ( ! empty( $class ) ) {
945
  $class = "class='" . esc_attr( join( ' ', $class ) ) . "'";
@@ -959,26 +928,26 @@ class FrmListHelper {
959
  $singular = $this->_args['singular'];
960
 
961
  $this->display_tablenav( 'top' );
962
- ?>
963
- <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
964
- <thead>
965
- <tr>
966
- <?php $this->print_column_headers(); ?>
967
- </tr>
968
- </thead>
969
-
970
- <tbody id="the-list"<?php echo( $singular ? " data-wp-lists='list:" . esc_attr( $singular ) . "'" : '' ); // WPCS: XSS ok. ?>>
971
- <?php $this->display_rows_or_placeholder(); ?>
972
- </tbody>
973
-
974
- <tfoot>
975
- <tr>
976
- <?php $this->print_column_headers( false ); ?>
977
- </tr>
978
- </tfoot>
979
-
980
- </table>
981
- <?php
982
  $this->display_tablenav( 'bottom' );
983
  }
984
 
@@ -999,27 +968,26 @@ class FrmListHelper {
999
  *
1000
  * @since 2.0.18
1001
  * @access protected
1002
- *
1003
  * @param string $which
1004
  */
1005
  protected function display_tablenav( $which ) {
1006
  if ( 'top' == $which ) {
1007
  wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1008
  }
1009
- ?>
1010
- <div class="tablenav <?php echo esc_attr( $which ); ?>">
1011
-
1012
- <div class="alignleft actions bulkactions">
1013
- <?php $this->bulk_actions( $which ); ?>
1014
- </div>
1015
- <?php
1016
- $this->extra_tablenav( $which );
1017
- $this->pagination( $which );
1018
- ?>
1019
 
1020
- <br class="clear"/>
 
1021
  </div>
1022
- <?php
 
 
 
 
 
 
 
1023
  }
1024
 
1025
  /**
@@ -1030,8 +998,7 @@ class FrmListHelper {
1030
  *
1031
  * @param string $which
1032
  */
1033
- protected function extra_tablenav( $which ) {
1034
- }
1035
 
1036
  /**
1037
  * Generate the tbody element for the list table.
@@ -1119,15 +1086,14 @@ class FrmListHelper {
1119
  * @since 4.3.0
1120
  * @access protected
1121
  *
1122
- * @param object $item The item being acted upon.
1123
  * @param string $column_name Current column name.
1124
- * @param string $primary Primary column name.
1125
- *
1126
  * @return string The row actions output. In this case, an empty string.
1127
  */
1128
  protected function handle_row_actions( $item, $column_name, $primary ) {
1129
  return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : '';
1130
- }
1131
 
1132
  /**
1133
  * Handle an incoming ajax request (called from admin-ajax.php)
@@ -1151,13 +1117,12 @@ class FrmListHelper {
1151
 
1152
  if ( isset( $this->_pagination_args['total_items'] ) ) {
1153
  $response['total_items_i18n'] = sprintf(
1154
- /* translators: %s: Number of items */
1155
  _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ),
1156
  number_format_i18n( $this->_pagination_args['total_items'] )
1157
  );
1158
  }
1159
  if ( isset( $this->_pagination_args['total_pages'] ) ) {
1160
- $response['total_pages'] = $this->_pagination_args['total_pages'];
1161
  $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1162
  }
1163
 
67
  protected $modes = array();
68
 
69
  /**
70
+ *
71
+ * @var array
72
+ */
73
+ protected $params;
74
 
75
  /**
76
  * Stores the value returned by ->get_column_info()
81
 
82
  protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
83
 
84
+ protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions', 'row_actions', 'view_switcher', 'get_items_per_page', 'pagination', 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav', 'single_row_columns' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  /**
87
+ * Construct the table object
88
+ */
89
  public function __construct( $args ) {
90
  $args = wp_parse_args(
91
  $args,
92
  array(
93
+ 'params' => array(),
94
+ 'plural' => '',
95
  'singular' => '',
96
+ 'ajax' => false,
97
+ 'screen' => null,
98
  )
99
  );
100
 
108
  $args['plural'] = $this->screen->base;
109
  }
110
 
111
+ $args['plural'] = sanitize_key( $args['plural'] );
112
  $args['singular'] = sanitize_key( $args['singular'] );
113
 
114
  $this->_args = $args;
171
  * An internal method that sets all the necessary pagination arguments
172
  *
173
  * @param array $args An associative array with information about the pagination
 
174
  * @access protected
175
  *
176
  * @param array|string $args
181
  array(
182
  'total_items' => 0,
183
  'total_pages' => 0,
184
+ 'per_page' => 0,
185
  )
186
  );
187
 
206
  *
207
  * @param string $key Pagination argument to retrieve. Common values include 'total_items',
208
  * 'total_pages', 'per_page', or 'infinite_scroll'.
 
209
  * @return int Number of items that correspond to the given pagination argument.
210
  */
211
  public function get_pagination_arg( $key ) {
258
  $this->hidden_search_inputs( $search_params );
259
  }
260
 
261
+ FrmAppHelper::show_search_box( $text, $input_id );
262
  }
263
 
264
  private function hidden_search_inputs( $param_name ) {
265
  if ( ! empty( $_REQUEST[ $param_name ] ) ) {
266
+ echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $_REQUEST[ $param_name ] ) . '" />';
 
267
  }
268
  }
269
 
353
  */
354
  $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
355
  $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
 
356
  $two = '';
357
  } else {
358
  $two = '2';
400
  }
401
 
402
  private static function get_bulk_action( $action_name ) {
403
+ $action = false;
404
  $action_param = self::get_param(
405
  array(
406
+ 'param' => $action_name,
407
  'sanitize' => 'sanitize_text_field',
408
  )
409
  );
410
+ if ( $action_param && -1 != $action_param ) {
411
  $action = $action_param;
412
  }
 
413
  return $action;
414
  }
415
 
421
  *
422
  * @param array $actions The list of actions
423
  * @param bool $always_visible Whether the actions should be always visible
 
424
  * @return string
425
  */
426
  protected function row_actions( $actions, $always_visible = false ) {
427
  $action_count = count( $actions );
 
428
  $i = 0;
429
 
430
  if ( ! $action_count ) {
433
 
434
  $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
435
  foreach ( $actions as $action => $link ) {
436
+ ++$i;
437
  ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
438
  $out .= "<span class='$action'>$link$sep</span>";
439
  }
453
  * @param string $current_mode
454
  */
455
  protected function view_switcher( $current_mode ) {
456
+ ?>
457
+ <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
458
  <div class="view-switch">
459
+ <?php
460
  foreach ( $this->modes as $mode => $title ) {
461
  $classes = array( 'view-' . $mode );
462
  if ( $current_mode == $mode ) {
470
  esc_html( $title )
471
  );
472
  }
473
+ ?>
474
  </div>
475
+ <?php
476
  }
477
 
478
  /**
500
  * @access protected
501
  *
502
  * @param string $option
503
+ * @param int $default
 
504
  * @return int
505
  */
506
  protected function get_items_per_page( $option, $default = 20 ) {
538
  return;
539
  }
540
 
541
+ $total_items = $this->_pagination_args['total_items'];
542
+ $total_pages = $this->_pagination_args['total_pages'];
543
  $infinite_scroll = false;
544
  if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
545
  $infinite_scroll = $this->_pagination_args['infinite_scroll'];
546
  }
547
 
 
548
  $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'formidable' ), number_format_i18n( $total_items ) ) . '</span>';
549
 
550
  $current = $this->get_pagenum();
586
  );
587
  }
588
  $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
 
 
589
  $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'formidable' ), $html_current_page, $html_total_pages ) . $total_pages_after;
590
 
591
  $page_links[] = $this->add_page_link(
631
  'next' => false,
632
  );
633
 
634
+ if ( $current == 1 ) {
635
  $disable['first'] = true;
636
  $disable['prev'] = true;
637
+ } elseif ( $current == 2 ) {
638
  $disable['first'] = true;
639
  }
640
 
641
+ if ( $current == $total_pages ) {
642
  $disable['last'] = true;
643
  $disable['next'] = true;
644
+ } elseif ( $current == $total_pages - 1 ) {
645
  $disable['last'] = true;
646
  }
647
 
655
  'prev' => __( 'Previous page', 'formidable' ),
656
  'next' => __( 'Next page', 'formidable' ),
657
  );
 
658
  return $labels[ $link ];
659
  }
660
 
670
  } else {
671
  $link = $this->add_active_link( $atts );
672
  }
 
673
  return $link;
674
  }
675
 
678
  }
679
 
680
  private function add_active_link( $atts ) {
681
+ $url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
682
  $label = $this->link_label( $atts['page'] );
 
683
  return sprintf(
684
  "<a class='button %s-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
685
  $atts['page'],
716
  */
717
  protected function get_default_primary_column_name() {
718
  $columns = $this->get_columns();
719
+ $column = '';
720
 
721
  // We need a primary defined so responsive views show something,
722
  // so let's fall back to the first non-checkbox column.
758
  * @param string $default Column name default for the specific list table, e.g. 'name'.
759
  * @param string $context Screen ID for specific list table, e.g. 'plugins'.
760
  */
761
+ $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
762
 
763
  if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
764
  $column = $default;
789
  }
790
 
791
  $columns = get_column_headers( $this->screen );
792
+ $hidden = get_hidden_columns( $this->screen );
793
 
794
  $sortable_columns = $this->get_sortable_columns();
795
  /**
819
  }
820
 
821
  $primary = $this->get_primary_column_name();
 
822
  $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
823
 
824
  return $this->_column_headers;
835
  public function get_column_count() {
836
  list ( $columns, $hidden ) = $this->get_column_info();
837
  $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
 
838
  return count( $columns ) - count( $hidden );
839
  }
840
 
855
  $current_url = remove_query_arg( 'paged', $current_url );
856
 
857
  if ( isset( $_GET['orderby'] ) ) {
858
+ $current_orderby = sanitize_text_field( $_GET['orderby'] );
859
  } else {
860
  $current_orderby = '';
861
  }
868
 
869
  if ( ! empty( $columns['cb'] ) ) {
870
  static $cb_counter = 1;
871
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'formidable' ) . '</label>'
872
+ . '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />';
873
+ $cb_counter++;
874
  }
875
 
876
  foreach ( $columns as $column_key => $column_display_name ) {
882
 
883
  if ( 'cb' == $column_key ) {
884
  $class[] = 'check-column';
885
+ } else if ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
886
  $class[] = 'num';
887
  }
888
 
894
  list( $orderby, $desc_first ) = $sortable[ $column_key ];
895
 
896
  if ( $current_orderby == $orderby ) {
897
+ $order = 'asc' == $current_order ? 'desc' : 'asc';
898
  $class[] = 'sorted';
899
  $class[] = $current_order;
900
  } else {
901
+ $order = $desc_first ? 'desc' : 'asc';
902
  $class[] = 'sortable';
903
  $class[] = $desc_first ? 'asc' : 'desc';
904
  }
906
  $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . esc_html( $column_display_name ) . '</span><span class="sorting-indicator"></span></a>';
907
  }
908
 
909
+ $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
910
  $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
911
+ $id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : '';
912
 
913
  if ( ! empty( $class ) ) {
914
  $class = "class='" . esc_attr( join( ' ', $class ) ) . "'";
928
  $singular = $this->_args['singular'];
929
 
930
  $this->display_tablenav( 'top' );
931
+ ?>
932
+ <table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
933
+ <thead>
934
+ <tr>
935
+ <?php $this->print_column_headers(); ?>
936
+ </tr>
937
+ </thead>
938
+
939
+ <tbody id="the-list"<?php echo ( $singular ? " data-wp-lists='list:" . esc_attr( $singular ) . "'" : '' ); // WPCS: XSS ok. ?>>
940
+ <?php $this->display_rows_or_placeholder(); ?>
941
+ </tbody>
942
+
943
+ <tfoot>
944
+ <tr>
945
+ <?php $this->print_column_headers( false ); ?>
946
+ </tr>
947
+ </tfoot>
948
+
949
+ </table>
950
+ <?php
951
  $this->display_tablenav( 'bottom' );
952
  }
953
 
968
  *
969
  * @since 2.0.18
970
  * @access protected
 
971
  * @param string $which
972
  */
973
  protected function display_tablenav( $which ) {
974
  if ( 'top' == $which ) {
975
  wp_nonce_field( 'bulk-' . $this->_args['plural'] );
976
  }
977
+ ?>
978
+ <div class="tablenav <?php echo esc_attr( $which ); ?>">
 
 
 
 
 
 
 
 
979
 
980
+ <div class="alignleft actions bulkactions">
981
+ <?php $this->bulk_actions( $which ); ?>
982
  </div>
983
+ <?php
984
+ $this->extra_tablenav( $which );
985
+ $this->pagination( $which );
986
+ ?>
987
+
988
+ <br class="clear" />
989
+ </div>
990
+ <?php
991
  }
992
 
993
  /**
998
  *
999
  * @param string $which
1000
  */
1001
+ protected function extra_tablenav( $which ) {}
 
1002
 
1003
  /**
1004
  * Generate the tbody element for the list table.
1086
  * @since 4.3.0
1087
  * @access protected
1088
  *
1089
+ * @param object $item The item being acted upon.
1090
  * @param string $column_name Current column name.
1091
+ * @param string $primary Primary column name.
 
1092
  * @return string The row actions output. In this case, an empty string.
1093
  */
1094
  protected function handle_row_actions( $item, $column_name, $primary ) {
1095
  return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'formidable' ) . '</span></button>' : '';
1096
+ }
1097
 
1098
  /**
1099
  * Handle an incoming ajax request (called from admin-ajax.php)
1117
 
1118
  if ( isset( $this->_pagination_args['total_items'] ) ) {
1119
  $response['total_items_i18n'] = sprintf(
 
1120
  _n( '%s item', '%s items', $this->_pagination_args['total_items'], 'formidable' ),
1121
  number_format_i18n( $this->_pagination_args['total_items'] )
1122
  );
1123
  }
1124
  if ( isset( $this->_pagination_args['total_pages'] ) ) {
1125
+ $response['total_pages'] = $this->_pagination_args['total_pages'];
1126
  $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1127
  }
1128
 
classes/helpers/FrmShortcodeHelper.php CHANGED
@@ -9,7 +9,6 @@ class FrmShortcodeHelper {
9
  * Get the shortcode attributes in key/value pairs from a string
10
  *
11
  * @since 2.02.12
12
- *
13
  * @param string $text
14
  *
15
  * @return array
@@ -31,7 +30,6 @@ class FrmShortcodeHelper {
31
  * Get the name of the shortcode from the regEx
32
  *
33
  * @since 3.0
34
- *
35
  * @param array $shortcodes
36
  * @param int $short_key The position in the shortcodes array
37
  * @param array $args
@@ -55,16 +53,16 @@ class FrmShortcodeHelper {
55
  if ( $args['conditional_check'] ) {
56
  if ( $args['conditional'] ) {
57
  $prefix = 'if ';
58
- } elseif ( $args['foreach'] ) {
59
  $prefix = 'foreach ';
60
  }
61
  }
62
 
63
  $with_tags = $args['conditional_check'] ? 3 : 2;
64
  if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
65
- $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
66
- $tag = str_replace( ']', '', $tag );
67
- $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag );
68
  $tags = preg_split( '/\s+/', $tag, 2 );
69
  if ( is_array( $tags ) ) {
70
  $tag = $tags[0];
9
  * Get the shortcode attributes in key/value pairs from a string
10
  *
11
  * @since 2.02.12
 
12
  * @param string $text
13
  *
14
  * @return array
30
  * Get the name of the shortcode from the regEx
31
  *
32
  * @since 3.0
 
33
  * @param array $shortcodes
34
  * @param int $short_key The position in the shortcodes array
35
  * @param array $args
53
  if ( $args['conditional_check'] ) {
54
  if ( $args['conditional'] ) {
55
  $prefix = 'if ';
56
+ } else if ( $args['foreach'] ) {
57
  $prefix = 'foreach ';
58
  }
59
  }
60
 
61
  $with_tags = $args['conditional_check'] ? 3 : 2;
62
  if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
63
+ $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
64
+ $tag = str_replace( ']', '', $tag );
65
+ $tag = str_replace( chr( 194 ) . chr( 160 ), ' ', $tag );
66
  $tags = preg_split( '/\s+/', $tag, 2 );
67
  if ( is_array( $tags ) ) {
68
  $tag = $tags[0];
classes/helpers/FrmStylesHelper.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  class FrmStylesHelper {
4
 
5
  public static function get_upload_base() {
@@ -11,84 +10,15 @@ class FrmStylesHelper {
11
  return $uploads;
12
  }
13
 
14
- /**
15
- * @since 4.0
16
- */
17
- public static function get_style_menu( $active = '' ) {
18
- ob_start();
19
- self::style_menu( $active );
20
- $menu = ob_get_contents();
21
- ob_end_clean();
22
-
23
- return $menu;
24
- }
25
-
26
  public static function style_menu( $active = '' ) {
27
- ?>
28
- <ul class="frm_form_nav">
29
- <li>
30
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles' ) ); ?>"
31
- class="<?php echo ( '' == $active ) ? 'current_page' : ''; ?>">
32
- <?php esc_html_e( 'Edit Styles', 'formidable' ); ?>
33
- </a>
34
- </li>
35
- <li>
36
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=manage' ) ); ?>"
37
- class="<?php echo ( 'manage' == $active ) ? 'current_page' : ''; ?>">
38
- <?php esc_html_e( 'Manage Styles', 'formidable' ); ?>
39
- </a>
40
- </li>
41
- <li>
42
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=custom_css' ) ); ?>"
43
- class="<?php echo ( 'custom_css' == $active ) ? 'current_page' : ''; ?>">
44
- <?php esc_html_e( 'Custom CSS', 'formidable' ); ?>
45
- </a>
46
- </li>
47
- </ul>
48
- <?php
49
- }
50
-
51
- /**
52
- * @since 4.0
53
- */
54
- public static function styler_save_button( $atts ) {
55
- $style = $atts['style'];
56
- if ( ! empty( $style->ID ) && empty( $style->menu_order ) ) {
57
- $delete_link = admin_url( 'admin.php?page=formidable-styles&frm_action=destroy&id=' . $style->ID );
58
- }
59
-
60
- include( FrmAppHelper::plugin_path() . '/classes/views/styles/header-buttons.php' );
61
- }
62
-
63
- /**
64
- * Called from the admin header.
65
- *
66
- * @since 4.0
67
- */
68
- public static function save_button() {
69
- ?>
70
- <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" />
71
- <?php
72
- }
73
-
74
- /**
75
- * Either get the heading or the style switcher.
76
- *
77
- * @since 4.0
78
- */
79
- public static function styler_switcher( $atts ) {
80
- if ( has_action( 'frm_style_switcher_heading' ) ) {
81
- do_action( 'frm_style_switcher_heading', $atts );
82
- } else {
83
- ?>
84
- <div class="frm_top_left">
85
- <h1>
86
- <?php echo esc_html( $atts['style']->post_title ); ?>
87
- </h1>
88
- </div>
89
- <?php
90
- }
91
- }
92
 
93
  /**
94
  * @since 2.05
@@ -144,31 +74,31 @@ class FrmStylesHelper {
144
  $minus_icons = self::minus_icons();
145
 
146
  return array(
147
- 6 => array(
148
  '-' => '62d',
149
  '+' => '62a',
150
  ),
151
- 0 => array(
152
  '-' => '60d',
153
  '+' => '609',
154
  ),
155
- 1 => array(
156
  '-' => '60e',
157
  '+' => '60c',
158
  ),
159
- 2 => array(
160
  '-' => '630',
161
  '+' => '631',
162
  ),
163
- 3 => array(
164
  '-' => '62b',
165
  '+' => '628',
166
  ),
167
- 4 => array(
168
  '-' => '62c',
169
  '+' => '629',
170
  ),
171
- 5 => array(
172
  '-' => '635',
173
  '+' => '634',
174
  ),
@@ -180,10 +110,10 @@ class FrmStylesHelper {
180
  );
181
  }
182
 
183
- /**
184
- * @since 2.0
185
- * @return The class for this icon
186
- */
187
  public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
188
  if ( 'arrow' == $type && is_numeric( $key ) ) {
189
  //frm_arrowup6_icon
@@ -194,62 +124,61 @@ class FrmStylesHelper {
194
  $class = 'frm_arrow' . $arrow[ $icon ];
195
  } else {
196
  //frm_minus1_icon
197
- $key = str_replace( 'p', '', $key );
198
- $plus = array(
199
  '-' => 'minus',
200
  '+' => 'plus',
201
  );
202
  $class = 'frm_' . $plus[ $icon ];
203
  }
204
 
205
- if ( $key ) {
206
- $class .= $key;
207
- }
208
- $class .= '_icon';
209
 
210
- return $class;
211
- }
212
 
213
  public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
214
  $function_name = $type . '_icons';
215
- $icons = self::$function_name();
216
  unset( $function_name );
217
 
218
- $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
219
- ?>
220
- <select name="<?php echo esc_attr( $frm_style->get_field_name( $name ) ); ?>"
221
- id="frm_<?php echo esc_attr( $name ); ?>" class="frm_icon_font frm_multiselect hide-if-js">
222
- <?php foreach ( $icons as $key => $icon ) { ?>
223
- <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $style->post_content[ $name ], $key ); ?>>
224
- <?php echo '&#xe' . esc_html( $icon['+'] ) . '; &#xe' . esc_html( $icon['-'] ) . ';'; ?>
225
- </option>
226
- <?php } ?>
227
- </select>
228
-
229
- <div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ); ?>_select">
230
- <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
231
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?>"></i>
232
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ); ?>"></i>
233
- <b class="caret"></b>
234
- </button>
235
- <ul class="multiselect-container frm-dropdown-menu">
236
- <?php foreach ( $icons as $key => $icon ) { ?>
237
- <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : ''; ?>>
238
- <a href="javascript:void(0);">
239
- <label>
240
- <input type="radio" value="<?php echo esc_attr( $key ); ?>"/>
241
- <span>
242
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '+', $type ) ); ?>"></i>
243
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '-', $type ) ); ?>"></i>
244
- </span>
245
- </label>
246
- </a>
247
- </li>
248
- <?php } ?>
249
- </ul>
250
- </div>
251
- <?php
252
- }
253
 
254
  public static function hex2rgb( $hex ) {
255
  $hex = str_replace( '#', '', $hex );
@@ -257,27 +186,16 @@ class FrmStylesHelper {
257
  list( $r, $g, $b ) = sscanf( $hex, '%02x%02x%02x' );
258
 
259
  $rgb = array( $r, $g, $b );
260
-
261
  return implode( ',', $rgb );
262
  }
263
 
264
- /**
265
- * @since 4.0
266
- */
267
- public static function hex2rgba( $hex, $a ) {
268
- $rgb = self::hex2rgb( $hex );
269
-
270
- return 'rgba(' . $rgb . ',' . $a . ')';
271
- }
272
-
273
  /**
274
  * @param $hex string - The original color in hex format #ffffff
275
  * @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter
276
- *
277
  * @since 2.3
278
  */
279
  public static function adjust_brightness( $hex, $steps ) {
280
- $steps = max( - 255, min( 255, $steps ) );
281
 
282
  // Normalize into a six character long hex string
283
  $hex = str_replace( '#', '', $hex );
@@ -289,11 +207,11 @@ class FrmStylesHelper {
289
 
290
  // Split into three parts: R, G and B
291
  $color_parts = str_split( $hex, 2 );
292
- $return = '#';
293
 
294
  foreach ( $color_parts as $color ) {
295
- $color = hexdec( $color ); // Convert to decimal
296
- $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
297
  $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
298
  }
299
 
@@ -306,24 +224,24 @@ class FrmStylesHelper {
306
  public static function get_settings_for_output( $style ) {
307
  if ( self::previewing_style() ) {
308
  if ( isset( $_POST['frm_style_setting'] ) && isset( $_POST['frm_style_setting']['post_content'] ) ) {
309
- $settings = wp_unslash( $_POST['frm_style_setting']['post_content'] );
310
  } else {
311
  $settings = $_GET;
312
  }
313
  FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
314
 
315
- $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
316
  $settings['style_class'] = '';
317
  if ( ! empty( $style_name ) ) {
318
  $settings['style_class'] = $style_name . '.';
319
  }
320
  } else {
321
- $settings = $style->post_content;
322
  $settings['style_class'] = 'frm_style_' . $style->post_name . '.';
323
  }
324
 
325
- $settings['style_class'] .= 'with_frm_style';
326
- $settings['font'] = stripslashes( $settings['font'] );
327
  $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
328
 
329
  $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
@@ -358,18 +276,9 @@ class FrmStylesHelper {
358
  */
359
  private static function allow_color_override() {
360
  $frm_style = new FrmStyle();
361
- $colors = $frm_style->get_color_settings();
362
-
363
- $transparent = array(
364
- 'fieldset_color',
365
- 'fieldset_bg_color',
366
- 'bg_color',
367
- 'section_bg_color',
368
- 'error_bg',
369
- 'success_bg_color',
370
- 'progress_bg_color',
371
- 'progress_active_bg_color',
372
- );
373
 
374
  return array(
375
  'transparent' => $transparent,
@@ -397,15 +306,14 @@ class FrmStylesHelper {
397
  */
398
  private static function description_margin_for_screensize( $width ) {
399
  $temp_label_width = str_replace( 'px', '', $width );
400
- $change_margin = false;
401
  if ( $temp_label_width >= 230 ) {
402
  $change_margin = '800px';
403
- } elseif ( $width >= 215 ) {
404
  $change_margin = '700px';
405
- } elseif ( $width >= 180 ) {
406
  $change_margin = '650px';
407
  }
408
-
409
  return $change_margin;
410
  }
411
 
@@ -414,7 +322,6 @@ class FrmStylesHelper {
414
  */
415
  public static function previewing_style() {
416
  $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] );
417
-
418
  return $ajax_change || isset( $_GET['flat'] );
419
  }
420
 
1
  <?php
 
2
  class FrmStylesHelper {
3
 
4
  public static function get_upload_base() {
10
  return $uploads;
11
  }
12
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  public static function style_menu( $active = '' ) {
14
+ ?>
15
+ <h2 class="nav-tab-wrapper">
16
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles' ) ) ?>" class="nav-tab <?php echo ( '' == $active ) ? 'nav-tab-active' : '' ?>"><?php esc_html_e( 'Edit Styles', 'formidable' ) ?></a>
17
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=manage' ) ) ?>" class="nav-tab <?php echo ( 'manage' == $active ) ? 'nav-tab-active' : '' ?>"><?php esc_html_e( 'Manage Form Styles', 'formidable' ) ?></a>
18
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=custom_css' ) ); ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Custom CSS', 'formidable' ); ?></a>
19
+ </h2>
20
+ <?php
21
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  /**
24
  * @since 2.05
74
  $minus_icons = self::minus_icons();
75
 
76
  return array(
77
+ 6 => array(
78
  '-' => '62d',
79
  '+' => '62a',
80
  ),
81
+ 0 => array(
82
  '-' => '60d',
83
  '+' => '609',
84
  ),
85
+ 1 => array(
86
  '-' => '60e',
87
  '+' => '60c',
88
  ),
89
+ 2 => array(
90
  '-' => '630',
91
  '+' => '631',
92
  ),
93
+ 3 => array(
94
  '-' => '62b',
95
  '+' => '628',
96
  ),
97
+ 4 => array(
98
  '-' => '62c',
99
  '+' => '629',
100
  ),
101
+ 5 => array(
102
  '-' => '635',
103
  '+' => '634',
104
  ),
110
  );
111
  }
112
 
113
+ /**
114
+ * @since 2.0
115
+ * @return The class for this icon
116
+ */
117
  public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
118
  if ( 'arrow' == $type && is_numeric( $key ) ) {
119
  //frm_arrowup6_icon
124
  $class = 'frm_arrow' . $arrow[ $icon ];
125
  } else {
126
  //frm_minus1_icon
127
+ $key = str_replace( 'p', '', $key );
128
+ $plus = array(
129
  '-' => 'minus',
130
  '+' => 'plus',
131
  );
132
  $class = 'frm_' . $plus[ $icon ];
133
  }
134
 
135
+ if ( $key ) {
136
+ $class .= $key;
137
+ }
138
+ $class .= '_icon';
139
 
140
+ return $class;
141
+ }
142
 
143
  public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
144
  $function_name = $type . '_icons';
145
+ $icons = self::$function_name();
146
  unset( $function_name );
147
 
148
+ $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
149
+ ?>
150
+ <select name="<?php echo esc_attr( $frm_style->get_field_name( $name ) ); ?>" id="frm_<?php echo esc_attr( $name ); ?>" class="frm_icon_font frm_multiselect hide-if-js">
151
+ <?php foreach ( $icons as $key => $icon ) { ?>
152
+ <option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[ $name ], $key ) ?>>
153
+ <?php echo '&#xe' . esc_html( $icon['+'] ) . '; &#xe' . esc_html( $icon['-'] ) . ';'; ?>
154
+ </option>
155
+ <?php } ?>
156
+ </select>
157
+
158
+ <div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ) ?>_select">
159
+ <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
160
+ <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ) ?>"></i>
161
+ <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ) ?>"></i>
162
+ <b class="caret"></b>
163
+ </button>
164
+ <ul class="multiselect-container frm-dropdown-menu">
165
+ <?php foreach ( $icons as $key => $icon ) { ?>
166
+ <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : '' ?>>
167
+ <a href="javascript:void(0);">
168
+ <label>
169
+ <input type="radio" value="<?php echo esc_attr( $key ) ?>"/>
170
+ <span>
171
+ <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '+', $type ) ) ?>"></i>
172
+ <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '-', $type ) ) ?>"></i>
173
+ </span>
174
+ </label>
175
+ </a>
176
+ </li>
177
+ <?php } ?>
178
+ </ul>
179
+ </div>
180
+ <?php
181
+ }
 
182
 
183
  public static function hex2rgb( $hex ) {
184
  $hex = str_replace( '#', '', $hex );
186
  list( $r, $g, $b ) = sscanf( $hex, '%02x%02x%02x' );
187
 
188
  $rgb = array( $r, $g, $b );
 
189
  return implode( ',', $rgb );
190
  }
191
 
 
 
 
 
 
 
 
 
 
192
  /**
193
  * @param $hex string - The original color in hex format #ffffff
194
  * @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter
 
195
  * @since 2.3
196
  */
197
  public static function adjust_brightness( $hex, $steps ) {
198
+ $steps = max( -255, min( 255, $steps ) );
199
 
200
  // Normalize into a six character long hex string
201
  $hex = str_replace( '#', '', $hex );
207
 
208
  // Split into three parts: R, G and B
209
  $color_parts = str_split( $hex, 2 );
210
+ $return = '#';
211
 
212
  foreach ( $color_parts as $color ) {
213
+ $color = hexdec( $color ); // Convert to decimal
214
+ $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
215
  $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
216
  }
217
 
224
  public static function get_settings_for_output( $style ) {
225
  if ( self::previewing_style() ) {
226
  if ( isset( $_POST['frm_style_setting'] ) && isset( $_POST['frm_style_setting']['post_content'] ) ) {
227
+ $settings = $_POST['frm_style_setting']['post_content'];
228
  } else {
229
  $settings = $_GET;
230
  }
231
  FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
232
 
233
+ $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
234
  $settings['style_class'] = '';
235
  if ( ! empty( $style_name ) ) {
236
  $settings['style_class'] = $style_name . '.';
237
  }
238
  } else {
239
+ $settings = $style->post_content;
240
  $settings['style_class'] = 'frm_style_' . $style->post_name . '.';
241
  }
242
 
243
+ $settings['style_class'] .= 'with_frm_style';
244
+ $settings['font'] = stripslashes( $settings['font'] );
245
  $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
246
 
247
  $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
276
  */
277
  private static function allow_color_override() {
278
  $frm_style = new FrmStyle();
279
+ $colors = $frm_style->get_color_settings();
280
+
281
+ $transparent = array( 'fieldset_color', 'fieldset_bg_color', 'bg_color', 'section_bg_color', 'error_bg', 'success_bg_color', 'progress_bg_color', 'progress_active_bg_color' );
 
 
 
 
 
 
 
 
 
282
 
283
  return array(
284
  'transparent' => $transparent,
306
  */
307
  private static function description_margin_for_screensize( $width ) {
308
  $temp_label_width = str_replace( 'px', '', $width );
309
+ $change_margin = false;
310
  if ( $temp_label_width >= 230 ) {
311
  $change_margin = '800px';
312
+ } else if ( $width >= 215 ) {
313
  $change_margin = '700px';
314
+ } else if ( $width >= 180 ) {
315
  $change_margin = '650px';
316
  }
 
317
  return $change_margin;
318
  }
319
 
322
  */
323
  public static function previewing_style() {
324
  $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] );
 
325
  return $ajax_change || isset( $_GET['flat'] );
326
  }
327
 
classes/helpers/FrmTipsHelper.php CHANGED
@@ -8,7 +8,7 @@ class FrmTipsHelper {
8
  }
9
 
10
  $tips = self::$callback();
11
- $tip = self::get_random_tip( $tips );
12
 
13
  if ( 'p' === $html ) {
14
  echo '<p>';
@@ -25,11 +25,11 @@ class FrmTipsHelper {
25
  ?>
26
  <a href="<?php echo esc_url( $link ); ?>" target="_blank" class="frm_pro_tip">
27
  <span>
28
- <i class="frm_icon_font frm_check1_icon"></i> <?php esc_html_e( 'Pro Tip:', 'formidable' ); ?>
29
  </span>
30
- <?php echo esc_html( $tip['tip'] ); ?>
31
  <?php if ( isset( $tip['call'] ) ) { ?>
32
- <span><?php echo esc_html( $tip['call'] ); ?></span>
33
  <?php } ?>
34
  </a>
35
  <?php
@@ -126,7 +126,6 @@ class FrmTipsHelper {
126
  'call' => __( 'Add form scheduling.', 'formidable' ),
127
  ),
128
  );
129
-
130
  return $tips;
131
  }
132
 
@@ -236,7 +235,6 @@ class FrmTipsHelper {
236
  'call' => __( 'Use multiple style templates.', 'formidable' ),
237
  ),
238
  );
239
-
240
  return $tips;
241
  }
242
 
@@ -268,7 +266,6 @@ class FrmTipsHelper {
268
  ),
269
  );
270
  $tips = array_merge( $tips, self::get_import_tip() );
271
-
272
  return $tips;
273
  }
274
 
@@ -283,12 +280,11 @@ class FrmTipsHelper {
283
  'call' => __( 'Upgrade to Pro.', 'formidable' ),
284
  ),
285
  );
286
-
287
  return $tips;
288
  }
289
 
290
  public static function get_banner_tip() {
291
- $tips = array(
292
  array(
293
  'link' => array(
294
  'medium' => 'banner',
@@ -314,16 +310,14 @@ class FrmTipsHelper {
314
  'call' => __( 'Collect instant payments, and send leads to MailChimp.', 'formidable' ),
315
  ),
316
  );
317
- $random = rand( 0, count( $tips ) - 1 );
318
- $tip = $tips[ $random ];
319
  $tip['num'] = $random;
320
-
321
  return $tip;
322
  }
323
 
324
  public static function get_random_tip( $tips ) {
325
  $random = rand( 0, count( $tips ) - 1 );
326
-
327
  return $tips[ $random ];
328
  }
329
  }
8
  }
9
 
10
  $tips = self::$callback();
11
+ $tip = self::get_random_tip( $tips );
12
 
13
  if ( 'p' === $html ) {
14
  echo '<p>';
25
  ?>
26
  <a href="<?php echo esc_url( $link ); ?>" target="_blank" class="frm_pro_tip">
27
  <span>
28
+ <i class="frm_icon_font frm_check1_icon"></i> <?php esc_html_e( 'Pro Tip:', 'formidable' ); ?>
29
  </span>
30
+ <?php echo esc_html( $tip['tip'] ) ?>
31
  <?php if ( isset( $tip['call'] ) ) { ?>
32
+ <span><?php echo esc_html( $tip['call'] ) ?></span>
33
  <?php } ?>
34
  </a>
35
  <?php
126
  'call' => __( 'Add form scheduling.', 'formidable' ),
127
  ),
128
  );
 
129
  return $tips;
130
  }
131
 
235
  'call' => __( 'Use multiple style templates.', 'formidable' ),
236
  ),
237
  );
 
238
  return $tips;
239
  }
240
 
266
  ),
267
  );
268
  $tips = array_merge( $tips, self::get_import_tip() );
 
269
  return $tips;
270
  }
271
 
280
  'call' => __( 'Upgrade to Pro.', 'formidable' ),
281
  ),
282
  );
 
283
  return $tips;
284
  }
285
 
286
  public static function get_banner_tip() {
287
+ $tips = array(
288
  array(
289
  'link' => array(
290
  'medium' => 'banner',
310
  'call' => __( 'Collect instant payments, and send leads to MailChimp.', 'formidable' ),
311
  ),
312
  );
313
+ $random = rand( 0, count( $tips ) - 1 );
314
+ $tip = $tips[ $random ];
315
  $tip['num'] = $random;
 
316
  return $tip;
317
  }
318
 
319
  public static function get_random_tip( $tips ) {
320
  $random = rand( 0, count( $tips ) - 1 );
 
321
  return $tips[ $random ];
322
  }
323
  }
classes/helpers/FrmXMLHelper.php CHANGED
@@ -25,13 +25,13 @@ class FrmXMLHelper {
25
  public static function import_xml( $file ) {
26
  if ( ! defined( 'WP_IMPORTING' ) ) {
27
  define( 'WP_IMPORTING', true );
28
- }
29
 
30
  if ( ! class_exists( 'DOMDocument' ) ) {
31
- return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
32
- }
33
 
34
- $dom = new DOMDocument();
35
  $success = $dom->loadXML( file_get_contents( $file ) );
36
  if ( ! $success ) {
37
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
@@ -62,13 +62,13 @@ class FrmXMLHelper {
62
  $imported = self::pre_import_data();
63
 
64
  foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
65
- // Grab cats, tags, and terms, or forms or posts.
66
  if ( isset( $xml->{$item_type} ) ) {
67
  $function_name = 'import_xml_' . $item_type . 's';
68
- $imported = self::$function_name( $xml->{$item_type}, $imported );
69
  unset( $function_name, $xml->{$item_type} );
70
- }
71
- }
72
 
73
  return apply_filters( 'frm_importing_xml', $imported, $xml );
74
  }
@@ -97,9 +97,9 @@ class FrmXMLHelper {
97
  }
98
 
99
  public static function import_xml_terms( $terms, $imported ) {
100
- foreach ( $terms as $t ) {
101
  if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
102
- continue;
103
  }
104
 
105
  $parent = self::get_term_parent_id( $t );
@@ -108,22 +108,22 @@ class FrmXMLHelper {
108
  (string) $t->term_name,
109
  (string) $t->term_taxonomy,
110
  array(
111
- 'slug' => (string) $t->term_slug,
112
- 'description' => (string) $t->term_description,
113
- 'parent' => empty( $parent ) ? 0 : $parent,
114
  )
115
  );
116
 
117
  if ( $term && is_array( $term ) ) {
118
- $imported['imported']['terms'] ++;
119
  $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
120
- }
121
 
122
  unset( $term, $t );
123
  }
124
 
125
  return $imported;
126
- }
127
 
128
  /**
129
  * @since 2.0.8
@@ -138,7 +138,6 @@ class FrmXMLHelper {
138
  $parent = 0;
139
  }
140
  }
141
-
142
  return $parent;
143
  }
144
 
@@ -149,45 +148,41 @@ class FrmXMLHelper {
149
  self::put_child_forms_first( $forms );
150
 
151
  foreach ( $forms as $item ) {
152
- $form = self::fill_form( $item );
153
 
154
  self::update_custom_style_setting_on_import( $form );
155
 
156
- $this_form = self::maybe_get_form( $form );
157
 
158
- $old_id = false;
159
  $form_fields = false;
160
  if ( ! empty( $this_form ) ) {
161
  $form_id = $this_form->id;
162
- $old_id = $this_form->id;
163
  self::update_form( $this_form, $form, $imported );
164
 
165
  $form_fields = self::get_form_fields( $form_id );
166
  } else {
167
  $form_id = FrmForm::create( $form );
168
- if ( $form_id ) {
169
- if ( empty( $form['parent_form_id'] ) ) {
170
- // Don't include the repeater form in the imported count.
171
- $imported['imported']['forms'] ++;
172
- }
173
-
174
- // Keep track of whether this specific form was updated or not.
175
  $imported['form_status'][ $form_id ] = 'imported';
176
  self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
177
- }
178
  }
179
 
180
  self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );
181
 
182
  self::delete_removed_fields( $form_fields );
183
 
184
- // Update field ids/keys to new ones.
185
  do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
186
 
187
  $imported['forms'][ (int) $item->id ] = $form_id;
188
 
189
- // Send pre 2.0 form options through function that creates actions.
190
- self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, true );
191
 
192
  do_action( 'frm_after_import_form', $form_id, $form );
193
 
@@ -197,25 +192,23 @@ class FrmXMLHelper {
197
  self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
198
 
199
  return $imported;
200
- }
201
 
202
  private static function fill_form( $item ) {
203
  $form = array(
204
- 'id' => (int) $item->id,
205
- 'form_key' => (string) $item->form_key,
206
- 'name' => (string) $item->name,
207
- 'description' => (string) $item->description,
208
- 'options' => (string) $item->options,
209
- 'logged_in' => (int) $item->logged_in,
210
- 'is_template' => (int) $item->is_template,
211
- 'editable' => (int) $item->editable,
212
- 'status' => (string) $item->status,
213
  'parent_form_id' => isset( $item->parent_form_id ) ? (int) $item->parent_form_id : 0,
214
- 'created_at' => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ),
215
  );
216
-
217
  $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
218
-
219
  return $form;
220
  }
221
 
@@ -237,25 +230,20 @@ class FrmXMLHelper {
237
  private static function update_form( $this_form, $form, &$imported ) {
238
  $form_id = $this_form->id;
239
  FrmForm::update( $form_id, $form );
240
- if ( empty( $form['parent_form_id'] ) ) {
241
- // Don't include the repeater form in the updated count.
242
- $imported['updated']['forms'] ++;
243
- }
244
-
245
  // Keep track of whether this specific form was updated or not
246
  $imported['form_status'][ $form_id ] = 'updated';
247
  }
248
 
249
  private static function get_form_fields( $form_id ) {
250
  $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
251
- $old_fields = array();
252
  foreach ( $form_fields as $f ) {
253
- $old_fields[ $f->id ] = $f;
254
  $old_fields[ $f->field_key ] = $f->id;
255
  unset( $f );
256
  }
257
  $form_fields = $old_fields;
258
-
259
  return $form_fields;
260
  }
261
 
@@ -274,14 +262,13 @@ class FrmXMLHelper {
274
  }
275
 
276
  /**
277
- * Put child forms first so they will be imported before parents
278
- *
279
- * @since 2.0.16
280
- *
281
- * @param array $forms
282
- */
283
  private static function put_child_forms_first( &$forms ) {
284
- $child_forms = array();
285
  $regular_forms = array();
286
 
287
  foreach ( $forms as $form ) {
@@ -298,14 +285,13 @@ class FrmXMLHelper {
298
  }
299
 
300
  /**
301
- * Keep track of all imported child forms
302
- *
303
- * @since 2.0.16
304
- *
305
- * @param int $form_id
306
- * @param int $parent_form_id
307
- * @param array $child_forms
308
- */
309
  private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
310
  if ( $parent_form_id ) {
311
  $child_forms[ $form_id ] = $parent_form_id;
@@ -313,14 +299,13 @@ class FrmXMLHelper {
313
  }
314
 
315
  /**
316
- * Update the parent_form_id on imported child forms
317
- * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported
318
- *
319
- * @since 2.0.6
320
- *
321
- * @param array $imported_forms
322
- * @param array $child_forms
323
- */
324
  private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
325
  foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
326
 
@@ -334,30 +319,19 @@ class FrmXMLHelper {
334
  }
335
 
336
  /**
337
- * Import all fields for a form
338
- *
339
- * @since 2.0.13
340
  *
341
- * TODO: Cut down on params
342
- */
 
 
343
  private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
344
  $in_section = 0;
345
 
346
  foreach ( $xml_fields as $field ) {
347
  $f = self::fill_field( $field, $form_id );
348
 
349
- $has_default = array(
350
- 'text',
351
- 'email',
352
- 'url',
353
- 'textarea',
354
- 'number',
355
- 'phone',
356
- 'date',
357
- 'hidden',
358
- 'password',
359
- 'tag',
360
- );
361
  if ( is_array( $f['default_value'] ) && in_array( $f['type'], $has_default, true ) ) {
362
  if ( count( $f['default_value'] ) === 1 ) {
363
  $f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
@@ -374,7 +348,7 @@ class FrmXMLHelper {
374
  // check for field to edit by field id
375
  if ( isset( $form_fields[ $f['id'] ] ) ) {
376
  FrmField::update( $f['id'], $f );
377
- $imported['updated']['fields'] ++;
378
 
379
  unset( $form_fields[ $f['id'] ] );
380
 
@@ -382,12 +356,12 @@ class FrmXMLHelper {
382
  if ( isset( $form_fields[ $f['field_key'] ] ) ) {
383
  unset( $form_fields[ $f['field_key'] ] );
384
  }
385
- } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
386
  // check for field to edit by field key
387
  unset( $f['id'] );
388
 
389
  FrmField::update( $form_fields[ $f['field_key'] ], $f );
390
- $imported['updated']['fields'] ++;
391
 
392
  unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
393
  unset( $form_fields[ $f['field_key'] ] ); //unset old field key
@@ -422,7 +396,6 @@ class FrmXMLHelper {
422
  * Update the current in_section value
423
  *
424
  * @since 2.0.25
425
- *
426
  * @param int $in_section
427
  * @param array $f
428
  */
@@ -444,13 +417,12 @@ class FrmXMLHelper {
444
  }
445
 
446
  /**
447
- * Switch the form_select on a repeating field or embedded form if it needs to be switched
448
- *
449
- * @since 2.0.16
450
- *
451
- * @param array $f
452
- * @param array $imported
453
- */
454
  private static function maybe_update_form_select( &$f, $imported ) {
455
  if ( ! isset( $imported['forms'] ) ) {
456
  return;
@@ -470,7 +442,6 @@ class FrmXMLHelper {
470
  * Update the get_values_form setting if the form was imported
471
  *
472
  * @since 2.01.0
473
- *
474
  * @param array $imported
475
  * @param array $f
476
  */
@@ -491,7 +462,6 @@ class FrmXMLHelper {
491
  * Create an imported field
492
  *
493
  * @since 2.0.25
494
- *
495
  * @param array $f
496
  * @param array $imported
497
  */
@@ -501,19 +471,18 @@ class FrmXMLHelper {
501
 
502
  $new_id = FrmField::create( $f );
503
  if ( $new_id != false ) {
504
- $imported['imported']['fields'] ++;
505
  do_action( 'frm_after_field_is_imported', $f, $new_id );
506
  }
507
  }
508
 
509
  /**
510
- * Updates the custom style setting on import
511
- * Convert the post slug to an ID
512
- *
513
- * @since 2.0.19
514
- *
515
- * @param array $form
516
- */
517
  private static function update_custom_style_setting_on_import( &$form ) {
518
  if ( ! isset( $form['options']['custom_style'] ) ) {
519
  return;
@@ -525,12 +494,12 @@ class FrmXMLHelper {
525
  } else {
526
  // Replace the style name with the style ID on import
527
  global $wpdb;
528
- $table = $wpdb->prefix . 'posts';
529
- $where = array(
530
  'post_name' => $form['options']['custom_style'],
531
  'post_type' => 'frm_styles',
532
  );
533
- $select = 'ID';
534
  $style_id = FrmDb::get_var( $table, $where, $select );
535
 
536
  if ( $style_id ) {
@@ -555,8 +524,8 @@ class FrmXMLHelper {
555
  $form = FrmForm::getOne( $form_id );
556
 
557
  if ( $form && isset( $form->options['old_style'] ) ) {
558
- $form = (array) $form;
559
- $saved_style = $form['options']['custom_style'];
560
  $form['options']['custom_style'] = $form['options']['old_style'];
561
  self::update_custom_style_setting_on_import( $form );
562
  $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
@@ -567,80 +536,80 @@ class FrmXMLHelper {
567
  }
568
 
569
  public static function import_xml_views( $views, $imported ) {
570
- $imported['posts'] = array();
571
- $form_action_type = FrmFormActionsController::$action_post_type;
572
 
573
- $post_types = array(
574
- 'frm_display' => 'views',
575
- $form_action_type => 'actions',
576
- 'frm_styles' => 'styles',
577
- );
578
 
579
- foreach ( $views as $item ) {
580
  $post = array(
581
- 'post_title' => (string) $item->title,
582
- 'post_name' => (string) $item->post_name,
583
- 'post_type' => (string) $item->post_type,
584
- 'post_password' => (string) $item->post_password,
585
- 'guid' => (string) $item->guid,
586
- 'post_status' => (string) $item->status,
587
- 'post_author' => FrmAppHelper::get_user_id_param( (string) $item->post_author ),
588
- 'post_id' => (int) $item->post_id,
589
- 'post_parent' => (int) $item->post_parent,
590
- 'menu_order' => (int) $item->menu_order,
591
- 'post_content' => FrmFieldsHelper::switch_field_ids( (string) $item->content ),
592
- 'post_excerpt' => FrmFieldsHelper::switch_field_ids( (string) $item->excerpt ),
593
- 'is_sticky' => (string) $item->is_sticky,
594
  'comment_status' => (string) $item->comment_status,
595
- 'post_date' => (string) $item->post_date,
596
- 'post_date_gmt' => (string) $item->post_date_gmt,
597
- 'ping_status' => (string) $item->ping_status,
598
- 'postmeta' => array(),
599
- 'tax_input' => array(),
600
  );
601
 
602
- $old_id = $post['post_id'];
603
  self::populate_post( $post, $item, $imported );
604
 
605
  unset( $item );
606
 
607
  $post_id = false;
608
- if ( $post['post_type'] == $form_action_type ) {
609
- $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
610
  if ( $action_control && is_object( $action_control ) ) {
611
  $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
612
  }
613
  unset( $action_control );
614
- } elseif ( $post['post_type'] == 'frm_styles' ) {
615
- // Properly encode post content before inserting the post
616
- $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
617
- $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
618
- $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
619
-
620
- // Create/update post now
621
- $post_id = wp_insert_post( $post );
622
  self::maybe_update_custom_css( $custom_css );
623
- } else {
624
- // Create/update post now
625
- $post_id = wp_insert_post( $post );
626
- }
627
 
628
  if ( ! is_numeric( $post_id ) ) {
629
- continue;
630
- }
631
 
632
  self::update_postmeta( $post, $post_id );
633
 
634
- $this_type = 'posts';
635
  if ( isset( $post_types[ $post['post_type'] ] ) ) {
636
  $this_type = $post_types[ $post['post_type'] ];
637
- }
638
 
639
  if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
640
- $imported['updated'][ $this_type ] ++;
641
- } else {
642
- $imported['imported'][ $this_type ] ++;
643
- }
644
 
645
  $imported['posts'][ (int) $old_id ] = $post_id;
646
 
@@ -652,16 +621,16 @@ class FrmXMLHelper {
652
  self::maybe_update_stylesheet( $imported );
653
 
654
  return $imported;
655
- }
656
 
657
- private static function populate_post( &$post, $item, $imported ) {
658
  if ( isset( $item->attachment_url ) ) {
659
  $post['attachment_url'] = (string) $item->attachment_url;
660
  }
661
 
662
  if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
663
- // update to new form id
664
- $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
665
  }
666
 
667
  // Don't allow default styles to take over a site's default style
@@ -677,57 +646,57 @@ class FrmXMLHelper {
677
  self::populate_taxonomies( $post, $item );
678
 
679
  self::maybe_editing_post( $post );
680
- }
681
 
682
- private static function populate_postmeta( &$post, $meta, $imported ) {
683
- global $frm_duplicate_ids;
684
 
685
- $m = array(
686
  'key' => (string) $meta->meta_key,
687
  'value' => (string) $meta->meta_value,
688
  );
689
 
690
  //switch old form and field ids to new ones
691
  if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
692
- $m['value'] = $imported['forms'][ (int) $m['value'] ];
693
  } else {
694
- $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
695
 
696
  if ( ! empty( $frm_duplicate_ids ) ) {
697
 
698
- if ( $m['key'] == 'frm_dyncontent' ) {
699
  $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
700
- } elseif ( $m['key'] == 'frm_options' ) {
701
 
702
  foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
703
  if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
704
  $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
705
- }
706
- }
707
-
708
- $check_dup_array = array();
709
- if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
710
- if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
711
- $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
712
- } elseif ( is_array( $m['value']['order_by'] ) ) {
713
- $check_dup_array[] = 'order_by';
714
- }
715
- }
716
-
717
- if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
718
- $check_dup_array[] = 'where';
719
- }
720
-
721
- foreach ( $check_dup_array as $check_k ) {
722
  foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
723
  if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
724
  $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
725
- }
726
  unset( $mk, $mv );
727
- }
728
- }
729
- }
730
- }
731
  }
732
 
733
  if ( ! is_array( $m['value'] ) ) {
@@ -735,32 +704,32 @@ class FrmXMLHelper {
735
  }
736
 
737
  $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
738
- }
739
 
740
- /**
741
- * Add terms to post
742
  *
743
- * @param array $post by reference
744
- * @param object $item The XML object data
745
- */
746
- private static function populate_taxonomies( &$post, $item ) {
747
  foreach ( $item->category as $c ) {
748
  $att = $c->attributes();
749
  if ( ! isset( $att['nicename'] ) ) {
750
- continue;
751
- }
752
 
753
- $taxonomy = (string) $att['domain'];
754
  if ( is_taxonomy_hierarchical( $taxonomy ) ) {
755
- $name = (string) $att['nicename'];
756
  $h_term = get_term_by( 'slug', $name, $taxonomy );
757
- if ( $h_term ) {
758
- $name = $h_term->term_id;
759
- }
760
  unset( $h_term );
761
- } else {
762
- $name = (string) $c;
763
- }
764
 
765
  if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
766
  $post['tax_input'][ $taxonomy ] = array();
@@ -769,21 +738,21 @@ class FrmXMLHelper {
769
  $post['tax_input'][ $taxonomy ][] = $name;
770
  unset( $name );
771
  }
772
- }
773
 
774
- /**
775
- * Edit post if the key and created time match
776
- */
777
- private static function maybe_editing_post( &$post ) {
778
  $match_by = array(
779
- 'post_type' => $post['post_type'],
780
- 'name' => $post['post_name'],
781
- 'post_status' => $post['post_status'],
782
- 'posts_per_page' => 1,
783
  );
784
 
785
  if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
786
- $match_by['include'] = $post['post_id'];
787
  unset( $match_by['name'] );
788
  }
789
 
@@ -793,23 +762,23 @@ class FrmXMLHelper {
793
  // set the id of the post to edit
794
  $post['ID'] = current( $editing )->ID;
795
  }
796
- }
797
 
798
- private static function update_postmeta( &$post, $post_id ) {
799
- foreach ( $post['postmeta'] as $k => $v ) {
800
- if ( '_edit_last' == $k ) {
801
  $v = FrmAppHelper::get_user_id_param( $v );
802
- } elseif ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
803
- // Change the attachment ID.
804
  $field_obj = FrmFieldFactory::get_field_type( 'file' );
805
- $v = $field_obj->get_file_id( $v );
806
- }
807
 
808
  update_post_meta( $post_id, $k, $v );
809
 
810
  unset( $k, $v );
811
- }
812
- }
813
 
814
  /**
815
  * If a template includes custom css, let's include it.
@@ -822,14 +791,14 @@ class FrmXMLHelper {
822
  return;
823
  }
824
 
825
- $frm_style = new FrmStyle();
826
- $default_style = $frm_style->get_default_style();
827
  $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
828
  $frm_style->save( $default_style );
829
  }
830
 
831
  private static function maybe_update_stylesheet( $imported ) {
832
- $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
833
  $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
834
  if ( $new_styles || $updated_styles ) {
835
  if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
@@ -842,33 +811,32 @@ class FrmXMLHelper {
842
  }
843
  }
844
 
845
- /**
846
- * @param string $message
847
- */
848
  public static function parse_message( $result, &$message, &$errors ) {
849
  if ( is_wp_error( $result ) ) {
850
- $errors[] = $result->get_error_message();
851
- } elseif ( ! $result ) {
852
- return;
853
- }
854
 
855
  if ( ! is_array( $result ) ) {
856
- $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
857
-
858
- return;
859
- }
860
 
861
- $t_strings = array(
862
- 'imported' => __( 'Imported', 'formidable' ),
863
- 'updated' => __( 'Updated', 'formidable' ),
864
- );
865
 
866
- $message = '<ul>';
867
- foreach ( $result as $type => $results ) {
868
  if ( ! isset( $t_strings[ $type ] ) ) {
869
- // only print imported and updated
870
- continue;
871
- }
872
 
873
  $s_message = array();
874
  foreach ( $results as $k => $m ) {
@@ -881,74 +849,40 @@ class FrmXMLHelper {
881
  $message .= implode( ', ', $s_message );
882
  $message .= '</li>';
883
  }
884
- }
885
-
886
- if ( $message == '<ul>' ) {
887
- $message = '';
888
- $errors[] = __( 'Nothing was imported or updated', 'formidable' );
889
- } else {
890
- self::add_form_link_to_message( $result, $message );
891
 
892
- $message .= '</ul>';
893
- }
894
- }
 
 
 
 
895
 
896
  public static function item_count_message( $m, $type, &$s_message ) {
897
- if ( ! $m ) {
898
- return;
899
- }
900
-
901
- $strings = array(
902
- /* translators: %1$s: Number of items */
903
- 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
904
- /* translators: %1$s: Number of items */
905
- 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
906
- /* translators: %1$s: Number of items */
907
- 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
908
- /* translators: %1$s: Number of items */
909
- 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
910
- /* translators: %1$s: Number of items */
911
- 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
912
- /* translators: %1$s: Number of items */
913
- 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
914
- /* translators: %1$s: Number of items */
915
- 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
916
- /* translators: %1$s: Number of items */
917
- 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
918
- );
919
 
920
  $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
921
- }
922
-
923
- /**
924
- * If a single form was imported, include a link in the success message.
925
- *
926
- * @since 4.0
927
- * @param array $result The response from the XML import.
928
- * @param string $message The response shown on the page after import.
929
- */
930
- private static function add_form_link_to_message( $result, &$message ) {
931
- $total_forms = $result['imported']['forms'] + $result['updated']['forms'];
932
- if ( $total_forms > 1 ) {
933
- return;
934
- }
935
-
936
- $primary_form = reset( $result['forms'] );
937
- if ( ! empty( $primary_form ) ) {
938
- $primary_form = FrmForm::getOne( $primary_form );
939
- $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id;
940
-
941
- $message .= '<li><a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html__( 'Go to imported form', 'formidable' ) . '</a></li>';
942
- }
943
- }
944
 
945
  /**
946
  * Prepare the form options for export
947
  *
948
  * @since 2.0.19
949
- *
950
  * @param string $options
951
- *
952
  * @return string
953
  */
954
  public static function prepare_form_options_for_export( $options ) {
@@ -957,8 +891,8 @@ class FrmXMLHelper {
957
  $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
958
  if ( $not_default ) {
959
  global $wpdb;
960
- $table = $wpdb->prefix . 'posts';
961
- $where = array( 'ID' => $options['custom_style'] );
962
  $select = 'post_name';
963
 
964
  $style_name = FrmDb::get_var( $table, $where, $select );
@@ -971,7 +905,6 @@ class FrmXMLHelper {
971
  }
972
  self::remove_default_form_options( $options );
973
  $options = serialize( $options );
974
-
975
  return self::cdata( $options );
976
  }
977
 
@@ -986,7 +919,7 @@ class FrmXMLHelper {
986
  if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
987
  $defaults += FrmProFormsHelper::get_default_opts();
988
  }
989
- self::remove_defaults( $defaults, $options );
990
  }
991
 
992
  /**
@@ -1006,19 +939,18 @@ class FrmXMLHelper {
1006
  private static function remove_default_field_options( &$field ) {
1007
  $defaults = self::default_field_options( $field->type );
1008
  if ( empty( $defaults['blank'] ) ) {
1009
- $global_settings = new FrmSettings();
1010
- $global_defaults = $global_settings->default_options();
1011
  $defaults['blank'] = $global_defaults['blank_msg'];
1012
  }
1013
 
1014
  $options = maybe_unserialize( $field->field_options );
1015
- self::remove_defaults( $defaults, $options );
1016
  self::remove_default_html( 'custom_html', $defaults, $options );
1017
 
1018
  // Get variations on the defaults.
1019
  if ( isset( $options['invalid'] ) ) {
1020
  $defaults = array(
1021
- /* translators: %s: Field name */
1022
  'invalid' => sprintf( __( '%s is invalid', 'formidable' ), $field->name ),
1023
  );
1024
  self::remove_defaults( $defaults, $options );
@@ -1038,7 +970,7 @@ class FrmXMLHelper {
1038
  return $defaults;
1039
  }
1040
 
1041
- /**
1042
  * Compare the default array to the saved values and
1043
  * remove if they are the same
1044
  *
@@ -1053,10 +985,10 @@ class FrmXMLHelper {
1053
  }
1054
  unset( $defaults[ $d ] );
1055
  }
1056
- $saved = array_diff_assoc( (array) $saved, $defaults );
1057
  }
1058
 
1059
- /**
1060
  * The line endings may prevent html from being equal when it should
1061
  *
1062
  * @since 3.06
@@ -1066,11 +998,10 @@ class FrmXMLHelper {
1066
  return;
1067
  }
1068
 
1069
- $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1070
  $default_html = $defaults[ $html_name ];
1071
  if ( $old_html == $default_html ) {
1072
  unset( $options[ $html_name ] );
1073
-
1074
  return;
1075
  }
1076
 
@@ -1085,13 +1016,13 @@ class FrmXMLHelper {
1085
  $str = maybe_unserialize( $str );
1086
  if ( is_array( $str ) ) {
1087
  $str = json_encode( $str );
1088
- } elseif ( seems_utf8( $str ) == false ) {
1089
  $str = utf8_encode( $str );
1090
  }
1091
 
1092
  if ( is_numeric( $str ) ) {
1093
- return $str;
1094
- }
1095
 
1096
  self::remove_invalid_characters_from_xml( $str );
1097
 
@@ -1105,7 +1036,6 @@ class FrmXMLHelper {
1105
  * Remove <US> character (unit separator) from exported strings
1106
  *
1107
  * @since 2.0.22
1108
- *
1109
  * @param string $str
1110
  */
1111
  private static function remove_invalid_characters_from_xml( &$str ) {
@@ -1113,103 +1043,84 @@ class FrmXMLHelper {
1113
  $str = str_replace( '\x1F', '', $str );
1114
  }
1115
 
1116
- public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1117
- // Get post type
1118
- $post_type = FrmFormActionsController::$action_post_type;
1119
 
1120
- // Set up imported index, if not set up yet
1121
- if ( ! isset( $imported['imported']['actions'] ) ) {
1122
- $imported['imported']['actions'] = 0;
1123
- }
1124
 
1125
- // Migrate post settings to action
1126
- self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
1127
 
1128
- // Migrate email settings to action
1129
- self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
1130
- }
1131
 
1132
- /**
1133
- * Migrate post settings to form action
1134
- *
1135
- * @param string $post_type
1136
- */
1137
- private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1138
  if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1139
- return;
1140
- }
1141
-
1142
- $new_action = array(
1143
- 'post_type' => $post_type,
1144
- 'post_excerpt' => 'wppost',
1145
- 'post_title' => __( 'Create Posts', 'formidable' ),
1146
- 'menu_order' => $form_id,
1147
- 'post_status' => 'publish',
1148
- 'post_content' => array(),
1149
- 'post_name' => $form_id . '_wppost_1',
1150
- );
1151
-
1152
- $post_settings = array(
1153
- 'post_type',
1154
- 'post_category',
1155
- 'post_content',
1156
- 'post_excerpt',
1157
- 'post_title',
1158
- 'post_name',
1159
- 'post_date',
1160
- 'post_status',
1161
- 'post_custom_fields',
1162
- 'post_password',
1163
- );
1164
-
1165
- foreach ( $post_settings as $post_setting ) {
1166
  if ( isset( $form_options[ $post_setting ] ) ) {
1167
  $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
1168
- }
1169
  unset( $post_setting );
1170
- }
1171
 
1172
  $new_action['event'] = array( 'create', 'update' );
1173
 
1174
- if ( $switch ) {
1175
- // Fields with string or int saved.
1176
- $basic_fields = array(
1177
- 'post_title',
1178
- 'post_content',
1179
- 'post_excerpt',
1180
- 'post_password',
1181
- 'post_date',
1182
- 'post_status',
1183
- );
1184
 
1185
- // Fields with arrays saved.
1186
  $array_fields = array( 'post_category', 'post_custom_fields' );
1187
 
1188
  $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
1189
- }
1190
  $new_action['post_content'] = json_encode( $new_action['post_content'] );
1191
 
1192
  $exists = get_posts(
1193
  array(
1194
- 'name' => $new_action['post_name'],
1195
- 'post_type' => $new_action['post_type'],
1196
- 'post_status' => $new_action['post_status'],
1197
- 'numberposts' => 1,
1198
  )
1199
  );
1200
 
1201
- if ( ! $exists ) {
1202
  // this isn't an email, but we need to use a class that will always be included
1203
  FrmDb::save_json_post( $new_action );
1204
- $imported['imported']['actions'] ++;
1205
- }
1206
- }
1207
 
1208
  /**
1209
  * Switch old field IDs for new field IDs in emails and post
1210
  *
1211
  * @since 2.0
1212
- *
1213
  * @param array $post_content - check for old field IDs
1214
  * @param array $basic_fields - fields with string or int saved
1215
  * @param array $array_fields - fields with arrays saved
@@ -1217,91 +1128,90 @@ class FrmXMLHelper {
1217
  * @return string $post_content - new field IDs
1218
  */
1219
  private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
1220
- global $frm_duplicate_ids;
1221
 
1222
- // If there aren't IDs that were switched, end now
1223
- if ( ! $frm_duplicate_ids ) {
1224
- return;
1225
- }
1226
 
1227
- // Get old IDs
1228
- $old = array_keys( $frm_duplicate_ids );
1229
 
1230
- // Get new IDs
1231
- $new = array_values( $frm_duplicate_ids );
1232
 
1233
- // Do a str_replace with each item to set the new IDs
1234
- foreach ( $post_content as $key => $setting ) {
1235
- if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
1236
- // Replace old IDs with new IDs
1237
  $post_content[ $key ] = str_replace( $old, $new, $setting );
1238
- } elseif ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
1239
- foreach ( $setting as $k => $val ) {
1240
- // Replace old IDs with new IDs
1241
  $post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
1242
- }
1243
- }
1244
- unset( $key, $setting );
1245
- }
1246
-
1247
- return $post_content;
1248
- }
1249
-
1250
- private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1251
- // No old notifications or autoresponders to carry over
1252
  if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
1253
- return;
1254
- }
1255
 
1256
- // Initialize notifications array
1257
- $notifications = array();
1258
 
1259
- // Migrate regular notifications
1260
- self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
1261
 
1262
- // Migrate autoresponders
1263
- self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
1264
 
1265
- if ( empty( $notifications ) ) {
1266
- return;
1267
- }
1268
 
1269
- foreach ( $notifications as $new_notification ) {
1270
- $new_notification['post_type'] = $post_type;
1271
- $new_notification['post_excerpt'] = 'email';
1272
- $new_notification['post_title'] = __( 'Email Notification', 'formidable' );
1273
- $new_notification['menu_order'] = $form_id;
1274
- $new_notification['post_status'] = 'publish';
1275
 
1276
- // Switch field IDs and keys, if needed
1277
- if ( $switch ) {
1278
 
1279
  // Switch field IDs in email conditional logic
1280
  self::switch_email_contition_field_ids( $new_notification['post_content'] );
1281
 
1282
  // Switch all other field IDs in email
1283
- $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
1284
- }
1285
- $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
1286
 
1287
  $exists = get_posts(
1288
  array(
1289
- 'name' => $new_notification['post_name'],
1290
- 'post_type' => $new_notification['post_type'],
1291
- 'post_status' => $new_notification['post_status'],
1292
- 'numberposts' => 1,
1293
  )
1294
  );
1295
 
1296
  if ( empty( $exists ) ) {
1297
  FrmDb::save_json_post( $new_notification );
1298
- $imported['imported']['actions'] ++;
1299
- }
1300
  unset( $new_notification );
1301
- }
1302
 
1303
  self::remove_deprecated_notification_settings( $form_id, $form_options );
1304
- }
1305
 
1306
  /**
1307
  * Remove deprecated notification settings after migration
@@ -1321,140 +1231,140 @@ class FrmXMLHelper {
1321
  FrmForm::update( $form_id, array( 'options' => $form_options ) );
1322
  }
1323
 
1324
- private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
1325
- if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
1326
- // add old settings into notification array
1327
  $form_options['notification'] = array( 0 => $form_options );
1328
- } elseif ( isset( $form_options['notification']['email_to'] ) ) {
1329
- // make sure it's in the correct format
1330
  $form_options['notification'] = array( 0 => $form_options['notification'] );
1331
- }
1332
 
1333
  if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) {
1334
- foreach ( $form_options['notification'] as $email_key => $notification ) {
1335
 
1336
  $atts = array(
1337
- 'email_to' => '',
1338
- 'reply_to' => '',
1339
  'reply_to_name' => '',
1340
- 'event' => '',
1341
- 'form_id' => $form_id,
1342
- 'email_key' => $email_key,
1343
  );
1344
 
1345
- // Format the email data
1346
- self::format_email_data( $atts, $notification );
1347
 
1348
  if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
1349
  do_action( 'frm_create_twilio_action', $atts, $notification );
1350
  }
1351
 
1352
- // Setup the new notification
1353
- $new_notification = array();
1354
- self::setup_new_notification( $new_notification, $notification, $atts );
1355
 
1356
- $notifications[] = $new_notification;
1357
- }
1358
- }
1359
- }
1360
 
1361
- private static function format_email_data( &$atts, $notification ) {
1362
- // Format email_to
1363
- self::format_email_to_data( $atts, $notification );
1364
 
1365
- // Format the reply to email and name
1366
  $reply_fields = array(
1367
  'reply_to' => '',
1368
  'reply_to_name' => '',
1369
  );
1370
- foreach ( $reply_fields as $f => $val ) {
1371
  if ( isset( $notification[ $f ] ) ) {
1372
  $atts[ $f ] = $notification[ $f ];
1373
  if ( 'custom' == $notification[ $f ] ) {
1374
  $atts[ $f ] = $notification[ 'cust_' . $f ];
1375
- } elseif ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
1376
  $atts[ $f ] = '[' . $atts[ $f ] . ']';
1377
- }
1378
- }
1379
- unset( $f, $val );
1380
- }
1381
 
1382
- // Format event
1383
  $atts['event'] = array( 'create' );
1384
- if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
1385
- $atts['event'][] = 'update';
1386
  } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
1387
  $atts['event'] = array( 'update' );
1388
- }
1389
- }
1390
 
1391
- private static function format_email_to_data( &$atts, $notification ) {
1392
- if ( isset( $notification['email_to'] ) ) {
1393
  $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
1394
- } else {
1395
- $atts['email_to'] = array();
1396
- }
1397
 
1398
- if ( isset( $notification['also_email_to'] ) ) {
1399
- $email_fields = (array) $notification['also_email_to'];
1400
- $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
1401
- unset( $email_fields );
1402
- }
1403
 
1404
- foreach ( $atts['email_to'] as $key => $email_field ) {
1405
 
1406
- if ( is_numeric( $email_field ) ) {
1407
  $atts['email_to'][ $key ] = '[' . $email_field . ']';
1408
- }
1409
 
1410
  if ( strpos( $email_field, '|' ) ) {
1411
- $email_opt = explode( '|', $email_field );
1412
- if ( isset( $email_opt[0] ) ) {
1413
  $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1414
- }
1415
- unset( $email_opt );
1416
- }
1417
- }
1418
  $atts['email_to'] = implode( ', ', $atts['email_to'] );
1419
- }
1420
-
1421
- private static function setup_new_notification( &$new_notification, $notification, $atts ) {
1422
- // Set up new notification
1423
- $new_notification = array(
1424
- 'post_content' => array(
1425
- 'email_to' => $atts['email_to'],
1426
- 'event' => $atts['event'],
1427
- ),
1428
- 'post_name' => $atts['form_id'] . '_email_' . $atts['email_key'],
1429
- );
1430
-
1431
- // Add more fields to the new notification
1432
- $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1433
- foreach ( $add_fields as $add_field ) {
1434
  if ( isset( $notification[ $add_field ] ) ) {
1435
  $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
1436
- } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1437
  $new_notification['post_content'][ $add_field ] = 0;
1438
- } else {
1439
  $new_notification['post_content'][ $add_field ] = '';
1440
- }
1441
- unset( $add_field );
1442
- }
1443
 
1444
  // Set reply to
1445
  $new_notification['post_content']['reply_to'] = $atts['reply_to'];
1446
 
1447
- // Set from
1448
  if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
1449
  $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>';
1450
- }
1451
- }
1452
 
1453
  /**
1454
- * Switch field IDs in pre-2.0 email conditional logic
1455
- *
1456
- * @param $post_content array, pass by reference
1457
- */
1458
  private static function switch_email_contition_field_ids( &$post_content ) {
1459
  // Switch field IDs in conditional logic
1460
  if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -1467,7 +1377,7 @@ class FrmXMLHelper {
1467
  }
1468
  }
1469
 
1470
- private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1471
  if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
1472
  // migrate autoresponder
1473
 
@@ -1483,19 +1393,19 @@ class FrmXMLHelper {
1483
  $email_field = '[' . $email_field . ']';
1484
  }
1485
 
1486
- $notification = $form_options;
1487
- $new_notification2 = array(
1488
- 'post_content' => array(
1489
  'email_message' => $notification['ar_email_message'],
1490
  'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
1491
  'email_to' => $email_field,
1492
  'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
1493
  'inc_user_info' => 0,
1494
  ),
1495
- 'post_name' => $form_id . '_email_' . count( $notifications ),
1496
- );
1497
 
1498
- $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1499
  $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
1500
 
1501
  if ( ! empty( $reply_to ) ) {
@@ -1506,9 +1416,9 @@ class FrmXMLHelper {
1506
  $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>';
1507
  }
1508
 
1509
- $notifications[] = $new_notification2;
1510
- unset( $new_notification2 );
1511
- }
1512
- }
1513
  }
1514
 
25
  public static function import_xml( $file ) {
26
  if ( ! defined( 'WP_IMPORTING' ) ) {
27
  define( 'WP_IMPORTING', true );
28
+ }
29
 
30
  if ( ! class_exists( 'DOMDocument' ) ) {
31
+ return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
32
+ }
33
 
34
+ $dom = new DOMDocument();
35
  $success = $dom->loadXML( file_get_contents( $file ) );
36
  if ( ! $success ) {
37
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
62
  $imported = self::pre_import_data();
63
 
64
  foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
65
+ // grab cats, tags, and terms, or forms or posts
66
  if ( isset( $xml->{$item_type} ) ) {
67
  $function_name = 'import_xml_' . $item_type . 's';
68
+ $imported = self::$function_name( $xml->{$item_type}, $imported );
69
  unset( $function_name, $xml->{$item_type} );
70
+ }
71
+ }
72
 
73
  return apply_filters( 'frm_importing_xml', $imported, $xml );
74
  }
97
  }
98
 
99
  public static function import_xml_terms( $terms, $imported ) {
100
+ foreach ( $terms as $t ) {
101
  if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
102
+ continue;
103
  }
104
 
105
  $parent = self::get_term_parent_id( $t );
108
  (string) $t->term_name,
109
  (string) $t->term_taxonomy,
110
  array(
111
+ 'slug' => (string) $t->term_slug,
112
+ 'description' => (string) $t->term_description,
113
+ 'parent' => empty( $parent ) ? 0 : $parent,
114
  )
115
  );
116
 
117
  if ( $term && is_array( $term ) ) {
118
+ $imported['imported']['terms']++;
119
  $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
120
+ }
121
 
122
  unset( $term, $t );
123
  }
124
 
125
  return $imported;
126
+ }
127
 
128
  /**
129
  * @since 2.0.8
138
  $parent = 0;
139
  }
140
  }
 
141
  return $parent;
142
  }
143
 
148
  self::put_child_forms_first( $forms );
149
 
150
  foreach ( $forms as $item ) {
151
+ $form = self::fill_form( $item );
152
 
153
  self::update_custom_style_setting_on_import( $form );
154
 
155
+ $this_form = self::maybe_get_form( $form );
156
 
157
+ $old_id = false;
158
  $form_fields = false;
159
  if ( ! empty( $this_form ) ) {
160
  $form_id = $this_form->id;
161
+ $old_id = $this_form->id;
162
  self::update_form( $this_form, $form, $imported );
163
 
164
  $form_fields = self::get_form_fields( $form_id );
165
  } else {
166
  $form_id = FrmForm::create( $form );
167
+ if ( $form_id ) {
168
+ $imported['imported']['forms']++;
169
+ // Keep track of whether this specific form was updated or not
 
 
 
 
170
  $imported['form_status'][ $form_id ] = 'imported';
171
  self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
172
+ }
173
  }
174
 
175
  self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );
176
 
177
  self::delete_removed_fields( $form_fields );
178
 
179
+ // Update field ids/keys to new ones
180
  do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
181
 
182
  $imported['forms'][ (int) $item->id ] = $form_id;
183
 
184
+ // Send pre 2.0 form options through function that creates actions
185
+ self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, true );
186
 
187
  do_action( 'frm_after_import_form', $form_id, $form );
188
 
192
  self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
193
 
194
  return $imported;
195
+ }
196
 
197
  private static function fill_form( $item ) {
198
  $form = array(
199
+ 'id' => (int) $item->id,
200
+ 'form_key' => (string) $item->form_key,
201
+ 'name' => (string) $item->name,
202
+ 'description' => (string) $item->description,
203
+ 'options' => (string) $item->options,
204
+ 'logged_in' => (int) $item->logged_in,
205
+ 'is_template' => (int) $item->is_template,
206
+ 'editable' => (int) $item->editable,
207
+ 'status' => (string) $item->status,
208
  'parent_form_id' => isset( $item->parent_form_id ) ? (int) $item->parent_form_id : 0,
209
+ 'created_at' => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ),
210
  );
 
211
  $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
 
212
  return $form;
213
  }
214
 
230
  private static function update_form( $this_form, $form, &$imported ) {
231
  $form_id = $this_form->id;
232
  FrmForm::update( $form_id, $form );
233
+ $imported['updated']['forms']++;
 
 
 
 
234
  // Keep track of whether this specific form was updated or not
235
  $imported['form_status'][ $form_id ] = 'updated';
236
  }
237
 
238
  private static function get_form_fields( $form_id ) {
239
  $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
240
+ $old_fields = array();
241
  foreach ( $form_fields as $f ) {
242
+ $old_fields[ $f->id ] = $f;
243
  $old_fields[ $f->field_key ] = $f->id;
244
  unset( $f );
245
  }
246
  $form_fields = $old_fields;
 
247
  return $form_fields;
248
  }
249
 
262
  }
263
 
264
  /**
265
+ * Put child forms first so they will be imported before parents
266
+ *
267
+ * @since 2.0.16
268
+ * @param array $forms
269
+ */
 
270
  private static function put_child_forms_first( &$forms ) {
271
+ $child_forms = array();
272
  $regular_forms = array();
273
 
274
  foreach ( $forms as $form ) {
285
  }
286
 
287
  /**
288
+ * Keep track of all imported child forms
289
+ *
290
+ * @since 2.0.16
291
+ * @param int $form_id
292
+ * @param int $parent_form_id
293
+ * @param array $child_forms
294
+ */
 
295
  private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
296
  if ( $parent_form_id ) {
297
  $child_forms[ $form_id ] = $parent_form_id;
299
  }
300
 
301
  /**
302
+ * Update the parent_form_id on imported child forms
303
+ * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported
304
+ *
305
+ * @since 2.0.6
306
+ * @param array $imported_forms
307
+ * @param array $child_forms
308
+ */
 
309
  private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
310
  foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
311
 
319
  }
320
 
321
  /**
322
+ * Import all fields for a form
 
 
323
  *
324
+ * @since 2.0.13
325
+ *
326
+ * TODO: Cut down on params
327
+ */
328
  private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
329
  $in_section = 0;
330
 
331
  foreach ( $xml_fields as $field ) {
332
  $f = self::fill_field( $field, $form_id );
333
 
334
+ $has_default = array( 'text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'hidden', 'password', 'tag' );
 
 
 
 
 
 
 
 
 
 
 
335
  if ( is_array( $f['default_value'] ) && in_array( $f['type'], $has_default, true ) ) {
336
  if ( count( $f['default_value'] ) === 1 ) {
337
  $f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
348
  // check for field to edit by field id
349
  if ( isset( $form_fields[ $f['id'] ] ) ) {
350
  FrmField::update( $f['id'], $f );
351
+ $imported['updated']['fields']++;
352
 
353
  unset( $form_fields[ $f['id'] ] );
354
 
356
  if ( isset( $form_fields[ $f['field_key'] ] ) ) {
357
  unset( $form_fields[ $f['field_key'] ] );
358
  }
359
+ } else if ( isset( $form_fields[ $f['field_key'] ] ) ) {
360
  // check for field to edit by field key
361
  unset( $f['id'] );
362
 
363
  FrmField::update( $form_fields[ $f['field_key'] ], $f );
364
+ $imported['updated']['fields']++;
365
 
366
  unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
367
  unset( $form_fields[ $f['field_key'] ] ); //unset old field key
396
  * Update the current in_section value
397
  *
398
  * @since 2.0.25
 
399
  * @param int $in_section
400
  * @param array $f
401
  */
417
  }
418
 
419
  /**
420
+ * Switch the form_select on a repeating field or embedded form if it needs to be switched
421
+ *
422
+ * @since 2.0.16
423
+ * @param array $f
424
+ * @param array $imported
425
+ */
 
426
  private static function maybe_update_form_select( &$f, $imported ) {
427
  if ( ! isset( $imported['forms'] ) ) {
428
  return;
442
  * Update the get_values_form setting if the form was imported
443
  *
444
  * @since 2.01.0
 
445
  * @param array $imported
446
  * @param array $f
447
  */
462
  * Create an imported field
463
  *
464
  * @since 2.0.25
 
465
  * @param array $f
466
  * @param array $imported
467
  */
471
 
472
  $new_id = FrmField::create( $f );
473
  if ( $new_id != false ) {
474
+ $imported['imported']['fields']++;
475
  do_action( 'frm_after_field_is_imported', $f, $new_id );
476
  }
477
  }
478
 
479
  /**
480
+ * Updates the custom style setting on import
481
+ * Convert the post slug to an ID
482
+ *
483
+ * @since 2.0.19
484
+ * @param array $form
485
+ */
 
486
  private static function update_custom_style_setting_on_import( &$form ) {
487
  if ( ! isset( $form['options']['custom_style'] ) ) {
488
  return;
494
  } else {
495
  // Replace the style name with the style ID on import
496
  global $wpdb;
497
+ $table = $wpdb->prefix . 'posts';
498
+ $where = array(
499
  'post_name' => $form['options']['custom_style'],
500
  'post_type' => 'frm_styles',
501
  );
502
+ $select = 'ID';
503
  $style_id = FrmDb::get_var( $table, $where, $select );
504
 
505
  if ( $style_id ) {
524
  $form = FrmForm::getOne( $form_id );
525
 
526
  if ( $form && isset( $form->options['old_style'] ) ) {
527
+ $form = (array) $form;
528
+ $saved_style = $form['options']['custom_style'];
529
  $form['options']['custom_style'] = $form['options']['old_style'];
530
  self::update_custom_style_setting_on_import( $form );
531
  $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
536
  }
537
 
538
  public static function import_xml_views( $views, $imported ) {
539
+ $imported['posts'] = array();
540
+ $form_action_type = FrmFormActionsController::$action_post_type;
541
 
542
+ $post_types = array(
543
+ 'frm_display' => 'views',
544
+ $form_action_type => 'actions',
545
+ 'frm_styles' => 'styles',
546
+ );
547
 
548
+ foreach ( $views as $item ) {
549
  $post = array(
550
+ 'post_title' => (string) $item->title,
551
+ 'post_name' => (string) $item->post_name,
552
+ 'post_type' => (string) $item->post_type,
553
+ 'post_password' => (string) $item->post_password,
554
+ 'guid' => (string) $item->guid,
555
+ 'post_status' => (string) $item->status,
556
+ 'post_author' => FrmAppHelper::get_user_id_param( (string) $item->post_author ),
557
+ 'post_id' => (int) $item->post_id,
558
+ 'post_parent' => (int) $item->post_parent,
559
+ 'menu_order' => (int) $item->menu_order,
560
+ 'post_content' => FrmFieldsHelper::switch_field_ids( (string) $item->content ),
561
+ 'post_excerpt' => FrmFieldsHelper::switch_field_ids( (string) $item->excerpt ),
562
+ 'is_sticky' => (string) $item->is_sticky,
563
  'comment_status' => (string) $item->comment_status,
564
+ 'post_date' => (string) $item->post_date,
565
+ 'post_date_gmt' => (string) $item->post_date_gmt,
566
+ 'ping_status' => (string) $item->ping_status,
567
+ 'postmeta' => array(),
568
+ 'tax_input' => array(),
569
  );
570
 
571
+ $old_id = $post['post_id'];
572
  self::populate_post( $post, $item, $imported );
573
 
574
  unset( $item );
575
 
576
  $post_id = false;
577
+ if ( $post['post_type'] == $form_action_type ) {
578
+ $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
579
  if ( $action_control && is_object( $action_control ) ) {
580
  $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
581
  }
582
  unset( $action_control );
583
+ } else if ( $post['post_type'] == 'frm_styles' ) {
584
+ // Properly encode post content before inserting the post
585
+ $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
586
+ $custom_css = isset( $post['post_content']['custom_css'] ) ? $post['post_content']['custom_css'] : '';
587
+ $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
588
+
589
+ // Create/update post now
590
+ $post_id = wp_insert_post( $post );
591
  self::maybe_update_custom_css( $custom_css );
592
+ } else {
593
+ // Create/update post now
594
+ $post_id = wp_insert_post( $post );
595
+ }
596
 
597
  if ( ! is_numeric( $post_id ) ) {
598
+ continue;
599
+ }
600
 
601
  self::update_postmeta( $post, $post_id );
602
 
603
+ $this_type = 'posts';
604
  if ( isset( $post_types[ $post['post_type'] ] ) ) {
605
  $this_type = $post_types[ $post['post_type'] ];
606
+ }
607
 
608
  if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
609
+ $imported['updated'][ $this_type ]++;
610
+ } else {
611
+ $imported['imported'][ $this_type ]++;
612
+ }
613
 
614
  $imported['posts'][ (int) $old_id ] = $post_id;
615
 
621
  self::maybe_update_stylesheet( $imported );
622
 
623
  return $imported;
624
+ }
625
 
626
+ private static function populate_post( &$post, $item, $imported ) {
627
  if ( isset( $item->attachment_url ) ) {
628
  $post['attachment_url'] = (string) $item->attachment_url;
629
  }
630
 
631
  if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
632
+ // update to new form id
633
+ $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
634
  }
635
 
636
  // Don't allow default styles to take over a site's default style
646
  self::populate_taxonomies( $post, $item );
647
 
648
  self::maybe_editing_post( $post );
649
+ }
650
 
651
+ private static function populate_postmeta( &$post, $meta, $imported ) {
652
+ global $frm_duplicate_ids;
653
 
654
+ $m = array(
655
  'key' => (string) $meta->meta_key,
656
  'value' => (string) $meta->meta_value,
657
  );
658
 
659
  //switch old form and field ids to new ones
660
  if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
661
+ $m['value'] = $imported['forms'][ (int) $m['value'] ];
662
  } else {
663
+ $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
664
 
665
  if ( ! empty( $frm_duplicate_ids ) ) {
666
 
667
+ if ( $m['key'] == 'frm_dyncontent' ) {
668
  $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
669
+ } else if ( $m['key'] == 'frm_options' ) {
670
 
671
  foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
672
  if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
673
  $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
674
+ }
675
+ }
676
+
677
+ $check_dup_array = array();
678
+ if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
679
+ if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
680
+ $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
681
+ } else if ( is_array( $m['value']['order_by'] ) ) {
682
+ $check_dup_array[] = 'order_by';
683
+ }
684
+ }
685
+
686
+ if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
687
+ $check_dup_array[] = 'where';
688
+ }
689
+
690
+ foreach ( $check_dup_array as $check_k ) {
691
  foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
692
  if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
693
  $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
694
+ }
695
  unset( $mk, $mv );
696
+ }
697
+ }
698
+ }
699
+ }
700
  }
701
 
702
  if ( ! is_array( $m['value'] ) ) {
704
  }
705
 
706
  $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
707
+ }
708
 
709
+ /**
710
+ * Add terms to post
711
  *
712
+ * @param array $post by reference
713
+ * @param object $item The XML object data
714
+ */
715
+ private static function populate_taxonomies( &$post, $item ) {
716
  foreach ( $item->category as $c ) {
717
  $att = $c->attributes();
718
  if ( ! isset( $att['nicename'] ) ) {
719
+ continue;
720
+ }
721
 
722
+ $taxonomy = (string) $att['domain'];
723
  if ( is_taxonomy_hierarchical( $taxonomy ) ) {
724
+ $name = (string) $att['nicename'];
725
  $h_term = get_term_by( 'slug', $name, $taxonomy );
726
+ if ( $h_term ) {
727
+ $name = $h_term->term_id;
728
+ }
729
  unset( $h_term );
730
+ } else {
731
+ $name = (string) $c;
732
+ }
733
 
734
  if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
735
  $post['tax_input'][ $taxonomy ] = array();
738
  $post['tax_input'][ $taxonomy ][] = $name;
739
  unset( $name );
740
  }
741
+ }
742
 
743
+ /**
744
+ * Edit post if the key and created time match
745
+ */
746
+ private static function maybe_editing_post( &$post ) {
747
  $match_by = array(
748
+ 'post_type' => $post['post_type'],
749
+ 'name' => $post['post_name'],
750
+ 'post_status' => $post['post_status'],
751
+ 'posts_per_page' => 1,
752
  );
753
 
754
  if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
755
+ $match_by['include'] = $post['post_id'];
756
  unset( $match_by['name'] );
757
  }
758
 
762
  // set the id of the post to edit
763
  $post['ID'] = current( $editing )->ID;
764
  }
765
+ }
766
 
767
+ private static function update_postmeta( &$post, $post_id ) {
768
+ foreach ( $post['postmeta'] as $k => $v ) {
769
+ if ( '_edit_last' == $k ) {
770
  $v = FrmAppHelper::get_user_id_param( $v );
771
+ } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
772
+ //change the attachment ID
773
  $field_obj = FrmFieldFactory::get_field_type( 'file' );
774
+ $v = $field_obj->get_file_id( $v );
775
+ }
776
 
777
  update_post_meta( $post_id, $k, $v );
778
 
779
  unset( $k, $v );
780
+ }
781
+ }
782
 
783
  /**
784
  * If a template includes custom css, let's include it.
791
  return;
792
  }
793
 
794
+ $frm_style = new FrmStyle();
795
+ $default_style = $frm_style->get_default_style();
796
  $default_style->post_content['custom_css'] .= "\r\n\r\n" . $custom_css;
797
  $frm_style->save( $default_style );
798
  }
799
 
800
  private static function maybe_update_stylesheet( $imported ) {
801
+ $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
802
  $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
803
  if ( $new_styles || $updated_styles ) {
804
  if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
811
  }
812
  }
813
 
814
+ /**
815
+ * @param string $message
816
+ */
817
  public static function parse_message( $result, &$message, &$errors ) {
818
  if ( is_wp_error( $result ) ) {
819
+ $errors[] = $result->get_error_message();
820
+ } else if ( ! $result ) {
821
+ return;
822
+ }
823
 
824
  if ( ! is_array( $result ) ) {
825
+ $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
826
+ return;
827
+ }
 
828
 
829
+ $t_strings = array(
830
+ 'imported' => __( 'Imported', 'formidable' ),
831
+ 'updated' => __( 'Updated', 'formidable' ),
832
+ );
833
 
834
+ $message = '<ul>';
835
+ foreach ( $result as $type => $results ) {
836
  if ( ! isset( $t_strings[ $type ] ) ) {
837
+ // only print imported and updated
838
+ continue;
839
+ }
840
 
841
  $s_message = array();
842
  foreach ( $results as $k => $m ) {
849
  $message .= implode( ', ', $s_message );
850
  $message .= '</li>';
851
  }
852
+ }
 
 
 
 
 
 
853
 
854
+ if ( $message == '<ul>' ) {
855
+ $message = '';
856
+ $errors[] = __( 'Nothing was imported or updated', 'formidable' );
857
+ } else {
858
+ $message .= '</ul>';
859
+ }
860
+ }
861
 
862
  public static function item_count_message( $m, $type, &$s_message ) {
863
+ if ( ! $m ) {
864
+ return;
865
+ }
866
+
867
+ $strings = array(
868
+ 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
869
+ 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
870
+ 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
871
+ 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
872
+ 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
873
+ 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
874
+ 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
875
+ 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
876
+ );
 
 
 
 
 
 
 
 
877
 
878
  $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
879
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
880
 
881
  /**
882
  * Prepare the form options for export
883
  *
884
  * @since 2.0.19
 
885
  * @param string $options
 
886
  * @return string
887
  */
888
  public static function prepare_form_options_for_export( $options ) {
891
  $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
892
  if ( $not_default ) {
893
  global $wpdb;
894
+ $table = $wpdb->prefix . 'posts';
895
+ $where = array( 'ID' => $options['custom_style'] );
896
  $select = 'post_name';
897
 
898
  $style_name = FrmDb::get_var( $table, $where, $select );
905
  }
906
  self::remove_default_form_options( $options );
907
  $options = serialize( $options );
 
908
  return self::cdata( $options );
909
  }
910
 
919
  if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
920
  $defaults += FrmProFormsHelper::get_default_opts();
921
  }
922
+ self::remove_defaults( $defaults, $options );
923
  }
924
 
925
  /**
939
  private static function remove_default_field_options( &$field ) {
940
  $defaults = self::default_field_options( $field->type );
941
  if ( empty( $defaults['blank'] ) ) {
942
+ $global_settings = new FrmSettings();
943
+ $global_defaults = $global_settings->default_options();
944
  $defaults['blank'] = $global_defaults['blank_msg'];
945
  }
946
 
947
  $options = maybe_unserialize( $field->field_options );
948
+ self::remove_defaults( $defaults, $options );
949
  self::remove_default_html( 'custom_html', $defaults, $options );
950
 
951
  // Get variations on the defaults.
952
  if ( isset( $options['invalid'] ) ) {
953
  $defaults = array(
 
954
  'invalid' => sprintf( __( '%s is invalid', 'formidable' ), $field->name ),
955
  );
956
  self::remove_defaults( $defaults, $options );
970
  return $defaults;
971
  }
972
 
973
+ /**
974
  * Compare the default array to the saved values and
975
  * remove if they are the same
976
  *
985
  }
986
  unset( $defaults[ $d ] );
987
  }
988
+ $saved = array_diff_assoc( (array) $saved, $defaults );
989
  }
990
 
991
+ /**
992
  * The line endings may prevent html from being equal when it should
993
  *
994
  * @since 3.06
998
  return;
999
  }
1000
 
1001
+ $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1002
  $default_html = $defaults[ $html_name ];
1003
  if ( $old_html == $default_html ) {
1004
  unset( $options[ $html_name ] );
 
1005
  return;
1006
  }
1007
 
1016
  $str = maybe_unserialize( $str );
1017
  if ( is_array( $str ) ) {
1018
  $str = json_encode( $str );
1019
+ } else if ( seems_utf8( $str ) == false ) {
1020
  $str = utf8_encode( $str );
1021
  }
1022
 
1023
  if ( is_numeric( $str ) ) {
1024
+ return $str;
1025
+ }
1026
 
1027
  self::remove_invalid_characters_from_xml( $str );
1028
 
1036
  * Remove <US> character (unit separator) from exported strings
1037
  *
1038
  * @since 2.0.22
 
1039
  * @param string $str
1040
  */
1041
  private static function remove_invalid_characters_from_xml( &$str ) {
1043
  $str = str_replace( '\x1F', '', $str );
1044
  }
1045
 
1046
+ public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1047
+ // Get post type
1048
+ $post_type = FrmFormActionsController::$action_post_type;
1049
 
1050
+ // Set up imported index, if not set up yet
1051
+ if ( ! isset( $imported['imported']['actions'] ) ) {
1052
+ $imported['imported']['actions'] = 0;
1053
+ }
1054
 
1055
+ // Migrate post settings to action
1056
+ self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
1057
 
1058
+ // Migrate email settings to action
1059
+ self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
1060
+ }
1061
 
1062
+ /**
1063
+ * Migrate post settings to form action
1064
+ *
1065
+ * @param string $post_type
1066
+ */
1067
+ private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1068
  if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1069
+ return;
1070
+ }
1071
+
1072
+ $new_action = array(
1073
+ 'post_type' => $post_type,
1074
+ 'post_excerpt' => 'wppost',
1075
+ 'post_title' => __( 'Create Posts', 'formidable' ),
1076
+ 'menu_order' => $form_id,
1077
+ 'post_status' => 'publish',
1078
+ 'post_content' => array(),
1079
+ 'post_name' => $form_id . '_wppost_1',
1080
+ );
1081
+
1082
+ $post_settings = array( 'post_type', 'post_category', 'post_content', 'post_excerpt', 'post_title', 'post_name', 'post_date', 'post_status', 'post_custom_fields', 'post_password' );
1083
+
1084
+ foreach ( $post_settings as $post_setting ) {
 
 
 
 
 
 
 
 
 
 
 
1085
  if ( isset( $form_options[ $post_setting ] ) ) {
1086
  $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
1087
+ }
1088
  unset( $post_setting );
1089
+ }
1090
 
1091
  $new_action['event'] = array( 'create', 'update' );
1092
 
1093
+ if ( $switch ) {
1094
+ // Fields with string or int saved
1095
+ $basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' );
 
 
 
 
 
 
 
1096
 
1097
+ // Fields with arrays saved
1098
  $array_fields = array( 'post_category', 'post_custom_fields' );
1099
 
1100
  $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
1101
+ }
1102
  $new_action['post_content'] = json_encode( $new_action['post_content'] );
1103
 
1104
  $exists = get_posts(
1105
  array(
1106
+ 'name' => $new_action['post_name'],
1107
+ 'post_type' => $new_action['post_type'],
1108
+ 'post_status' => $new_action['post_status'],
1109
+ 'numberposts' => 1,
1110
  )
1111
  );
1112
 
1113
+ if ( ! $exists ) {
1114
  // this isn't an email, but we need to use a class that will always be included
1115
  FrmDb::save_json_post( $new_action );
1116
+ $imported['imported']['actions']++;
1117
+ }
1118
+ }
1119
 
1120
  /**
1121
  * Switch old field IDs for new field IDs in emails and post
1122
  *
1123
  * @since 2.0
 
1124
  * @param array $post_content - check for old field IDs
1125
  * @param array $basic_fields - fields with string or int saved
1126
  * @param array $array_fields - fields with arrays saved
1128
  * @return string $post_content - new field IDs
1129
  */
1130
  private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
1131
+ global $frm_duplicate_ids;
1132
 
1133
+ // If there aren't IDs that were switched, end now
1134
+ if ( ! $frm_duplicate_ids ) {
1135
+ return;
1136
+ }
1137
 
1138
+ // Get old IDs
1139
+ $old = array_keys( $frm_duplicate_ids );
1140
 
1141
+ // Get new IDs
1142
+ $new = array_values( $frm_duplicate_ids );
1143
 
1144
+ // Do a str_replace with each item to set the new IDs
1145
+ foreach ( $post_content as $key => $setting ) {
1146
+ if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
1147
+ // Replace old IDs with new IDs
1148
  $post_content[ $key ] = str_replace( $old, $new, $setting );
1149
+ } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
1150
+ foreach ( $setting as $k => $val ) {
1151
+ // Replace old IDs with new IDs
1152
  $post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
1153
+ }
1154
+ }
1155
+ unset( $key, $setting );
1156
+ }
1157
+ return $post_content;
1158
+ }
1159
+
1160
+ private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1161
+ // No old notifications or autoresponders to carry over
 
1162
  if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
1163
+ return;
1164
+ }
1165
 
1166
+ // Initialize notifications array
1167
+ $notifications = array();
1168
 
1169
+ // Migrate regular notifications
1170
+ self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
1171
 
1172
+ // Migrate autoresponders
1173
+ self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
1174
 
1175
+ if ( empty( $notifications ) ) {
1176
+ return;
1177
+ }
1178
 
1179
+ foreach ( $notifications as $new_notification ) {
1180
+ $new_notification['post_type'] = $post_type;
1181
+ $new_notification['post_excerpt'] = 'email';
1182
+ $new_notification['post_title'] = __( 'Email Notification', 'formidable' );
1183
+ $new_notification['menu_order'] = $form_id;
1184
+ $new_notification['post_status'] = 'publish';
1185
 
1186
+ // Switch field IDs and keys, if needed
1187
+ if ( $switch ) {
1188
 
1189
  // Switch field IDs in email conditional logic
1190
  self::switch_email_contition_field_ids( $new_notification['post_content'] );
1191
 
1192
  // Switch all other field IDs in email
1193
+ $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
1194
+ }
1195
+ $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
1196
 
1197
  $exists = get_posts(
1198
  array(
1199
+ 'name' => $new_notification['post_name'],
1200
+ 'post_type' => $new_notification['post_type'],
1201
+ 'post_status' => $new_notification['post_status'],
1202
+ 'numberposts' => 1,
1203
  )
1204
  );
1205
 
1206
  if ( empty( $exists ) ) {
1207
  FrmDb::save_json_post( $new_notification );
1208
+ $imported['imported']['actions']++;
1209
+ }
1210
  unset( $new_notification );
1211
+ }
1212
 
1213
  self::remove_deprecated_notification_settings( $form_id, $form_options );
1214
+ }
1215
 
1216
  /**
1217
  * Remove deprecated notification settings after migration
1231
  FrmForm::update( $form_id, array( 'options' => $form_options ) );
1232
  }
1233
 
1234
+ private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
1235
+ if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
1236
+ // add old settings into notification array
1237
  $form_options['notification'] = array( 0 => $form_options );
1238
+ } else if ( isset( $form_options['notification']['email_to'] ) ) {
1239
+ // make sure it's in the correct format
1240
  $form_options['notification'] = array( 0 => $form_options['notification'] );
1241
+ }
1242
 
1243
  if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) {
1244
+ foreach ( $form_options['notification'] as $email_key => $notification ) {
1245
 
1246
  $atts = array(
1247
+ 'email_to' => '',
1248
+ 'reply_to' => '',
1249
  'reply_to_name' => '',
1250
+ 'event' => '',
1251
+ 'form_id' => $form_id,
1252
+ 'email_key' => $email_key,
1253
  );
1254
 
1255
+ // Format the email data
1256
+ self::format_email_data( $atts, $notification );
1257
 
1258
  if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
1259
  do_action( 'frm_create_twilio_action', $atts, $notification );
1260
  }
1261
 
1262
+ // Setup the new notification
1263
+ $new_notification = array();
1264
+ self::setup_new_notification( $new_notification, $notification, $atts );
1265
 
1266
+ $notifications[] = $new_notification;
1267
+ }
1268
+ }
1269
+ }
1270
 
1271
+ private static function format_email_data( &$atts, $notification ) {
1272
+ // Format email_to
1273
+ self::format_email_to_data( $atts, $notification );
1274
 
1275
+ // Format the reply to email and name
1276
  $reply_fields = array(
1277
  'reply_to' => '',
1278
  'reply_to_name' => '',
1279
  );
1280
+ foreach ( $reply_fields as $f => $val ) {
1281
  if ( isset( $notification[ $f ] ) ) {
1282
  $atts[ $f ] = $notification[ $f ];
1283
  if ( 'custom' == $notification[ $f ] ) {
1284
  $atts[ $f ] = $notification[ 'cust_' . $f ];
1285
+ } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
1286
  $atts[ $f ] = '[' . $atts[ $f ] . ']';
1287
+ }
1288
+ }
1289
+ unset( $f, $val );
1290
+ }
1291
 
1292
+ // Format event
1293
  $atts['event'] = array( 'create' );
1294
+ if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
1295
+ $atts['event'][] = 'update';
1296
  } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
1297
  $atts['event'] = array( 'update' );
1298
+ }
1299
+ }
1300
 
1301
+ private static function format_email_to_data( &$atts, $notification ) {
1302
+ if ( isset( $notification['email_to'] ) ) {
1303
  $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
1304
+ } else {
1305
+ $atts['email_to'] = array();
1306
+ }
1307
 
1308
+ if ( isset( $notification['also_email_to'] ) ) {
1309
+ $email_fields = (array) $notification['also_email_to'];
1310
+ $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
1311
+ unset( $email_fields );
1312
+ }
1313
 
1314
+ foreach ( $atts['email_to'] as $key => $email_field ) {
1315
 
1316
+ if ( is_numeric( $email_field ) ) {
1317
  $atts['email_to'][ $key ] = '[' . $email_field . ']';
1318
+ }
1319
 
1320
  if ( strpos( $email_field, '|' ) ) {
1321
+ $email_opt = explode( '|', $email_field );
1322
+ if ( isset( $email_opt[0] ) ) {
1323
  $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1324
+ }
1325
+ unset( $email_opt );
1326
+ }
1327
+ }
1328
  $atts['email_to'] = implode( ', ', $atts['email_to'] );
1329
+ }
1330
+
1331
+ private static function setup_new_notification( &$new_notification, $notification, $atts ) {
1332
+ // Set up new notification
1333
+ $new_notification = array(
1334
+ 'post_content' => array(
1335
+ 'email_to' => $atts['email_to'],
1336
+ 'event' => $atts['event'],
1337
+ ),
1338
+ 'post_name' => $atts['form_id'] . '_email_' . $atts['email_key'],
1339
+ );
1340
+
1341
+ // Add more fields to the new notification
1342
+ $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1343
+ foreach ( $add_fields as $add_field ) {
1344
  if ( isset( $notification[ $add_field ] ) ) {
1345
  $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
1346
+ } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1347
  $new_notification['post_content'][ $add_field ] = 0;
1348
+ } else {
1349
  $new_notification['post_content'][ $add_field ] = '';
1350
+ }
1351
+ unset( $add_field );
1352
+ }
1353
 
1354
  // Set reply to
1355
  $new_notification['post_content']['reply_to'] = $atts['reply_to'];
1356
 
1357
+ // Set from
1358
  if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
1359
  $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>';
1360
+ }
1361
+ }
1362
 
1363
  /**
1364
+ * Switch field IDs in pre-2.0 email conditional logic
1365
+ *
1366
+ * @param $post_content array, pass by reference
1367
+ */
1368
  private static function switch_email_contition_field_ids( &$post_content ) {
1369
  // Switch field IDs in conditional logic
1370
  if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
1377
  }
1378
  }
1379
 
1380
+ private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1381
  if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
1382
  // migrate autoresponder
1383
 
1393
  $email_field = '[' . $email_field . ']';
1394
  }
1395
 
1396
+ $notification = $form_options;
1397
+ $new_notification2 = array(
1398
+ 'post_content' => array(
1399
  'email_message' => $notification['ar_email_message'],
1400
  'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
1401
  'email_to' => $email_field,
1402
  'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
1403
  'inc_user_info' => 0,
1404
  ),
1405
+ 'post_name' => $form_id . '_email_' . count( $notifications ),
1406
+ );
1407
 
1408
+ $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1409
  $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
1410
 
1411
  if ( ! empty( $reply_to ) ) {
1416
  $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>';
1417
  }
1418
 
1419
+ $notifications[] = $new_notification2;
1420
+ unset( $new_notification2 );
1421
+ }
1422
+ }
1423
  }
1424
 
classes/models/FrmAddon.php CHANGED
@@ -29,7 +29,7 @@ class FrmAddon {
29
  }
30
 
31
  $this->plugin_folder = plugin_basename( $this->plugin_file );
32
- $this->license = $this->get_license();
33
 
34
  add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) );
35
  $this->edd_plugin_updater();
@@ -42,17 +42,15 @@ class FrmAddon {
42
 
43
  public function insert_installed_addon( $plugins ) {
44
  $plugins[ $this->plugin_slug ] = $this;
45
-
46
  return $plugins;
47
  }
48
 
49
  public static function get_addon( $plugin_slug ) {
50
  $plugins = apply_filters( 'frm_installed_addons', array() );
51
- $plugin = false;
52
  if ( isset( $plugins[ $plugin_slug ] ) ) {
53
  $plugin = $plugins[ $plugin_slug ];
54
  }
55
-
56
  return $plugin;
57
  }
58
 
@@ -78,10 +76,9 @@ class FrmAddon {
78
  *
79
  * @uses api_request()
80
  *
81
- * @param mixed $_data
82
- * @param string $_action
83
- * @param object $_args
84
- *
85
  * @return object $_data
86
  */
87
  public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
@@ -101,15 +98,15 @@ class FrmAddon {
101
  'name' => $this->plugin_name,
102
  'excerpt' => '',
103
  'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>',
104
- 'banners' => array(
105
- 'high' => '',
106
- 'low' => 'https://ps.w.org/formidable/assets/banner-1544x500.png',
107
- ),
108
  );
109
  } else {
110
- $api = new FrmFormApi( $this->license );
111
  $plugins = $api->get_api_info();
112
- $_data = $plugins[ $item_id ];
113
  }
114
 
115
  $_data['sections'] = array(
@@ -176,7 +173,6 @@ class FrmAddon {
176
  $license = '';
177
  }
178
  }
179
-
180
  return $license;
181
  }
182
 
@@ -187,7 +183,6 @@ class FrmAddon {
187
  */
188
  public function get_defined_license() {
189
  $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
190
-
191
  return defined( $consant_name ) ? constant( $consant_name ) : false;
192
  }
193
 
@@ -203,7 +198,6 @@ class FrmAddon {
203
  */
204
  private function is_time_to_auto_activate() {
205
  $last_try = get_option( $this->option_name . 'last_activate' );
206
-
207
  return ( ! $last_try || $last_try < strtotime( '-1 day' ) );
208
  }
209
 
@@ -217,7 +211,6 @@ class FrmAddon {
217
 
218
  /**
219
  * @since 3.04.03
220
- *
221
  * @param array error
222
  */
223
  public function maybe_clear_license( $error ) {
@@ -274,7 +267,7 @@ class FrmAddon {
274
  /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
275
  $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=licenses_settings' ) ) . '">', '</a>' );
276
  } else {
277
- $api = new FrmFormApi( $this->license );
278
  $errors = $api->error_for_license();
279
  if ( ! empty( $errors ) ) {
280
  $message = reset( $errors );
@@ -286,8 +279,7 @@ class FrmAddon {
286
  }
287
 
288
  $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
289
- $id = sanitize_title( $plugin['Name'] ) . '-next';
290
-
291
  echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>';
292
  echo FrmAppHelper::kses( $message, 'a' ); // WPCS: XSS ok.
293
  echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
@@ -324,7 +316,6 @@ class FrmAddon {
324
  * Check if the plugin information is correct to allow an update
325
  *
326
  * @since 3.04.03
327
- *
328
  * @param object $transient - the current plugin info saved for update
329
  */
330
  private function prepare_update_details( &$transient ) {
@@ -354,8 +345,8 @@ class FrmAddon {
354
  * @since 3.04.03
355
  */
356
  protected function get_api_info( $license ) {
357
- $api = new FrmFormApi( $license );
358
- $addon = $api->get_addon_for_license( $this );
359
 
360
  // if there is no download url, this license does not apply to the addon
361
  if ( isset( $addon['package'] ) ) {
@@ -379,7 +370,7 @@ class FrmAddon {
379
  $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0;
380
  if ( ! empty( $timeout ) && time() > $timeout ) {
381
  $version_info = false; // Cache is expired
382
- $api = new FrmFormApi( $this->license );
383
  $api->reset_cached();
384
  }
385
  }
@@ -395,7 +386,7 @@ class FrmAddon {
395
  $version_info->new_version = $version_info->beta['version'];
396
  $version_info->package = $version_info->beta['package'];
397
  if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) {
398
- $version_info->plugin = $version_info->beta['plugin'];
399
  }
400
  }
401
  }
@@ -415,7 +406,6 @@ class FrmAddon {
415
 
416
  private function has_been_cleared() {
417
  $last_cleared = get_option( 'frm_last_cleared' );
418
-
419
  return ( $last_cleared && $last_cleared > date( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
420
  }
421
 
@@ -470,10 +460,10 @@ class FrmAddon {
470
  );
471
  }
472
 
473
- $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
474
- $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
475
  $this_plugin = self::get_addon( $plugin_slug );
476
- $response = $this_plugin->activate_license( $license );
477
 
478
  echo json_encode( $response );
479
  wp_die();
@@ -483,7 +473,7 @@ class FrmAddon {
483
  $this->set_license( $license );
484
  $this->license = $license;
485
 
486
- $response = $this->get_license_status();
487
  $response['message'] = '';
488
  $response['success'] = false;
489
 
@@ -499,7 +489,7 @@ class FrmAddon {
499
 
500
  $is_valid = false;
501
  if ( 'valid' === $response['status'] ) {
502
- $is_valid = 'valid';
503
  $response['success'] = true;
504
  }
505
  $this->set_active( $is_valid );
@@ -515,13 +505,12 @@ class FrmAddon {
515
  );
516
  if ( empty( $this->license ) ) {
517
  $response['error'] = false;
518
-
519
  return $response;
520
  }
521
 
522
  try {
523
  $response['error'] = false;
524
- $license_data = $this->send_mothership_request( 'activate_license' );
525
 
526
  // $license_data->license will be either "valid" or "invalid"
527
  if ( is_array( $license_data ) ) {
@@ -540,13 +529,13 @@ class FrmAddon {
540
 
541
  private function get_messages() {
542
  return array(
543
- 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ),
544
- 'invalid' => __( 'That license key is invalid', 'formidable' ),
545
- 'expired' => __( 'That license is expired', 'formidable' ),
546
- 'revoked' => __( 'That license has been refunded', 'formidable' ),
547
  'no_activations_left' => __( 'That license has been used on too many sites', 'formidable' ),
548
- 'invalid_item_id' => __( 'Oops! That is the wrong license key for this plugin.', 'formidable' ),
549
- 'missing' => __( 'That license key is invalid', 'formidable' ),
550
  );
551
  }
552
 
@@ -554,9 +543,9 @@ class FrmAddon {
554
  FrmAppHelper::permission_check( 'frm_change_settings' );
555
  check_ajax_referer( 'frm_ajax', 'nonce' );
556
 
557
- $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
558
- $this_plugin = self::get_addon( $plugin_slug );
559
- $license = $this_plugin->get_license();
560
  $this_plugin->license = $license;
561
 
562
  $response = array(
@@ -595,8 +584,8 @@ class FrmAddon {
595
  }
596
 
597
  $arg_array = array(
598
- 'body' => $api_params,
599
- 'timeout' => 25,
600
  'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
601
  );
602
 
29
  }
30
 
31
  $this->plugin_folder = plugin_basename( $this->plugin_file );
32
+ $this->license = $this->get_license();
33
 
34
  add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) );
35
  $this->edd_plugin_updater();
42
 
43
  public function insert_installed_addon( $plugins ) {
44
  $plugins[ $this->plugin_slug ] = $this;
 
45
  return $plugins;
46
  }
47
 
48
  public static function get_addon( $plugin_slug ) {
49
  $plugins = apply_filters( 'frm_installed_addons', array() );
50
+ $plugin = false;
51
  if ( isset( $plugins[ $plugin_slug ] ) ) {
52
  $plugin = $plugins[ $plugin_slug ];
53
  }
 
54
  return $plugin;
55
  }
56
 
76
  *
77
  * @uses api_request()
78
  *
79
+ * @param mixed $_data
80
+ * @param string $_action
81
+ * @param object $_args
 
82
  * @return object $_data
83
  */
84
  public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
98
  'name' => $this->plugin_name,
99
  'excerpt' => '',
100
  'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>',
101
+ 'banners' => array(
102
+ 'high' => '',
103
+ 'low' => 'https://ps.w.org/formidable/assets/banner-1544x500.png',
104
+ ),
105
  );
106
  } else {
107
+ $api = new FrmFormApi( $this->license );
108
  $plugins = $api->get_api_info();
109
+ $_data = $plugins[ $item_id ];
110
  }
111
 
112
  $_data['sections'] = array(
173
  $license = '';
174
  }
175
  }
 
176
  return $license;
177
  }
178
 
183
  */
184
  public function get_defined_license() {
185
  $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
 
186
  return defined( $consant_name ) ? constant( $consant_name ) : false;
187
  }
188
 
198
  */
199
  private function is_time_to_auto_activate() {
200
  $last_try = get_option( $this->option_name . 'last_activate' );
 
201
  return ( ! $last_try || $last_try < strtotime( '-1 day' ) );
202
  }
203
 
211
 
212
  /**
213
  * @since 3.04.03
 
214
  * @param array error
215
  */
216
  public function maybe_clear_license( $error ) {
267
  /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
268
  $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings&t=licenses_settings' ) ) . '">', '</a>' );
269
  } else {
270
+ $api = new FrmFormApi( $this->license );
271
  $errors = $api->error_for_license();
272
  if ( ! empty( $errors ) ) {
273
  $message = reset( $errors );
279
  }
280
 
281
  $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
282
+ $id = sanitize_title( $plugin['Name'] ) . '-next';
 
283
  echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>';
284
  echo FrmAppHelper::kses( $message, 'a' ); // WPCS: XSS ok.
285
  echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
316
  * Check if the plugin information is correct to allow an update
317
  *
318
  * @since 3.04.03
 
319
  * @param object $transient - the current plugin info saved for update
320
  */
321
  private function prepare_update_details( &$transient ) {
345
  * @since 3.04.03
346
  */
347
  protected function get_api_info( $license ) {
348
+ $api = new FrmFormApi( $license );
349
+ $addon = $api->get_addon_for_license( $this );
350
 
351
  // if there is no download url, this license does not apply to the addon
352
  if ( isset( $addon['package'] ) ) {
370
  $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0;
371
  if ( ! empty( $timeout ) && time() > $timeout ) {
372
  $version_info = false; // Cache is expired
373
+ $api = new FrmFormApi( $this->license );
374
  $api->reset_cached();
375
  }
376
  }
386
  $version_info->new_version = $version_info->beta['version'];
387
  $version_info->package = $version_info->beta['package'];
388
  if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) {
389
+ $version_info->plugin = $version_info->beta['plugin'];
390
  }
391
  }
392
  }
406
 
407
  private function has_been_cleared() {
408
  $last_cleared = get_option( 'frm_last_cleared' );
 
409
  return ( $last_cleared && $last_cleared > date( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
410
  }
411
 
460
  );
461
  }
462
 
463
+ $license = stripslashes( sanitize_text_field( $_POST['license'] ) );
464
+ $plugin_slug = sanitize_text_field( $_POST['plugin'] );
465
  $this_plugin = self::get_addon( $plugin_slug );
466
+ $response = $this_plugin->activate_license( $license );
467
 
468
  echo json_encode( $response );
469
  wp_die();
473
  $this->set_license( $license );
474
  $this->license = $license;
475
 
476
+ $response = $this->get_license_status();
477
  $response['message'] = '';
478
  $response['success'] = false;
479
 
489
 
490
  $is_valid = false;
491
  if ( 'valid' === $response['status'] ) {
492
+ $is_valid = 'valid';
493
  $response['success'] = true;
494
  }
495
  $this->set_active( $is_valid );
505
  );
506
  if ( empty( $this->license ) ) {
507
  $response['error'] = false;
 
508
  return $response;
509
  }
510
 
511
  try {
512
  $response['error'] = false;
513
+ $license_data = $this->send_mothership_request( 'activate_license' );
514
 
515
  // $license_data->license will be either "valid" or "invalid"
516
  if ( is_array( $license_data ) ) {
529
 
530
  private function get_messages() {
531
  return array(
532
+ 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ),
533
+ 'invalid' => __( 'That license key is invalid', 'formidable' ),
534
+ 'expired' => __( 'That license is expired', 'formidable' ),
535
+ 'revoked' => __( 'That license has been refunded', 'formidable' ),
536
  'no_activations_left' => __( 'That license has been used on too many sites', 'formidable' ),
537
+ 'invalid_item_id' => __( 'Oops! That is the wrong license key for this plugin.', 'formidable' ),
538
+ 'missing' => __( 'That license key is invalid', 'formidable' ),
539
  );
540
  }
541
 
543
  FrmAppHelper::permission_check( 'frm_change_settings' );
544
  check_ajax_referer( 'frm_ajax', 'nonce' );
545
 
546
+ $plugin_slug = sanitize_text_field( $_POST['plugin'] );
547
+ $this_plugin = self::get_addon( $plugin_slug );
548
+ $license = $this_plugin->get_license();
549
  $this_plugin->license = $license;
550
 
551
  $response = array(
584
  }
585
 
586
  $arg_array = array(
587
+ 'body' => $api_params,
588
+ 'timeout' => 25,
589
  'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
590
  );
591
 
classes/models/FrmCreateFile.php CHANGED
@@ -16,12 +16,12 @@ class FrmCreateFile {
16
  private $has_permission = false;
17
 
18
  public function __construct( $atts ) {
19
- $this->folder_name = isset( $atts['folder_name'] ) ? $atts['folder_name'] : '';
20
- $this->file_name = $atts['file_name'];
21
  $this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : '';
22
- $this->uploads = wp_upload_dir();
23
  $this->set_new_file_path( $atts );
24
- $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
25
  $this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
26
 
27
  $this->check_permission();
@@ -62,7 +62,7 @@ class FrmCreateFile {
62
  if ( file_exists( $this->new_file_path ) ) {
63
 
64
  $existing_content = $this->get_contents();
65
- $file_content = $existing_content . $file_content;
66
  }
67
 
68
  $this->create_file( $file_content );
@@ -107,7 +107,6 @@ class FrmCreateFile {
107
  if ( empty( $file ) ) {
108
  $file = $this->new_file_path;
109
  }
110
-
111
  return $wp_filesystem->get_contents( $file );
112
  }
113
 
@@ -141,12 +140,12 @@ class FrmCreateFile {
141
  }
142
 
143
  private function get_needed_dirs() {
144
- $dir_names = explode( '/', $this->folder_name );
145
  $needed_dirs = array();
146
 
147
  $next_dir = '';
148
  foreach ( $dir_names as $dir ) {
149
- $next_dir .= '/' . $dir;
150
  $needed_dirs[] = $this->uploads['basedir'] . $next_dir;
151
  }
152
 
@@ -164,7 +163,6 @@ class FrmCreateFile {
164
  } else {
165
  $creds = $this->get_ftp_creds( $access_type );
166
  }
167
-
168
  return $creds;
169
  }
170
 
@@ -182,7 +180,7 @@ class FrmCreateFile {
182
  $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : '';
183
 
184
  // Check to see if we are setting the public/private keys for ssh
185
- $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : '';
186
  $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : '';
187
 
188
  // Sanitize the hostname, Some people might pass in odd-data:
@@ -199,16 +197,16 @@ class FrmCreateFile {
199
 
200
  if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) {
201
  $credentials['connection_type'] = 'ssh';
202
- } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) {
203
  //Only the FTP Extension understands SSL
204
  $credentials['connection_type'] = 'ftps';
205
- } elseif ( ! isset( $credentials['connection_type'] ) ) {
206
  //All else fails (And it's not defaulted to something else saved), Default to FTP
207
  $credentials['connection_type'] = 'ftp';
208
  }
209
 
210
  $has_creds = ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) );
211
- $can_ssh = ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) );
212
  if ( $has_creds || $can_ssh ) {
213
  $stored_credentials = $credentials;
214
  if ( ! empty( $stored_credentials['port'] ) ) {
16
  private $has_permission = false;
17
 
18
  public function __construct( $atts ) {
19
+ $this->folder_name = isset( $atts['folder_name'] ) ? $atts['folder_name'] : '';
20
+ $this->file_name = $atts['file_name'];
21
  $this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : '';
22
+ $this->uploads = wp_upload_dir();
23
  $this->set_new_file_path( $atts );
24
+ $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
25
  $this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
26
 
27
  $this->check_permission();
62
  if ( file_exists( $this->new_file_path ) ) {
63
 
64
  $existing_content = $this->get_contents();
65
+ $file_content = $existing_content . $file_content;
66
  }
67
 
68
  $this->create_file( $file_content );
107
  if ( empty( $file ) ) {
108
  $file = $this->new_file_path;
109
  }
 
110
  return $wp_filesystem->get_contents( $file );
111
  }
112
 
140
  }
141
 
142
  private function get_needed_dirs() {
143
+ $dir_names = explode( '/', $this->folder_name );
144
  $needed_dirs = array();
145
 
146
  $next_dir = '';
147
  foreach ( $dir_names as $dir ) {
148
+ $next_dir .= '/' . $dir;
149
  $needed_dirs[] = $this->uploads['basedir'] . $next_dir;
150
  }
151
 
163
  } else {
164
  $creds = $this->get_ftp_creds( $access_type );
165
  }
 
166
  return $creds;
167
  }
168
 
180
  $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : '';
181
 
182
  // Check to see if we are setting the public/private keys for ssh
183
+ $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : '';
184
  $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : '';
185
 
186
  // Sanitize the hostname, Some people might pass in odd-data:
197
 
198
  if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) {
199
  $credentials['connection_type'] = 'ssh';
200
+ } else if ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) {
201
  //Only the FTP Extension understands SSL
202
  $credentials['connection_type'] = 'ftps';
203
+ } else if ( ! isset( $credentials['connection_type'] ) ) {
204
  //All else fails (And it's not defaulted to something else saved), Default to FTP
205
  $credentials['connection_type'] = 'ftp';
206
  }
207
 
208
  $has_creds = ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) );
209
+ $can_ssh = ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) );
210
  if ( $has_creds || $can_ssh ) {
211
  $stored_credentials = $credentials;
212
  if ( ! empty( $stored_credentials['port'] ) ) {
classes/models/FrmDb.php CHANGED
@@ -1,42 +1,41 @@
1
  <?php
2
 
3
  class FrmDb {
4
- public $fields;
5
- public $forms;
6
- public $entries;
7
- public $entry_metas;
8
 
9
- public function __construct() {
10
  if ( ! defined( 'ABSPATH' ) ) {
11
  die( 'You are not allowed to call this page directly.' );
12
  }
13
 
14
  _deprecated_function( __METHOD__, '2.05.06', 'FrmMigrate' );
15
- global $wpdb;
16
- $this->fields = $wpdb->prefix . 'frm_fields';
17
- $this->forms = $wpdb->prefix . 'frm_forms';
18
- $this->entries = $wpdb->prefix . 'frm_items';
19
- $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
20
- }
21
 
22
- /**
23
- * Change array into format $wpdb->prepare can use
24
  *
25
  * @param array $args
26
  * @param string $starts_with
27
- */
28
- public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
  if ( empty( $args ) ) {
30
  // add an arg to prevent prepare from failing
31
  $args = array(
32
- 'where' => $starts_with . '1=%d',
33
  'values' => array( 1 ),
34
  );
35
-
36
  return;
37
- }
38
 
39
- $where = '';
40
  $values = array();
41
 
42
  if ( is_array( $args ) ) {
@@ -45,26 +44,26 @@ class FrmDb {
45
  }
46
 
47
  $args = compact( 'where', 'values' );
48
- }
49
 
50
- /**
51
  * @param array $args
52
- * @param string $base_where
53
- * @param string $where
54
  * @param array $values
55
- */
56
- public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
57
- $condition = ' AND';
58
- if ( isset( $args['or'] ) ) {
59
- $condition = ' OR';
60
- unset( $args['or'] );
61
- }
62
 
63
  foreach ( $args as $key => $value ) {
64
- $where .= empty( $where ) ? $base_where : $condition;
65
  $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
66
  if ( is_numeric( $key ) || $array_inc_null ) {
67
- $where .= ' ( ';
68
  $nested_where = '';
69
  if ( $array_inc_null ) {
70
  foreach ( $value as $val ) {
@@ -85,28 +84,28 @@ class FrmDb {
85
  }
86
  }
87
 
88
- /**
89
- * @param string $key
90
  * @param string|array $value
91
- * @param string $where
92
  * @param array $values
93
- */
94
- private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
95
  $key = trim( $key );
96
 
97
  if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
98
- $k = explode( ' ', $key );
99
- $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
100
- $values[] = '%Y-%m-%d %H:%i:%s';
101
- } else {
102
  $where .= ' ' . $key;
103
- }
104
 
105
  $lowercase_key = explode( ' ', strtolower( $key ) );
106
  $lowercase_key = end( $lowercase_key );
107
 
108
- if ( is_array( $value ) ) {
109
- // translate array of values to "in"
110
  if ( strpos( $lowercase_key, 'like' ) !== false ) {
111
  $where = preg_replace( '/' . $key . '$/', '', $where );
112
  $where .= '(';
@@ -115,40 +114,40 @@ class FrmDb {
115
  if ( ! $start ) {
116
  $where .= ' OR ';
117
  }
118
- $start = false;
119
- $where .= $key . ' %s';
120
  $values[] = '%' . self::esc_like( $v ) . '%';
121
  }
122
  $where .= ')';
123
- } elseif ( ! empty( $value ) ) {
124
- $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
125
  $values = array_merge( $values, $value );
126
  }
127
- } elseif ( strpos( $lowercase_key, 'like' ) !== false ) {
128
  /**
129
  * Allow string to start or end with the value
130
  * If the key is like% then skip the first % for starts with
131
  * If the key is %like then skip the last % for ends with
132
  */
133
  $start = '%';
134
- $end = '%';
135
  if ( $lowercase_key == 'like%' ) {
136
  $start = '';
137
  $where = rtrim( $where, '%' );
138
- } elseif ( $lowercase_key == '%like' ) {
139
- $end = '';
140
  $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
141
  $where .= 'like';
142
  }
143
 
144
- $where .= ' %s';
145
  $values[] = $start . self::esc_like( $value ) . $end;
146
 
147
- } elseif ( $value === null ) {
148
- $where .= ' IS NULL';
149
- } else {
150
  // allow a - to prevent = from being added
151
- if ( substr( $key, - 1 ) == '-' ) {
152
  $where = rtrim( $where, '-' );
153
  } else {
154
  $where .= '=';
@@ -156,20 +155,19 @@ class FrmDb {
156
 
157
  self::add_query_placeholder( $key, $value, $where );
158
 
159
- $values[] = $value;
160
- }
161
- }
162
 
163
  /**
164
  * Add %d, or %s to query
165
  *
166
  * @since 2.02.05
167
- *
168
  * @param string $key
169
  * @param int|string $value
170
  * @param string $where
171
  */
172
- private static function add_query_placeholder( $key, $value, &$where ) {
173
  if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
174
  $value = $value + 0; // switch string to number
175
  $where .= is_float( $value ) ? '%f' : '%d';
@@ -178,18 +176,16 @@ class FrmDb {
178
  }
179
  }
180
 
181
- /**
182
- * @param string $table
183
  * @param array $where
184
  * @param array $args
185
- *
186
  * @return int
187
- */
188
- public static function get_count( $table, $where = array(), $args = array() ) {
189
- $count = self::get_var( $table, $where, 'COUNT(*)', $args );
190
-
191
- return $count;
192
- }
193
 
194
  /**
195
  * @param string $table
@@ -198,21 +194,19 @@ class FrmDb {
198
  * @param array $args
199
  * @param string $limit
200
  * @param string $type
201
- *
202
  * @return array|null|string|object
203
  */
204
- public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
205
- $group = '';
206
- self::get_group_and_table_name( $table, $group );
207
  self::convert_options_to_array( $args, '', $limit );
208
 
209
  $query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
210
 
211
  $cache_key = self::generate_cache_key( $where, $args, $field, $type );
212
- $results = self::check_cache( $cache_key, $group, $query, 'get_' . $type );
213
-
214
- return $results;
215
- }
216
 
217
  /**
218
  * Generate a cache key from the where query, field, type, and other arguments
@@ -228,7 +222,7 @@ class FrmDb {
228
  */
229
  private static function generate_cache_key( $where, $args, $field, $type ) {
230
  $cache_key = '';
231
- $where = FrmAppHelper::array_flatten( $where );
232
  foreach ( $where as $key => $value ) {
233
  $cache_key .= $key . '_' . $value;
234
  }
@@ -238,71 +232,64 @@ class FrmDb {
238
  return $cache_key;
239
  }
240
 
241
- /**
242
- * @param string $table
243
- * @param array $where
244
  * @param string $field
245
  * @param array $args
246
  * @param string $limit
247
- *
248
  * @return mixed
249
- */
250
- public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
251
- return self::get_var( $table, $where, $field, $args, $limit, 'col' );
252
- }
253
-
254
- /**
255
- * @since 2.0
256
- *
257
- * @param string $table
258
  * @param array $where
259
  * @param string $fields
260
  * @param array $args
261
- *
262
  * @return mixed
263
- */
264
- public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
265
- $args['limit'] = 1;
 
 
266
 
267
- return self::get_var( $table, $where, $fields, $args, '', 'row' );
268
- }
269
-
270
- /**
271
- * Prepare a key/value array before DB call
272
  *
273
- * @since 2.0
274
- *
275
- * @param string $table
276
  * @param array $where
277
  * @param string $fields
278
  * @param array $args
279
- *
280
  * @return mixed
281
- */
282
- public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
283
- return self::get_var( $table, $where, $fields, $args, '', 'results' );
284
- }
285
 
286
  /**
287
  * Check for like, not like, in, not in, =, !=, >, <, <=, >=
288
  * Return a value to append to the where array key
289
  *
290
  * @param string $where_is
291
- *
292
  * @return string
293
  */
294
  public static function append_where_is( $where_is ) {
295
  $switch_to = array(
296
- '=' => '',
297
- '!=' => '!',
298
- '<=' => '<',
299
- '>=' => '>',
300
- 'like' => 'like',
301
  'not like' => 'not like',
302
- 'in' => '',
303
- 'not in' => 'not',
304
- 'like%' => 'like%',
305
- '%like' => '%like',
306
  );
307
 
308
  $where_is = strtolower( $where_is );
@@ -319,56 +306,56 @@ class FrmDb {
319
  return '';
320
  }
321
 
322
- /**
323
- * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
324
- * Also add the wpdb->prefix to the table if it's missing
325
- *
326
- * @param string $table
327
- * @param string $group
328
- */
329
- private static function get_group_and_table_name( &$table, &$group ) {
330
  global $wpdb, $wpmuBaseTablePrefix;
331
 
332
  $table_parts = explode( ' ', $table );
333
- $group = reset( $table_parts );
334
- $group = str_replace( $wpdb->prefix, '', $group );
335
 
336
  $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
337
- $group = str_replace( $prefix, '', $group );
338
 
339
- if ( $group == $table ) {
340
- $table = $wpdb->prefix . $table;
341
- }
342
 
343
  // switch to singular group name
344
  $group = rtrim( $group, 's' );
345
- }
346
 
347
- private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
348
  if ( ! is_array( $args ) ) {
349
  $args = array( 'order_by' => $args );
350
- }
351
 
352
- if ( ! empty( $order_by ) ) {
353
- $args['order_by'] = $order_by;
354
- }
355
 
356
- if ( ! empty( $limit ) ) {
357
- $args['limit'] = $limit;
358
- }
359
 
360
- $temp_args = $args;
361
- foreach ( $temp_args as $k => $v ) {
362
- if ( $v == '' ) {
363
  unset( $args[ $k ] );
364
- continue;
365
- }
366
 
367
- $db_name = strtoupper( str_replace( '_', ' ', $k ) );
368
- if ( strpos( $v, $db_name ) === false ) {
369
  $args[ $k ] = $db_name . ' ' . $v;
370
- }
371
- }
372
 
373
  // Make sure LIMIT is the last argument
374
  if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -376,17 +363,15 @@ class FrmDb {
376
  unset( $args['limit'] );
377
  $args['limit'] = $temp_limit;
378
  }
379
- }
380
 
381
  /**
382
  * Get the associative array results for the given columns, table, and where query
383
  *
384
  * @since 2.02.05
385
- *
386
  * @param string $columns
387
  * @param string $table
388
  * @param array $where
389
- *
390
  * @return mixed
391
  */
392
  public static function get_associative_array_results( $columns, $table, $where ) {
@@ -396,7 +381,7 @@ class FrmDb {
396
  $query = self::generate_query_string_from_pieces( $columns, $table, $where );
397
 
398
  $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) );
399
- $results = self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
400
 
401
  return $results;
402
  }
@@ -410,7 +395,6 @@ class FrmDb {
410
  * @param string $table
411
  * @param mixed $where
412
  * @param array $args
413
- *
414
  * @return string
415
  */
416
  private static function generate_query_string_from_pieces( $columns, $table, $where, $args = array() ) {
@@ -451,24 +435,21 @@ class FrmDb {
451
  }
452
  }
453
 
454
- /**
455
- * Added for < WP 4.0 compatability
456
- *
457
- * @since 2.05.06
458
- *
459
- * @param string $term The value to escape
460
- *
461
- * @return string The escaped value
462
- */
463
  public static function esc_like( $term ) {
464
- global $wpdb;
465
-
466
  return $wpdb->esc_like( $term );
467
- }
468
 
469
  /**
470
  * @since 2.05.06
471
- *
472
  * @param string $order_query
473
  */
474
  public static function esc_order( $order_query ) {
@@ -484,7 +465,7 @@ class FrmDb {
484
 
485
  $order_query = explode( ' ', trim( $order_query ) );
486
 
487
- $order = trim( reset( $order_query ) );
488
  $safe_order = array( 'count(*)' );
489
  if ( ! in_array( strtolower( $order ), $safe_order ) ) {
490
  $order = preg_replace( '/[^a-zA-Z0-9\-\_\.\+]/', '', $order );
@@ -513,7 +494,6 @@ class FrmDb {
513
 
514
  /**
515
  * @param string $limit
516
- *
517
  * @since 2.05.06
518
  */
519
  public static function esc_limit( $limit ) {
@@ -534,7 +514,6 @@ class FrmDb {
534
  }
535
 
536
  $limit = implode( ',', $limit );
537
-
538
  return ' LIMIT ' . $limit;
539
  }
540
 
@@ -545,7 +524,6 @@ class FrmDb {
545
  */
546
  public static function prepare_array_values( $array, $type = '%s' ) {
547
  $placeholders = array_fill( 0, count( $array ), $type );
548
-
549
  return implode( ', ', $placeholders );
550
  }
551
 
@@ -577,7 +555,7 @@ class FrmDb {
577
  * @since 2.05.06
578
  */
579
  public static function save_settings( $settings, $group ) {
580
- $settings = (array) $settings;
581
  $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
582
 
583
  if ( empty( $settings['ID'] ) ) {
@@ -614,18 +592,17 @@ class FrmDb {
614
  return $post;
615
  }
616
 
617
- /**
618
- * Check cache before fetching values and saving to cache
619
- *
620
- * @since 2.05.06
621
- *
622
- * @param string $cache_key The unique name for this cache
623
- * @param string $group The name of the cache group
624
- * @param string $query If blank, don't run a db call
625
- * @param string $type The wpdb function to use with this query
626
- *
627
- * @return mixed $results The cache or query results
628
- */
629
  public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
630
  $results = wp_cache_get( $cache_key, $group );
631
  if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
@@ -664,7 +641,7 @@ class FrmDb {
664
  * @since 2.05.06
665
  */
666
  public static function add_key_to_group_cache( $key, $group ) {
667
- $cached = self::get_group_cached_keys( $group );
668
  $cached[ $key ] = $key;
669
  wp_cache_set( 'cached_keys', $cached, $group, 300 );
670
  }
@@ -683,7 +660,6 @@ class FrmDb {
683
 
684
  /**
685
  * @since 2.05.06
686
- *
687
  * @param string $cache_key
688
  */
689
  public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
@@ -691,13 +667,13 @@ class FrmDb {
691
  wp_cache_delete( $cache_key, $group );
692
  }
693
 
694
- /**
695
- * Delete all caching in a single group
696
- *
697
- * @since 2.05.06
698
- *
699
- * @param string $group The name of the cache group
700
- */
701
  public static function cache_delete_group( $group ) {
702
  $cached_keys = self::get_group_cached_keys( $group );
703
 
1
  <?php
2
 
3
  class FrmDb {
4
+ public $fields;
5
+ public $forms;
6
+ public $entries;
7
+ public $entry_metas;
8
 
9
+ public function __construct() {
10
  if ( ! defined( 'ABSPATH' ) ) {
11
  die( 'You are not allowed to call this page directly.' );
12
  }
13
 
14
  _deprecated_function( __METHOD__, '2.05.06', 'FrmMigrate' );
15
+ global $wpdb;
16
+ $this->fields = $wpdb->prefix . 'frm_fields';
17
+ $this->forms = $wpdb->prefix . 'frm_forms';
18
+ $this->entries = $wpdb->prefix . 'frm_items';
19
+ $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
20
+ }
21
 
22
+ /**
23
+ * Change array into format $wpdb->prepare can use
24
  *
25
  * @param array $args
26
  * @param string $starts_with
27
+ */
28
+ public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
  if ( empty( $args ) ) {
30
  // add an arg to prevent prepare from failing
31
  $args = array(
32
+ 'where' => $starts_with . '1=%d',
33
  'values' => array( 1 ),
34
  );
 
35
  return;
36
+ }
37
 
38
+ $where = '';
39
  $values = array();
40
 
41
  if ( is_array( $args ) ) {
44
  }
45
 
46
  $args = compact( 'where', 'values' );
47
+ }
48
 
49
+ /**
50
  * @param array $args
51
+ * @param string $base_where
52
+ * @param string $where
53
  * @param array $values
54
+ */
55
+ public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
56
+ $condition = ' AND';
57
+ if ( isset( $args['or'] ) ) {
58
+ $condition = ' OR';
59
+ unset( $args['or'] );
60
+ }
61
 
62
  foreach ( $args as $key => $value ) {
63
+ $where .= empty( $where ) ? $base_where : $condition;
64
  $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
65
  if ( is_numeric( $key ) || $array_inc_null ) {
66
+ $where .= ' ( ';
67
  $nested_where = '';
68
  if ( $array_inc_null ) {
69
  foreach ( $value as $val ) {
84
  }
85
  }
86
 
87
+ /**
88
+ * @param string $key
89
  * @param string|array $value
90
+ * @param string $where
91
  * @param array $values
92
+ */
93
+ private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
94
  $key = trim( $key );
95
 
96
  if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
97
+ $k = explode( ' ', $key );
98
+ $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
99
+ $values[] = '%Y-%m-%d %H:%i:%s';
100
+ } else {
101
  $where .= ' ' . $key;
102
+ }
103
 
104
  $lowercase_key = explode( ' ', strtolower( $key ) );
105
  $lowercase_key = end( $lowercase_key );
106
 
107
+ if ( is_array( $value ) ) {
108
+ // translate array of values to "in"
109
  if ( strpos( $lowercase_key, 'like' ) !== false ) {
110
  $where = preg_replace( '/' . $key . '$/', '', $where );
111
  $where .= '(';
114
  if ( ! $start ) {
115
  $where .= ' OR ';
116
  }
117
+ $start = false;
118
+ $where .= $key . ' %s';
119
  $values[] = '%' . self::esc_like( $v ) . '%';
120
  }
121
  $where .= ')';
122
+ } else if ( ! empty( $value ) ) {
123
+ $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
124
  $values = array_merge( $values, $value );
125
  }
126
+ } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
127
  /**
128
  * Allow string to start or end with the value
129
  * If the key is like% then skip the first % for starts with
130
  * If the key is %like then skip the last % for ends with
131
  */
132
  $start = '%';
133
+ $end = '%';
134
  if ( $lowercase_key == 'like%' ) {
135
  $start = '';
136
  $where = rtrim( $where, '%' );
137
+ } else if ( $lowercase_key == '%like' ) {
138
+ $end = '';
139
  $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
140
  $where .= 'like';
141
  }
142
 
143
+ $where .= ' %s';
144
  $values[] = $start . self::esc_like( $value ) . $end;
145
 
146
+ } else if ( $value === null ) {
147
+ $where .= ' IS NULL';
148
+ } else {
149
  // allow a - to prevent = from being added
150
+ if ( substr( $key, -1 ) == '-' ) {
151
  $where = rtrim( $where, '-' );
152
  } else {
153
  $where .= '=';
155
 
156
  self::add_query_placeholder( $key, $value, $where );
157
 
158
+ $values[] = $value;
159
+ }
160
+ }
161
 
162
  /**
163
  * Add %d, or %s to query
164
  *
165
  * @since 2.02.05
 
166
  * @param string $key
167
  * @param int|string $value
168
  * @param string $where
169
  */
170
+ private static function add_query_placeholder( $key, $value, &$where ) {
171
  if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
172
  $value = $value + 0; // switch string to number
173
  $where .= is_float( $value ) ? '%f' : '%d';
176
  }
177
  }
178
 
179
+ /**
180
+ * @param string $table
181
  * @param array $where
182
  * @param array $args
 
183
  * @return int
184
+ */
185
+ public static function get_count( $table, $where = array(), $args = array() ) {
186
+ $count = self::get_var( $table, $where, 'COUNT(*)', $args );
187
+ return $count;
188
+ }
 
189
 
190
  /**
191
  * @param string $table
194
  * @param array $args
195
  * @param string $limit
196
  * @param string $type
 
197
  * @return array|null|string|object
198
  */
199
+ public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
200
+ $group = '';
201
+ self::get_group_and_table_name( $table, $group );
202
  self::convert_options_to_array( $args, '', $limit );
203
 
204
  $query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
205
 
206
  $cache_key = self::generate_cache_key( $where, $args, $field, $type );
207
+ $results = self::check_cache( $cache_key, $group, $query, 'get_' . $type );
208
+ return $results;
209
+ }
 
210
 
211
  /**
212
  * Generate a cache key from the where query, field, type, and other arguments
222
  */
223
  private static function generate_cache_key( $where, $args, $field, $type ) {
224
  $cache_key = '';
225
+ $where = FrmAppHelper::array_flatten( $where );
226
  foreach ( $where as $key => $value ) {
227
  $cache_key .= $key . '_' . $value;
228
  }
232
  return $cache_key;
233
  }
234
 
235
+ /**
236
+ * @param string $table
237
+ * @param array $where
238
  * @param string $field
239
  * @param array $args
240
  * @param string $limit
 
241
  * @return mixed
242
+ */
243
+ public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
244
+ return self::get_var( $table, $where, $field, $args, $limit, 'col' );
245
+ }
246
+
247
+ /**
248
+ * @since 2.0
249
+ * @param string $table
 
250
  * @param array $where
251
  * @param string $fields
252
  * @param array $args
 
253
  * @return mixed
254
+ */
255
+ public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
256
+ $args['limit'] = 1;
257
+ return self::get_var( $table, $where, $fields, $args, '', 'row' );
258
+ }
259
 
260
+ /**
261
+ * Prepare a key/value array before DB call
 
 
 
262
  *
263
+ * @since 2.0
264
+ * @param string $table
 
265
  * @param array $where
266
  * @param string $fields
267
  * @param array $args
 
268
  * @return mixed
269
+ */
270
+ public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
271
+ return self::get_var( $table, $where, $fields, $args, '', 'results' );
272
+ }
273
 
274
  /**
275
  * Check for like, not like, in, not in, =, !=, >, <, <=, >=
276
  * Return a value to append to the where array key
277
  *
278
  * @param string $where_is
 
279
  * @return string
280
  */
281
  public static function append_where_is( $where_is ) {
282
  $switch_to = array(
283
+ '=' => '',
284
+ '!=' => '!',
285
+ '<=' => '<',
286
+ '>=' => '>',
287
+ 'like' => 'like',
288
  'not like' => 'not like',
289
+ 'in' => '',
290
+ 'not in' => 'not',
291
+ 'like%' => 'like%',
292
+ '%like' => '%like',
293
  );
294
 
295
  $where_is = strtolower( $where_is );
306
  return '';
307
  }
308
 
309
+ /**
310
+ * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
311
+ * Also add the wpdb->prefix to the table if it's missing
312
+ *
313
+ * @param string $table
314
+ * @param string $group
315
+ */
316
+ private static function get_group_and_table_name( &$table, &$group ) {
317
  global $wpdb, $wpmuBaseTablePrefix;
318
 
319
  $table_parts = explode( ' ', $table );
320
+ $group = reset( $table_parts );
321
+ $group = str_replace( $wpdb->prefix, '', $group );
322
 
323
  $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
324
+ $group = str_replace( $prefix, '', $group );
325
 
326
+ if ( $group == $table ) {
327
+ $table = $wpdb->prefix . $table;
328
+ }
329
 
330
  // switch to singular group name
331
  $group = rtrim( $group, 's' );
332
+ }
333
 
334
+ private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
335
  if ( ! is_array( $args ) ) {
336
  $args = array( 'order_by' => $args );
337
+ }
338
 
339
+ if ( ! empty( $order_by ) ) {
340
+ $args['order_by'] = $order_by;
341
+ }
342
 
343
+ if ( ! empty( $limit ) ) {
344
+ $args['limit'] = $limit;
345
+ }
346
 
347
+ $temp_args = $args;
348
+ foreach ( $temp_args as $k => $v ) {
349
+ if ( $v == '' ) {
350
  unset( $args[ $k ] );
351
+ continue;
352
+ }
353
 
354
+ $db_name = strtoupper( str_replace( '_', ' ', $k ) );
355
+ if ( strpos( $v, $db_name ) === false ) {
356
  $args[ $k ] = $db_name . ' ' . $v;
357
+ }
358
+ }
359
 
360
  // Make sure LIMIT is the last argument
361
  if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
363
  unset( $args['limit'] );
364
  $args['limit'] = $temp_limit;
365
  }
366
+ }
367
 
368
  /**
369
  * Get the associative array results for the given columns, table, and where query
370
  *
371
  * @since 2.02.05
 
372
  * @param string $columns
373
  * @param string $table
374
  * @param array $where
 
375
  * @return mixed
376
  */
377
  public static function get_associative_array_results( $columns, $table, $where ) {
381
  $query = self::generate_query_string_from_pieces( $columns, $table, $where );
382
 
383
  $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) );
384
+ $results = self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
385
 
386
  return $results;
387
  }
395
  * @param string $table
396
  * @param mixed $where
397
  * @param array $args
 
398
  * @return string
399
  */
400
  private static function generate_query_string_from_pieces( $columns, $table, $where, $args = array() ) {
435
  }
436
  }
437
 
438
+ /**
439
+ * Added for < WP 4.0 compatability
440
+ *
441
+ * @since 2.05.06
442
+ *
443
+ * @param string $term The value to escape
444
+ * @return string The escaped value
445
+ */
 
446
  public static function esc_like( $term ) {
447
+ global $wpdb;
 
448
  return $wpdb->esc_like( $term );
449
+ }
450
 
451
  /**
452
  * @since 2.05.06
 
453
  * @param string $order_query
454
  */
455
  public static function esc_order( $order_query ) {
465
 
466
  $order_query = explode( ' ', trim( $order_query ) );
467
 
468
+ $order = trim( reset( $order_query ) );
469
  $safe_order = array( 'count(*)' );
470
  if ( ! in_array( strtolower( $order ), $safe_order ) ) {
471
  $order = preg_replace( '/[^a-zA-Z0-9\-\_\.\+]/', '', $order );
494
 
495
  /**
496
  * @param string $limit
 
497
  * @since 2.05.06
498
  */
499
  public static function esc_limit( $limit ) {
514
  }
515
 
516
  $limit = implode( ',', $limit );
 
517
  return ' LIMIT ' . $limit;
518
  }
519
 
524
  */
525
  public static function prepare_array_values( $array, $type = '%s' ) {
526
  $placeholders = array_fill( 0, count( $array ), $type );
 
527
  return implode( ', ', $placeholders );
528
  }
529
 
555
  * @since 2.05.06
556
  */
557
  public static function save_settings( $settings, $group ) {
558
+ $settings = (array) $settings;
559
  $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
560
 
561
  if ( empty( $settings['ID'] ) ) {
592
  return $post;
593
  }
594
 
595
+ /**
596
+ * Check cache before fetching values and saving to cache
597
+ *
598
+ * @since 2.05.06
599
+ *
600
+ * @param string $cache_key The unique name for this cache
601
+ * @param string $group The name of the cache group
602
+ * @param string $query If blank, don't run a db call
603
+ * @param string $type The wpdb function to use with this query
604
+ * @return mixed $results The cache or query results
605
+ */
 
606
  public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
607
  $results = wp_cache_get( $cache_key, $group );
608
  if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
641
  * @since 2.05.06
642
  */
643
  public static function add_key_to_group_cache( $key, $group ) {
644
+ $cached = self::get_group_cached_keys( $group );
645
  $cached[ $key ] = $key;
646
  wp_cache_set( 'cached_keys', $cached, $group, 300 );
647
  }
660
 
661
  /**
662
  * @since 2.05.06
 
663
  * @param string $cache_key
664
  */
665
  public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
667
  wp_cache_delete( $cache_key, $group );
668
  }
669
 
670
+ /**
671
+ * Delete all caching in a single group
672
+ *
673
+ * @since 2.05.06
674
+ *
675
+ * @param string $group The name of the cache group
676
+ */
677
  public static function cache_delete_group( $group ) {
678
  $cached_keys = self::get_group_cached_keys( $group );
679
 
classes/models/FrmEmail.php CHANGED
@@ -85,7 +85,7 @@ class FrmEmail {
85
  $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args );
86
  $to = $this->explode_emails( $to );
87
 
88
- $where = array(
89
  'it.field_id !' => 0,
90
  'it.item_id' => $this->entry->id,
91
  );
@@ -298,7 +298,7 @@ class FrmEmail {
298
 
299
  // Add the user info if it isn't already included
300
  if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
301
- $data = maybe_unserialize( $this->entry->description );
302
  $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
303
  $this->maybe_add_ip( $mail_body );
304
  $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
@@ -449,7 +449,7 @@ class FrmEmail {
449
  * @return array
450
  */
451
  private function package_header() {
452
- $header = array();
453
 
454
  if ( ! empty( $this->cc ) ) {
455
  $header[] = 'CC: ' . implode( ',', $this->cc );
@@ -522,7 +522,6 @@ class FrmEmail {
522
  * @since 2.03.04
523
  *
524
  * @param string $emails
525
- *
526
  * @return array|string $emails
527
  */
528
  private function explode_emails( $emails ) {
@@ -638,7 +637,6 @@ class FrmEmail {
638
  $parts = explode( '<', $email );
639
  $email = trim( $parts[1], '>' );
640
  }
641
-
642
  return $email;
643
  }
644
 
@@ -673,7 +671,6 @@ class FrmEmail {
673
  if ( '' !== $name ) {
674
  $email = $name . ' <' . $email . '>';
675
  }
676
-
677
  return $email;
678
  }
679
 
85
  $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args );
86
  $to = $this->explode_emails( $to );
87
 
88
+ $where = array(
89
  'it.field_id !' => 0,
90
  'it.item_id' => $this->entry->id,
91
  );
298
 
299
  // Add the user info if it isn't already included
300
  if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
301
+ $data = maybe_unserialize( $this->entry->description );
302
  $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
303
  $this->maybe_add_ip( $mail_body );
304
  $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
449
  * @return array
450
  */
451
  private function package_header() {
452
+ $header = array();
453
 
454
  if ( ! empty( $this->cc ) ) {
455
  $header[] = 'CC: ' . implode( ',', $this->cc );
522
  * @since 2.03.04
523
  *
524
  * @param string $emails
 
525
  * @return array|string $emails
526
  */
527
  private function explode_emails( $emails ) {
637
  $parts = explode( '<', $email );
638
  $email = trim( $parts[1], '>' );
639
  }
 
640
  return $email;
641
  }
642
 
671
  if ( '' !== $name ) {
672
  $email = $name . ' <' . $email . '>';
673
  }
 
674
  return $email;
675
  }
676
 
classes/models/FrmEntry.php CHANGED
@@ -6,12 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  class FrmEntry {
7
 
8
  /**
9
- * Create a new entry
10
- *
11
- * @param array $values
12
- *
13
- * @return int | boolean $entry_id
14
- */
15
  public static function create( $values ) {
16
  $entry_id = self::create_entry( $values, 'standard' );
17
 
@@ -19,13 +18,12 @@ class FrmEntry {
19
  }
20
 
21
  /**
22
- * Create a new entry with some differences depending on type
23
- *
24
- * @param array $values
25
- * @param string $type
26
- *
27
- * @return int | boolean $entry_id
28
- */
29
  private static function create_entry( $values, $type ) {
30
  $new_values = self::before_insert_entry_in_database( $values, $type );
31
 
@@ -51,40 +49,40 @@ class FrmEntry {
51
  return false;
52
  }
53
 
54
- $check_val = $new_values;
55
  $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
56
 
57
  unset( $check_val['created_at'], $check_val['updated_at'] );
58
  unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
59
 
60
- if ( $new_values['item_key'] == $new_values['name'] ) {
61
  unset( $check_val['name'] );
62
- }
63
 
64
- global $wpdb;
65
  $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
66
 
67
  if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
68
- return false;
69
- }
70
 
71
- $is_duplicate = false;
72
- foreach ( $entry_exists as $entry_exist ) {
73
- $is_duplicate = true;
74
 
75
  // make sure it's a duplicate
76
- $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
77
- $field_metas = array();
78
- foreach ( $metas as $meta ) {
79
  $field_metas[ $meta->field_id ] = $meta->meta_value;
80
- }
81
 
82
- // If prev entry is empty and current entry is not, they are not duplicates
83
- $filtered_vals = array_filter( $values['item_meta'] );
84
  $field_metas = array_filter( $field_metas );
85
- if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
86
- return false;
87
- }
88
 
89
  // compare serialized values and not arrays
90
  $new_meta = array_map( 'maybe_serialize', $filtered_vals );
@@ -101,29 +99,27 @@ class FrmEntry {
101
  }
102
 
103
  $diff = array_diff_assoc( $field_metas, $new_meta );
104
- foreach ( $diff as $field_id => $meta_value ) {
105
  if ( ! empty( $meta_value ) ) {
106
- $is_duplicate = false;
107
- continue;
108
- }
109
- }
110
 
111
- if ( $is_duplicate ) {
112
  break;
113
- }
114
- }
115
 
116
- return $is_duplicate;
117
- }
118
 
119
  /**
120
  * Determine if an entry needs to be checked as a possible duplicate
121
  *
122
  * @since 2.0.23
123
- *
124
  * @param array $values
125
  * @param int $duplicate_entry_time
126
- *
127
  * @return bool
128
  */
129
  private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) {
@@ -150,7 +146,7 @@ class FrmEntry {
150
 
151
  $values = self::getOne( $id );
152
 
153
- $new_values = array();
154
  $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
155
  $new_values['name'] = $values->name;
156
  $new_values['is_draft'] = $values->is_draft;
@@ -161,34 +157,32 @@ class FrmEntry {
161
  $new_values['updated_at'] = $new_values['created_at'];
162
 
163
  $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
164
- if ( ! $query_results ) {
165
- return false;
166
- }
167
 
168
- $entry_id = $wpdb->insert_id;
169
 
170
- global $frm_vars;
171
  if ( ! isset( $frm_vars['saved_entries'] ) ) {
172
- $frm_vars['saved_entries'] = array();
173
- }
174
- $frm_vars['saved_entries'][] = (int) $entry_id;
175
 
176
  FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
177
  self::clear_cache();
178
 
179
  do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
180
-
181
- return $entry_id;
182
- }
183
 
184
  /**
185
- * Update an entry (not via XML)
186
- *
187
- * @param int $id
188
- * @param array $values
189
- *
190
- * @return boolean|int $update_results
191
- */
192
  public static function update( $id, $values ) {
193
  $update_results = self::update_entry( $id, $values, 'standard' );
194
 
@@ -196,15 +190,14 @@ class FrmEntry {
196
  }
197
 
198
  /**
199
- * Update an entry with some differences depending on the update type
200
- *
201
- * @since 2.0.16
202
- *
203
- * @param int $id
204
- * @param array $values
205
- *
206
- * @return boolean|int $query_results
207
- */
208
  private static function update_entry( $id, $values, $update_type ) {
209
  global $wpdb;
210
 
@@ -223,15 +216,14 @@ class FrmEntry {
223
  }
224
 
225
  public static function destroy( $id ) {
226
- global $wpdb;
227
- $id = (int) $id;
228
 
229
  $entry = self::getOne( $id );
230
- if ( ! $entry ) {
231
- $result = false;
232
-
233
- return $result;
234
- }
235
 
236
  do_action( 'frm_before_destroy_entry', $id, $entry );
237
 
@@ -240,19 +232,18 @@ class FrmEntry {
240
 
241
  self::clear_cache();
242
 
243
- return $result;
244
- }
245
 
246
  public static function update_form( $id, $value, $form_id ) {
247
- global $wpdb;
248
  $form_id = isset( $value ) ? $form_id : null;
249
- $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
250
  if ( $result ) {
251
  self::clear_cache();
252
  }
253
-
254
- return $result;
255
- }
256
 
257
  /**
258
  * Clear entry caching
@@ -278,7 +269,6 @@ class FrmEntry {
278
  if ( is_array( $name ) ) {
279
  $name = reset( $name );
280
  }
281
-
282
  return $name;
283
  }
284
 
@@ -286,7 +276,6 @@ class FrmEntry {
286
  * If $entry is numeric, get the entry object
287
  *
288
  * @param int|object $entry by reference
289
- *
290
  * @since 2.0.9
291
  */
292
  public static function maybe_get_entry( &$entry ) {
@@ -298,20 +287,19 @@ class FrmEntry {
298
  }
299
 
300
  public static function getOne( $id, $meta = false ) {
301
- global $wpdb;
302
 
303
- $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
304
  LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
305
 
306
- $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
307
- $query_args = array( $id );
308
- $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok.
309
 
310
- if ( ! $meta ) {
311
  $entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
312
-
313
  return stripslashes_deep( $entry );
314
- }
315
 
316
  $entry = FrmDb::check_cache( $id, 'frm_entry' );
317
  if ( $entry !== false ) {
@@ -322,96 +310,95 @@ class FrmEntry {
322
  $entry = self::get_meta( $entry );
323
 
324
  return stripslashes_deep( $entry );
325
- }
326
 
327
  public static function get_meta( $entry ) {
328
- if ( ! $entry ) {
329
- return $entry;
330
- }
331
 
332
- global $wpdb;
333
  $metas = FrmDb::get_results(
334
  $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id',
335
  array(
336
- 'item_id' => $entry->id,
337
  'field_id !' => 0,
338
  ),
339
  'field_id, meta_value, field_key, item_id'
340
  );
341
 
342
- $entry->metas = array();
343
 
344
  $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
345
- foreach ( $metas as $meta_val ) {
346
- if ( $meta_val->item_id == $entry->id ) {
347
  $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
348
  if ( $include_key ) {
349
  $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
350
  }
351
- continue;
352
- }
353
 
354
- // include sub entries in an array
355
  if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
356
  $entry->metas[ $meta_val->field_id ] = array();
357
- }
358
 
359
  $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
360
 
361
  unset( $meta_val );
362
- }
363
  unset( $metas );
364
 
365
  FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
366
 
367
- return $entry;
368
- }
369
 
370
- /**
371
- * @param string $id
372
- */
373
  public static function exists( $id ) {
374
- global $wpdb;
375
-
376
- if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
377
- $exists = true;
378
 
379
- return $exists;
380
- }
 
 
381
 
382
  if ( is_numeric( $id ) ) {
383
- $where = array( 'id' => $id );
384
- } else {
385
- $where = array( 'item_key' => $id );
386
- }
387
  $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
388
 
389
  return ( $id && $id > 0 );
390
- }
391
 
392
- public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
393
  global $wpdb;
394
 
395
  $limit = FrmDb::esc_limit( $limit );
396
 
397
  $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
398
- $entries = wp_cache_get( $cache_key, 'frm_entry' );
399
 
400
- if ( false === $entries ) {
401
- $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
402
- $table = $wpdb->prefix . 'frm_items it ';
403
 
404
- if ( $inc_form ) {
405
- $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
406
- $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
407
- }
408
 
409
- if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
410
- // sort by a requested field
411
- $field_id = (int) $order_matches[1];
412
- $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
413
  unset( $order_matches, $field_id );
414
- }
415
 
416
  // prepare the query
417
  $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
@@ -420,45 +407,45 @@ class FrmEntry {
420
  unset( $query );
421
 
422
  FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
423
- }
424
 
425
- if ( ! $meta || ! $entries ) {
426
  return stripslashes_deep( $entries );
427
- }
428
  unset( $meta );
429
 
430
  if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
431
  $where = array( 'it.form_id' => substr( $where, 11 ) );
432
- }
433
 
434
- $meta_where = array( 'field_id !' => 0 );
435
  if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
436
- $meta_where['fi.form_id'] = $where['it.form_id'];
437
- } else {
438
- $meta_where['item_id'] = array_keys( $entries );
439
- }
440
 
441
- $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
442
 
443
- unset( $meta_where );
444
 
445
- if ( ! $metas ) {
446
  return stripslashes_deep( $entries );
447
- }
448
 
449
- foreach ( $metas as $m_key => $meta_val ) {
450
- if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
451
- continue;
452
- }
453
 
454
- if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
455
  $entries[ $meta_val->item_id ]->metas = array();
456
- }
457
 
458
  $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
459
 
460
  unset( $m_key, $meta_val );
461
- }
462
 
463
  if ( ! FrmAppHelper::prevent_caching() ) {
464
  foreach ( $entries as $entry ) {
@@ -468,35 +455,35 @@ class FrmEntry {
468
  }
469
 
470
  return stripslashes_deep( $entries );
471
- }
472
 
473
- // Pagination Methods
474
  /**
475
  * @param int|array|string If int, use the form id.
476
  */
477
- public static function getRecordCount( $where = '' ) {
478
- global $wpdb;
479
  $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
480
 
481
  if ( is_numeric( $where ) ) {
482
- $table_join = 'frm_items';
483
- $where = array( 'form_id' => $where );
484
- }
485
 
486
- if ( is_array( $where ) ) {
487
- $count = FrmDb::get_count( $table_join, $where );
488
- } else {
489
  $cache_key = 'count_' . maybe_serialize( $where );
490
- $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
491
- $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
492
- }
493
 
494
- return $count;
495
- }
496
 
497
- public static function getPageCount( $p_size, $where = '' ) {
498
  $p_size = (int) $p_size;
499
- $count = 1;
500
  if ( $p_size ) {
501
  if ( ! is_numeric( $where ) ) {
502
  $where = self::getRecordCount( $where );
@@ -505,18 +492,16 @@ class FrmEntry {
505
  }
506
 
507
  return $count;
508
- }
509
 
510
  /**
511
- * Prepare the data before inserting it into the database
512
- *
513
- * @since 2.0.16
514
- *
515
- * @param array $values
516
- * @param string $type
517
- *
518
- * @return array $new_values
519
- */
520
  private static function before_insert_entry_in_database( &$values, $type ) {
521
 
522
  self::sanitize_entry_post( $values );
@@ -531,15 +516,13 @@ class FrmEntry {
531
  }
532
 
533
  /**
534
- * Create an entry and perform after create actions
535
- *
536
- * @since 2.0.16
537
- *
538
- * @param array $values
539
- * @param array $new_values
540
- *
541
- * @return boolean|int $entry_id
542
- */
543
  private static function continue_to_create_entry( $values, $new_values ) {
544
  $entry_id = self::insert_entry_into_database( $new_values );
545
  if ( ! $entry_id ) {
@@ -551,40 +534,37 @@ class FrmEntry {
551
  return $entry_id;
552
  }
553
 
554
- /**
555
- * Sanitize the POST values before we use them
556
- *
557
- * @since 2.0
558
- *
559
- * @param array $values The POST values by reference
560
- */
561
- public static function sanitize_entry_post( &$values ) {
562
- $sanitize_method = array(
563
- 'form_id' => 'absint',
564
- 'frm_action' => 'sanitize_title',
565
- 'form_key' => 'sanitize_title',
566
- 'item_key' => 'sanitize_title',
567
- 'item_name' => 'sanitize_text_field',
568
- 'frm_saving_draft' => 'absint',
569
- 'is_draft' => 'absint',
570
- 'post_id' => 'absint',
571
- 'parent_item_id' => 'absint',
572
- 'created_at' => 'sanitize_text_field',
573
- 'updated_at' => 'sanitize_text_field',
574
- );
575
-
576
- FrmAppHelper::sanitize_request( $sanitize_method, $values );
577
- }
578
-
579
- /**
580
- * Prepare the new values for inserting into the database
581
- *
582
- * @since 2.0.16
583
- *
584
- * @param array $values
585
- *
586
- * @return array $new_values
587
- */
588
  private static function package_entry_data( &$values ) {
589
  global $wpdb;
590
 
@@ -592,19 +572,19 @@ class FrmEntry {
592
  $values['item_key'] = '';
593
  }
594
 
595
- $item_name = self::get_new_entry_name( $values, $values['item_key'] );
596
  $new_values = array(
597
- 'item_key' => FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key' ),
598
- 'name' => FrmAppHelper::truncate( $item_name, 255, 1, '' ),
599
- 'ip' => self::get_ip( $values ),
600
- 'is_draft' => self::get_is_draft_value( $values ),
601
- 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
602
- 'post_id' => (int) self::get_entry_value( $values, 'post_id', 0 ),
603
  'parent_item_id' => (int) self::get_entry_value( $values, 'parent_item_id', 0 ),
604
- 'created_at' => self::get_created_at( $values ),
605
- 'updated_at' => self::get_updated_at( $values ),
606
- 'description' => self::get_entry_description( $values ),
607
- 'user_id' => self::get_entry_user_id( $values ),
608
  );
609
 
610
  $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
@@ -621,9 +601,7 @@ class FrmEntry {
621
  * Allow the import to override the value.
622
  *
623
  * @since 2.03.10
624
- *
625
  * @param array $values
626
- *
627
  * @return string
628
  */
629
  private static function get_ip( $values ) {
@@ -635,45 +613,38 @@ class FrmEntry {
635
  if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
636
  $ip = self::get_entry_value( $values, 'ip', $ip );
637
  }
638
-
639
  return $ip;
640
  }
641
 
642
  /**
643
- * Get the is_draft value for a new entry
644
- *
645
- * @since 2.0.16
646
- *
647
- * @param array $values
648
- *
649
- * @return int
650
- */
651
  private static function get_is_draft_value( $values ) {
652
  return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
653
  }
654
 
655
  /**
656
- * Get the created_at value for a new entry
657
- *
658
- * @since 2.0.16
659
- *
660
- * @param array $values
661
- *
662
- * @return string
663
- */
664
  private static function get_created_at( $values ) {
665
  return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) );
666
  }
667
 
668
  /**
669
- * Get the updated_at value for a new entry
670
- *
671
- * @since 2.0.16
672
- *
673
- * @param array $values
674
- *
675
- * @return string
676
- */
677
  private static function get_updated_at( $values ) {
678
  if ( isset( $values['updated_at'] ) ) {
679
  $updated_at = $values['updated_at'];
@@ -685,14 +656,12 @@ class FrmEntry {
685
  }
686
 
687
  /**
688
- * Get the description value for a new entry
689
- *
690
- * @since 2.0.16
691
- *
692
- * @param array $values
693
- *
694
- * @return string
695
- */
696
  private static function get_entry_description( $values ) {
697
  if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
698
  $description = maybe_serialize( $values['description'] );
@@ -709,34 +678,30 @@ class FrmEntry {
709
  }
710
 
711
  /**
712
- * Get the user_id value for a new entry
713
- *
714
- * @since 2.0.16
715
- *
716
- * @param array $values
717
- *
718
- * @return int
719
- */
720
  private static function get_entry_user_id( $values ) {
721
  if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
722
  $user_id = $values['frm_user_id'];
723
  } else {
724
  $current_user_id = get_current_user_id();
725
- $user_id = $current_user_id ? $current_user_id : 0;
726
  }
727
 
728
  return $user_id;
729
  }
730
 
731
  /**
732
- * Insert new entry into the database
733
- *
734
- * @since 2.0.16
735
- *
736
- * @param array $new_values
737
- *
738
- * @return int | boolean $entry_id
739
- */
740
  private static function insert_entry_into_database( $new_values ) {
741
  global $wpdb;
742
 
@@ -752,12 +717,11 @@ class FrmEntry {
752
  }
753
 
754
  /**
755
- * Add the new entry to global $frm_vars
756
- *
757
- * @since 2.0.16
758
- *
759
- * @param int $entry_id
760
- */
761
  private static function add_new_entry_to_frm_vars( $entry_id ) {
762
  global $frm_vars;
763
 
@@ -769,13 +733,12 @@ class FrmEntry {
769
  }
770
 
771
  /**
772
- * Add entry metas, if there are any
773
- *
774
- * @since 2.0.16
775
- *
776
- * @param array $values
777
- * @param int $entry_id
778
- */
779
  private static function maybe_add_entry_metas( $values, $entry_id ) {
780
  if ( isset( $values['item_meta'] ) ) {
781
  FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -783,13 +746,12 @@ class FrmEntry {
783
  }
784
 
785
  /**
786
- * Trigger frm_after_create_entry hooks
787
- *
788
- * @since 2.0.16
789
- *
790
- * @param int $entry_id
791
- * @param array $new_values
792
- */
793
  private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
794
  // this is a child entry
795
  $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -799,14 +761,13 @@ class FrmEntry {
799
  }
800
 
801
  /**
802
- * Actions to perform immediately after an entry is inserted in the frm_items database
803
- *
804
- * @since 2.0.16
805
- *
806
- * @param array $values
807
- * @param array $new_values
808
- * @param int $entry_id
809
- */
810
  private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
811
 
812
  self::add_new_entry_to_frm_vars( $entry_id );
@@ -819,16 +780,14 @@ class FrmEntry {
819
  }
820
 
821
  /**
822
- * Perform some actions right before updating an entry
823
- *
824
- * @since 2.0.16
825
- *
826
- * @param int $id
827
- * @param array $values
828
- * @param string $update_type
829
- *
830
- * @return boolean $update
831
- */
832
  private static function before_update_entry( $id, &$values, $update_type ) {
833
  $update = true;
834
 
@@ -846,22 +805,20 @@ class FrmEntry {
846
  }
847
 
848
  /**
849
- * Package the entry data for updating
850
- *
851
- * @since 2.0.16
852
- *
853
- * @param int $id
854
- * @param array $values
855
- *
856
- * @return array $new_values
857
- */
858
  private static function package_entry_to_update( $id, $values ) {
859
  global $wpdb;
860
 
861
  $new_values = array(
862
- 'name' => self::get_new_entry_name( $values ),
863
- 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
864
- 'is_draft' => self::get_is_draft_value( $values ),
865
  'updated_at' => current_time( 'mysql', 1 ),
866
  'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
867
  );
@@ -888,15 +845,14 @@ class FrmEntry {
888
  }
889
 
890
  /**
891
- * Perform some actions right after updating an entry
892
- *
893
- * @since 2.0.16
894
- *
895
- * @param boolean|int $query_results
896
- * @param int $id
897
- * @param array $values
898
- * @param array $new_values
899
- */
900
  private static function after_update_entry( $query_results, $id, $values, $new_values ) {
901
  if ( $query_results ) {
902
  self::clear_cache();
@@ -918,15 +874,13 @@ class FrmEntry {
918
  }
919
 
920
  /**
921
- * Create entry from an XML import
922
- * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
923
- *
924
- * @since 2.0.16
925
- *
926
- * @param array $values
927
- *
928
- * @return int | boolean $entry_id
929
- */
930
  public static function create_entry_from_xml( $values ) {
931
  $entry_id = self::create_entry( $values, 'xml' );
932
 
@@ -934,16 +888,14 @@ class FrmEntry {
934
  }
935
 
936
  /**
937
- * Update entry from an XML import
938
- * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
939
- *
940
- * @since 2.0.16
941
- *
942
- * @param int $id
943
- * @param array $values
944
- *
945
- * @return int | boolean $updated
946
- */
947
  public static function update_entry_from_xml( $id, $values ) {
948
  $updated = self::update_entry( $id, $values, 'xml' );
949
 
@@ -952,12 +904,10 @@ class FrmEntry {
952
 
953
  /**
954
  * @param string $key
955
- *
956
  * @return int entry_id
957
  */
958
  public static function get_id_by_key( $key ) {
959
  $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
960
-
961
  return (int) $entry_id;
962
  }
963
  }
6
  class FrmEntry {
7
 
8
  /**
9
+ * Create a new entry
10
+ *
11
+ * @param array $values
12
+ * @return int | boolean $entry_id
13
+ */
 
14
  public static function create( $values ) {
15
  $entry_id = self::create_entry( $values, 'standard' );
16
 
18
  }
19
 
20
  /**
21
+ * Create a new entry with some differences depending on type
22
+ *
23
+ * @param array $values
24
+ * @param string $type
25
+ * @return int | boolean $entry_id
26
+ */
 
27
  private static function create_entry( $values, $type ) {
28
  $new_values = self::before_insert_entry_in_database( $values, $type );
29
 
49
  return false;
50
  }
51
 
52
+ $check_val = $new_values;
53
  $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
54
 
55
  unset( $check_val['created_at'], $check_val['updated_at'] );
56
  unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
57
 
58
+ if ( $new_values['item_key'] == $new_values['name'] ) {
59
  unset( $check_val['name'] );
60
+ }
61
 
62
+ global $wpdb;
63
  $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
64
 
65
  if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
66
+ return false;
67
+ }
68
 
69
+ $is_duplicate = false;
70
+ foreach ( $entry_exists as $entry_exist ) {
71
+ $is_duplicate = true;
72
 
73
  // make sure it's a duplicate
74
+ $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
75
+ $field_metas = array();
76
+ foreach ( $metas as $meta ) {
77
  $field_metas[ $meta->field_id ] = $meta->meta_value;
78
+ }
79
 
80
+ // If prev entry is empty and current entry is not, they are not duplicates
81
+ $filtered_vals = array_filter( $values['item_meta'] );
82
  $field_metas = array_filter( $field_metas );
83
+ if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
84
+ return false;
85
+ }
86
 
87
  // compare serialized values and not arrays
88
  $new_meta = array_map( 'maybe_serialize', $filtered_vals );
99
  }
100
 
101
  $diff = array_diff_assoc( $field_metas, $new_meta );
102
+ foreach ( $diff as $field_id => $meta_value ) {
103
  if ( ! empty( $meta_value ) ) {
104
+ $is_duplicate = false;
105
+ continue;
106
+ }
107
+ }
108
 
109
+ if ( $is_duplicate ) {
110
  break;
111
+ }
112
+ }
113
 
114
+ return $is_duplicate;
115
+ }
116
 
117
  /**
118
  * Determine if an entry needs to be checked as a possible duplicate
119
  *
120
  * @since 2.0.23
 
121
  * @param array $values
122
  * @param int $duplicate_entry_time
 
123
  * @return bool
124
  */
125
  private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) {
146
 
147
  $values = self::getOne( $id );
148
 
149
+ $new_values = array();
150
  $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
151
  $new_values['name'] = $values->name;
152
  $new_values['is_draft'] = $values->is_draft;
157
  $new_values['updated_at'] = $new_values['created_at'];
158
 
159
  $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
160
+ if ( ! $query_results ) {
161
+ return false;
162
+ }
163
 
164
+ $entry_id = $wpdb->insert_id;
165
 
166
+ global $frm_vars;
167
  if ( ! isset( $frm_vars['saved_entries'] ) ) {
168
+ $frm_vars['saved_entries'] = array();
169
+ }
170
+ $frm_vars['saved_entries'][] = (int) $entry_id;
171
 
172
  FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
173
  self::clear_cache();
174
 
175
  do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
176
+ return $entry_id;
177
+ }
 
178
 
179
  /**
180
+ * Update an entry (not via XML)
181
+ *
182
+ * @param int $id
183
+ * @param array $values
184
+ * @return boolean|int $update_results
185
+ */
 
186
  public static function update( $id, $values ) {
187
  $update_results = self::update_entry( $id, $values, 'standard' );
188
 
190
  }
191
 
192
  /**
193
+ * Update an entry with some differences depending on the update type
194
+ *
195
+ * @since 2.0.16
196
+ *
197
+ * @param int $id
198
+ * @param array $values
199
+ * @return boolean|int $query_results
200
+ */
 
201
  private static function update_entry( $id, $values, $update_type ) {
202
  global $wpdb;
203
 
216
  }
217
 
218
  public static function destroy( $id ) {
219
+ global $wpdb;
220
+ $id = (int) $id;
221
 
222
  $entry = self::getOne( $id );
223
+ if ( ! $entry ) {
224
+ $result = false;
225
+ return $result;
226
+ }
 
227
 
228
  do_action( 'frm_before_destroy_entry', $id, $entry );
229
 
232
 
233
  self::clear_cache();
234
 
235
+ return $result;
236
+ }
237
 
238
  public static function update_form( $id, $value, $form_id ) {
239
+ global $wpdb;
240
  $form_id = isset( $value ) ? $form_id : null;
241
+ $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
242
  if ( $result ) {
243
  self::clear_cache();
244
  }
245
+ return $result;
246
+ }
 
247
 
248
  /**
249
  * Clear entry caching
269
  if ( is_array( $name ) ) {
270
  $name = reset( $name );
271
  }
 
272
  return $name;
273
  }
274
 
276
  * If $entry is numeric, get the entry object
277
  *
278
  * @param int|object $entry by reference
 
279
  * @since 2.0.9
280
  */
281
  public static function maybe_get_entry( &$entry ) {
287
  }
288
 
289
  public static function getOne( $id, $meta = false ) {
290
+ global $wpdb;
291
 
292
+ $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
293
  LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
294
 
295
+ $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
296
+ $query_args = array( $id );
297
+ $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok.
298
 
299
+ if ( ! $meta ) {
300
  $entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
 
301
  return stripslashes_deep( $entry );
302
+ }
303
 
304
  $entry = FrmDb::check_cache( $id, 'frm_entry' );
305
  if ( $entry !== false ) {
310
  $entry = self::get_meta( $entry );
311
 
312
  return stripslashes_deep( $entry );
313
+ }
314
 
315
  public static function get_meta( $entry ) {
316
+ if ( ! $entry ) {
317
+ return $entry;
318
+ }
319
 
320
+ global $wpdb;
321
  $metas = FrmDb::get_results(
322
  $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id',
323
  array(
324
+ 'item_id' => $entry->id,
325
  'field_id !' => 0,
326
  ),
327
  'field_id, meta_value, field_key, item_id'
328
  );
329
 
330
+ $entry->metas = array();
331
 
332
  $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
333
+ foreach ( $metas as $meta_val ) {
334
+ if ( $meta_val->item_id == $entry->id ) {
335
  $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
336
  if ( $include_key ) {
337
  $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
338
  }
339
+ continue;
340
+ }
341
 
342
+ // include sub entries in an array
343
  if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
344
  $entry->metas[ $meta_val->field_id ] = array();
345
+ }
346
 
347
  $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
348
 
349
  unset( $meta_val );
350
+ }
351
  unset( $metas );
352
 
353
  FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
354
 
355
+ return $entry;
356
+ }
357
 
358
+ /**
359
+ * @param string $id
360
+ */
361
  public static function exists( $id ) {
362
+ global $wpdb;
 
 
 
363
 
364
+ if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
365
+ $exists = true;
366
+ return $exists;
367
+ }
368
 
369
  if ( is_numeric( $id ) ) {
370
+ $where = array( 'id' => $id );
371
+ } else {
372
+ $where = array( 'item_key' => $id );
373
+ }
374
  $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
375
 
376
  return ( $id && $id > 0 );
377
+ }
378
 
379
+ public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
380
  global $wpdb;
381
 
382
  $limit = FrmDb::esc_limit( $limit );
383
 
384
  $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
385
+ $entries = wp_cache_get( $cache_key, 'frm_entry' );
386
 
387
+ if ( false === $entries ) {
388
+ $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
389
+ $table = $wpdb->prefix . 'frm_items it ';
390
 
391
+ if ( $inc_form ) {
392
+ $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
393
+ $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
394
+ }
395
 
396
+ if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
397
+ // sort by a requested field
398
+ $field_id = (int) $order_matches[1];
399
+ $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
400
  unset( $order_matches, $field_id );
401
+ }
402
 
403
  // prepare the query
404
  $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
407
  unset( $query );
408
 
409
  FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
410
+ }
411
 
412
+ if ( ! $meta || ! $entries ) {
413
  return stripslashes_deep( $entries );
414
+ }
415
  unset( $meta );
416
 
417
  if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
418
  $where = array( 'it.form_id' => substr( $where, 11 ) );
419
+ }
420
 
421
+ $meta_where = array( 'field_id !' => 0 );
422
  if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
423
+ $meta_where['fi.form_id'] = $where['it.form_id'];
424
+ } else {
425
+ $meta_where['item_id'] = array_keys( $entries );
426
+ }
427
 
428
+ $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
429
 
430
+ unset( $meta_where );
431
 
432
+ if ( ! $metas ) {
433
  return stripslashes_deep( $entries );
434
+ }
435
 
436
+ foreach ( $metas as $m_key => $meta_val ) {
437
+ if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
438
+ continue;
439
+ }
440
 
441
+ if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
442
  $entries[ $meta_val->item_id ]->metas = array();
443
+ }
444
 
445
  $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
446
 
447
  unset( $m_key, $meta_val );
448
+ }
449
 
450
  if ( ! FrmAppHelper::prevent_caching() ) {
451
  foreach ( $entries as $entry ) {
455
  }
456
 
457
  return stripslashes_deep( $entries );
458
+ }
459
 
460
+ // Pagination Methods
461
  /**
462
  * @param int|array|string If int, use the form id.
463
  */
464
+ public static function getRecordCount( $where = '' ) {
465
+ global $wpdb;
466
  $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
467
 
468
  if ( is_numeric( $where ) ) {
469
+ $table_join = 'frm_items';
470
+ $where = array( 'form_id' => $where );
471
+ }
472
 
473
+ if ( is_array( $where ) ) {
474
+ $count = FrmDb::get_count( $table_join, $where );
475
+ } else {
476
  $cache_key = 'count_' . maybe_serialize( $where );
477
+ $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
478
+ $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
479
+ }
480
 
481
+ return $count;
482
+ }
483
 
484
+ public static function getPageCount( $p_size, $where = '' ) {
485
  $p_size = (int) $p_size;
486
+ $count = 1;
487
  if ( $p_size ) {
488
  if ( ! is_numeric( $where ) ) {
489
  $where = self::getRecordCount( $where );
492
  }
493
 
494
  return $count;
495
+ }
496
 
497
  /**
498
+ * Prepare the data before inserting it into the database
499
+ *
500
+ * @since 2.0.16
501
+ * @param array $values
502
+ * @param string $type
503
+ * @return array $new_values
504
+ */
 
 
505
  private static function before_insert_entry_in_database( &$values, $type ) {
506
 
507
  self::sanitize_entry_post( $values );
516
  }
517
 
518
  /**
519
+ * Create an entry and perform after create actions
520
+ *
521
+ * @since 2.0.16
522
+ * @param array $values
523
+ * @param array $new_values
524
+ * @return boolean|int $entry_id
525
+ */
 
 
526
  private static function continue_to_create_entry( $values, $new_values ) {
527
  $entry_id = self::insert_entry_into_database( $new_values );
528
  if ( ! $entry_id ) {
534
  return $entry_id;
535
  }
536
 
537
+ /**
538
+ * Sanitize the POST values before we use them
539
+ *
540
+ * @since 2.0
541
+ * @param array $values The POST values by reference
542
+ */
543
+ public static function sanitize_entry_post( &$values ) {
544
+ $sanitize_method = array(
545
+ 'form_id' => 'absint',
546
+ 'frm_action' => 'sanitize_title',
547
+ 'form_key' => 'sanitize_title',
548
+ 'item_key' => 'sanitize_title',
549
+ 'item_name' => 'sanitize_text_field',
550
+ 'frm_saving_draft' => 'absint',
551
+ 'is_draft' => 'absint',
552
+ 'post_id' => 'absint',
553
+ 'parent_item_id' => 'absint',
554
+ 'created_at' => 'sanitize_text_field',
555
+ 'updated_at' => 'sanitize_text_field',
556
+ );
557
+
558
+ FrmAppHelper::sanitize_request( $sanitize_method, $values );
559
+ }
560
+
561
+ /**
562
+ * Prepare the new values for inserting into the database
563
+ *
564
+ * @since 2.0.16
565
+ * @param array $values
566
+ * @return array $new_values
567
+ */
 
 
 
568
  private static function package_entry_data( &$values ) {
569
  global $wpdb;
570
 
572
  $values['item_key'] = '';
573
  }
574
 
575
+ $item_name = self::get_new_entry_name( $values, $values['item_key'] );
576
  $new_values = array(
577
+ 'item_key' => FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key' ),
578
+ 'name' => FrmAppHelper::truncate( $item_name, 255, 1, '' ),
579
+ 'ip' => self::get_ip( $values ),
580
+ 'is_draft' => self::get_is_draft_value( $values ),
581
+ 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
582
+ 'post_id' => (int) self::get_entry_value( $values, 'post_id', 0 ),
583
  'parent_item_id' => (int) self::get_entry_value( $values, 'parent_item_id', 0 ),
584
+ 'created_at' => self::get_created_at( $values ),
585
+ 'updated_at' => self::get_updated_at( $values ),
586
+ 'description' => self::get_entry_description( $values ),
587
+ 'user_id' => self::get_entry_user_id( $values ),
588
  );
589
 
590
  $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
601
  * Allow the import to override the value.
602
  *
603
  * @since 2.03.10
 
604
  * @param array $values
 
605
  * @return string
606
  */
607
  private static function get_ip( $values ) {
613
  if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
614
  $ip = self::get_entry_value( $values, 'ip', $ip );
615
  }
 
616
  return $ip;
617
  }
618
 
619
  /**
620
+ * Get the is_draft value for a new entry
621
+ *
622
+ * @since 2.0.16
623
+ * @param array $values
624
+ * @return int
625
+ */
 
 
626
  private static function get_is_draft_value( $values ) {
627
  return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
628
  }
629
 
630
  /**
631
+ * Get the created_at value for a new entry
632
+ *
633
+ * @since 2.0.16
634
+ * @param array $values
635
+ * @return string
636
+ */
 
 
637
  private static function get_created_at( $values ) {
638
  return self::get_entry_value( $values, 'created_at', current_time( 'mysql', 1 ) );
639
  }
640
 
641
  /**
642
+ * Get the updated_at value for a new entry
643
+ *
644
+ * @since 2.0.16
645
+ * @param array $values
646
+ * @return string
647
+ */
 
 
648
  private static function get_updated_at( $values ) {
649
  if ( isset( $values['updated_at'] ) ) {
650
  $updated_at = $values['updated_at'];
656
  }
657
 
658
  /**
659
+ * Get the description value for a new entry
660
+ *
661
+ * @since 2.0.16
662
+ * @param array $values
663
+ * @return string
664
+ */
 
 
665
  private static function get_entry_description( $values ) {
666
  if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
667
  $description = maybe_serialize( $values['description'] );
678
  }
679
 
680
  /**
681
+ * Get the user_id value for a new entry
682
+ *
683
+ * @since 2.0.16
684
+ * @param array $values
685
+ * @return int
686
+ */
 
 
687
  private static function get_entry_user_id( $values ) {
688
  if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
689
  $user_id = $values['frm_user_id'];
690
  } else {
691
  $current_user_id = get_current_user_id();
692
+ $user_id = $current_user_id ? $current_user_id : 0;
693
  }
694
 
695
  return $user_id;
696
  }
697
 
698
  /**
699
+ * Insert new entry into the database
700
+ *
701
+ * @since 2.0.16
702
+ * @param array $new_values
703
+ * @return int | boolean $entry_id
704
+ */
 
 
705
  private static function insert_entry_into_database( $new_values ) {
706
  global $wpdb;
707
 
717
  }
718
 
719
  /**
720
+ * Add the new entry to global $frm_vars
721
+ *
722
+ * @since 2.0.16
723
+ * @param int $entry_id
724
+ */
 
725
  private static function add_new_entry_to_frm_vars( $entry_id ) {
726
  global $frm_vars;
727
 
733
  }
734
 
735
  /**
736
+ * Add entry metas, if there are any
737
+ *
738
+ * @since 2.0.16
739
+ * @param array $values
740
+ * @param int $entry_id
741
+ */
 
742
  private static function maybe_add_entry_metas( $values, $entry_id ) {
743
  if ( isset( $values['item_meta'] ) ) {
744
  FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
746
  }
747
 
748
  /**
749
+ * Trigger frm_after_create_entry hooks
750
+ *
751
+ * @since 2.0.16
752
+ * @param int $entry_id
753
+ * @param array $new_values
754
+ */
 
755
  private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
756
  // this is a child entry
757
  $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
761
  }
762
 
763
  /**
764
+ * Actions to perform immediately after an entry is inserted in the frm_items database
765
+ *
766
+ * @since 2.0.16
767
+ * @param array $values
768
+ * @param array $new_values
769
+ * @param int $entry_id
770
+ */
 
771
  private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
772
 
773
  self::add_new_entry_to_frm_vars( $entry_id );
780
  }
781
 
782
  /**
783
+ * Perform some actions right before updating an entry
784
+ *
785
+ * @since 2.0.16
786
+ * @param int $id
787
+ * @param array $values
788
+ * @param string $update_type
789
+ * @return boolean $update
790
+ */
 
 
791
  private static function before_update_entry( $id, &$values, $update_type ) {
792
  $update = true;
793
 
805
  }
806
 
807
  /**
808
+ * Package the entry data for updating
809
+ *
810
+ * @since 2.0.16
811
+ * @param int $id
812
+ * @param array $values
813
+ * @return array $new_values
814
+ */
 
 
815
  private static function package_entry_to_update( $id, $values ) {
816
  global $wpdb;
817
 
818
  $new_values = array(
819
+ 'name' => self::get_new_entry_name( $values ),
820
+ 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
821
+ 'is_draft' => self::get_is_draft_value( $values ),
822
  'updated_at' => current_time( 'mysql', 1 ),
823
  'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
824
  );
845
  }
846
 
847
  /**
848
+ * Perform some actions right after updating an entry
849
+ *
850
+ * @since 2.0.16
851
+ * @param boolean|int $query_results
852
+ * @param int $id
853
+ * @param array $values
854
+ * @param array $new_values
855
+ */
 
856
  private static function after_update_entry( $query_results, $id, $values, $new_values ) {
857
  if ( $query_results ) {
858
  self::clear_cache();
874
  }
875
 
876
  /**
877
+ * Create entry from an XML import
878
+ * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
879
+ *
880
+ * @since 2.0.16
881
+ * @param array $values
882
+ * @return int | boolean $entry_id
883
+ */
 
 
884
  public static function create_entry_from_xml( $values ) {
885
  $entry_id = self::create_entry( $values, 'xml' );
886
 
888
  }
889
 
890
  /**
891
+ * Update entry from an XML import
892
+ * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
893
+ *
894
+ * @since 2.0.16
895
+ * @param int $id
896
+ * @param array $values
897
+ * @return int | boolean $updated
898
+ */
 
 
899
  public static function update_entry_from_xml( $id, $values ) {
900
  $updated = self::update_entry( $id, $values, 'xml' );
901
 
904
 
905
  /**
906
  * @param string $key
 
907
  * @return int entry_id
908
  */
909
  public static function get_id_by_key( $key ) {
910
  $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
 
911
  return (int) $entry_id;
912
  }
913
  }
classes/models/FrmEntryFormatter.php CHANGED
@@ -130,7 +130,7 @@ class FrmEntryFormatter {
130
  } else {
131
  $this->entry = FrmEntry::getOne( $atts['entry']->id, true );
132
  }
133
- } elseif ( $atts['id'] ) {
134
  $this->entry = FrmEntry::getOne( $atts['id'], true );
135
  }
136
  }
@@ -143,7 +143,7 @@ class FrmEntryFormatter {
143
  * @param array $atts
144
  */
145
  protected function init_entry_values( $atts ) {
146
- $entry_atts = $this->prepare_entry_attributes( $atts );
147
  $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
148
  }
149
 
@@ -181,11 +181,11 @@ class FrmEntryFormatter {
181
 
182
  $this->format = 'array';
183
 
184
- } elseif ( $atts['format'] === 'json' ) {
185
 
186
  $this->format = 'json';
187
 
188
- } elseif ( $atts['format'] === 'text' ) {
189
 
190
  if ( $this->is_plain_text === true ) {
191
  $this->format = 'plain_text_block';
@@ -219,7 +219,7 @@ class FrmEntryFormatter {
219
  protected function init_is_plain_text( $atts ) {
220
  if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
221
  $this->is_plain_text = true;
222
- } elseif ( $atts['format'] !== 'text' ) {
223
  $this->is_plain_text = true;
224
  }
225
  }
@@ -325,8 +325,8 @@ class FrmEntryFormatter {
325
  * @since 3.0
326
  */
327
  protected function init_atts( $atts ) {
328
- $atts['source'] = 'entry_formatter';
329
- $atts['wpautop'] = false;
330
  $atts['return_array'] = true;
331
 
332
  $unset = array( 'id', 'entry', 'form_id', 'format', 'plain_text' );
@@ -367,13 +367,13 @@ class FrmEntryFormatter {
367
  if ( $this->format === 'json' ) {
368
  $content = json_encode( $this->prepare_array() );
369
 
370
- } elseif ( $this->format === 'array' ) {
371
  $content = $this->prepare_array();
372
 
373
- } elseif ( $this->format === 'table' ) {
374
  $content = $this->prepare_html_table();
375
 
376
- } elseif ( $this->format === 'plain_text_block' ) {
377
  $content = $this->prepare_plain_text_block();
378
 
379
  } else {
@@ -484,7 +484,6 @@ class FrmEntryFormatter {
484
  if ( $this->include_field_in_content( $field_value ) ) {
485
 
486
  $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
487
-
488
  $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
489
 
490
  $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
@@ -545,7 +544,7 @@ class FrmEntryFormatter {
545
 
546
  if ( $this->format === 'plain_text_block' ) {
547
  $this->add_plain_text_row_for_included_extra( $field_value, $content );
548
- } elseif ( $this->format === 'table' ) {
549
  $this->add_html_row_for_included_extra( $field_value, $content );
550
  }
551
  }
@@ -565,7 +564,7 @@ class FrmEntryFormatter {
565
 
566
  if ( $this->format === 'plain_text_block' ) {
567
  $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
568
- } elseif ( $this->format === 'table' ) {
569
  $value_args = $this->package_value_args( $field_value );
570
  $this->add_html_row( $value_args, $content );
571
  }
@@ -670,7 +669,7 @@ class FrmEntryFormatter {
670
  protected function add_standard_row( $field_value, &$content ) {
671
  if ( $this->format === 'plain_text_block' ) {
672
  $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
673
- } elseif ( $this->format === 'table' ) {
674
  $value_args = $this->package_value_args( $field_value );
675
  $this->add_html_row( $value_args, $content );
676
  }
@@ -687,9 +686,9 @@ class FrmEntryFormatter {
687
  */
688
  protected function package_value_args( $field_value ) {
689
  return array(
690
- 'label' => $field_value->get_field_label(),
691
- 'value' => $field_value->get_displayed_value(),
692
- 'field_type' => $field_value->get_field_type(),
693
  );
694
  }
695
 
@@ -706,9 +705,9 @@ class FrmEntryFormatter {
706
  foreach ( $this->entry_values->get_user_info() as $user_info ) {
707
 
708
  $value_args = array(
709
- 'label' => $user_info['label'],
710
- 'value' => $user_info['value'],
711
- 'field_type' => 'none',
712
  );
713
 
714
  $this->add_html_row( $value_args, $content );
@@ -811,6 +810,7 @@ class FrmEntryFormatter {
811
  return $this->strip_html( $value );
812
  }
813
 
 
814
  /**
815
  * Prepare a field's display value for an HTML table
816
  *
@@ -878,7 +878,7 @@ class FrmEntryFormatter {
878
  foreach ( $value as $key => $single_value ) {
879
  $value[ $key ] = $this->strip_html( $single_value );
880
  }
881
- } elseif ( $this->is_plain_text && ! is_array( $value ) ) {
882
  if ( strpos( $value, '<img' ) !== false ) {
883
  $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
884
  $value = trim( $value );
130
  } else {
131
  $this->entry = FrmEntry::getOne( $atts['entry']->id, true );
132
  }
133
+ } else if ( $atts['id'] ) {
134
  $this->entry = FrmEntry::getOne( $atts['id'], true );
135
  }
136
  }
143
  * @param array $atts
144
  */
145
  protected function init_entry_values( $atts ) {
146
+ $entry_atts = $this->prepare_entry_attributes( $atts );
147
  $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
148
  }
149
 
181
 
182
  $this->format = 'array';
183
 
184
+ } else if ( $atts['format'] === 'json' ) {
185
 
186
  $this->format = 'json';
187
 
188
+ } else if ( $atts['format'] === 'text' ) {
189
 
190
  if ( $this->is_plain_text === true ) {
191
  $this->format = 'plain_text_block';
219
  protected function init_is_plain_text( $atts ) {
220
  if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
221
  $this->is_plain_text = true;
222
+ } else if ( $atts['format'] !== 'text' ) {
223
  $this->is_plain_text = true;
224
  }
225
  }
325
  * @since 3.0
326
  */
327
  protected function init_atts( $atts ) {
328
+ $atts['source'] = 'entry_formatter';
329
+ $atts['wpautop'] = false;
330
  $atts['return_array'] = true;
331
 
332
  $unset = array( 'id', 'entry', 'form_id', 'format', 'plain_text' );
367
  if ( $this->format === 'json' ) {
368
  $content = json_encode( $this->prepare_array() );
369
 
370
+ } else if ( $this->format === 'array' ) {
371
  $content = $this->prepare_array();
372
 
373
+ } else if ( $this->format === 'table' ) {
374
  $content = $this->prepare_html_table();
375
 
376
+ } else if ( $this->format === 'plain_text_block' ) {
377
  $content = $this->prepare_plain_text_block();
378
 
379
  } else {
484
  if ( $this->include_field_in_content( $field_value ) ) {
485
 
486
  $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
 
487
  $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
488
 
489
  $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
544
 
545
  if ( $this->format === 'plain_text_block' ) {
546
  $this->add_plain_text_row_for_included_extra( $field_value, $content );
547
+ } else if ( $this->format === 'table' ) {
548
  $this->add_html_row_for_included_extra( $field_value, $content );
549
  }
550
  }
564
 
565
  if ( $this->format === 'plain_text_block' ) {
566
  $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
567
+ } else if ( $this->format === 'table' ) {
568
  $value_args = $this->package_value_args( $field_value );
569
  $this->add_html_row( $value_args, $content );
570
  }
669
  protected function add_standard_row( $field_value, &$content ) {
670
  if ( $this->format === 'plain_text_block' ) {
671
  $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
672
+ } else if ( $this->format === 'table' ) {
673
  $value_args = $this->package_value_args( $field_value );
674
  $this->add_html_row( $value_args, $content );
675
  }
686
  */
687
  protected function package_value_args( $field_value ) {
688
  return array(
689
+ 'label' => $field_value->get_field_label(),
690
+ 'value' => $field_value->get_displayed_value(),
691
+ 'field_type' => $field_value->get_field_type(),
692
  );
693
  }
694
 
705
  foreach ( $this->entry_values->get_user_info() as $user_info ) {
706
 
707
  $value_args = array(
708
+ 'label' => $user_info['label'],
709
+ 'value' => $user_info['value'],
710
+ 'field_type' => 'none',
711
  );
712
 
713
  $this->add_html_row( $value_args, $content );
810
  return $this->strip_html( $value );
811
  }
812
 
813
+
814
  /**
815
  * Prepare a field's display value for an HTML table
816
  *
878
  foreach ( $value as $key => $single_value ) {
879
  $value[ $key ] = $this->strip_html( $single_value );
880
  }
881
+ } else if ( $this->is_plain_text && ! is_array( $value ) ) {
882
  if ( strpos( $value, '<img' ) !== false ) {
883
  $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
884
  $value = trim( $value );
classes/models/FrmEntryMeta.php CHANGED
@@ -5,23 +5,23 @@ if ( ! defined( 'ABSPATH' ) ) {
5
 
6
  class FrmEntryMeta {
7
 
8
- /**
9
- * @param string $meta_key
10
- */
11
  public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
12
- global $wpdb;
13
 
14
- if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
- // don't save blank fields
16
- return 0;
17
- }
18
 
19
- $new_values = array(
20
- 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21
- 'item_id' => $entry_id,
22
- 'field_id' => $field_id,
23
- 'created_at' => current_time( 'mysql', 1 ),
24
- );
25
 
26
  self::set_value_before_save( $new_values );
27
  $new_values = apply_filters( 'frm_add_entry_meta', $new_values );
@@ -36,8 +36,8 @@ class FrmEntryMeta {
36
  $id = 0;
37
  }
38
 
39
- return $id;
40
- }
41
 
42
  /**
43
  * @param int $entry_id
@@ -48,18 +48,18 @@ class FrmEntryMeta {
48
  * @return bool|false|int
49
  */
50
  public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
51
- if ( ! $field_id ) {
52
- return false;
53
- }
54
 
55
- global $wpdb;
56
 
57
- $values = array(
58
  'item_id' => $entry_id,
59
  'field_id' => $field_id,
60
  );
61
- $where_values = $values;
62
- $values['meta_value'] = $meta_value;
63
  self::set_value_before_save( $values );
64
  $values = apply_filters( 'frm_update_entry_meta', $values );
65
 
@@ -72,7 +72,7 @@ class FrmEntryMeta {
72
  self::clear_cache();
73
 
74
  return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
75
- }
76
 
77
  /**
78
  * @since 3.0
@@ -81,7 +81,6 @@ class FrmEntryMeta {
81
  $field = FrmField::getOne( $values['field_id'] );
82
  if ( $field ) {
83
  $field_obj = FrmFieldFactory::get_field_object( $field );
84
-
85
  $values['meta_value'] = $field_obj->set_value_before_save( $values['meta_value'] );
86
  }
87
  }
@@ -92,7 +91,7 @@ class FrmEntryMeta {
92
  private static function get_value_to_save( $atts, &$value ) {
93
  if ( is_object( $atts['field'] ) ) {
94
  $field_obj = FrmFieldFactory::get_field_object( $atts['field'] );
95
- $value = $field_obj->get_value_to_save(
96
  $value,
97
  array(
98
  'entry_id' => $atts['entry_id'],
@@ -105,7 +104,7 @@ class FrmEntryMeta {
105
  }
106
 
107
  public static function update_entry_metas( $entry_id, $values ) {
108
- global $wpdb;
109
 
110
  $prev_values = FrmDb::get_col(
111
  $wpdb->prefix . 'frm_item_metas',
@@ -116,7 +115,7 @@ class FrmEntryMeta {
116
  'field_id'
117
  );
118
 
119
- foreach ( $values as $field_id => $meta_value ) {
120
  $field = false;
121
  if ( ! empty( $field_id ) ) {
122
  $field = FrmField::getOne( $field_id );
@@ -159,7 +158,7 @@ class FrmEntryMeta {
159
  // Delete any leftovers
160
  $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
161
  self::clear_cache();
162
- }
163
 
164
  public static function duplicate_entry_metas( $old_id, $new_id ) {
165
  $metas = self::get_entry_meta_info( $old_id );
@@ -171,11 +170,10 @@ class FrmEntryMeta {
171
  }
172
 
173
  public static function delete_entry_meta( $entry_id, $field_id ) {
174
- global $wpdb;
175
  self::clear_cache();
176
-
177
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) );
178
- }
179
 
180
  /**
181
  * Clear entry meta caching
@@ -200,110 +198,109 @@ class FrmEntryMeta {
200
  }
201
 
202
  public static function get_entry_meta_by_field( $entry_id, $field_id ) {
203
- global $wpdb;
204
 
205
  if ( is_object( $entry_id ) ) {
206
- $entry = $entry_id;
207
  $entry_id = $entry->id;
208
- $cached = $entry;
209
  } else {
210
  $entry_id = (int) $entry_id;
211
- $cached = FrmDb::check_cache( $entry_id, 'frm_entry' );
212
  }
213
 
214
  if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
215
  $result = $cached->metas[ $field_id ];
216
-
217
  return stripslashes_deep( $result );
218
- }
219
 
220
  $get_table = $wpdb->prefix . 'frm_item_metas';
221
- $query = array( 'item_id' => $entry_id );
222
  if ( is_numeric( $field_id ) ) {
223
  $query['field_id'] = $field_id;
224
- } else {
225
- $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
226
  $query['fi.field_key'] = $field_id;
227
- }
228
 
229
  $result = FrmDb::get_var( $get_table, $query, 'meta_value' );
230
  $result = maybe_unserialize( $result );
231
  $result = stripslashes_deep( $result );
232
 
233
- return $result;
234
- }
235
 
236
- public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
237
  $defaults = array(
238
- 'value' => false,
239
- 'unique' => false,
240
  'stripslashes' => true,
241
- 'is_draft' => false,
242
  );
243
- $args = wp_parse_args( $args, $defaults );
244
 
245
- $query = array();
246
  self::meta_field_query( $field_id, $order, $limit, $args, $query );
247
  $query = implode( ' ', $query );
248
 
249
  $cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
250
- $values = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_col' );
251
 
252
- if ( ! $args['stripslashes'] ) {
253
- return $values;
254
- }
255
 
256
  foreach ( $values as $k => $v ) {
257
  $values[ $k ] = maybe_unserialize( $v );
258
  unset( $k, $v );
259
- }
260
 
261
  return stripslashes_deep( $values );
262
- }
263
 
264
- /**
265
- * @param string $order
266
- * @param string $limit
267
- */
268
  private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) {
269
- global $wpdb;
270
- $query[] = 'SELECT';
271
- $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
272
  $query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em ';
273
 
274
- if ( ! $args['is_draft'] ) {
275
  $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
276
- }
277
 
278
  if ( is_numeric( $field_id ) ) {
279
  $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id );
280
  } else {
281
  $query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
282
- }
283
 
284
- if ( ! $args['is_draft'] ) {
285
- $query[] = 'AND e.is_draft=0';
286
- }
287
 
288
- if ( $args['value'] ) {
289
  $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] );
290
- }
291
- $query[] = $order . $limit;
292
- }
293
 
294
  public static function get_entry_meta_info( $entry_id ) {
295
  return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) );
296
- }
297
 
298
  public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
299
- global $wpdb;
300
- $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
301
  fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
302
  FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
303
  FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
304
 
305
  $cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
306
- $results = FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
307
 
308
  if ( ! $results || ! $stripslashes ) {
309
  return $results;
@@ -315,36 +312,35 @@ class FrmEntryMeta {
315
  }
316
 
317
  return $results;
318
- }
319
 
320
- public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
321
  $defaults = array(
322
  'is_draft' => false,
323
  'user_id' => '',
324
  'group_by' => '',
325
  );
326
- $args = wp_parse_args( $args, $defaults );
327
 
328
- $query = array();
329
  self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query );
330
  $query = implode( ' ', $query );
331
 
332
  $cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
333
-
334
  return FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
335
- }
336
 
337
- /**
338
- * @param string|array $where
339
- * @param string $order_by
340
- * @param string $limit
341
- */
342
  private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
343
- global $wpdb;
344
- $query[] = 'SELECT';
345
 
346
  $defaults = array( 'return_parent_id' => false );
347
- $args = array_merge( $defaults, $args );
348
 
349
  if ( $args['return_parent_id'] ) {
350
  $query[] = $unique ? 'DISTINCT(e.parent_item_id)' : 'e.parent_item_id';
@@ -356,31 +352,30 @@ class FrmEntryMeta {
356
 
357
  $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
358
  if ( is_array( $where ) ) {
359
- if ( ! $args['is_draft'] ) {
360
- $where['e.is_draft'] = 0;
361
- } elseif ( $args['is_draft'] == 1 ) {
362
- $where['e.is_draft'] = 1;
363
- }
364
 
365
  if ( ! empty( $args['user_id'] ) ) {
366
- $where['e.user_id'] = $args['user_id'];
367
- }
368
  $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
369
 
370
  if ( $args['group_by'] ) {
371
  $query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
372
  }
373
-
374
- return;
375
- }
376
 
377
  $draft_where = '';
378
- $user_where = '';
379
- if ( ! $args['is_draft'] ) {
380
  $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
381
- } elseif ( $args['is_draft'] == 1 ) {
382
  $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
383
- }
384
 
385
  if ( ! empty( $args['user_id'] ) ) {
386
  $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] );
@@ -389,56 +384,56 @@ class FrmEntryMeta {
389
  if ( strpos( $where, ' GROUP BY ' ) ) {
390
  // don't inject WHERE filtering after GROUP BY
391
  $parts = explode( ' GROUP BY ', $where );
392
- $where = $parts[0];
393
- $where .= $draft_where . $user_where;
394
  $where .= ' GROUP BY ' . $parts[1];
395
- } else {
396
- $where .= $draft_where . $user_where;
397
- }
398
 
399
  // The query has already been prepared
400
  $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
401
- }
402
 
403
- public static function search_entry_metas( $search, $field_id = '', $operator ) {
404
  $cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
405
- $results = wp_cache_get( $cache_key, 'frm_entry' );
406
- if ( false !== $results ) {
407
- return $results;
408
- }
409
 
410
- global $wpdb;
411
  if ( is_array( $search ) ) {
412
- $where = '';
413
  foreach ( $search as $field => $value ) {
414
  if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) {
415
- continue;
416
- }
417
 
418
- switch ( $field ) {
419
- case 'year':
420
  $value = '%' . $value;
421
  break;
422
- case 'month':
423
- $value .= '%';
424
  break;
425
- case 'day':
426
  $value = '%' . $value . '%';
427
- }
428
  $where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value ); // WPCS: unprepared SQL ok.
429
- }
430
  $where .= $wpdb->prepare( ' field_id=%d', $field_id );
431
  $query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where );
432
- } else {
433
  if ( $operator == 'LIKE' ) {
434
- $search = '%' . $search . '%';
435
  }
436
  $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id ); // WPCS: unprepared SQL ok.
437
- }
438
 
439
  $results = $wpdb->get_col( $query, 0 ); // WPCS: unprepared SQL ok.
440
  FrmDb::set_cache( $cache_key, $results, 'frm_entry' );
441
 
442
- return $results;
443
- }
444
  }
5
 
6
  class FrmEntryMeta {
7
 
8
+ /**
9
+ * @param string $meta_key
10
+ */
11
  public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
12
+ global $wpdb;
13
 
14
+ if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
+ // don't save blank fields
16
+ return 0;
17
+ }
18
 
19
+ $new_values = array(
20
+ 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21
+ 'item_id' => $entry_id,
22
+ 'field_id' => $field_id,
23
+ 'created_at' => current_time( 'mysql', 1 ),
24
+ );
25
 
26
  self::set_value_before_save( $new_values );
27
  $new_values = apply_filters( 'frm_add_entry_meta', $new_values );
36
  $id = 0;
37
  }
38
 
39
+ return $id;
40
+ }
41
 
42
  /**
43
  * @param int $entry_id
48
  * @return bool|false|int
49
  */
50
  public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
51
+ if ( ! $field_id ) {
52
+ return false;
53
+ }
54
 
55
+ global $wpdb;
56
 
57
+ $values = array(
58
  'item_id' => $entry_id,
59
  'field_id' => $field_id,
60
  );
61
+ $where_values = $values;
62
+ $values['meta_value'] = $meta_value;
63
  self::set_value_before_save( $values );
64
  $values = apply_filters( 'frm_update_entry_meta', $values );
65
 
72
  self::clear_cache();
73
 
74
  return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
75
+ }
76
 
77
  /**
78
  * @since 3.0
81
  $field = FrmField::getOne( $values['field_id'] );
82
  if ( $field ) {
83
  $field_obj = FrmFieldFactory::get_field_object( $field );
 
84
  $values['meta_value'] = $field_obj->set_value_before_save( $values['meta_value'] );
85
  }
86
  }
91
  private static function get_value_to_save( $atts, &$value ) {
92
  if ( is_object( $atts['field'] ) ) {
93
  $field_obj = FrmFieldFactory::get_field_object( $atts['field'] );
94
+ $value = $field_obj->get_value_to_save(
95
  $value,
96
  array(
97
  'entry_id' => $atts['entry_id'],
104
  }
105
 
106
  public static function update_entry_metas( $entry_id, $values ) {
107
+ global $wpdb;
108
 
109
  $prev_values = FrmDb::get_col(
110
  $wpdb->prefix . 'frm_item_metas',
115
  'field_id'
116
  );
117
 
118
+ foreach ( $values as $field_id => $meta_value ) {
119
  $field = false;
120
  if ( ! empty( $field_id ) ) {
121
  $field = FrmField::getOne( $field_id );
158
  // Delete any leftovers
159
  $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
160
  self::clear_cache();
161
+ }
162
 
163
  public static function duplicate_entry_metas( $old_id, $new_id ) {
164
  $metas = self::get_entry_meta_info( $old_id );
170
  }
171
 
172
  public static function delete_entry_meta( $entry_id, $field_id ) {
173
+ global $wpdb;
174
  self::clear_cache();
 
175
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) );
176
+ }
177
 
178
  /**
179
  * Clear entry meta caching
198
  }
199
 
200
  public static function get_entry_meta_by_field( $entry_id, $field_id ) {
201
+ global $wpdb;
202
 
203
  if ( is_object( $entry_id ) ) {
204
+ $entry = $entry_id;
205
  $entry_id = $entry->id;
206
+ $cached = $entry;
207
  } else {
208
  $entry_id = (int) $entry_id;
209
+ $cached = FrmDb::check_cache( $entry_id, 'frm_entry' );
210
  }
211
 
212
  if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
213
  $result = $cached->metas[ $field_id ];
 
214
  return stripslashes_deep( $result );
215
+ }
216
 
217
  $get_table = $wpdb->prefix . 'frm_item_metas';
218
+ $query = array( 'item_id' => $entry_id );
219
  if ( is_numeric( $field_id ) ) {
220
  $query['field_id'] = $field_id;
221
+ } else {
222
+ $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
223
  $query['fi.field_key'] = $field_id;
224
+ }
225
 
226
  $result = FrmDb::get_var( $get_table, $query, 'meta_value' );
227
  $result = maybe_unserialize( $result );
228
  $result = stripslashes_deep( $result );
229
 
230
+ return $result;
231
+ }
232
 
233
+ public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
234
  $defaults = array(
235
+ 'value' => false,
236
+ 'unique' => false,
237
  'stripslashes' => true,
238
+ 'is_draft' => false,
239
  );
240
+ $args = wp_parse_args( $args, $defaults );
241
 
242
+ $query = array();
243
  self::meta_field_query( $field_id, $order, $limit, $args, $query );
244
  $query = implode( ' ', $query );
245
 
246
  $cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
247
+ $values = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_col' );
248
 
249
+ if ( ! $args['stripslashes'] ) {
250
+ return $values;
251
+ }
252
 
253
  foreach ( $values as $k => $v ) {
254
  $values[ $k ] = maybe_unserialize( $v );
255
  unset( $k, $v );
256
+ }
257
 
258
  return stripslashes_deep( $values );
259
+ }
260
 
261
+ /**
262
+ * @param string $order
263
+ * @param string $limit
264
+ */
265
  private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) {
266
+ global $wpdb;
267
+ $query[] = 'SELECT';
268
+ $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
269
  $query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em ';
270
 
271
+ if ( ! $args['is_draft'] ) {
272
  $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
273
+ }
274
 
275
  if ( is_numeric( $field_id ) ) {
276
  $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id );
277
  } else {
278
  $query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
279
+ }
280
 
281
+ if ( ! $args['is_draft'] ) {
282
+ $query[] = 'AND e.is_draft=0';
283
+ }
284
 
285
+ if ( $args['value'] ) {
286
  $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] );
287
+ }
288
+ $query[] = $order . $limit;
289
+ }
290
 
291
  public static function get_entry_meta_info( $entry_id ) {
292
  return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) );
293
+ }
294
 
295
  public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
296
+ global $wpdb;
297
+ $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
298
  fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
299
  FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
300
  FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
301
 
302
  $cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
303
+ $results = FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
304
 
305
  if ( ! $results || ! $stripslashes ) {
306
  return $results;
312
  }
313
 
314
  return $results;
315
+ }
316
 
317
+ public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
318
  $defaults = array(
319
  'is_draft' => false,
320
  'user_id' => '',
321
  'group_by' => '',
322
  );
323
+ $args = wp_parse_args( $args, $defaults );
324
 
325
+ $query = array();
326
  self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query );
327
  $query = implode( ' ', $query );
328
 
329
  $cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
 
330
  return FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
331
+ }
332
 
333
+ /**
334
+ * @param string|array $where
335
+ * @param string $order_by
336
+ * @param string $limit
337
+ */
338
  private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
339
+ global $wpdb;
340
+ $query[] = 'SELECT';
341
 
342
  $defaults = array( 'return_parent_id' => false );
343
+ $args = array_merge( $defaults, $args );
344
 
345
  if ( $args['return_parent_id'] ) {
346
  $query[] = $unique ? 'DISTINCT(e.parent_item_id)' : 'e.parent_item_id';
352
 
353
  $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
354
  if ( is_array( $where ) ) {
355
+ if ( ! $args['is_draft'] ) {
356
+ $where['e.is_draft'] = 0;
357
+ } else if ( $args['is_draft'] == 1 ) {
358
+ $where['e.is_draft'] = 1;
359
+ }
360
 
361
  if ( ! empty( $args['user_id'] ) ) {
362
+ $where['e.user_id'] = $args['user_id'];
363
+ }
364
  $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
365
 
366
  if ( $args['group_by'] ) {
367
  $query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
368
  }
369
+ return;
370
+ }
 
371
 
372
  $draft_where = '';
373
+ $user_where = '';
374
+ if ( ! $args['is_draft'] ) {
375
  $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
376
+ } else if ( $args['is_draft'] == 1 ) {
377
  $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
378
+ }
379
 
380
  if ( ! empty( $args['user_id'] ) ) {
381
  $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] );
384
  if ( strpos( $where, ' GROUP BY ' ) ) {
385
  // don't inject WHERE filtering after GROUP BY
386
  $parts = explode( ' GROUP BY ', $where );
387
+ $where = $parts[0];
388
+ $where .= $draft_where . $user_where;
389
  $where .= ' GROUP BY ' . $parts[1];
390
+ } else {
391
+ $where .= $draft_where . $user_where;
392
+ }
393
 
394
  // The query has already been prepared
395
  $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
396
+ }
397
 
398
+ public static function search_entry_metas( $search, $field_id = '', $operator ) {
399
  $cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
400
+ $results = wp_cache_get( $cache_key, 'frm_entry' );
401
+ if ( false !== $results ) {
402
+ return $results;
403
+ }
404
 
405
+ global $wpdb;
406
  if ( is_array( $search ) ) {
407
+ $where = '';
408
  foreach ( $search as $field => $value ) {
409
  if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) {
410
+ continue;
411
+ }
412
 
413
+ switch ( $field ) {
414
+ case 'year':
415
  $value = '%' . $value;
416
  break;
417
+ case 'month':
418
+ $value .= '%';
419
  break;
420
+ case 'day':
421
  $value = '%' . $value . '%';
422
+ }
423
  $where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value ); // WPCS: unprepared SQL ok.
424
+ }
425
  $where .= $wpdb->prepare( ' field_id=%d', $field_id );
426
  $query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where );
427
+ } else {
428
  if ( $operator == 'LIKE' ) {
429
+ $search = '%' . $search . '%';
430
  }
431
  $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id ); // WPCS: unprepared SQL ok.
432
+ }
433
 
434
  $results = $wpdb->get_col( $query, 0 ); // WPCS: unprepared SQL ok.
435
  FrmDb::set_cache( $cache_key, $results, 'frm_entry' );
436
 
437
+ return $results;
438
+ }
439
  }
classes/models/FrmEntryShortcodeFormatter.php CHANGED
@@ -83,7 +83,6 @@ class FrmEntryShortcodeFormatter {
83
  * Initialize the form_id property
84
  *
85
  * @since 2.04
86
- *
87
  * @param $form_id
88
  */
89
  protected function init_form_id( $form_id ) {
@@ -148,7 +147,7 @@ class FrmEntryShortcodeFormatter {
148
 
149
  if ( $this->format == 'array' ) {
150
  $content = $this->get_array();
151
- } elseif ( $this->is_plain_text_format() ) {
152
  $content = $this->get_plain_text();
153
  } else {
154
  $content = $this->get_table();
83
  * Initialize the form_id property
84
  *
85
  * @since 2.04
 
86
  * @param $form_id
87
  */
88
  protected function init_form_id( $form_id ) {
147
 
148
  if ( $this->format == 'array' ) {
149
  $content = $this->get_array();
150
+ } else if ( $this->is_plain_text_format() ) {
151
  $content = $this->get_plain_text();
152
  } else {
153
  $content = $this->get_table();
classes/models/FrmEntryValidate.php CHANGED
@@ -1,19 +1,18 @@
1
  <?php
2
 
3
  class FrmEntryValidate {
4
- public static function validate( $values, $exclude = false ) {
5
- FrmEntry::sanitize_entry_post( $values );
6
- $errors = array();
7
 
8
  if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) {
9
- $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
10
-
11
- return $errors;
12
- }
13
 
14
  if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
15
- $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
16
- }
17
 
18
  self::set_item_key( $values );
19
 
@@ -40,7 +39,7 @@ class FrmEntryValidate {
40
  if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
41
  global $wpdb;
42
  $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
43
- $_POST['item_key'] = $values['item_key'];
44
  }
45
  }
46
 
@@ -58,24 +57,24 @@ class FrmEntryValidate {
58
  return FrmField::getAll( $where, 'field_order' );
59
  }
60
 
61
- public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
62
- $defaults = array(
63
- 'id' => $posted_field->id,
64
- 'parent_field_id' => '', // the id of the repeat or embed form
65
- 'key_pointer' => '', // the pointer in the posted array
66
- 'exclude' => array(), // exclude these field types from validation
67
- );
68
- $args = wp_parse_args( $args, $defaults );
69
 
70
  if ( empty( $args['parent_field_id'] ) ) {
71
  $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
72
- } else {
73
- // value is from a nested form
74
- $value = $values;
75
- }
76
 
77
- // Check for values in "Other" fields
78
- FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
79
 
80
  self::maybe_clear_value_for_default_blank_setting( $posted_field, $value );
81
 
@@ -88,11 +87,11 @@ class FrmEntryValidate {
88
  $value = trim( $value );
89
  }
90
 
91
- if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) {
92
  $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
93
- } elseif ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { // WPCS: CSRF ok.
94
- $_POST['item_name'] = $value;
95
- }
96
 
97
  FrmEntriesHelper::set_posted_value( $posted_field, $value, $args );
98
 
@@ -104,12 +103,11 @@ class FrmEntryValidate {
104
 
105
  $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args );
106
  $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
107
- }
108
 
109
  private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) {
110
- $placeholder = FrmField::get_option( $field, 'placeholder' );
111
- $is_default = ( ! empty( $placeholder ) && $value == $placeholder );
112
- $is_label = false;
113
 
114
  if ( ! $is_default ) {
115
  $position = FrmField::get_option( $field, 'label' );
@@ -126,8 +124,8 @@ class FrmEntryValidate {
126
  }
127
 
128
  public static function validate_field_types( &$errors, $posted_field, $value, $args ) {
129
- $field_obj = FrmFieldFactory::get_field_object( $posted_field );
130
- $args['value'] = $value;
131
  $args['errors'] = $errors;
132
 
133
  $new_errors = $field_obj->validate( $args );
@@ -162,7 +160,6 @@ class FrmEntryValidate {
162
  }
163
 
164
  $pattern = '/' . $pattern . '/';
165
-
166
  return $pattern;
167
  }
168
 
@@ -177,9 +174,7 @@ class FrmEntryValidate {
177
  * Create a regular expression from a phone number format
178
  *
179
  * @since 2.02.02
180
- *
181
  * @param string $pattern
182
- *
183
  * @return string
184
  */
185
  private static function create_regular_expression_from_format( $pattern ) {
@@ -196,7 +191,7 @@ class FrmEntryValidate {
196
  $pattern = str_replace( '/', '\/', $pattern );
197
 
198
  if ( strpos( $pattern, '\?' ) !== false ) {
199
- $parts = explode( '\?', $pattern );
200
  $pattern = '';
201
  foreach ( $parts as $part ) {
202
  if ( empty( $pattern ) ) {
@@ -218,72 +213,68 @@ class FrmEntryValidate {
218
  * @param array $values
219
  * @param array $errors by reference
220
  */
221
- public static function spam_check( $exclude, $values, &$errors ) {
222
- if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
223
- // only check spam if there are no other errors
224
- return;
225
- }
226
 
227
  if ( self::is_honeypot_spam() || self::is_spam_bot() ) {
228
  $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
229
  }
230
 
231
- if ( self::blacklist_check( $values ) ) {
232
- $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' );
233
- }
234
 
235
- if ( self::is_akismet_spam( $values ) ) {
236
  if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) {
237
  $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
238
  }
239
- }
240
- }
241
 
242
  private static function is_honeypot_spam() {
243
  $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' );
244
-
245
  return ( $honeypot_value !== '' );
246
  }
247
 
248
  private static function is_spam_bot() {
249
  $ip = FrmAppHelper::get_ip_address();
250
-
251
  return empty( $ip );
252
  }
253
 
254
  private static function is_akismet_spam( $values ) {
255
  global $wpcom_api_key;
256
-
257
  return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) );
258
  }
259
 
260
  private static function is_akismet_enabled_for_user( $form_id ) {
261
  $form = FrmForm::getOne( $form_id );
262
-
263
  return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) );
264
  }
265
 
266
- public static function blacklist_check( $values ) {
267
  if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) {
268
- return false;
269
- }
270
 
271
- $mod_keys = trim( get_option( 'blacklist_keys' ) );
272
- if ( empty( $mod_keys ) ) {
273
- return false;
274
- }
275
 
276
  $content = FrmEntriesHelper::entry_array_to_string( $values );
277
  if ( empty( $content ) ) {
278
  return false;
279
  }
280
 
281
- $ip = FrmAppHelper::get_ip_address();
282
  $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
283
- $user_info = self::get_spam_check_user_info( $values );
284
 
285
  return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent );
286
- }
287
 
288
  /**
289
  * Check entries for Akismet spam
@@ -303,7 +294,7 @@ class FrmEntryValidate {
303
  self::parse_akismet_array( $datas, $values );
304
 
305
  $query_string = _http_build_query( $datas, '', '&' );
306
- $response = Akismet::http_post( $query_string, 'comment-check' );
307
 
308
  return ( is_array( $response ) && $response[1] == 'true' );
309
  }
@@ -318,11 +309,11 @@ class FrmEntryValidate {
318
  }
319
 
320
  private static function add_site_info_to_akismet( &$datas ) {
321
- $datas['blog'] = FrmAppHelper::site_url();
322
- $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
323
- $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
324
- $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false;
325
- $datas['blog_lang'] = get_locale();
326
  $datas['blog_charset'] = get_option( 'blog_charset' );
327
 
328
  if ( akismet_test_mode() ) {
@@ -332,7 +323,7 @@ class FrmEntryValidate {
332
 
333
  private static function add_user_info_to_akismet( &$datas, $values ) {
334
  $user_info = self::get_spam_check_user_info( $values );
335
- $datas = $datas + $user_info;
336
 
337
  if ( isset( $user_info['user_ID'] ) ) {
338
  $datas['user_role'] = Akismet::get_user_roles( $user_info['user_ID'] );
@@ -344,16 +335,15 @@ class FrmEntryValidate {
344
 
345
  if ( is_user_logged_in() ) {
346
  $user = wp_get_current_user();
347
-
348
- $datas['user_ID'] = $user->ID;
349
- $datas['user_id'] = $user->ID;
350
- $datas['comment_author'] = $user->display_name;
351
  $datas['comment_author_email'] = $user->user_email;
352
- $datas['comment_author_url'] = $user->user_url;
353
  } else {
354
- $datas['comment_author'] = '';
355
  $datas['comment_author_email'] = '';
356
- $datas['comment_author_url'] = '';
357
 
358
  $values = array_filter( $values );
359
  foreach ( $values as $value ) {
1
  <?php
2
 
3
  class FrmEntryValidate {
4
+ public static function validate( $values, $exclude = false ) {
5
+ FrmEntry::sanitize_entry_post( $values );
6
+ $errors = array();
7
 
8
  if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) {
9
+ $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
10
+ return $errors;
11
+ }
 
12
 
13
  if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
14
+ $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
15
+ }
16
 
17
  self::set_item_key( $values );
18
 
39
  if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
40
  global $wpdb;
41
  $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
42
+ $_POST['item_key'] = $values['item_key'];
43
  }
44
  }
45
 
57
  return FrmField::getAll( $where, 'field_order' );
58
  }
59
 
60
+ public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
61
+ $defaults = array(
62
+ 'id' => $posted_field->id,
63
+ 'parent_field_id' => '', // the id of the repeat or embed form
64
+ 'key_pointer' => '', // the pointer in the posted array
65
+ 'exclude' => array(), // exclude these field types from validation
66
+ );
67
+ $args = wp_parse_args( $args, $defaults );
68
 
69
  if ( empty( $args['parent_field_id'] ) ) {
70
  $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
71
+ } else {
72
+ // value is from a nested form
73
+ $value = $values;
74
+ }
75
 
76
+ // Check for values in "Other" fields
77
+ FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
78
 
79
  self::maybe_clear_value_for_default_blank_setting( $posted_field, $value );
80
 
87
  $value = trim( $value );
88
  }
89
 
90
+ if ( $posted_field->required == '1' && FrmAppHelper::is_empty_value( $value ) ) {
91
  $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
92
+ } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { // WPCS: CSRF ok.
93
+ $_POST['item_name'] = $value;
94
+ }
95
 
96
  FrmEntriesHelper::set_posted_value( $posted_field, $value, $args );
97
 
103
 
104
  $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args );
105
  $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
106
+ }
107
 
108
  private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) {
109
+ $is_default = ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value );
110
+ $is_label = false;
 
111
 
112
  if ( ! $is_default ) {
113
  $position = FrmField::get_option( $field, 'label' );
124
  }
125
 
126
  public static function validate_field_types( &$errors, $posted_field, $value, $args ) {
127
+ $field_obj = FrmFieldFactory::get_field_object( $posted_field );
128
+ $args['value'] = $value;
129
  $args['errors'] = $errors;
130
 
131
  $new_errors = $field_obj->validate( $args );
160
  }
161
 
162
  $pattern = '/' . $pattern . '/';
 
163
  return $pattern;
164
  }
165
 
174
  * Create a regular expression from a phone number format
175
  *
176
  * @since 2.02.02
 
177
  * @param string $pattern
 
178
  * @return string
179
  */
180
  private static function create_regular_expression_from_format( $pattern ) {
191
  $pattern = str_replace( '/', '\/', $pattern );
192
 
193
  if ( strpos( $pattern, '\?' ) !== false ) {
194
+ $parts = explode( '\?', $pattern );
195
  $pattern = '';
196
  foreach ( $parts as $part ) {
197
  if ( empty( $pattern ) ) {
213
  * @param array $values
214
  * @param array $errors by reference
215
  */
216
+ public static function spam_check( $exclude, $values, &$errors ) {
217
+ if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
218
+ // only check spam if there are no other errors
219
+ return;
220
+ }
221
 
222
  if ( self::is_honeypot_spam() || self::is_spam_bot() ) {
223
  $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
224
  }
225
 
226
+ if ( self::blacklist_check( $values ) ) {
227
+ $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' );
228
+ }
229
 
230
+ if ( self::is_akismet_spam( $values ) ) {
231
  if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) {
232
  $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
233
  }
234
+ }
235
+ }
236
 
237
  private static function is_honeypot_spam() {
238
  $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' );
 
239
  return ( $honeypot_value !== '' );
240
  }
241
 
242
  private static function is_spam_bot() {
243
  $ip = FrmAppHelper::get_ip_address();
 
244
  return empty( $ip );
245
  }
246
 
247
  private static function is_akismet_spam( $values ) {
248
  global $wpcom_api_key;
 
249
  return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) );
250
  }
251
 
252
  private static function is_akismet_enabled_for_user( $form_id ) {
253
  $form = FrmForm::getOne( $form_id );
 
254
  return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) );
255
  }
256
 
257
+ public static function blacklist_check( $values ) {
258
  if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) {
259
+ return false;
260
+ }
261
 
262
+ $mod_keys = trim( get_option( 'blacklist_keys' ) );
263
+ if ( empty( $mod_keys ) ) {
264
+ return false;
265
+ }
266
 
267
  $content = FrmEntriesHelper::entry_array_to_string( $values );
268
  if ( empty( $content ) ) {
269
  return false;
270
  }
271
 
272
+ $ip = FrmAppHelper::get_ip_address();
273
  $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
274
+ $user_info = self::get_spam_check_user_info( $values );
275
 
276
  return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent );
277
+ }
278
 
279
  /**
280
  * Check entries for Akismet spam
294
  self::parse_akismet_array( $datas, $values );
295
 
296
  $query_string = _http_build_query( $datas, '', '&' );
297
+ $response = Akismet::http_post( $query_string, 'comment-check' );
298
 
299
  return ( is_array( $response ) && $response[1] == 'true' );
300
  }
309
  }
310
 
311
  private static function add_site_info_to_akismet( &$datas ) {
312
+ $datas['blog'] = FrmAppHelper::site_url();
313
+ $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
314
+ $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
315
+ $datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false;
316
+ $datas['blog_lang'] = get_locale();
317
  $datas['blog_charset'] = get_option( 'blog_charset' );
318
 
319
  if ( akismet_test_mode() ) {
323
 
324
  private static function add_user_info_to_akismet( &$datas, $values ) {
325
  $user_info = self::get_spam_check_user_info( $values );
326
+ $datas = $datas + $user_info;
327
 
328
  if ( isset( $user_info['user_ID'] ) ) {
329
  $datas['user_role'] = Akismet::get_user_roles( $user_info['user_ID'] );
335
 
336
  if ( is_user_logged_in() ) {
337
  $user = wp_get_current_user();
338
+ $datas['user_ID'] = $user->ID;
339
+ $datas['user_id'] = $user->ID;
340
+ $datas['comment_author'] = $user->display_name;
 
341
  $datas['comment_author_email'] = $user->user_email;
342
+ $datas['comment_author_url'] = $user->user_url;
343
  } else {
344
+ $datas['comment_author'] = '';
345
  $datas['comment_author_email'] = '';
346
+ $datas['comment_author_url'] = '';
347
 
348
  $values = array_filter( $values );
349
  foreach ( $values as $value ) {
classes/models/FrmEntryValues.php CHANGED
@@ -193,7 +193,7 @@ class FrmEntryValues {
193
  $entry_description = (array) maybe_unserialize( $this->entry->description );
194
  } else {
195
  $entry_description = array(
196
- 'browser' => '',
197
  'referrer' => '',
198
  );
199
  }
@@ -205,7 +205,7 @@ class FrmEntryValues {
205
 
206
  $browser = array(
207
  'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
208
- 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ),
209
  );
210
 
211
  $referrer = array(
@@ -214,8 +214,8 @@ class FrmEntryValues {
214
  );
215
 
216
  $this->user_info = array(
217
- 'ip' => $ip,
218
- 'browser' => $browser,
219
  'referrer' => $referrer,
220
  );
221
  }
@@ -243,7 +243,7 @@ class FrmEntryValues {
243
  protected function is_field_included( $field ) {
244
  if ( ! empty( $this->include_fields ) ) {
245
  $is_included = $this->is_field_in_array( $field, $this->include_fields );
246
- } elseif ( ! empty( $this->exclude_fields ) ) {
247
  $is_included = ! $this->is_field_in_array( $field, $this->exclude_fields );
248
  } else {
249
  $is_included = true;
193
  $entry_description = (array) maybe_unserialize( $this->entry->description );
194
  } else {
195
  $entry_description = array(
196
+ 'browser' => '',
197
  'referrer' => '',
198
  );
199
  }
205
 
206
  $browser = array(
207
  'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
208
+ 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ),
209
  );
210
 
211
  $referrer = array(
214
  );
215
 
216
  $this->user_info = array(
217
+ 'ip' => $ip,
218
+ 'browser' => $browser,
219
  'referrer' => $referrer,
220
  );
221
  }
243
  protected function is_field_included( $field ) {
244
  if ( ! empty( $this->include_fields ) ) {
245
  $is_included = $this->is_field_in_array( $field, $this->include_fields );
246
+ } else if ( ! empty( $this->exclude_fields ) ) {
247
  $is_included = ! $this->is_field_in_array( $field, $this->exclude_fields );
248
  } else {
249
  $is_included = true;
classes/models/FrmField.php CHANGED
@@ -10,57 +10,57 @@ class FrmField {
10
 
11
  public static function field_selection() {
12
  $fields = array(
13
- 'text' => array(
14
- 'name' => __( 'Text', 'formidable' ),
15
- 'icon' => 'frm_icon_font frm_text2_icon',
16
  ),
17
- 'textarea' => array(
18
- 'name' => __( 'Paragraph', 'formidable' ),
19
- 'icon' => 'frm_icon_font frm_paragraph_icon',
20
  ),
21
- 'checkbox' => array(
22
- 'name' => __( 'Checkboxes', 'formidable' ),
23
- 'icon' => 'frm_icon_font frm_check_square_icon',
24
  ),
25
- 'radio' => array(
26
- 'name' => __( 'Radio Buttons', 'formidable' ),
27
- 'icon' => 'frm_icon_font frm_radio_checked_icon',
28
  ),
29
- 'select' => array(
30
- 'name' => __( 'Dropdown', 'formidable' ),
31
- 'icon' => 'frm_icon_font frm_caret_square_down_icon',
32
  ),
33
- 'email' => array(
34
- 'name' => __( 'Email', 'formidable' ),
35
- 'icon' => 'frm_icon_font frm_email_icon',
36
  ),
37
- 'url' => array(
38
- 'name' => __( 'Website/URL', 'formidable' ),
39
- 'icon' => 'frm_icon_font frm_link_icon',
40
  ),
41
- 'number' => array(
42
- 'name' => __( 'Number', 'formidable' ),
43
- 'icon' => 'frm_icon_font frm_hashtag_icon',
44
  ),
45
- 'phone' => array(
46
- 'name' => __( 'Phone', 'formidable' ),
47
- 'icon' => 'frm_icon_font frm_phone_icon',
48
  ),
49
- 'html' => array(
50
- 'name' => __( 'HTML', 'formidable' ),
51
- 'icon' => 'frm_icon_font frm_code_icon',
52
  ),
53
- 'hidden' => array(
54
- 'name' => __( 'Hidden Field', 'formidable' ),
55
- 'icon' => 'frm_icon_font frm_eye_slash_icon',
56
  ),
57
- 'user_id' => array(
58
- 'name' => __( 'User ID', 'formidable' ),
59
- 'icon' => 'frm_icon_font frm_user_icon',
60
  ),
61
- 'captcha' => array(
62
- 'name' => __( 'reCAPTCHA', 'formidable' ),
63
- 'icon' => 'frm_icon_font frm_shield_check_icon',
64
  ),
65
  );
66
 
@@ -69,91 +69,91 @@ class FrmField {
69
 
70
  public static function pro_field_selection() {
71
  $fields = array(
72
- 'file' => array(
73
- 'name' => __( 'File Upload', 'formidable' ),
74
- 'icon' => 'frm_icon_font frm_upload_icon',
75
  ),
76
- 'rte' => array(
77
- 'name' => __( 'Rich Text', 'formidable' ),
78
- 'icon' => 'frm_icon_font frm_align_right_icon',
79
  ),
80
- 'date' => array(
81
- 'name' => __( 'Date', 'formidable' ),
82
- 'icon' => 'frm_icon_font frm_calendar_icon',
83
  ),
84
- 'time' => array(
85
- 'name' => __( 'Time', 'formidable' ),
86
- 'icon' => 'frm_icon_font frm_clock_icon',
87
  ),
88
- 'scale' => array(
89
- 'name' => __( 'Scale', 'formidable' ),
90
- 'icon' => 'frm_icon_font frm_linear_scale_icon',
91
  ),
92
- 'star' => array(
93
- 'name' => __( 'Star Rating', 'formidable' ),
94
- 'icon' => 'frm_icon_font frm_star_icon',
95
  ),
96
- 'range' => array(
97
- 'name' => __( 'Slider', 'formidable' ),
98
- 'icon' => 'frm_icon_font frm_code_commit_icon',
99
  ),
100
- 'toggle' => array(
101
- 'name' => __( 'Toggle', 'formidable' ),
102
- 'icon' => 'frm_icon_font frm_toggle_on_icon',
103
  ),
104
- 'data' => array(
105
- 'name' => __( 'Dynamic', 'formidable' ),
106
- 'icon' => 'frm_icon_font frm_sitemap_icon',
107
  ),
108
- 'lookup' => array(
109
- 'name' => __( 'Lookup', 'formidable' ),
110
- 'icon' => 'frm_icon_font frm_search_icon',
111
  ),
112
  'divider|repeat' => array(
113
- 'name' => __( 'Repeater', 'formidable' ),
114
- 'icon' => 'frm_icon_font frm_repeater_icon',
115
  ),
116
- 'end_divider' => array(
117
- 'name' => __( 'Section Buttons', 'formidable' ),
118
  'switch_from' => 'divider',
119
  ),
120
- 'divider' => array(
121
- 'name' => __( 'Section', 'formidable' ),
122
- 'icon' => 'frm_icon_font frm_header_icon',
123
  ),
124
- 'break' => array(
125
- 'name' => __( 'Page Break', 'formidable' ),
126
- 'icon' => 'frm_icon_font frm_page_break_icon',
127
  ),
128
- 'form' => array(
129
- 'name' => __( 'Embed Form', 'formidable' ),
130
- 'icon' => 'frm_icon_font frm_file_text_icon',
131
  ),
132
- 'password' => array(
133
- 'name' => __( 'Password', 'formidable' ),
134
- 'icon' => 'frm_icon_font frm_lock_open_icon',
135
  ),
136
- 'tag' => array(
137
- 'name' => __( 'Tags', 'formidable' ),
138
- 'icon' => 'frm_icon_font frm_price_tags_icon',
139
  ),
140
- 'credit_card' => array(
141
  'name' => __( 'Credit Card', 'formidable' ),
142
- 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade',
143
  'addon' => 'stripe',
144
  ),
145
- 'address' => array(
146
- 'name' => __( 'Address', 'formidable' ),
147
- 'icon' => 'frm_icon_font frm_location_icon',
148
  ),
149
  'signature' => array(
150
  'name' => __( 'Signature', 'formidable' ),
151
- 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
152
  'addon' => 'signature',
153
  ),
154
  'quiz_score' => array(
155
  'name' => __( 'Quiz Score', 'formidable' ),
156
- 'icon' => 'frm_icon_font frm_percent_icon frm_show_upgrade',
157
  'addon' => 'quizzes',
158
  ),
159
  );
@@ -167,52 +167,44 @@ class FrmField {
167
  return apply_filters( 'frm_pro_available_fields', $fields );
168
  }
169
 
170
- /**
171
- * @since 4.0
172
- */
173
- public static function all_field_selection() {
174
- $pro_field_selection = self::pro_field_selection();
175
- return array_merge( $pro_field_selection, self::field_selection() );
176
- }
177
 
178
- public static function create( $values, $return = true ) {
179
- global $wpdb, $frm_duplicate_ids;
180
-
181
- $new_values = array();
182
- $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
183
  $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
184
 
185
  foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
186
  $new_values[ $col ] = $values[ $col ];
187
- }
188
 
189
- $new_values['options'] = $values['options'];
190
 
191
- $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
192
- $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
193
- $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
194
- $new_values['field_options'] = $values['field_options'];
195
- $new_values['created_at'] = current_time( 'mysql', 1 );
196
 
197
  if ( isset( $values['id'] ) ) {
198
  $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
199
- $new_values = apply_filters( 'frm_duplicated_field', $new_values );
200
- }
201
 
202
  self::preserve_format_option_backslashes( $new_values );
203
 
204
  foreach ( $new_values as $k => $v ) {
205
- if ( is_array( $v ) ) {
206
  $new_values[ $k ] = serialize( $v );
207
  }
208
- unset( $k, $v );
209
- }
210
 
211
- //if(isset($values['id']) and is_numeric($values['id']))
212
- // $new_values['id'] = $values['id'];
213
 
214
  $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
215
- $new_id = 0;
216
  if ( $query_results ) {
217
  self::delete_form_transient( $new_values['form_id'] );
218
  $new_id = $wpdb->insert_id;
@@ -226,33 +218,32 @@ class FrmField {
226
  if ( isset( $values['id'] ) ) {
227
  $frm_duplicate_ids[ $values['id'] ] = $new_id;
228
  }
229
-
230
  return $new_id;
231
  } else {
232
  return false;
233
  }
234
- }
235
 
236
- public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
237
- global $frm_duplicate_ids;
238
 
239
- $where = array(
240
  array(
241
- 'or' => 1,
242
- 'fi.form_id' => $old_form_id,
243
  'fr.parent_form_id' => $old_form_id,
244
  ),
245
  );
246
  $fields = self::getAll( $where, 'field_order', '', $blog_id );
247
 
248
- foreach ( (array) $fields as $field ) {
249
  $new_key = $copy_keys ? $field->field_key : '';
250
- if ( $copy_keys && substr( $field->field_key, - 1 ) == 2 ) {
251
  $new_key = rtrim( $new_key, 2 );
252
  }
253
 
254
- $values = array();
255
- FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
256
 
257
  // If this is a repeating section, create new form
258
  if ( self::is_repeating_field( $field ) ) {
@@ -280,16 +271,16 @@ class FrmField {
280
 
281
  $values['description'] = FrmFieldsHelper::switch_field_ids( $values['description'] );
282
 
283
- $values = apply_filters( 'frm_duplicated_field', $values );
284
- $new_id = self::create( $values );
285
- $frm_duplicate_ids[ $field->id ] = $new_id;
286
  $frm_duplicate_ids[ $field->field_key ] = $new_id;
287
  unset( $field );
288
- }
289
- }
290
 
291
  public static function update( $id, $values ) {
292
- global $wpdb;
293
 
294
  $id = absint( $id );
295
 
@@ -298,8 +289,8 @@ class FrmField {
298
  }
299
 
300
  if ( isset( $values['required'] ) ) {
301
- $values['required'] = (int) $values['required'];
302
- }
303
 
304
  self::preserve_format_option_backslashes( $values );
305
 
@@ -321,42 +312,41 @@ class FrmField {
321
 
322
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
323
 
324
- $form_id = 0;
325
  if ( isset( $values['form_id'] ) ) {
326
- $form_id = absint( $values['form_id'] );
327
  } else {
328
  $field = self::getOne( $id );
329
- if ( $field ) {
330
- $form_id = $field->form_id;
331
- }
332
  unset( $field );
333
- }
334
  unset( $values );
335
 
336
  if ( $query_results ) {
337
- wp_cache_delete( $id, 'frm_field' );
338
- if ( $form_id ) {
339
- self::delete_form_transient( $form_id );
340
- }
341
- }
342
 
343
- return $query_results;
344
- }
345
 
346
  /**
347
- * Keep backslashes in the phone format option
348
- *
349
- * @since 2.0.8
350
- *
351
- * @param $values array - pass by reference
352
- */
353
  private static function preserve_format_option_backslashes( &$values ) {
354
  if ( isset( $values['field_options']['format'] ) ) {
355
  $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
356
  }
357
  }
358
 
359
- public static function destroy( $id ) {
360
  global $wpdb;
361
 
362
  do_action( 'frm_before_destroy_field', $id );
@@ -370,9 +360,8 @@ class FrmField {
370
  self::delete_form_transient( $field->form_id );
371
 
372
  $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
373
-
374
  return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
375
- }
376
 
377
  public static function delete_form_transient( $form_id ) {
378
  $form_id = absint( $form_id );
@@ -387,10 +376,10 @@ class FrmField {
387
  FrmDb::cache_delete_group( 'frm_field' );
388
 
389
  $form = FrmForm::getOne( $form_id );
390
- if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
391
- self::delete_form_transient( $form->parent_form_id );
392
- }
393
- }
394
 
395
  /**
396
  * If $field is numeric, get the field object
@@ -410,29 +399,29 @@ class FrmField {
410
  return null;
411
  }
412
 
413
- global $wpdb;
414
 
415
  $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
416
  $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // WPCS: unprepared SQL ok.
417
 
418
- $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
419
 
420
  if ( empty( $results ) ) {
421
  self::filter_field( $filter, $results );
422
- return $results;
423
- }
424
 
425
  if ( is_numeric( $id ) ) {
426
  FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
427
- } elseif ( $results ) {
428
  FrmDb::set_cache( $results->id, $results, 'frm_field' );
429
- }
430
 
431
  self::prepare_options( $results );
432
  self::filter_field( $filter, $results );
433
 
434
  return stripslashes_deep( $results );
435
- }
436
 
437
  /**
438
  * @since 3.06.01
@@ -454,26 +443,26 @@ class FrmField {
454
  * @param int|string The field id or key
455
  * @param mixed $col The name of the column in the fields database table
456
  */
457
- public static function get_type( $id, $col = 'type' ) {
458
- $field = FrmDb::check_cache( $id, 'frm_field' );
459
- if ( $field ) {
460
- $type = $field->{$col};
461
- } else {
462
  $where = array(
463
  'or' => 1,
464
  'id' => $id,
465
  'field_key' => $id,
466
  );
467
- $type = FrmDb::get_var( 'frm_fields', $where, $col );
468
- }
469
 
470
- return $type;
471
- }
472
 
473
  public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
474
- if ( ! $form_id ) {
475
- return array();
476
- }
477
 
478
  $results = self::get_fields_from_transients(
479
  $form_id,
@@ -483,97 +472,96 @@ class FrmField {
483
  )
484
  );
485
  if ( ! empty( $results ) ) {
486
- $fields = array();
487
- $count = 0;
488
- foreach ( $results as $result ) {
489
- if ( $type != $result->type ) {
490
- continue;
491
- }
492
 
493
  $fields[ $result->id ] = $result;
494
- $count ++;
495
- if ( $limit == 1 ) {
496
- $fields = $result;
497
- break;
498
- }
499
 
500
  if ( ! empty( $limit ) && $count >= $limit ) {
501
- break;
502
- }
503
 
504
  unset( $result );
505
  }
506
-
507
  return stripslashes_deep( $fields );
508
- }
509
 
510
- self::$use_cache = false;
511
 
512
  $where = array(
513
  'fi.form_id' => (int) $form_id,
514
  'fi.type' => $type,
515
  );
516
  self::maybe_include_repeating_fields( $inc_sub, $where );
517
- $results = self::getAll( $where, 'field_order', $limit );
518
- self::$use_cache = true;
519
  self::include_sub_fields( $results, $inc_sub, $type );
520
 
521
- return $results;
522
- }
523
 
524
  public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
525
- if ( ! (int) $form_id ) {
526
- return array();
527
- }
528
 
529
  $results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) );
530
  if ( ! empty( $results ) ) {
531
  if ( empty( $limit ) ) {
532
  return $results;
533
- }
534
 
535
- $fields = array();
536
- $count = 0;
537
- foreach ( $results as $result ) {
538
- $count ++;
539
  $fields[ $result->id ] = $result;
540
  if ( ! empty( $limit ) && $count >= $limit ) {
541
- break;
542
- }
543
- }
544
 
545
  return $fields;
546
- }
547
 
548
- self::$use_cache = false;
549
 
550
  $where = array( 'fi.form_id' => absint( $form_id ) );
551
  self::maybe_include_repeating_fields( $inc_repeat, $where );
552
  $results = self::getAll( $where, 'field_order', $limit );
553
 
554
- self::$use_cache = true;
555
 
556
  self::include_sub_fields( $results, $inc_embed, 'all' );
557
 
558
  if ( empty( $limit ) ) {
559
  self::set_field_transient( $results, $form_id, 0, compact( 'inc_embed', 'inc_repeat' ) );
560
- }
561
 
562
  return $results;
563
- }
564
 
565
  /**
566
- * If repeating fields should be included, adjust $where accordingly
567
- *
568
- * @param string $inc_repeat
569
- * @param array $where - pass by reference
570
- */
571
  private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
572
  if ( $inc_repeat == 'include' ) {
573
  $form_id = $where['fi.form_id'];
574
  $where[] = array(
575
- 'or' => 1,
576
- 'fi.form_id' => $form_id,
577
  'fr.parent_form_id' => $form_id,
578
  );
579
  unset( $where['fi.form_id'] );
@@ -582,57 +570,57 @@ class FrmField {
582
 
583
  public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
584
  if ( 'include' != $inc_embed || empty( $results ) ) {
585
- return;
586
- }
587
 
588
- $form_fields = $results;
589
  $index_offset = 1;
590
- foreach ( $form_fields as $k => $field ) {
591
  if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
592
- continue;
593
- }
594
 
595
- if ( $type == 'all' ) {
596
- $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
597
- } else {
598
  $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
599
- }
600
 
601
  if ( ! empty( $sub_fields ) ) {
602
- $index = $k + $index_offset;
603
  $index_offset += count( $sub_fields );
604
  array_splice( $results, $index, 0, $sub_fields );
605
  }
606
  unset( $field, $sub_fields );
607
- }
608
- }
609
 
610
  public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
611
  $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
612
- if ( self::$use_cache ) {
613
- // make sure old cache doesn't get saved as a transient
614
  $results = wp_cache_get( $cache_key, 'frm_field' );
615
- if ( false !== $results ) {
616
  return stripslashes_deep( $results );
617
- }
618
- }
619
 
620
- global $wpdb;
621
 
622
- if ( $blog_id && is_multisite() ) {
623
- global $wpmuBaseTablePrefix;
624
- if ( $wpmuBaseTablePrefix ) {
625
  $prefix = $wpmuBaseTablePrefix . $blog_id . '_';
626
- } else {
627
- $prefix = $wpdb->get_blog_prefix( $blog_id );
628
- }
629
 
630
- $table_name = $prefix . 'frm_fields';
631
  $form_table_name = $prefix . 'frm_forms';
632
  } else {
633
- $table_name = $wpdb->prefix . 'frm_fields';
634
  $form_table_name = $wpdb->prefix . 'frm_forms';
635
- }
636
 
637
  if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
638
  $order_by = ' ORDER BY ' . $order_by;
@@ -640,11 +628,11 @@ class FrmField {
640
 
641
  $limit = FrmDb::esc_limit( $limit );
642
 
643
- $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
644
- $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
645
 
646
  if ( is_array( $where ) ) {
647
- $args = array(
648
  'order_by' => $order_by,
649
  'limit' => $limit,
650
  );
@@ -654,9 +642,9 @@ class FrmField {
654
  $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
655
 
656
  $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
657
- $results = $wpdb->$function_name( $query );
658
- }
659
- unset( $where );
660
 
661
  self::format_field_results( $results );
662
 
@@ -675,12 +663,12 @@ class FrmField {
675
  FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
676
 
677
  $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
678
- $results[ $r_key ]->options = maybe_unserialize( $result->options );
679
  $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
680
 
681
  unset( $r_key, $result );
682
  }
683
- } elseif ( $results ) {
684
  FrmDb::set_cache( $results->id, $results, 'frm_field' );
685
  FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
686
 
@@ -696,7 +684,7 @@ class FrmField {
696
  private static function prepare_options( &$results ) {
697
  $results->field_options = maybe_unserialize( $results->field_options );
698
 
699
- $results->options = maybe_unserialize( $results->options );
700
  $results->default_value = maybe_unserialize( $results->default_value );
701
  }
702
 
@@ -709,7 +697,6 @@ class FrmField {
709
  private static function get_fields_from_transients( $form_id, $args ) {
710
  $fields = array();
711
  self::get_next_transient( $fields, 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'] );
712
-
713
  return $fields;
714
  }
715
 
@@ -719,7 +706,7 @@ class FrmField {
719
  * @since 2.0.1
720
  */
721
  private static function get_next_transient( &$fields, $base_name, $next = 0 ) {
722
- $name = $next ? $base_name . $next : $base_name;
723
  $next_fields = get_transient( $name );
724
 
725
  if ( $next_fields ) {
@@ -727,7 +714,7 @@ class FrmField {
727
 
728
  if ( count( $next_fields ) >= self::$transient_size ) {
729
  // if this transient is full, check for another
730
- $next ++;
731
  self::get_next_transient( $fields, $base_name, $next );
732
  }
733
  }
@@ -739,23 +726,22 @@ class FrmField {
739
  * @since 2.0.1
740
  */
741
  private static function set_field_transient( &$fields, $form_id, $next = 0, $args = array() ) {
742
- $base_name = 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'];
743
  $field_chunks = array_chunk( $fields, self::$transient_size );
744
 
745
  foreach ( $field_chunks as $field ) {
746
  $name = $next ? $base_name . $next : $base_name;
747
- $set = set_transient( $name, $field, 60 * 60 * 6 );
748
  if ( ! $set ) {
749
  // the transient didn't save
750
  if ( $name != $base_name ) {
751
  // if the first saved an others fail, this will show an incmoplete form
752
  self::delete_form_transient( $form_id );
753
  }
754
-
755
  return;
756
  }
757
 
758
- $next ++;
759
  }
760
  }
761
 
@@ -773,7 +759,6 @@ class FrmField {
773
  * @since 2.0.9
774
  *
775
  * @param array|object $field
776
- *
777
  * @return boolean
778
  */
779
  public static function is_field_with_multiple_values( $field ) {
@@ -805,7 +790,7 @@ class FrmField {
805
  * @return string
806
  */
807
  public static function get_original_field_type( $field ) {
808
- $field_type = self::get_field_type( $field );
809
  $original_type = self::get_option( $field, 'original_type' );
810
 
811
  if ( ! empty( $original_type ) && $original_type != $field_type ) {
@@ -822,9 +807,10 @@ class FrmField {
822
  * @return boolean
823
  */
824
  public static function is_multiple_select( $field ) {
825
- $field_type = self::get_field_type( $field );
826
- $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
827
 
 
828
  return apply_filters( 'frm_is_multiple_select', $is_multiple, $field );
829
  }
830
 
@@ -836,7 +822,6 @@ class FrmField {
836
  */
837
  public static function is_read_only( $field ) {
838
  global $frm_vars;
839
-
840
  return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
841
  }
842
 
@@ -846,7 +831,6 @@ class FrmField {
846
  public static function is_required( $field ) {
847
  $required = ( $field['required'] != '0' );
848
  $required = apply_filters( 'frm_is_field_required', $required, $field );
849
-
850
  return $required;
851
  }
852
 
@@ -901,7 +885,6 @@ class FrmField {
901
  } else {
902
  $option = self::get_option_in_object( $field, $option );
903
  }
904
-
905
  return $option;
906
  }
907
 
@@ -914,32 +897,28 @@ class FrmField {
914
  }
915
 
916
  /**
917
- * @since 2.0.09
918
- */
919
  public static function is_repeating_field( $field ) {
920
  if ( is_array( $field ) ) {
921
  $is_repeating_field = ( 'divider' == $field['type'] );
922
  } else {
923
  $is_repeating_field = ( 'divider' == $field->type );
924
  }
925
-
926
  return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
927
  }
928
 
929
  /**
930
  * @param string $key
931
- *
932
  * @return int field id
933
  */
934
  public static function get_id_by_key( $key ) {
935
  $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
936
-
937
  return (int) $id;
938
  }
939
 
940
  /**
941
  * @param string $id
942
- *
943
  * @return string
944
  */
945
  public static function get_key_by_id( $id ) {
@@ -948,7 +927,6 @@ class FrmField {
948
 
949
  public static function is_image( $field ) {
950
  $type = self::get_field_type( $field );
951
-
952
  return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
953
  }
954
 
@@ -958,7 +936,6 @@ class FrmField {
958
  * @since 3.0
959
  *
960
  * @param array|object $field
961
- *
962
  * @return boolean true if field type is radio or Dynamic radio
963
  */
964
  public static function is_radio( $field ) {
@@ -971,7 +948,6 @@ class FrmField {
971
  * @since 3.0
972
  *
973
  * @param array|object $field
974
- *
975
  * @return boolean true if field type is checkbox or Dynamic checkbox
976
  */
977
  public static function is_checkbox( $field ) {
@@ -985,12 +961,11 @@ class FrmField {
985
  *
986
  * @param array|object $field
987
  * @param string $is_type Options include radio, checkbox, text
988
- *
989
  * @return boolean true if field type is checkbox or Dynamic checkbox
990
  */
991
  public static function is_field_type( $field, $is_type ) {
992
  $field_type = self::get_original_field_type( $field );
993
- $data_type = self::get_option( $field, 'data_type' );
994
 
995
  return (
996
  $is_type === $field_type ||
10
 
11
  public static function field_selection() {
12
  $fields = array(
13
+ 'text' => array(
14
+ 'name' => __( 'Text', 'formidable' ),
15
+ 'icon' => 'frm_css_icon frm_text_icon',
16
  ),
17
+ 'textarea' => array(
18
+ 'name' => __( 'Paragraph', 'formidable' ),
19
+ 'icon' => 'frm_icon_font frm_paragraph_icon',
20
  ),
21
+ 'checkbox' => array(
22
+ 'name' => __( 'Checkboxes', 'formidable' ),
23
+ 'icon' => 'frm_icon_font frm_check-square_icon',
24
  ),
25
+ 'radio' => array(
26
+ 'name' => __( 'Radio Button', 'formidable' ),
27
+ 'icon' => 'frm_icon_font frm_radio-checked_icon',
28
  ),
29
+ 'select' => array(
30
+ 'name' => __( 'Dropdown', 'formidable' ),
31
+ 'icon' => 'frm_icon_font frm_caret-square-down_icon',
32
  ),
33
+ 'email' => array(
34
+ 'name' => __( 'Email', 'formidable' ),
35
+ 'icon' => 'frm_icon_font frm_envelope_icon',
36
  ),
37
+ 'url' => array(
38
+ 'name' => __( 'Website/URL', 'formidable' ),
39
+ 'icon' => 'dashicons dashicons-admin-links',
40
  ),
41
+ 'number' => array(
42
+ 'name' => __( 'Number', 'formidable' ),
43
+ 'icon' => 'frm_css_icon frm_number_icon',
44
  ),
45
+ 'phone' => array(
46
+ 'name' => __( 'Phone', 'formidable' ),
47
+ 'icon' => 'frm_icon_font frm_phone_icon',
48
  ),
49
+ 'html' => array(
50
+ 'name' => __( 'HTML', 'formidable' ),
51
+ 'icon' => 'frm_icon_font frm_embed2_icon',
52
  ),
53
+ 'hidden' => array(
54
+ 'name' => __( 'Hidden Field', 'formidable' ),
55
+ 'icon' => 'frm_icon_font frm_eye-slash_icon',
56
  ),
57
+ 'user_id' => array(
58
+ 'name' => __( 'User ID', 'formidable' ),
59
+ 'icon' => 'frm_icon_font frm_user_icon',
60
  ),
61
+ 'captcha' => array(
62
+ 'name' => __( 'reCAPTCHA', 'formidable' ),
63
+ 'icon' => 'frm_icon_font frm_shield-check_icon',
64
  ),
65
  );
66
 
69
 
70
  public static function pro_field_selection() {
71
  $fields = array(
72
+ 'file' => array(
73
+ 'name' => __( 'File Upload', 'formidable' ),
74
+ 'icon' => 'frm_icon_font frm_upload2_icon',
75
  ),
76
+ 'rte' => array(
77
+ 'name' => __( 'Rich Text', 'formidable' ),
78
+ 'icon' => 'dashicons dashicons-editor-alignright',
79
  ),
80
+ 'date' => array(
81
+ 'name' => __( 'Date', 'formidable' ),
82
+ 'icon' => 'frm_icon_font frm_calendar_icon',
83
  ),
84
+ 'time' => array(
85
+ 'name' => __( 'Time', 'formidable' ),
86
+ 'icon' => 'frm_icon_font frm_clock-o_icon',
87
  ),
88
+ 'scale' => array(
89
+ 'name' => __( 'Scale', 'formidable' ),
90
+ 'icon' => 'frm_icon_font frm_linear_scale_icon',
91
  ),
92
+ 'star' => array(
93
+ 'name' => __( 'Star Rating', 'formidable' ),
94
+ 'icon' => 'frm_icon_font frm_star-full_icon',
95
  ),
96
+ 'range' => array(
97
+ 'name' => __( 'Slider', 'formidable' ),
98
+ 'icon' => 'frm_icon_font frm_sliders_icon',
99
  ),
100
+ 'toggle' => array(
101
+ 'name' => __( 'Toggle', 'formidable' ),
102
+ 'icon' => 'frm_icon_font frm_toggle-on_icon',
103
  ),
104
+ 'data' => array(
105
+ 'name' => __( 'Dynamic', 'formidable' ),
106
+ 'icon' => 'frm_icon_font frm_sitemap_icon',
107
  ),
108
+ 'lookup' => array(
109
+ 'name' => __( 'Lookup', 'formidable' ),
110
+ 'icon' => 'frm_icon_font frm_search_icon',
111
  ),
112
  'divider|repeat' => array(
113
+ 'name' => __( 'Repeater', 'formidable' ),
114
+ 'icon' => 'frm_icon_font frm_repeat_icon',
115
  ),
116
+ 'end_divider' => array(
117
+ 'name' => __( 'End Section', 'formidable' ),
118
  'switch_from' => 'divider',
119
  ),
120
+ 'divider' => array(
121
+ 'name' => __( 'Section', 'formidable' ),
122
+ 'icon' => 'frm_css_icon frm_heading_icon',
123
  ),
124
+ 'break' => array(
125
+ 'name' => __( 'Page Break', 'formidable' ),
126
+ 'icon' => 'frm_icon_font frm_page-break_icon',
127
  ),
128
+ 'form' => array(
129
+ 'name' => __( 'Embed Form', 'formidable' ),
130
+ 'icon' => 'dashicons dashicons-editor-table',
131
  ),
132
+ 'password' => array(
133
+ 'name' => __( 'Password', 'formidable' ),
134
+ 'icon' => 'frm_icon_font frm_key_icon',
135
  ),
136
+ 'tag' => array(
137
+ 'name' => __( 'Tags', 'formidable' ),
138
+ 'icon' => 'frm_icon_font frm_price-tags_icon',
139
  ),
140
+ 'credit_card' => array(
141
  'name' => __( 'Credit Card', 'formidable' ),
142
+ 'icon' => 'frm_icon_font frm_credit-card-alt_icon frm_show_upgrade',
143
  'addon' => 'stripe',
144
  ),
145
+ 'address' => array(
146
+ 'name' => __( 'Address', 'formidable' ),
147
+ 'icon' => 'frm_icon_font frm_location_icon',
148
  ),
149
  'signature' => array(
150
  'name' => __( 'Signature', 'formidable' ),
151
+ 'icon' => 'frm_icon_font frm_pencil_icon frm_show_upgrade',
152
  'addon' => 'signature',
153
  ),
154
  'quiz_score' => array(
155
  'name' => __( 'Quiz Score', 'formidable' ),
156
+ 'icon' => 'frm_icon_font frm_calculator_icon frm_show_upgrade',
157
  'addon' => 'quizzes',
158
  ),
159
  );
167
  return apply_filters( 'frm_pro_available_fields', $fields );
168
  }
169
 
170
+ public static function create( $values, $return = true ) {
171
+ global $wpdb, $frm_duplicate_ids;
 
 
 
 
 
172
 
173
+ $new_values = array();
174
+ $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
 
 
 
175
  $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
176
 
177
  foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
178
  $new_values[ $col ] = $values[ $col ];
179
+ }
180
 
181
+ $new_values['options'] = $values['options'];
182
 
183
+ $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
184
+ $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
185
+ $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
186
+ $new_values['field_options'] = $values['field_options'];
187
+ $new_values['created_at'] = current_time( 'mysql', 1 );
188
 
189
  if ( isset( $values['id'] ) ) {
190
  $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
191
+ $new_values = apply_filters( 'frm_duplicated_field', $new_values );
192
+ }
193
 
194
  self::preserve_format_option_backslashes( $new_values );
195
 
196
  foreach ( $new_values as $k => $v ) {
197
+ if ( is_array( $v ) ) {
198
  $new_values[ $k ] = serialize( $v );
199
  }
200
+ unset( $k, $v );
201
+ }
202
 
203
+ //if(isset($values['id']) and is_numeric($values['id']))
204
+ // $new_values['id'] = $values['id'];
205
 
206
  $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
207
+ $new_id = 0;
208
  if ( $query_results ) {
209
  self::delete_form_transient( $new_values['form_id'] );
210
  $new_id = $wpdb->insert_id;
218
  if ( isset( $values['id'] ) ) {
219
  $frm_duplicate_ids[ $values['id'] ] = $new_id;
220
  }
 
221
  return $new_id;
222
  } else {
223
  return false;
224
  }
225
+ }
226
 
227
+ public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
228
+ global $frm_duplicate_ids;
229
 
230
+ $where = array(
231
  array(
232
+ 'or' => 1,
233
+ 'fi.form_id' => $old_form_id,
234
  'fr.parent_form_id' => $old_form_id,
235
  ),
236
  );
237
  $fields = self::getAll( $where, 'field_order', '', $blog_id );
238
 
239
+ foreach ( (array) $fields as $field ) {
240
  $new_key = $copy_keys ? $field->field_key : '';
241
+ if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
242
  $new_key = rtrim( $new_key, 2 );
243
  }
244
 
245
+ $values = array();
246
+ FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
247
 
248
  // If this is a repeating section, create new form
249
  if ( self::is_repeating_field( $field ) ) {
271
 
272
  $values['description'] = FrmFieldsHelper::switch_field_ids( $values['description'] );
273
 
274
+ $values = apply_filters( 'frm_duplicated_field', $values );
275
+ $new_id = self::create( $values );
276
+ $frm_duplicate_ids[ $field->id ] = $new_id;
277
  $frm_duplicate_ids[ $field->field_key ] = $new_id;
278
  unset( $field );
279
+ }
280
+ }
281
 
282
  public static function update( $id, $values ) {
283
+ global $wpdb;
284
 
285
  $id = absint( $id );
286
 
289
  }
290
 
291
  if ( isset( $values['required'] ) ) {
292
+ $values['required'] = (int) $values['required'];
293
+ }
294
 
295
  self::preserve_format_option_backslashes( $values );
296
 
312
 
313
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
314
 
315
+ $form_id = 0;
316
  if ( isset( $values['form_id'] ) ) {
317
+ $form_id = absint( $values['form_id'] );
318
  } else {
319
  $field = self::getOne( $id );
320
+ if ( $field ) {
321
+ $form_id = $field->form_id;
322
+ }
323
  unset( $field );
324
+ }
325
  unset( $values );
326
 
327
  if ( $query_results ) {
328
+ wp_cache_delete( $id, 'frm_field' );
329
+ if ( $form_id ) {
330
+ self::delete_form_transient( $form_id );
331
+ }
332
+ }
333
 
334
+ return $query_results;
335
+ }
336
 
337
  /**
338
+ * Keep backslashes in the phone format option
339
+ *
340
+ * @since 2.0.8
341
+ * @param $values array - pass by reference
342
+ */
 
343
  private static function preserve_format_option_backslashes( &$values ) {
344
  if ( isset( $values['field_options']['format'] ) ) {
345
  $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
346
  }
347
  }
348
 
349
+ public static function destroy( $id ) {
350
  global $wpdb;
351
 
352
  do_action( 'frm_before_destroy_field', $id );
360
  self::delete_form_transient( $field->form_id );
361
 
362
  $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
 
363
  return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
364
+ }
365
 
366
  public static function delete_form_transient( $form_id ) {
367
  $form_id = absint( $form_id );
376
  FrmDb::cache_delete_group( 'frm_field' );
377
 
378
  $form = FrmForm::getOne( $form_id );
379
+ if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
380
+ self::delete_form_transient( $form->parent_form_id );
381
+ }
382
+ }
383
 
384
  /**
385
  * If $field is numeric, get the field object
399
  return null;
400
  }
401
 
402
+ global $wpdb;
403
 
404
  $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
405
  $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // WPCS: unprepared SQL ok.
406
 
407
+ $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
408
 
409
  if ( empty( $results ) ) {
410
  self::filter_field( $filter, $results );
411
+ return $results;
412
+ }
413
 
414
  if ( is_numeric( $id ) ) {
415
  FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
416
+ } else if ( $results ) {
417
  FrmDb::set_cache( $results->id, $results, 'frm_field' );
418
+ }
419
 
420
  self::prepare_options( $results );
421
  self::filter_field( $filter, $results );
422
 
423
  return stripslashes_deep( $results );
424
+ }
425
 
426
  /**
427
  * @since 3.06.01
443
  * @param int|string The field id or key
444
  * @param mixed $col The name of the column in the fields database table
445
  */
446
+ public static function get_type( $id, $col = 'type' ) {
447
+ $field = FrmDb::check_cache( $id, 'frm_field' );
448
+ if ( $field ) {
449
+ $type = $field->{$col};
450
+ } else {
451
  $where = array(
452
  'or' => 1,
453
  'id' => $id,
454
  'field_key' => $id,
455
  );
456
+ $type = FrmDb::get_var( 'frm_fields', $where, $col );
457
+ }
458
 
459
+ return $type;
460
+ }
461
 
462
  public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
463
+ if ( ! $form_id ) {
464
+ return array();
465
+ }
466
 
467
  $results = self::get_fields_from_transients(
468
  $form_id,
472
  )
473
  );
474
  if ( ! empty( $results ) ) {
475
+ $fields = array();
476
+ $count = 0;
477
+ foreach ( $results as $result ) {
478
+ if ( $type != $result->type ) {
479
+ continue;
480
+ }
481
 
482
  $fields[ $result->id ] = $result;
483
+ $count++;
484
+ if ( $limit == 1 ) {
485
+ $fields = $result;
486
+ break;
487
+ }
488
 
489
  if ( ! empty( $limit ) && $count >= $limit ) {
490
+ break;
491
+ }
492
 
493
  unset( $result );
494
  }
 
495
  return stripslashes_deep( $fields );
496
+ }
497
 
498
+ self::$use_cache = false;
499
 
500
  $where = array(
501
  'fi.form_id' => (int) $form_id,
502
  'fi.type' => $type,
503
  );
504
  self::maybe_include_repeating_fields( $inc_sub, $where );
505
+ $results = self::getAll( $where, 'field_order', $limit );
506
+ self::$use_cache = true;
507
  self::include_sub_fields( $results, $inc_sub, $type );
508
 
509
+ return $results;
510
+ }
511
 
512
  public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
513
+ if ( ! (int) $form_id ) {
514
+ return array();
515
+ }
516
 
517
  $results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) );
518
  if ( ! empty( $results ) ) {
519
  if ( empty( $limit ) ) {
520
  return $results;
521
+ }
522
 
523
+ $fields = array();
524
+ $count = 0;
525
+ foreach ( $results as $result ) {
526
+ $count++;
527
  $fields[ $result->id ] = $result;
528
  if ( ! empty( $limit ) && $count >= $limit ) {
529
+ break;
530
+ }
531
+ }
532
 
533
  return $fields;
534
+ }
535
 
536
+ self::$use_cache = false;
537
 
538
  $where = array( 'fi.form_id' => absint( $form_id ) );
539
  self::maybe_include_repeating_fields( $inc_repeat, $where );
540
  $results = self::getAll( $where, 'field_order', $limit );
541
 
542
+ self::$use_cache = true;
543
 
544
  self::include_sub_fields( $results, $inc_embed, 'all' );
545
 
546
  if ( empty( $limit ) ) {
547
  self::set_field_transient( $results, $form_id, 0, compact( 'inc_embed', 'inc_repeat' ) );
548
+ }
549
 
550
  return $results;
551
+ }
552
 
553
  /**
554
+ * If repeating fields should be included, adjust $where accordingly
555
+ *
556
+ * @param string $inc_repeat
557
+ * @param array $where - pass by reference
558
+ */
559
  private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
560
  if ( $inc_repeat == 'include' ) {
561
  $form_id = $where['fi.form_id'];
562
  $where[] = array(
563
+ 'or' => 1,
564
+ 'fi.form_id' => $form_id,
565
  'fr.parent_form_id' => $form_id,
566
  );
567
  unset( $where['fi.form_id'] );
570
 
571
  public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
572
  if ( 'include' != $inc_embed || empty( $results ) ) {
573
+ return;
574
+ }
575
 
576
+ $form_fields = $results;
577
  $index_offset = 1;
578
+ foreach ( $form_fields as $k => $field ) {
579
  if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
580
+ continue;
581
+ }
582
 
583
+ if ( $type == 'all' ) {
584
+ $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
585
+ } else {
586
  $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
587
+ }
588
 
589
  if ( ! empty( $sub_fields ) ) {
590
+ $index = $k + $index_offset;
591
  $index_offset += count( $sub_fields );
592
  array_splice( $results, $index, 0, $sub_fields );
593
  }
594
  unset( $field, $sub_fields );
595
+ }
596
+ }
597
 
598
  public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
599
  $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
600
+ if ( self::$use_cache ) {
601
+ // make sure old cache doesn't get saved as a transient
602
  $results = wp_cache_get( $cache_key, 'frm_field' );
603
+ if ( false !== $results ) {
604
  return stripslashes_deep( $results );
605
+ }
606
+ }
607
 
608
+ global $wpdb;
609
 
610
+ if ( $blog_id && is_multisite() ) {
611
+ global $wpmuBaseTablePrefix;
612
+ if ( $wpmuBaseTablePrefix ) {
613
  $prefix = $wpmuBaseTablePrefix . $blog_id . '_';
614
+ } else {
615
+ $prefix = $wpdb->get_blog_prefix( $blog_id );
616
+ }
617
 
618
+ $table_name = $prefix . 'frm_fields';
619
  $form_table_name = $prefix . 'frm_forms';
620
  } else {
621
+ $table_name = $wpdb->prefix . 'frm_fields';
622
  $form_table_name = $wpdb->prefix . 'frm_forms';
623
+ }
624
 
625
  if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
626
  $order_by = ' ORDER BY ' . $order_by;
628
 
629
  $limit = FrmDb::esc_limit( $limit );
630
 
631
+ $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
632
+ $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
633
 
634
  if ( is_array( $where ) ) {
635
+ $args = array(
636
  'order_by' => $order_by,
637
  'limit' => $limit,
638
  );
642
  $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
643
 
644
  $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
645
+ $results = $wpdb->$function_name( $query );
646
+ }
647
+ unset( $where );
648
 
649
  self::format_field_results( $results );
650
 
663
  FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
664
 
665
  $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
666
+ $results[ $r_key ]->options = maybe_unserialize( $result->options );
667
  $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
668
 
669
  unset( $r_key, $result );
670
  }
671
+ } else if ( $results ) {
672
  FrmDb::set_cache( $results->id, $results, 'frm_field' );
673
  FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
674
 
684
  private static function prepare_options( &$results ) {
685
  $results->field_options = maybe_unserialize( $results->field_options );
686
 
687
+ $results->options = maybe_unserialize( $results->options );
688
  $results->default_value = maybe_unserialize( $results->default_value );
689
  }
690
 
697
  private static function get_fields_from_transients( $form_id, $args ) {
698
  $fields = array();
699
  self::get_next_transient( $fields, 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'] );
 
700
  return $fields;
701
  }
702
 
706
  * @since 2.0.1
707
  */
708
  private static function get_next_transient( &$fields, $base_name, $next = 0 ) {
709
+ $name = $next ? $base_name . $next : $base_name;
710
  $next_fields = get_transient( $name );
711
 
712
  if ( $next_fields ) {
714
 
715
  if ( count( $next_fields ) >= self::$transient_size ) {
716
  // if this transient is full, check for another
717
+ $next++;
718
  self::get_next_transient( $fields, $base_name, $next );
719
  }
720
  }
726
  * @since 2.0.1
727
  */
728
  private static function set_field_transient( &$fields, $form_id, $next = 0, $args = array() ) {
729
+ $base_name = 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'];
730
  $field_chunks = array_chunk( $fields, self::$transient_size );
731
 
732
  foreach ( $field_chunks as $field ) {
733
  $name = $next ? $base_name . $next : $base_name;
734
+ $set = set_transient( $name, $field, 60 * 60 * 6 );
735
  if ( ! $set ) {
736
  // the transient didn't save
737
  if ( $name != $base_name ) {
738
  // if the first saved an others fail, this will show an incmoplete form
739
  self::delete_form_transient( $form_id );
740
  }
 
741
  return;
742
  }
743
 
744
+ $next++;
745
  }
746
  }
747
 
759
  * @since 2.0.9
760
  *
761
  * @param array|object $field
 
762
  * @return boolean
763
  */
764
  public static function is_field_with_multiple_values( $field ) {
790
  * @return string
791
  */
792
  public static function get_original_field_type( $field ) {
793
+ $field_type = self::get_field_type( $field );
794
  $original_type = self::get_option( $field, 'original_type' );
795
 
796
  if ( ! empty( $original_type ) && $original_type != $field_type ) {
807
  * @return boolean
808
  */
809
  public static function is_multiple_select( $field ) {
810
+ $field_type = self::get_field_type( $field );
811
+ $data_type = self::get_option( $field, 'data_type' );
812
 
813
+ $is_multiple = self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select' ) ) );
814
  return apply_filters( 'frm_is_multiple_select', $is_multiple, $field );
815
  }
816
 
822
  */
823
  public static function is_read_only( $field ) {
824
  global $frm_vars;
 
825
  return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
826
  }
827
 
831
  public static function is_required( $field ) {
832
  $required = ( $field['required'] != '0' );
833
  $required = apply_filters( 'frm_is_field_required', $required, $field );
 
834
  return $required;
835
  }
836
 
885
  } else {
886
  $option = self::get_option_in_object( $field, $option );
887
  }
 
888
  return $option;
889
  }
890
 
897
  }
898
 
899
  /**
900
+ * @since 2.0.09
901
+ */
902
  public static function is_repeating_field( $field ) {
903
  if ( is_array( $field ) ) {
904
  $is_repeating_field = ( 'divider' == $field['type'] );
905
  } else {
906
  $is_repeating_field = ( 'divider' == $field->type );
907
  }
 
908
  return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
909
  }
910
 
911
  /**
912
  * @param string $key
 
913
  * @return int field id
914
  */
915
  public static function get_id_by_key( $key ) {
916
  $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
 
917
  return (int) $id;
918
  }
919
 
920
  /**
921
  * @param string $id
 
922
  * @return string
923
  */
924
  public static function get_key_by_id( $id ) {
927
 
928
  public static function is_image( $field ) {
929
  $type = self::get_field_type( $field );
 
930
  return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
931
  }
932
 
936
  * @since 3.0
937
  *
938
  * @param array|object $field
 
939
  * @return boolean true if field type is radio or Dynamic radio
940
  */
941
  public static function is_radio( $field ) {
948
  * @since 3.0
949
  *
950
  * @param array|object $field
 
951
  * @return boolean true if field type is checkbox or Dynamic checkbox
952
  */
953
  public static function is_checkbox( $field ) {
961
  *
962
  * @param array|object $field
963
  * @param string $is_type Options include radio, checkbox, text
 
964
  * @return boolean true if field type is checkbox or Dynamic checkbox
965
  */
966
  public static function is_field_type( $field, $is_type ) {
967
  $field_type = self::get_original_field_type( $field );
968
+ $data_type = self::get_option( $field, 'data_type' );
969
 
970
  return (
971
  $is_type === $field_type ||
classes/models/FrmFieldFormHtml.php CHANGED
@@ -10,7 +10,7 @@ class FrmFieldFormHtml {
10
  private $html_id;
11
 
12
  /**
13
- * @var FrmFieldType
14
  */
15
  private $field_obj;
16
 
@@ -83,8 +83,8 @@ class FrmFieldFormHtml {
83
  */
84
  private function set_pass_args( $atts ) {
85
  $this->pass_args = $atts;
86
-
87
  $exclude = array( 'field_obj', 'html' );
 
88
  foreach ( $exclude as $ex ) {
89
  if ( isset( $atts[ $ex ] ) ) {
90
  unset( $this->pass_args[ $ex ] );
@@ -167,7 +167,7 @@ class FrmFieldFormHtml {
167
  * @since 3.0
168
  */
169
  private function maybe_replace_description_shortcode( $wp_processed = false ) {
170
- $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
171
  $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed );
172
  if ( $should_replace ) {
173
  $this->replace_description_shortcode();
@@ -250,7 +250,7 @@ class FrmFieldFormHtml {
250
  */
251
  private function replace_required_class() {
252
  $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : '';
253
- $this->html = str_replace( '[required_class]', $required_class, $this->html );
254
  }
255
 
256
  /**
@@ -317,7 +317,7 @@ class FrmFieldFormHtml {
317
 
318
  foreach ( $shortcodes[0] as $short_key => $tag ) {
319
  $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
320
- $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
321
 
322
  $replace_with = '';
323
 
@@ -338,7 +338,6 @@ class FrmFieldFormHtml {
338
  */
339
  private function replace_input_shortcode( $shortcode_atts ) {
340
  $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts );
341
-
342
  return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts );
343
  }
344
 
@@ -349,7 +348,7 @@ class FrmFieldFormHtml {
349
  */
350
  private function prepare_input_shortcode_atts( $shortcode_atts ) {
351
  if ( isset( $shortcode_atts['opt'] ) ) {
352
- $shortcode_atts['opt'] --;
353
  }
354
 
355
  $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
@@ -376,7 +375,7 @@ class FrmFieldFormHtml {
376
  */
377
  private function add_class_to_label() {
378
  $label_class = $this->field_obj->get_label_class();
379
- $this->html = str_replace( '[label_position]', $label_class, $this->html );
380
  if ( $this->field_obj->get_field_column( 'label' ) == 'inside' && $this->field_obj->get_field_column( 'value' ) != '' ) {
381
  $this->html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $this->html );
382
  }
@@ -388,7 +387,7 @@ class FrmFieldFormHtml {
388
  * @since 3.0
389
  */
390
  private function replace_entry_key() {
391
- $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
392
  $this->html = str_replace( '[entry_key]', $entry_key, $this->html );
393
  }
394
 
@@ -407,6 +406,7 @@ class FrmFieldFormHtml {
407
  $this->html = str_replace( '[error_class]', $classes, $this->html );
408
  }
409
 
 
410
  /**
411
  * Get the classes for a field div
412
  *
10
  private $html_id;
11
 
12
  /**
13
+ * @var FrmFieldType
14
  */
15
  private $field_obj;
16
 
83
  */
84
  private function set_pass_args( $atts ) {
85
  $this->pass_args = $atts;
 
86
  $exclude = array( 'field_obj', 'html' );
87
+
88
  foreach ( $exclude as $ex ) {
89
  if ( isset( $atts[ $ex ] ) ) {
90
  unset( $this->pass_args[ $ex ] );
167
  * @since 3.0
168
  */
169
  private function maybe_replace_description_shortcode( $wp_processed = false ) {
170
+ $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
171
  $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed );
172
  if ( $should_replace ) {
173
  $this->replace_description_shortcode();
250
  */
251
  private function replace_required_class() {
252
  $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : '';
253
+ $this->html = str_replace( '[required_class]', $required_class, $this->html );
254
  }
255
 
256
  /**
317
 
318
  foreach ( $shortcodes[0] as $short_key => $tag ) {
319
  $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
320
+ $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
321
 
322
  $replace_with = '';
323
 
338
  */
339
  private function replace_input_shortcode( $shortcode_atts ) {
340
  $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts );
 
341
  return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts );
342
  }
343
 
348
  */
349
  private function prepare_input_shortcode_atts( $shortcode_atts ) {
350
  if ( isset( $shortcode_atts['opt'] ) ) {
351
+ $shortcode_atts['opt']--;
352
  }
353
 
354
  $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
375
  */
376
  private function add_class_to_label() {
377
  $label_class = $this->field_obj->get_label_class();
378
+ $this->html = str_replace( '[label_position]', $label_class, $this->html );
379
  if ( $this->field_obj->get_field_column( 'label' ) == 'inside' && $this->field_obj->get_field_column( 'value' ) != '' ) {
380
  $this->html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $this->html );
381
  }
387
  * @since 3.0
388
  */
389
  private function replace_entry_key() {
390
+ $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
391
  $this->html = str_replace( '[entry_key]', $entry_key, $this->html );
392
  }
393
 
406
  $this->html = str_replace( '[error_class]', $classes, $this->html );
407
  }
408
 
409
+
410
  /**
411
  * Get the classes for a field div
412
  *
classes/models/FrmFieldOption.php CHANGED
@@ -33,7 +33,7 @@ class FrmFieldOption {
33
 
34
  public function __construct( $option_key, $option, $args = array() ) {
35
  $this->option_key = $option_key;
36
- $this->option = $option;
37
  $this->set_option_label();
38
  $this->set_saved_value();
39
  }
33
 
34
  public function __construct( $option_key, $option, $args = array() ) {
35
  $this->option_key = $option_key;
36
+ $this->option = $option;
37
  $this->set_option_label();
38
  $this->set_saved_value();
39
  }
classes/models/FrmFieldValue.php CHANGED
@@ -45,7 +45,7 @@ class FrmFieldValue {
45
  }
46
 
47
  $this->entry_id = $entry->id;
48
- $this->field = $field;
49
  $this->init_saved_value( $entry );
50
  }
51
 
@@ -59,7 +59,7 @@ class FrmFieldValue {
59
  protected function init_saved_value( $entry ) {
60
  if ( $this->field->type === 'html' ) {
61
  $this->saved_value = $this->field->description;
62
- } elseif ( isset( $entry->metas[ $this->field->id ] ) ) {
63
  $this->saved_value = $entry->metas[ $this->field->id ];
64
  } else {
65
  $this->saved_value = '';
@@ -160,7 +160,6 @@ class FrmFieldValue {
160
  protected function generate_displayed_value_for_field_type( $atts ) {
161
  if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) {
162
  $field_obj = FrmFieldFactory::get_field_object( $this->field );
163
-
164
  $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts );
165
  }
166
  }
@@ -178,7 +177,7 @@ class FrmFieldValue {
178
  // TODO: maybe change from 'source' to 'run_filters' = 'email'
179
  if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) {
180
  // Deprecated frm_email_value hook
181
- $meta = array(
182
  'item_id' => $entry->id,
183
  'field_id' => $this->field->id,
184
  'meta_value' => $this->saved_value,
45
  }
46
 
47
  $this->entry_id = $entry->id;
48
+ $this->field = $field;
49
  $this->init_saved_value( $entry );
50
  }
51
 
59
  protected function init_saved_value( $entry ) {
60
  if ( $this->field->type === 'html' ) {
61
  $this->saved_value = $this->field->description;
62
+ } else if ( isset( $entry->metas[ $this->field->id ] ) ) {
63
  $this->saved_value = $entry->metas[ $this->field->id ];
64
  } else {
65
  $this->saved_value = '';
160
  protected function generate_displayed_value_for_field_type( $atts ) {
161
  if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) {
162
  $field_obj = FrmFieldFactory::get_field_object( $this->field );
 
163
  $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts );
164
  }
165
  }
177
  // TODO: maybe change from 'source' to 'run_filters' = 'email'
178
  if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) {
179
  // Deprecated frm_email_value hook
180
+ $meta = array(
181
  'item_id' => $entry->id,
182
  'field_id' => $this->field->id,
183
  'meta_value' => $this->saved_value,
classes/models/FrmFieldValueSelector.php CHANGED
@@ -36,6 +36,7 @@ class FrmFieldValueSelector {
36
  */
37
  protected $options = array();
38
 
 
39
  /**
40
  * @var string
41
  *
@@ -136,7 +137,7 @@ class FrmFieldValueSelector {
136
  * @since 2.03.05
137
  */
138
  protected function set_options() {
139
- $field_obj = FrmFieldFactory::get_field_object( $this->db_row );
140
  $this->options = $field_obj->get_options( array() );
141
  }
142
 
36
  */
37
  protected $options = array();
38
 
39
+
40
  /**
41
  * @var string
42
  *
137
  * @since 2.03.05
138
  */
139
  protected function set_options() {
140
+ $field_obj = FrmFieldFactory::get_field_object( $this->db_row );
141
  $this->options = $field_obj->get_options( array() );
142
  }
143
 
classes/models/FrmForm.php CHANGED
@@ -1,84 +1,84 @@
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) {
3
- die( 'You are not allowed to call this page directly.' );
4
  }
5
 
6
  class FrmForm {
7
 
8
- /**
9
- * @return int|boolean id on success or false on failure
10
- */
11
- public static function create( $values ) {
12
- global $wpdb;
13
 
14
  $new_values = array(
15
- 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
- 'name' => $values['name'],
17
- 'description' => $values['description'],
18
- 'status' => isset( $values['status'] ) ? $values['status'] : 'published',
19
- 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
- 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21
  'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
- 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
- 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
24
  );
25
 
26
  $options = isset( $values['options'] ) ? (array) $values['options'] : array();
27
  FrmFormsHelper::fill_form_options( $options, $values );
28
 
29
  $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
30
- $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
31
  $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
32
 
33
- $options = apply_filters( 'frm_form_options_before_update', $options, $values );
34
  $new_values['options'] = serialize( $options );
35
 
36
- //if(isset($values['id']) && is_numeric($values['id']))
37
- // $new_values['id'] = $values['id'];
38
 
39
  $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
40
 
41
- $id = $wpdb->insert_id;
42
 
43
  // Clear form caching
44
  self::clear_form_cache();
45
 
46
- return $id;
47
- }
48
-
49
- /**
50
- * @return int|boolean ID on success or false on failure
51
- */
52
- public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
53
- global $wpdb;
54
-
55
- $values = self::getOne( $id, $blog_id );
56
- if ( ! $values ) {
57
- return false;
58
- }
59
-
60
- $new_key = $copy_keys ? $values->form_key : '';
61
-
62
- $new_values = array(
63
- 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
64
- 'name' => $values->name,
65
- 'description' => $values->description,
66
- 'status' => $values->status ? $values->status : 'published',
67
- 'logged_in' => $values->logged_in ? $values->logged_in : 0,
68
- 'editable' => $values->editable ? $values->editable : 0,
69
- 'created_at' => current_time( 'mysql', 1 ),
70
- 'is_template' => $template ? 1 : 0,
71
- );
72
-
73
- if ( $blog_id ) {
74
- $new_values['status'] = 'published';
75
- $new_options = maybe_unserialize( $values->options );
76
  $new_options['email_to'] = get_option( 'admin_email' );
77
- $new_options['copy'] = false;
78
- $new_values['options'] = $new_options;
79
- } else {
80
- $new_values['options'] = $values->options;
81
- }
82
 
83
  if ( is_array( $new_values['options'] ) ) {
84
  $new_values['options'] = serialize( $new_values['options'] );
@@ -86,24 +86,23 @@ class FrmForm {
86
 
87
  $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
88
 
89
- if ( $query_results ) {
90
  // Clear form caching
91
  self::clear_form_cache();
92
 
93
- $form_id = $wpdb->insert_id;
94
  FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
95
 
96
- // update form settings after fields are created
97
  do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
 
 
98
 
99
- return $form_id;
100
- }
101
-
102
- return false;
103
- }
104
 
105
  public static function after_duplicate( $form_id, $values ) {
106
- $new_opts = maybe_unserialize( $values['options'] );
107
  $values['options'] = $new_opts;
108
 
109
  if ( isset( $new_opts['success_msg'] ) ) {
@@ -112,48 +111,48 @@ class FrmForm {
112
 
113
  $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
114
 
115
- if ( $new_opts != $values['options'] ) {
116
- global $wpdb;
117
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
118
- }
119
- }
120
 
121
- /**
122
- * @return int|boolean
123
- */
124
- public static function update( $id, $values, $create_link = false ) {
125
- global $wpdb;
126
 
127
- if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
- $values['status'] = 'published';
129
- }
130
 
131
  if ( isset( $values['form_key'] ) ) {
132
  $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133
- }
134
 
135
  $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136
 
137
  $new_values = self::set_update_options( array(), $values );
138
 
139
- foreach ( $values as $value_key => $value ) {
140
  if ( $value_key && in_array( $value_key, $form_fields ) ) {
141
  $new_values[ $value_key ] = $value;
142
- }
143
- }
144
 
145
- if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
- $new_values['status'] = $values['new_status'];
147
- }
148
 
149
- if ( ! empty( $new_values ) ) {
150
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
151
- if ( $query_results ) {
152
  self::clear_form_cache();
153
- }
154
- } else {
155
- $query_results = true;
156
- }
157
  unset( $new_values );
158
 
159
  $values = self::update_fields( $id, $values );
@@ -161,39 +160,40 @@ class FrmForm {
161
  do_action( 'frm_update_form', $id, $values );
162
  do_action( 'frm_update_form_' . $id, $values );
163
 
164
- return $query_results;
165
- }
166
 
167
- /**
168
- * @return array
169
- */
170
  public static function set_update_options( $new_values, $values ) {
171
  if ( ! isset( $values['options'] ) ) {
172
- return $new_values;
173
- }
174
 
175
  $options = isset( $values['options'] ) ? (array) $values['options'] : array();
176
  FrmFormsHelper::fill_form_options( $options, $values );
177
 
178
  $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
179
- $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
180
- $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
181
- $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
182
 
183
- $options = apply_filters( 'frm_form_options_before_update', $options, $values );
184
  $new_values['options'] = serialize( $options );
185
 
186
  return $new_values;
187
- }
188
 
189
- /**
190
- * @return array
191
- */
 
192
  public static function update_fields( $id, $values ) {
193
 
194
  if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
195
- return $values;
196
- }
197
 
198
  $all_fields = FrmField::get_all_for_form( $id );
199
  if ( empty( $all_fields ) ) {
@@ -204,26 +204,26 @@ class FrmForm {
204
  $values['item_meta'] = array();
205
  }
206
 
207
- $field_array = array();
208
- $existing_keys = array_keys( $values['item_meta'] );
209
- foreach ( $all_fields as $fid ) {
210
  if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
211
  $values['item_meta'][ $fid->id ] = '';
212
- }
213
  $field_array[ $fid->id ] = $fid;
214
- }
215
  unset( $all_fields );
216
 
217
- foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
  if ( isset( $field_array[ $field_id ] ) ) {
219
  $field = $field_array[ $field_id ];
220
- } else {
221
  $field = FrmField::getOne( $field_id );
222
- }
223
 
224
- if ( ! $field ) {
225
- continue;
226
- }
227
 
228
  $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229
  if ( $is_settings_page ) {
@@ -242,13 +242,14 @@ class FrmForm {
242
  foreach ( $update_options as $opt => $default ) {
243
  $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default;
244
  self::sanitize_field_opt( $opt, $field->field_options[ $opt ] );
245
- }
246
 
247
  $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
 
248
 
249
  $new_field = array(
250
  'field_options' => $field->field_options,
251
- 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? maybe_serialize( $values[ 'default_value_' . $field_id ] ) : '',
252
  );
253
 
254
  self::prepare_field_update_values( $field, $values, $new_field );
@@ -256,11 +257,11 @@ class FrmForm {
256
  FrmField::update( $field_id, $new_field );
257
 
258
  FrmField::delete_form_transient( $field->form_id );
259
- }
260
  self::clear_form_cache();
261
 
262
- return $values;
263
- }
264
 
265
  private static function sanitize_field_opt( $opt, &$value ) {
266
  if ( is_string( $value ) ) {
@@ -278,9 +279,8 @@ class FrmForm {
278
  */
279
  private static function get_settings_page_html( $values, &$field ) {
280
  if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
281
- $prev_opts = array();
282
  $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
283
-
284
  $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
285
  } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
286
  $prev_opts = $field->field_options;
@@ -296,7 +296,6 @@ class FrmForm {
296
 
297
  private static function prepare_field_update_values( $field, $values, &$new_field ) {
298
  $field_cols = array(
299
- 'field_order' => 0,
300
  'field_key' => '',
301
  'required' => false,
302
  'type' => '',
@@ -306,14 +305,8 @@ class FrmForm {
306
  );
307
  foreach ( $field_cols as $col => $default ) {
308
  $default = ( $default === '' ) ? $field->{$col} : $default;
309
-
310
  $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
311
  }
312
-
313
- // Don't save the template option.
314
- if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) {
315
- unset( $new_field['options']['000'] );
316
- }
317
  }
318
 
319
  /**
@@ -335,60 +328,59 @@ class FrmForm {
335
  return apply_filters( 'frm_form_strings', $strings, $form );
336
  }
337
 
338
- /**
339
- * @param string $status
340
- *
341
- * @return int|boolean
342
- */
343
  public static function set_status( $id, $status ) {
344
- if ( 'trash' == $status ) {
345
  return self::trash( $id );
346
- }
347
 
348
- $statuses = array( 'published', 'draft', 'trash' );
349
- if ( ! in_array( $status, $statuses ) ) {
350
- return false;
351
- }
352
 
353
- global $wpdb;
354
 
355
  if ( is_array( $id ) ) {
356
  $where = array(
357
- 'id' => $id,
358
  'parent_form_id' => $id,
359
- 'or' => 1,
360
  );
361
  FrmDb::get_where_clause_and_values( $where );
362
  array_unshift( $where['values'], $status );
363
 
364
  $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
365
- } else {
366
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
367
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
368
- }
369
 
370
- if ( $query_results ) {
371
  self::clear_form_cache();
372
- }
373
 
374
- return $query_results;
375
- }
376
 
377
- /**
378
- * @return int|boolean
379
- */
380
  public static function trash( $id ) {
381
- if ( ! EMPTY_TRASH_DAYS ) {
382
- return self::destroy( $id );
383
- }
384
 
385
  $form = self::getOne( $id );
386
- if ( ! $form ) {
387
- return false;
388
- }
389
 
390
- $options = $form->options;
391
- $options['trash_time'] = time();
392
 
393
  global $wpdb;
394
  $query_results = $wpdb->update(
@@ -413,39 +405,39 @@ class FrmForm {
413
  )
414
  );
415
 
416
- if ( $query_results ) {
417
  self::clear_form_cache();
418
- }
419
 
420
- return $query_results;
421
- }
422
 
423
- /**
424
- * @return int|boolean
425
- */
426
  public static function destroy( $id ) {
427
- global $wpdb;
428
 
429
  $form = self::getOne( $id );
430
- if ( ! $form ) {
431
- return false;
432
- }
433
  $id = $form->id;
434
 
435
- // Disconnect the entries from this form
436
  $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
437
  foreach ( $entries as $entry_id ) {
438
  FrmEntry::destroy( $entry_id );
439
  unset( $entry_id );
440
  }
441
 
442
- // Disconnect the fields from this form
443
  $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
444
 
445
  $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
446
- if ( $query_results ) {
447
- // Delete all form actions linked to this form
448
- $action_control = FrmFormActionsController::get_form_actions( 'email' );
449
  $action_control->destroy( $id, 'all' );
450
 
451
  // Clear form caching
@@ -453,10 +445,10 @@ class FrmForm {
453
 
454
  do_action( 'frm_destroy_form', $id );
455
  do_action( 'frm_destroy_form_' . $id );
456
- }
457
 
458
- return $query_results;
459
- }
460
 
461
  /**
462
  * Delete trashed forms based on how long they have been trashed
@@ -481,68 +473,61 @@ class FrmForm {
481
  $form->options = maybe_unserialize( $form->options );
482
  if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
483
  self::destroy( $form->id );
484
- $count ++;
485
  }
486
 
487
  unset( $form );
488
  }
489
-
490
  return $count;
491
  }
492
 
493
- /**
494
- * @return string form name
495
- */
496
- public static function getName( $id ) {
497
  $form = FrmDb::check_cache( $id, 'frm_form' );
498
- if ( $form ) {
499
  $r = stripslashes( $form->name );
 
 
500
 
501
- return $r;
502
- }
 
503
 
504
- $query_key = is_numeric( $id ) ? 'id' : 'form_key';
505
- $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
506
- $r = stripslashes( $r );
507
 
508
- return $r;
509
- }
510
-
511
- /**
512
  * @since 3.0
513
- *
514
- * @param string $key
515
- *
516
- * @return int form id
517
- */
518
  public static function get_id_by_key( $key ) {
519
  return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
520
- }
521
 
522
- /**
523
  * @since 3.0
524
- *
525
- * @param int $id
526
- *
527
- * @return string form key
528
- */
529
  public static function get_key_by_id( $id ) {
530
- $id = (int) $id;
531
  $cache = FrmDb::check_cache( $id, 'frm_form' );
532
- if ( $cache ) {
533
- return $cache->form_key;
534
- }
535
 
536
- $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
537
 
538
- return $key;
539
- }
540
 
541
  /**
542
  * If $form is numeric, get the form object
543
  *
544
  * @param object|int $form
545
- *
546
  * @since 2.0.9
547
  */
548
  public static function maybe_get_form( &$form ) {
@@ -551,51 +536,50 @@ class FrmForm {
551
  }
552
  }
553
 
554
- /**
555
- * @return object form
556
- */
557
- public static function getOne( $id, $blog_id = false ) {
558
- global $wpdb;
559
 
560
- if ( $blog_id && is_multisite() ) {
561
- global $wpmuBaseTablePrefix;
562
  $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
563
 
564
  $table_name = $prefix . 'frm_forms';
565
- } else {
566
  $table_name = $wpdb->prefix . 'frm_forms';
567
- $cache = wp_cache_get( $id, 'frm_form' );
568
- if ( $cache ) {
569
  if ( isset( $cache->options ) ) {
570
  $cache->options = maybe_unserialize( $cache->options );
571
- }
572
 
573
  return stripslashes_deep( $cache );
574
- }
575
- }
576
 
577
  if ( is_numeric( $id ) ) {
578
- $where = array( 'id' => $id );
579
- } else {
580
- $where = array( 'form_key' => $id );
581
- }
582
 
583
- $results = FrmDb::get_row( $table_name, $where );
584
 
585
  if ( isset( $results->options ) ) {
586
  FrmDb::set_cache( $results->id, $results, 'frm_form' );
587
  $results->options = maybe_unserialize( $results->options );
588
- }
589
-
590
  return stripslashes_deep( $results );
591
- }
592
 
593
- /**
594
- * @return object|array of objects
595
- */
596
  public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
597
  if ( is_array( $where ) && ! empty( $where ) ) {
598
- if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) {
599
  // don't get trashed templates
600
  $where['status'] = array( null, '', 'published' );
601
  }
@@ -605,7 +589,7 @@ class FrmForm {
605
  global $wpdb;
606
 
607
  // the query has already been prepared if this is not an array
608
- $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit );
609
  $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok.
610
  }
611
 
@@ -622,7 +606,7 @@ class FrmForm {
622
  }
623
 
624
  return stripslashes_deep( $results );
625
- }
626
 
627
  /**
628
  * Get all published forms
@@ -632,28 +616,27 @@ class FrmForm {
632
  */
633
  public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
634
  $query['is_template'] = 0;
635
- $query['status'] = array( null, '', 'published' );
636
  if ( $inc_children == 'exclude' ) {
637
  $query['parent_form_id'] = array( null, 0 );
638
  }
639
 
640
  $forms = self::getAll( $query, 'name', $limit );
641
-
642
  return $forms;
643
  }
644
 
645
- /**
646
- * @return object count of forms
647
- */
648
- public static function get_count() {
649
- global $wpdb;
650
 
651
- $cache_key = 'frm_form_counts';
652
 
653
- $counts = wp_cache_get( $cache_key, 'frm_form' );
654
- if ( false !== $counts ) {
655
- return $counts;
656
- }
657
 
658
  $results = (array) FrmDb::get_results(
659
  'frm_forms',
@@ -666,31 +649,31 @@ class FrmForm {
666
  );
667
 
668
  $statuses = array( 'published', 'draft', 'template', 'trash' );
669
- $counts = array_fill_keys( $statuses, 0 );
670
-
671
- foreach ( $results as $row ) {
672
- if ( 'trash' != $row->status ) {
673
- if ( $row->is_template ) {
674
- $counts['template'] ++;
675
- } else {
676
- $counts['published'] ++;
677
- }
678
- } else {
679
- $counts['trash'] ++;
680
- }
681
-
682
- if ( 'draft' == $row->status ) {
683
- $counts['draft'] ++;
684
- }
685
 
686
  unset( $row );
687
- }
688
 
689
- $counts = (object) $counts;
690
  FrmDb::set_cache( $cache_key, $counts, 'frm_form' );
691
 
692
- return $counts;
693
- }
694
 
695
  /**
696
  * Clear form caching
@@ -703,14 +686,14 @@ class FrmForm {
703
  FrmDb::cache_delete_group( 'frm_form' );
704
  }
705
 
706
- /**
707
- * @return array of errors
708
- */
709
  public static function validate( $values ) {
710
- $errors = array();
711
 
712
  return apply_filters( 'frm_validate_form', $errors, $values );
713
- }
714
 
715
  public static function get_params( $form = null ) {
716
  global $frm_vars;
@@ -726,7 +709,7 @@ class FrmForm {
726
  }
727
 
728
  $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok.
729
- $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
730
 
731
  $default_values = array(
732
  'id' => '',
@@ -741,7 +724,7 @@ class FrmForm {
741
  'action' => $action,
742
  );
743
 
744
- $values = array();
745
  $values['posted_form_id'] = FrmAppHelper::get_param( 'form_id', '', 'get', 'absint' );
746
  if ( ! $values['posted_form_id'] ) {
747
  $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -764,9 +747,7 @@ class FrmForm {
764
  }
765
  }
766
 
767
- if ( in_array( $values['action'], array( 'create', 'update' ) ) &&
768
- ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) // WPCS: CSRF ok.
769
- ) {
770
  $values['action'] = 'new';
771
  }
772
 
@@ -774,15 +755,15 @@ class FrmForm {
774
  }
775
 
776
  public static function list_page_params() {
777
- $values = array();
778
  $defaults = array(
779
  'template' => 0,
780
- 'id' => '',
781
- 'paged' => 1,
782
- 'form' => '',
783
- 'search' => '',
784
- 'sort' => '',
785
- 'sdir' => '',
786
  );
787
  foreach ( $defaults as $var => $default ) {
788
  $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
@@ -795,11 +776,11 @@ class FrmForm {
795
  $form_id = $form;
796
  if ( $form === null ) {
797
  $form_id = self::get_current_form_id();
798
- } elseif ( $form && is_object( $form ) ) {
799
  $form_id = $form->id;
800
  }
801
 
802
- $values = array();
803
  $defaults = array(
804
  'id' => '',
805
  'form_name' => '',
@@ -841,16 +822,14 @@ class FrmForm {
841
  if ( $form_id ) {
842
  $form_id = self::set_current_form( $form_id );
843
  }
844
-
845
  return $form_id;
846
  }
847
 
848
  public static function get_current_form( $form_id = 0 ) {
849
  $form = self::maybe_get_current_form( $form_id );
850
  if ( is_numeric( $form ) ) {
851
- $form = self::set_current_form( $form );
852
  }
853
-
854
  return $form;
855
  }
856
 
@@ -878,7 +857,7 @@ class FrmForm {
878
  $frm_vars['forms_loaded'][] = $small_form;
879
 
880
  if ( $this_load && empty( $global_load ) ) {
881
- $global_load = true;
882
  $frm_vars['load_css'] = true;
883
  }
884
 
@@ -888,7 +867,6 @@ class FrmForm {
888
  public static function show_submit( $form ) {
889
  $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
890
  $show = apply_filters( 'frm_show_submit_button', $show, $form );
891
-
892
  return $show;
893
  }
894
 
@@ -897,26 +875,14 @@ class FrmForm {
897
  */
898
  public static function get_option( $atts ) {
899
  $form = $atts['form'];
900
-
901
  return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default'];
902
  }
903
 
904
- /**
905
- * Get the link to edit this form.
906
- *
907
- * @since 4.0
908
- * @param int $form_id The id of the form.
909
- */
910
- public static function get_edit_link( $form_id ) {
911
- return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id );
912
- }
913
-
914
  /**
915
  * @deprecated 3.0
916
  * @codeCoverageIgnore
917
  *
918
  * @param string $key
919
- *
920
  * @return int form id
921
  */
922
  public static function getIdByKey( $key ) {
1
  <?php
2
  if ( ! defined( 'ABSPATH' ) ) {
3
+ die( 'You are not allowed to call this page directly.' );
4
  }
5
 
6
  class FrmForm {
7
 
8
+ /**
9
+ * @return int|boolean id on success or false on failure
10
+ */
11
+ public static function create( $values ) {
12
+ global $wpdb;
13
 
14
  $new_values = array(
15
+ 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
+ 'name' => $values['name'],
17
+ 'description' => $values['description'],
18
+ 'status' => isset( $values['status'] ) ? $values['status'] : 'draft',
19
+ 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
+ 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21
  'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
+ 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
+ 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
24
  );
25
 
26
  $options = isset( $values['options'] ) ? (array) $values['options'] : array();
27
  FrmFormsHelper::fill_form_options( $options, $values );
28
 
29
  $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
30
+ $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
31
  $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
32
 
33
+ $options = apply_filters( 'frm_form_options_before_update', $options, $values );
34
  $new_values['options'] = serialize( $options );
35
 
36
+ //if(isset($values['id']) && is_numeric($values['id']))
37
+ // $new_values['id'] = $values['id'];
38
 
39
  $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
40
 
41
+ $id = $wpdb->insert_id;
42
 
43
  // Clear form caching
44
  self::clear_form_cache();
45
 
46
+ return $id;
47
+ }
48
+
49
+ /**
50
+ * @return int|boolean ID on success or false on failure
51
+ */
52
+ public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
53
+ global $wpdb;
54
+
55
+ $values = self::getOne( $id, $blog_id );
56
+ if ( ! $values ) {
57
+ return false;
58
+ }
59
+
60
+ $new_key = $copy_keys ? $values->form_key : '';
61
+
62
+ $new_values = array(
63
+ 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
64
+ 'name' => $values->name,
65
+ 'description' => $values->description,
66
+ 'status' => $template ? 'published' : 'draft',
67
+ 'logged_in' => $values->logged_in ? $values->logged_in : 0,
68
+ 'editable' => $values->editable ? $values->editable : 0,
69
+ 'created_at' => current_time( 'mysql', 1 ),
70
+ 'is_template' => $template ? 1 : 0,
71
+ );
72
+
73
+ if ( $blog_id ) {
74
+ $new_values['status'] = 'published';
75
+ $new_options = maybe_unserialize( $values->options );
76
  $new_options['email_to'] = get_option( 'admin_email' );
77
+ $new_options['copy'] = false;
78
+ $new_values['options'] = $new_options;
79
+ } else {
80
+ $new_values['options'] = $values->options;
81
+ }
82
 
83
  if ( is_array( $new_values['options'] ) ) {
84
  $new_values['options'] = serialize( $new_values['options'] );
86
 
87
  $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
88
 
89
+ if ( $query_results ) {
90
  // Clear form caching
91
  self::clear_form_cache();
92
 
93
+ $form_id = $wpdb->insert_id;
94
  FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
95
 
96
+ // update form settings after fields are created
97
  do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
98
+ return $form_id;
99
+ }
100
 
101
+ return false;
102
+ }
 
 
 
103
 
104
  public static function after_duplicate( $form_id, $values ) {
105
+ $new_opts = maybe_unserialize( $values['options'] );
106
  $values['options'] = $new_opts;
107
 
108
  if ( isset( $new_opts['success_msg'] ) ) {
111
 
112
  $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
113
 
114
+ if ( $new_opts != $values['options'] ) {
115
+ global $wpdb;
116
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
117
+ }
118
+ }
119
 
120
+ /**
121
+ * @return int|boolean
122
+ */
123
+ public static function update( $id, $values, $create_link = false ) {
124
+ global $wpdb;
125
 
126
+ if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
+ $values['status'] = 'published';
128
+ }
129
 
130
  if ( isset( $values['form_key'] ) ) {
131
  $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
132
+ }
133
 
134
  $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
135
 
136
  $new_values = self::set_update_options( array(), $values );
137
 
138
+ foreach ( $values as $value_key => $value ) {
139
  if ( $value_key && in_array( $value_key, $form_fields ) ) {
140
  $new_values[ $value_key ] = $value;
141
+ }
142
+ }
143
 
144
+ if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
+ $new_values['status'] = $values['new_status'];
146
+ }
147
 
148
+ if ( ! empty( $new_values ) ) {
149
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
150
+ if ( $query_results ) {
151
  self::clear_form_cache();
152
+ }
153
+ } else {
154
+ $query_results = true;
155
+ }
156
  unset( $new_values );
157
 
158
  $values = self::update_fields( $id, $values );
160
  do_action( 'frm_update_form', $id, $values );
161
  do_action( 'frm_update_form_' . $id, $values );
162
 
163
+ return $query_results;
164
+ }
165
 
166
+ /**
167
+ * @return array
168
+ */
169
  public static function set_update_options( $new_values, $values ) {
170
  if ( ! isset( $values['options'] ) ) {
171
+ return $new_values;
172
+ }
173
 
174
  $options = isset( $values['options'] ) ? (array) $values['options'] : array();
175
  FrmFormsHelper::fill_form_options( $options, $values );
176
 
177
  $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
178
+ $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
179
+ $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
180
+ $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
181
 
182
+ $options = apply_filters( 'frm_form_options_before_update', $options, $values );
183
  $new_values['options'] = serialize( $options );
184
 
185
  return $new_values;
186
+ }
187
 
188
+
189
+ /**
190
+ * @return array
191
+ */
192
  public static function update_fields( $id, $values ) {
193
 
194
  if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
195
+ return $values;
196
+ }
197
 
198
  $all_fields = FrmField::get_all_for_form( $id );
199
  if ( empty( $all_fields ) ) {
204
  $values['item_meta'] = array();
205
  }
206
 
207
+ $field_array = array();
208
+ $existing_keys = array_keys( $values['item_meta'] );
209
+ foreach ( $all_fields as $fid ) {
210
  if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
211
  $values['item_meta'][ $fid->id ] = '';
212
+ }
213
  $field_array[ $fid->id ] = $fid;
214
+ }
215
  unset( $all_fields );
216
 
217
+ foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
  if ( isset( $field_array[ $field_id ] ) ) {
219
  $field = $field_array[ $field_id ];
220
+ } else {
221
  $field = FrmField::getOne( $field_id );
222
+ }
223
 
224
+ if ( ! $field ) {
225
+ continue;
226
+ }
227
 
228
  $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229
  if ( $is_settings_page ) {
242
  foreach ( $update_options as $opt => $default ) {
243
  $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default;
244
  self::sanitize_field_opt( $opt, $field->field_options[ $opt ] );
245
+ }
246
 
247
  $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
248
+ $default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
249
 
250
  $new_field = array(
251
  'field_options' => $field->field_options,
252
+ 'default_value' => $default_value,
253
  );
254
 
255
  self::prepare_field_update_values( $field, $values, $new_field );
257
  FrmField::update( $field_id, $new_field );
258
 
259
  FrmField::delete_form_transient( $field->form_id );
260
+ }
261
  self::clear_form_cache();
262
 
263
+ return $values;
264
+ }
265
 
266
  private static function sanitize_field_opt( $opt, &$value ) {
267
  if ( is_string( $value ) ) {
279
  */
280
  private static function get_settings_page_html( $values, &$field ) {
281
  if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) {
282
+ $prev_opts = array();
283
  $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type );
 
284
  $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html;
285
  } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) {
286
  $prev_opts = $field->field_options;
296
 
297
  private static function prepare_field_update_values( $field, $values, &$new_field ) {
298
  $field_cols = array(
 
299
  'field_key' => '',
300
  'required' => false,
301
  'type' => '',
305
  );
306
  foreach ( $field_cols as $col => $default ) {
307
  $default = ( $default === '' ) ? $field->{$col} : $default;
 
308
  $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
309
  }
 
 
 
 
 
310
  }
311
 
312
  /**
328
  return apply_filters( 'frm_form_strings', $strings, $form );
329
  }
330
 
331
+ /**
332
+ * @param string $status
333
+ * @return int|boolean
334
+ */
 
335
  public static function set_status( $id, $status ) {
336
+ if ( 'trash' == $status ) {
337
  return self::trash( $id );
338
+ }
339
 
340
+ $statuses = array( 'published', 'draft', 'trash' );
341
+ if ( ! in_array( $status, $statuses ) ) {
342
+ return false;
343
+ }
344
 
345
+ global $wpdb;
346
 
347
  if ( is_array( $id ) ) {
348
  $where = array(
349
+ 'id' => $id,
350
  'parent_form_id' => $id,
351
+ 'or' => 1,
352
  );
353
  FrmDb::get_where_clause_and_values( $where );
354
  array_unshift( $where['values'], $status );
355
 
356
  $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok.
357
+ } else {
358
  $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
359
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
360
+ }
361
 
362
+ if ( $query_results ) {
363
  self::clear_form_cache();
364
+ }
365
 
366
+ return $query_results;
367
+ }
368
 
369
+ /**
370
+ * @return int|boolean
371
+ */
372
  public static function trash( $id ) {
373
+ if ( ! EMPTY_TRASH_DAYS ) {
374
+ return self::destroy( $id );
375
+ }
376
 
377
  $form = self::getOne( $id );
378
+ if ( ! $form ) {
379
+ return false;
380
+ }
381
 
382
+ $options = $form->options;
383
+ $options['trash_time'] = time();
384
 
385
  global $wpdb;
386
  $query_results = $wpdb->update(
405
  )
406
  );
407
 
408
+ if ( $query_results ) {
409
  self::clear_form_cache();
410
+ }
411
 
412
+ return $query_results;
413
+ }
414
 
415
+ /**
416
+ * @return int|boolean
417
+ */
418
  public static function destroy( $id ) {
419
+ global $wpdb;
420
 
421
  $form = self::getOne( $id );
422
+ if ( ! $form ) {
423
+ return false;
424
+ }
425
  $id = $form->id;
426
 
427
+ // Disconnect the entries from this form
428
  $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
429
  foreach ( $entries as $entry_id ) {
430
  FrmEntry::destroy( $entry_id );
431
  unset( $entry_id );
432
  }
433
 
434
+ // Disconnect the fields from this form
435
  $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
436
 
437
  $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
438
+ if ( $query_results ) {
439
+ // Delete all form actions linked to this form
440
+ $action_control = FrmFormActionsController::get_form_actions( 'email' );
441
  $action_control->destroy( $id, 'all' );
442
 
443
  // Clear form caching
445
 
446
  do_action( 'frm_destroy_form', $id );
447
  do_action( 'frm_destroy_form_' . $id );
448
+ }
449
 
450
+ return $query_results;
451
+ }
452
 
453
  /**
454
  * Delete trashed forms based on how long they have been trashed
473
  $form->options = maybe_unserialize( $form->options );
474
  if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
475
  self::destroy( $form->id );
476
+ $count++;
477
  }
478
 
479
  unset( $form );
480
  }
 
481
  return $count;
482
  }
483
 
484
+ /**
485
+ * @return string form name
486
+ */
487
+ public static function getName( $id ) {
488
  $form = FrmDb::check_cache( $id, 'frm_form' );
489
+ if ( $form ) {
490
  $r = stripslashes( $form->name );
491
+ return $r;
492
+ }
493
 
494
+ $query_key = is_numeric( $id ) ? 'id' : 'form_key';
495
+ $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
496
+ $r = stripslashes( $r );
497
 
498
+ return $r;
499
+ }
 
500
 
501
+ /**
 
 
 
502
  * @since 3.0
503
+ * @param string $key
504
+ * @return int form id
505
+ */
 
 
506
  public static function get_id_by_key( $key ) {
507
  return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
508
+ }
509
 
510
+ /**
511
  * @since 3.0
512
+ * @param int $id
513
+ * @return string form key
514
+ */
 
 
515
  public static function get_key_by_id( $id ) {
516
+ $id = (int) $id;
517
  $cache = FrmDb::check_cache( $id, 'frm_form' );
518
+ if ( $cache ) {
519
+ return $cache->form_key;
520
+ }
521
 
522
+ $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
523
 
524
+ return $key;
525
+ }
526
 
527
  /**
528
  * If $form is numeric, get the form object
529
  *
530
  * @param object|int $form
 
531
  * @since 2.0.9
532
  */
533
  public static function maybe_get_form( &$form ) {
536
  }
537
  }
538
 
539
+ /**
540
+ * @return object form
541
+ */
542
+ public static function getOne( $id, $blog_id = false ) {
543
+ global $wpdb;
544
 
545
+ if ( $blog_id && is_multisite() ) {
546
+ global $wpmuBaseTablePrefix;
547
  $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
548
 
549
  $table_name = $prefix . 'frm_forms';
550
+ } else {
551
  $table_name = $wpdb->prefix . 'frm_forms';
552
+ $cache = wp_cache_get( $id, 'frm_form' );
553
+ if ( $cache ) {
554
  if ( isset( $cache->options ) ) {
555
  $cache->options = maybe_unserialize( $cache->options );
556
+ }
557
 
558
  return stripslashes_deep( $cache );
559
+ }
560
+ }
561
 
562
  if ( is_numeric( $id ) ) {
563
+ $where = array( 'id' => $id );
564
+ } else {
565
+ $where = array( 'form_key' => $id );
566
+ }
567
 
568
+ $results = FrmDb::get_row( $table_name, $where );
569
 
570
  if ( isset( $results->options ) ) {
571
  FrmDb::set_cache( $results->id, $results, 'frm_form' );
572
  $results->options = maybe_unserialize( $results->options );
573
+ }
 
574
  return stripslashes_deep( $results );
575
+ }
576
 
577
+ /**
578
+ * @return object|array of objects
579
+ */
580
  public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
581
  if ( is_array( $where ) && ! empty( $where ) ) {
582
+ if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) ) {
583
  // don't get trashed templates
584
  $where['status'] = array( null, '', 'published' );
585
  }
589
  global $wpdb;
590
 
591
  // the query has already been prepared if this is not an array
592
+ $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit );
593
  $results = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok.
594
  }
595
 
606
  }
607
 
608
  return stripslashes_deep( $results );
609
+ }
610
 
611
  /**
612
  * Get all published forms
616
  */
617
  public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
618
  $query['is_template'] = 0;
619
+ $query['status'] = array( null, '', 'published' );
620
  if ( $inc_children == 'exclude' ) {
621
  $query['parent_form_id'] = array( null, 0 );
622
  }
623
 
624
  $forms = self::getAll( $query, 'name', $limit );
 
625
  return $forms;
626
  }
627
 
628
+ /**
629
+ * @return object count of forms
630
+ */
631
+ public static function get_count() {
632
+ global $wpdb;
633
 
634
+ $cache_key = 'frm_form_counts';
635
 
636
+ $counts = wp_cache_get( $cache_key, 'frm_form' );
637
+ if ( false !== $counts ) {
638
+ return $counts;
639
+ }
640
 
641
  $results = (array) FrmDb::get_results(
642
  'frm_forms',
649
  );
650
 
651
  $statuses = array( 'published', 'draft', 'template', 'trash' );
652
+ $counts = array_fill_keys( $statuses, 0 );
653
+
654
+ foreach ( $results as $row ) {
655
+ if ( 'trash' != $row->status ) {
656
+ if ( $row->is_template ) {
657
+ $counts['template']++;
658
+ } else {
659
+ $counts['published']++;
660
+ }
661
+ } else {
662
+ $counts['trash']++;
663
+ }
664
+
665
+ if ( 'draft' == $row->status ) {
666
+ $counts['draft']++;
667
+ }
668
 
669
  unset( $row );
670
+ }
671
 
672
+ $counts = (object) $counts;
673
  FrmDb::set_cache( $cache_key, $counts, 'frm_form' );
674
 
675
+ return $counts;
676
+ }
677
 
678
  /**
679
  * Clear form caching
686
  FrmDb::cache_delete_group( 'frm_form' );
687
  }
688
 
689
+ /**
690
+ * @return array of errors
691
+ */
692
  public static function validate( $values ) {
693
+ $errors = array();
694
 
695
  return apply_filters( 'frm_validate_form', $errors, $values );
696
+ }
697
 
698
  public static function get_params( $form = null ) {
699
  global $frm_vars;
709
  }
710
 
711
  $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok.
712
+ $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
713
 
714
  $default_values = array(
715
  'id' => '',
724
  'action' => $action,
725
  );
726
 
727
+ $values = array();
728
  $values['posted_form_id'] = FrmAppHelper::get_param( 'form_id', '', 'get', 'absint' );
729
  if ( ! $values['posted_form_id'] ) {
730
  $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
747
  }
748
  }
749
 
750
+ if ( in_array( $values['action'], array( 'create', 'update' ) ) && ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) ) { // WPCS: CSRF ok.
 
 
751
  $values['action'] = 'new';
752
  }
753
 
755
  }
756
 
757
  public static function list_page_params() {
758
+ $values = array();
759
  $defaults = array(
760
  'template' => 0,
761
+ 'id' => '',
762
+ 'paged' => 1,
763
+ 'form' => '',
764
+ 'search' => '',
765
+ 'sort' => '',
766
+ 'sdir' => '',
767
  );
768
  foreach ( $defaults as $var => $default ) {
769
  $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
776
  $form_id = $form;
777
  if ( $form === null ) {
778
  $form_id = self::get_current_form_id();
779
+ } else if ( $form && is_object( $form ) ) {
780
  $form_id = $form->id;
781
  }
782
 
783
+ $values = array();
784
  $defaults = array(
785
  'id' => '',
786
  'form_name' => '',
822
  if ( $form_id ) {
823
  $form_id = self::set_current_form( $form_id );
824
  }
 
825
  return $form_id;
826
  }
827
 
828
  public static function get_current_form( $form_id = 0 ) {
829
  $form = self::maybe_get_current_form( $form_id );
830
  if ( is_numeric( $form ) ) {
831
+ $form = self::set_current_form( $form );
832
  }
 
833
  return $form;
834
  }
835
 
857
  $frm_vars['forms_loaded'][] = $small_form;
858
 
859
  if ( $this_load && empty( $global_load ) ) {
860
+ $global_load = true;
861
  $frm_vars['load_css'] = true;
862
  }
863
 
867
  public static function show_submit( $form ) {
868
  $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() );
869
  $show = apply_filters( 'frm_show_submit_button', $show, $form );
 
870
  return $show;
871
  }
872
 
875
  */
876
  public static function get_option( $atts ) {
877
  $form = $atts['form'];
 
878
  return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default'];
879
  }
880
 
 
 
 
 
 
 
 
 
 
 
881
  /**
882
  * @deprecated 3.0
883
  * @codeCoverageIgnore
884
  *
885
  * @param string $key
 
886
  * @return int form id
887
  */
888
  public static function getIdByKey( $key ) {
classes/models/FrmFormAction.php CHANGED
@@ -22,7 +22,6 @@ class FrmFormAction {
22
  *
23
  * @param array $new_instance New settings for this instance as input by the user via form()
24
  * @param array $old_instance Old settings for this instance
25
- *
26
  * @return array Settings to save or bool false to cancel saving
27
  */
28
  public function update( $new_instance, $old_instance ) {
@@ -30,13 +29,12 @@ class FrmFormAction {
30
  }
31
 
32
  /**
33
- * Echo the settings update form
34
  *
35
  * @param array $instance Current settings
36
  */
37
  public function form( $instance, $args = array() ) {
38
  echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
39
-
40
  return 'noform';
41
  }
42
 
@@ -44,15 +42,15 @@ class FrmFormAction {
44
  * @return array of the default options
45
  */
46
  public function get_defaults() {
47
- return array();
48
  }
49
 
50
  public function get_switch_fields() {
51
- return array();
52
  }
53
 
54
  public function migrate_values( $action, $form ) {
55
- return $action;
56
  }
57
 
58
  // Functions you'll need to call.
@@ -75,47 +73,24 @@ class FrmFormAction {
75
  die( 'You are not allowed to call this page directly.' );
76
  }
77
 
78
- $this->id_base = strtolower( $id_base );
79
- $this->name = $name;
80
  $this->option_name = 'frm_' . $this->id_base . '_action';
81
 
82
- $default_options = array(
83
- 'classes' => '',
84
- 'active' => true,
85
- 'event' => array( 'create' ),
86
- 'limit' => 1,
87
- 'force_event' => false,
88
- 'priority' => 20,
89
- 'ajax_load' => true,
90
- 'plugin' => $this->id_base,
91
- 'tooltip' => $name,
92
- 'group' => $id_base,
93
- 'color' => '',
94
- );
95
-
96
- $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
97
- $group = $this->get_group( $action_options );
98
- $action_options['group'] = $group['id'];
99
-
100
- if ( ! isset( $action_options['color'] ) ) {
101
- $colors = array( 'green', 'orange', 'purple' );
102
- shuffle( $colors );
103
- $action_options['color'] = 'var(--' . reset( $colors ) . ')';
104
- }
105
-
106
- $upgrade_class = $action_options['classes'] === 'frm_show_upgrade';
107
- if ( $action_options['group'] === $id_base ) {
108
- $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
109
- $action_options['classes'] = $group['icon'];
110
- } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
111
- $action_options['classes'] = $group['icon'];
112
- }
113
-
114
- if ( $upgrade_class ) {
115
- $action_options['classes'] .= ' frm_show_upgrade';
116
- }
117
-
118
- $this->action_options = wp_parse_args( $action_options, $default_options );
119
  $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
120
  }
121
 
@@ -126,44 +101,18 @@ class FrmFormAction {
126
  self::__construct( $id_base, $name, $action_options, $control_options );
127
  }
128
 
129
- /**
130
- * @since 4.0
131
- */
132
- protected function get_group( $action_options ) {
133
- $groups = FrmFormActionsController::form_action_groups();
134
- $group = 'misc';
135
-
136
- if ( isset( $action_options['group'] ) && isset( $groups[ $action_options['group'] ] ) ) {
137
- $group = $action_options['group'];
138
- } elseif ( isset( $groups[ $this->id_base ] ) ) {
139
- $group = $this->id_base;
140
- } else {
141
- foreach ( $groups as $name => $check_group ) {
142
- if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'] ) ) {
143
- $group = $name;
144
- break;
145
- }
146
- }
147
- }
148
-
149
- $groups[ $group ]['id'] = $group;
150
- return $groups[ $group ];
151
- }
152
-
153
  /**
154
  * Constructs name attributes for use in form() fields
155
  *
156
  * This function should be used in form() methods to create name attributes for fields to be saved by update()
157
  *
158
  * @param string $field_name Field name
159
- *
160
  * @return string Name attribute for $field_name
161
  */
162
  public function get_field_name( $field_name, $post_field = 'post_content' ) {
163
  $name = $this->option_name . '[' . $this->number . ']';
164
  $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
165
  $name .= '[' . $field_name . ']';
166
-
167
  return $name;
168
  }
169
 
@@ -173,7 +122,6 @@ class FrmFormAction {
173
  * This function should be used in form() methods to create id attributes for fields to be saved by update()
174
  *
175
  * @param string $field_name Field name
176
- *
177
  * @return string ID attribute for $field_name
178
  */
179
  public function get_field_id( $field_name ) {
@@ -184,16 +132,16 @@ class FrmFormAction {
184
 
185
  public function _set( $number ) {
186
  $this->number = $number;
187
- $this->id = $this->id_base . '-' . $number;
188
  }
189
 
190
  public function prepare_new( $form_id = false ) {
191
- if ( $form_id ) {
192
- $this->form_id = $form_id;
193
- }
194
 
195
- $post_content = array();
196
- $default_values = $this->get_global_defaults();
197
 
198
  // fill default values
199
  $post_content = wp_parse_args( $post_content, $default_values );
@@ -202,145 +150,144 @@ class FrmFormAction {
202
  $post_content['event'] = array( reset( $this->action_options['event'] ) );
203
  }
204
 
205
- $form_action = array(
206
- 'post_title' => $this->name,
207
- 'post_content' => $post_content,
208
- 'post_excerpt' => $this->id_base,
209
- 'ID' => '',
210
- 'post_status' => 'publish',
211
- 'post_type' => FrmFormActionsController::$action_post_type,
212
- 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
213
- 'menu_order' => $this->form_id,
214
- );
215
  unset( $post_content );
216
 
217
- return (object) $form_action;
218
- }
219
 
220
  public function create( $form_id ) {
221
- $this->form_id = $form_id;
222
 
223
- $action = $this->prepare_new();
224
 
225
  return $this->save_settings( $action );
226
- }
227
 
228
  public function duplicate_form_actions( $form_id, $old_id ) {
229
- if ( $form_id == $old_id ) {
230
- // don't duplicate the actions if this is a template getting updated
231
- return;
232
- }
233
 
234
- $this->form_id = $old_id;
235
- $actions = $this->get_all( $old_id );
236
 
237
- $this->form_id = $form_id;
238
- foreach ( $actions as $action ) {
239
  $this->duplicate_one( $action, $form_id );
240
  unset( $action );
241
- }
242
- }
243
-
244
- /* Check if imported action should be created or updated
245
- *
246
- * @since 2.0
247
- *
248
- * @param array $action
249
- * @return integer $post_id
250
- */
251
- public function maybe_create_action( $action, $forms ) {
252
  if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
253
- // Update action only
254
- $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
255
- $post_id = $this->save_settings( $action );
256
- } else {
257
  // Create action
258
  $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
259
- $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
260
- }
261
-
262
- return $post_id;
263
- }
264
 
265
  public function duplicate_one( $action, $form_id ) {
266
- global $frm_duplicate_ids;
267
 
268
- $action->menu_order = $form_id;
269
- $switch = $this->get_global_switch_fields();
270
- foreach ( (array) $action->post_content as $key => $val ) {
271
  if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
272
  $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
273
- } elseif ( ! is_array( $val ) ) {
274
  $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
275
- } elseif ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
276
- // loop through each value if empty
277
  if ( empty( $switch[ $key ] ) ) {
278
  $switch[ $key ] = array_keys( $val );
279
  }
280
 
281
  foreach ( $switch[ $key ] as $subkey ) {
282
  $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
283
- }
284
- }
285
 
286
  unset( $key, $val );
287
  }
288
  unset( $action->ID );
289
 
290
  return $this->save_settings( $action );
291
- }
292
 
293
  private function duplicate_array_walk( $action, $subkey, $val ) {
294
- global $frm_duplicate_ids;
295
 
296
  if ( is_array( $subkey ) ) {
297
- foreach ( $subkey as $subkey2 ) {
298
- foreach ( (array) $val as $ck => $cv ) {
299
  if ( is_array( $cv ) ) {
300
  $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
301
- } elseif ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
302
  $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
303
- }
304
- }
305
- }
306
- } else {
307
- foreach ( (array) $val as $ck => $cv ) {
308
  if ( is_array( $cv ) ) {
309
  $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
310
- } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
311
  $action[ $ck ] = $frm_duplicate_ids[ $cv ];
312
- }
313
- }
314
- }
315
 
316
- return $action;
317
- }
318
 
319
  /**
320
  * Deal with changed settings.
321
  *
322
  * Do NOT over-ride this function
323
  */
324
- public function update_callback( $form_id ) {
325
- $this->form_id = $form_id;
326
 
327
- $all_instances = $this->get_settings();
328
 
329
- // We need to update the data
330
- if ( $this->updated ) {
331
- return;
332
- }
333
 
334
  if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
335
- $settings = wp_unslash( $_POST[ $this->option_name ] );
336
- } else {
337
- return;
338
- }
339
 
340
- $action_ids = array();
341
 
342
- foreach ( $settings as $number => $new_instance ) {
343
- $this->_set( $number );
344
 
345
  $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
346
 
@@ -349,19 +296,19 @@ class FrmFormAction {
349
  }
350
 
351
  // settings were never opened, so don't update
352
- if ( ! isset( $new_instance['post_title'] ) ) {
353
  $this->maybe_update_status( $new_instance, $old_instance );
354
- $action_ids[] = $new_instance['ID'];
355
- $this->updated = true;
356
- continue;
357
- }
358
 
359
  $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
360
  $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
361
  $new_instance['menu_order'] = $this->form_id;
362
  $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
363
 
364
- $instance = $this->update( $new_instance, $old_instance );
365
 
366
  /**
367
  * Filter an action's settings before saving.
@@ -371,10 +318,10 @@ class FrmFormAction {
371
  *
372
  * @since 2.0
373
  *
374
- * @param array $instance The current widget instance's settings.
375
- * @param array $new_instance Array of new widget settings.
376
- * @param array $old_instance Array of old widget settings.
377
- * @param WP_Widget $this The current widget instance.
378
  */
379
  $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
380
 
@@ -387,11 +334,11 @@ class FrmFormAction {
387
 
388
  $action_ids[] = $this->save_settings( $instance );
389
 
390
- $this->updated = true;
391
- }
392
 
393
- return $action_ids;
394
- }
395
 
396
  /**
397
  * If the status of the action has changed, update it
@@ -412,7 +359,6 @@ class FrmFormAction {
412
 
413
  public function save_settings( $settings ) {
414
  self::clear_cache();
415
-
416
  return FrmDb::save_settings( $settings, 'frm_actions' );
417
  }
418
 
@@ -422,20 +368,19 @@ class FrmFormAction {
422
  $action = $this->prepare_action( $action );
423
  $this->_set( $id );
424
  }
425
-
426
- return $action;
427
  }
428
 
429
  public function get_one( $form_id ) {
430
  return $this->get_all( $form_id, 1 );
431
  }
432
 
433
- public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
434
- $action_controls = FrmFormActionsController::get_form_actions( $type );
435
  if ( empty( $action_controls ) ) {
436
- // don't continue if there are no available actions
437
- return array();
438
- }
439
 
440
  if ( 'all' != $type ) {
441
  return $action_controls->get_all( $form_id, $atts );
@@ -445,37 +390,37 @@ class FrmFormAction {
445
 
446
  $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
447
 
448
- $args = self::action_args( $form_id, $limit );
449
  $args['post_status'] = $atts['post_status'];
450
- $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
451
 
452
- if ( ! $actions ) {
453
- return array();
454
- }
455
 
456
- $settings = array();
457
- foreach ( $actions as $action ) {
458
  // some plugins/themes are formatting the post_excerpt
459
  $action->post_excerpt = sanitize_title( $action->post_excerpt );
460
 
461
  if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
462
- continue;
463
- }
464
 
465
- $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
466
  $settings[ $action->ID ] = $action;
467
 
468
  if ( count( $settings ) >= $limit ) {
469
  break;
470
  }
471
- }
472
 
473
- if ( 1 === $limit ) {
474
  $settings = reset( $settings );
475
- }
476
 
477
- return $settings;
478
- }
479
 
480
  /**
481
  * @since 3.04
@@ -493,7 +438,7 @@ class FrmFormAction {
493
  'limit' => 99,
494
  'post_status' => $default_status,
495
  );
496
- $args = wp_parse_args( $args, $defaults );
497
  }
498
 
499
  /**
@@ -504,18 +449,15 @@ class FrmFormAction {
504
  return false;
505
  }
506
  $action_control = FrmFormActionsController::get_form_actions( $type );
507
-
508
  return $action_control->get_single_action( $action_id );
509
  }
510
 
511
  /**
512
  * @param int $form_id
513
- *
514
  * @return bool
515
  */
516
  public static function form_has_action_type( $form_id, $type ) {
517
  $payment_actions = self::get_action_for_form( $form_id, $type );
518
-
519
  return ! empty( $payment_actions );
520
  }
521
 
@@ -523,19 +465,19 @@ class FrmFormAction {
523
  self::prepare_get_action( $atts, 'any' );
524
  $limit = $atts['limit'];
525
 
526
- if ( $form_id ) {
527
- $this->form_id = $form_id;
528
- }
529
 
530
- $type = $this->id_base;
531
 
532
- global $frm_vars;
533
- $frm_vars['action_type'] = $type;
534
 
535
  add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
536
  $query = self::action_args( $form_id, $limit );
537
  $query['post_status'] = $atts['post_status'];
538
- $query['suppress_filters'] = false;
539
 
540
  $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
541
  unset( $query );
@@ -543,25 +485,25 @@ class FrmFormAction {
543
  remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
544
 
545
  if ( empty( $actions ) ) {
546
- return array();
547
- }
548
 
549
- $settings = array();
550
- foreach ( $actions as $action ) {
551
  if ( count( $settings ) >= $limit ) {
552
- continue;
553
- }
554
 
555
  $action = $this->prepare_action( $action );
556
 
557
  $settings[ $action->ID ] = $action;
558
- }
559
 
560
- if ( 1 === $limit ) {
561
  $settings = reset( $settings );
562
- }
563
 
564
- return $settings;
565
  }
566
 
567
  public static function action_args( $form_id = 0, $limit = 99 ) {
@@ -584,45 +526,45 @@ class FrmFormAction {
584
  $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
585
  $action->post_excerpt = sanitize_title( $action->post_excerpt );
586
 
587
- $default_values = $this->get_global_defaults();
588
 
589
- // fill default values
590
- $action->post_content += $default_values;
591
 
592
- foreach ( $default_values as $k => $vals ) {
593
  if ( is_array( $vals ) && ! empty( $vals ) ) {
594
  if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
595
- continue;
596
- }
597
  $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
598
- }
599
- }
600
 
601
  if ( ! is_array( $action->post_content['event'] ) ) {
602
  $action->post_content['event'] = explode( ',', $action->post_content['event'] );
603
  }
604
 
605
- return $action;
606
  }
607
 
608
  public function destroy( $form_id = false, $type = 'default' ) {
609
- global $wpdb;
610
 
611
- $this->form_id = $form_id;
612
 
613
- $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
614
- if ( $form_id ) {
615
- $query['menu_order'] = $form_id;
616
- }
617
- if ( 'all' != $type ) {
618
- $query['post_excerpt'] = $this->id_base;
619
- }
620
 
621
- $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
622
 
623
- foreach ( $post_ids as $id ) {
624
  wp_delete_post( $id );
625
- }
626
  self::clear_cache();
627
  }
628
 
@@ -640,53 +582,52 @@ class FrmFormAction {
640
  }
641
 
642
  public function get_global_defaults() {
643
- $defaults = $this->get_defaults();
644
 
645
  if ( ! isset( $defaults['event'] ) ) {
646
  $defaults['event'] = array( 'create' );
647
- }
648
 
649
  if ( ! isset( $defaults['conditions'] ) ) {
650
- $defaults['conditions'] = array(
651
- 'send_stop' => '',
652
- 'any_all' => '',
653
- );
654
- }
655
 
656
- return $defaults;
657
  }
658
 
659
  public function get_global_switch_fields() {
660
- $switch = $this->get_switch_fields();
661
  $switch['conditions'] = array( 'hide_field' );
662
-
663
- return $switch;
664
  }
665
 
666
  /**
667
  * Migrate settings from form->options into new action.
668
  */
669
  public function migrate_to_2( $form, $update = 'update' ) {
670
- $action = $this->prepare_new( $form->id );
671
  $form->options = maybe_unserialize( $form->options );
672
 
673
- // fill with existing options
674
- foreach ( $action->post_content as $name => $val ) {
675
  if ( isset( $form->options[ $name ] ) ) {
676
  $action->post_content[ $name ] = $form->options[ $name ];
677
  unset( $form->options[ $name ] );
678
- }
679
- }
680
 
681
  $action = $this->migrate_values( $action, $form );
682
 
683
- // check if action already exists
684
  $post_id = get_posts(
685
  array(
686
- 'name' => $action->post_name,
687
- 'post_type' => FrmFormActionsController::$action_post_type,
688
- 'post_status' => $action->post_status,
689
- 'numberposts' => 1,
690
  )
691
  );
692
 
@@ -695,22 +636,22 @@ class FrmFormAction {
695
  $post_id = $this->save_settings( $action );
696
  }
697
 
698
- if ( $post_id && 'update' == $update ) {
699
- global $wpdb;
700
  $form->options = maybe_serialize( $form->options );
701
 
702
- // update form options
703
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
704
- FrmForm::clear_form_cache();
705
- }
706
 
707
- return $post_id;
708
- }
709
 
710
  public static function action_conditions_met( $action, $entry ) {
711
  $notification = $action->post_content;
712
- $stop = false;
713
- $met = array();
714
 
715
  if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
716
  return $stop;
@@ -751,7 +692,6 @@ class FrmFormAction {
751
  * Prepare the logic value for comparison against the entered value
752
  *
753
  * @since 2.01.02
754
- *
755
  * @param array|string $logic_value
756
  */
757
  private static function prepare_logic_value( &$logic_value ) {
@@ -764,14 +704,13 @@ class FrmFormAction {
764
  }
765
  }
766
 
 
767
  /**
768
  * Get the value from a specific field and entry
769
  *
770
  * @since 2.01.02
771
- *
772
  * @param object $entry
773
  * @param int $field_id
774
- *
775
  * @return array|bool|mixed|string
776
  */
777
  private static function get_value_from_entry( $entry, $field_id ) {
@@ -779,8 +718,8 @@ class FrmFormAction {
779
 
780
  if ( isset( $entry->metas[ $field_id ] ) ) {
781
  $observed_value = $entry->metas[ $field_id ];
782
- } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
783
- $field = FrmField::getOne( $field_id );
784
  $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
785
  $entry,
786
  $field,
@@ -796,21 +735,20 @@ class FrmFormAction {
796
 
797
  public static function default_action_opts( $class = '' ) {
798
  return array(
799
- 'classes' => 'frm_icon_font ' . $class,
800
- 'active' => false,
801
- 'limit' => 0,
802
  );
803
  }
804
 
805
  public static function trigger_labels() {
806
  $triggers = array(
807
- 'draft' => __( 'Draft is saved', 'formidable' ),
808
- 'create' => __( 'Entry is created', 'formidable' ),
809
- 'update' => __( 'Entry is updated', 'formidable' ),
810
- 'delete' => __( 'Entry is deleted', 'formidable' ),
811
- 'import' => __( 'Entry is imported', 'formidable' ),
812
  );
813
-
814
  return apply_filters( 'frm_action_triggers', $triggers );
815
  }
816
  }
22
  *
23
  * @param array $new_instance New settings for this instance as input by the user via form()
24
  * @param array $old_instance Old settings for this instance
 
25
  * @return array Settings to save or bool false to cancel saving
26
  */
27
  public function update( $new_instance, $old_instance ) {
29
  }
30
 
31
  /**
32
+ * Echo the settings update form
33
  *
34
  * @param array $instance Current settings
35
  */
36
  public function form( $instance, $args = array() ) {
37
  echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
 
38
  return 'noform';
39
  }
40
 
42
  * @return array of the default options
43
  */
44
  public function get_defaults() {
45
+ return array();
46
  }
47
 
48
  public function get_switch_fields() {
49
+ return array();
50
  }
51
 
52
  public function migrate_values( $action, $form ) {
53
+ return $action;
54
  }
55
 
56
  // Functions you'll need to call.
73
  die( 'You are not allowed to call this page directly.' );
74
  }
75
 
76
+ $this->id_base = strtolower( $id_base );
77
+ $this->name = $name;
78
  $this->option_name = 'frm_' . $this->id_base . '_action';
79
 
80
+ $default_options = array(
81
+ 'classes' => '',
82
+ 'active' => true,
83
+ 'event' => array( 'create' ),
84
+ 'limit' => 1,
85
+ 'force_event' => false,
86
+ 'priority' => 20,
87
+ 'ajax_load' => true,
88
+ 'plugin' => $this->id_base,
89
+ 'tooltip' => $name,
90
+ );
91
+
92
+ $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
93
+ $this->action_options = wp_parse_args( $action_options, $default_options );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
95
  }
96
 
101
  self::__construct( $id_base, $name, $action_options, $control_options );
102
  }
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  /**
105
  * Constructs name attributes for use in form() fields
106
  *
107
  * This function should be used in form() methods to create name attributes for fields to be saved by update()
108
  *
109
  * @param string $field_name Field name
 
110
  * @return string Name attribute for $field_name
111
  */
112
  public function get_field_name( $field_name, $post_field = 'post_content' ) {
113
  $name = $this->option_name . '[' . $this->number . ']';
114
  $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
115
  $name .= '[' . $field_name . ']';
 
116
  return $name;
117
  }
118
 
122
  * This function should be used in form() methods to create id attributes for fields to be saved by update()
123
  *
124
  * @param string $field_name Field name
 
125
  * @return string ID attribute for $field_name
126
  */
127
  public function get_field_id( $field_name ) {
132
 
133
  public function _set( $number ) {
134
  $this->number = $number;
135
+ $this->id = $this->id_base . '-' . $number;
136
  }
137
 
138
  public function prepare_new( $form_id = false ) {
139
+ if ( $form_id ) {
140
+ $this->form_id = $form_id;
141
+ }
142
 
143
+ $post_content = array();
144
+ $default_values = $this->get_global_defaults();
145
 
146
  // fill default values
147
  $post_content = wp_parse_args( $post_content, $default_values );
150
  $post_content['event'] = array( reset( $this->action_options['event'] ) );
151
  }
152
 
153
+ $form_action = array(
154
+ 'post_title' => $this->name,
155
+ 'post_content' => $post_content,
156
+ 'post_excerpt' => $this->id_base,
157
+ 'ID' => '',
158
+ 'post_status' => 'publish',
159
+ 'post_type' => FrmFormActionsController::$action_post_type,
160
+ 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
161
+ 'menu_order' => $this->form_id,
162
+ );
163
  unset( $post_content );
164
 
165
+ return (object) $form_action;
166
+ }
167
 
168
  public function create( $form_id ) {
169
+ $this->form_id = $form_id;
170
 
171
+ $action = $this->prepare_new();
172
 
173
  return $this->save_settings( $action );
174
+ }
175
 
176
  public function duplicate_form_actions( $form_id, $old_id ) {
177
+ if ( $form_id == $old_id ) {
178
+ // don't duplicate the actions if this is a template getting updated
179
+ return;
180
+ }
181
 
182
+ $this->form_id = $old_id;
183
+ $actions = $this->get_all( $old_id );
184
 
185
+ $this->form_id = $form_id;
186
+ foreach ( $actions as $action ) {
187
  $this->duplicate_one( $action, $form_id );
188
  unset( $action );
189
+ }
190
+ }
191
+
192
+ /* Check if imported action should be created or updated
193
+ *
194
+ * Since 2.0
195
+ *
196
+ * @param array $action
197
+ * @return integer $post_id
198
+ */
199
+ public function maybe_create_action( $action, $forms ) {
200
  if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
201
+ // Update action only
202
+ $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
203
+ $post_id = $this->save_settings( $action );
204
+ } else {
205
  // Create action
206
  $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
207
+ $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
208
+ }
209
+ return $post_id;
210
+ }
 
211
 
212
  public function duplicate_one( $action, $form_id ) {
213
+ global $frm_duplicate_ids;
214
 
215
+ $action->menu_order = $form_id;
216
+ $switch = $this->get_global_switch_fields();
217
+ foreach ( (array) $action->post_content as $key => $val ) {
218
  if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
219
  $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
220
+ } else if ( ! is_array( $val ) ) {
221
  $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
222
+ } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
223
+ // loop through each value if empty
224
  if ( empty( $switch[ $key ] ) ) {
225
  $switch[ $key ] = array_keys( $val );
226
  }
227
 
228
  foreach ( $switch[ $key ] as $subkey ) {
229
  $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
230
+ }
231
+ }
232
 
233
  unset( $key, $val );
234
  }
235
  unset( $action->ID );
236
 
237
  return $this->save_settings( $action );
238
+ }
239
 
240
  private function duplicate_array_walk( $action, $subkey, $val ) {
241
+ global $frm_duplicate_ids;
242
 
243
  if ( is_array( $subkey ) ) {
244
+ foreach ( $subkey as $subkey2 ) {
245
+ foreach ( (array) $val as $ck => $cv ) {
246
  if ( is_array( $cv ) ) {
247
  $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
248
+ } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
249
  $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
250
+ }
251
+ }
252
+ }
253
+ } else {
254
+ foreach ( (array) $val as $ck => $cv ) {
255
  if ( is_array( $cv ) ) {
256
  $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
257
+ } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
258
  $action[ $ck ] = $frm_duplicate_ids[ $cv ];
259
+ }
260
+ }
261
+ }
262
 
263
+ return $action;
264
+ }
265
 
266
  /**
267
  * Deal with changed settings.
268
  *
269
  * Do NOT over-ride this function
270
  */
271
+ public function update_callback( $form_id ) {
272
+ $this->form_id = $form_id;
273
 
274
+ $all_instances = $this->get_settings();
275
 
276
+ // We need to update the data
277
+ if ( $this->updated ) {
278
+ return;
279
+ }
280
 
281
  if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
282
+ $settings = $_POST[ $this->option_name ];
283
+ } else {
284
+ return;
285
+ }
286
 
287
+ $action_ids = array();
288
 
289
+ foreach ( $settings as $number => $new_instance ) {
290
+ $this->_set( $number );
291
 
292
  $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
293
 
296
  }
297
 
298
  // settings were never opened, so don't update
299
+ if ( ! isset( $new_instance['post_title'] ) ) {
300
  $this->maybe_update_status( $new_instance, $old_instance );
301
+ $action_ids[] = $new_instance['ID'];
302
+ $this->updated = true;
303
+ continue;
304
+ }
305
 
306
  $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
307
  $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
308
  $new_instance['menu_order'] = $this->form_id;
309
  $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
310
 
311
+ $instance = $this->update( $new_instance, $old_instance );
312
 
313
  /**
314
  * Filter an action's settings before saving.
318
  *
319
  * @since 2.0
320
  *
321
+ * @param array $instance The current widget instance's settings.
322
+ * @param array $new_instance Array of new widget settings.
323
+ * @param array $old_instance Array of old widget settings.
324
+ * @param WP_Widget $this The current widget instance.
325
  */
326
  $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
327
 
334
 
335
  $action_ids[] = $this->save_settings( $instance );
336
 
337
+ $this->updated = true;
338
+ }
339
 
340
+ return $action_ids;
341
+ }
342
 
343
  /**
344
  * If the status of the action has changed, update it
359
 
360
  public function save_settings( $settings ) {
361
  self::clear_cache();
 
362
  return FrmDb::save_settings( $settings, 'frm_actions' );
363
  }
364
 
368
  $action = $this->prepare_action( $action );
369
  $this->_set( $id );
370
  }
371
+ return $action;
 
372
  }
373
 
374
  public function get_one( $form_id ) {
375
  return $this->get_all( $form_id, 1 );
376
  }
377
 
378
+ public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
379
+ $action_controls = FrmFormActionsController::get_form_actions( $type );
380
  if ( empty( $action_controls ) ) {
381
+ // don't continue if there are no available actions
382
+ return array();
383
+ }
384
 
385
  if ( 'all' != $type ) {
386
  return $action_controls->get_all( $form_id, $atts );
390
 
391
  $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
392
 
393
+ $args = self::action_args( $form_id, $limit );
394
  $args['post_status'] = $atts['post_status'];
395
+ $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
396
 
397
+ if ( ! $actions ) {
398
+ return array();
399
+ }
400
 
401
+ $settings = array();
402
+ foreach ( $actions as $action ) {
403
  // some plugins/themes are formatting the post_excerpt
404
  $action->post_excerpt = sanitize_title( $action->post_excerpt );
405
 
406
  if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
407
+ continue;
408
+ }
409
 
410
+ $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
411
  $settings[ $action->ID ] = $action;
412
 
413
  if ( count( $settings ) >= $limit ) {
414
  break;
415
  }
416
+ }
417
 
418
+ if ( 1 === $limit ) {
419
  $settings = reset( $settings );
420
+ }
421
 
422
+ return $settings;
423
+ }
424
 
425
  /**
426
  * @since 3.04
438
  'limit' => 99,
439
  'post_status' => $default_status,
440
  );
441
+ $args = wp_parse_args( $args, $defaults );
442
  }
443
 
444
  /**
449
  return false;
450
  }
451
  $action_control = FrmFormActionsController::get_form_actions( $type );
 
452
  return $action_control->get_single_action( $action_id );
453
  }
454
 
455
  /**
456
  * @param int $form_id
 
457
  * @return bool
458
  */
459
  public static function form_has_action_type( $form_id, $type ) {
460
  $payment_actions = self::get_action_for_form( $form_id, $type );
 
461
  return ! empty( $payment_actions );
462
  }
463
 
465
  self::prepare_get_action( $atts, 'any' );
466
  $limit = $atts['limit'];
467
 
468
+ if ( $form_id ) {
469
+ $this->form_id = $form_id;
470
+ }
471
 
472
+ $type = $this->id_base;
473
 
474
+ global $frm_vars;
475
+ $frm_vars['action_type'] = $type;
476
 
477
  add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
478
  $query = self::action_args( $form_id, $limit );
479
  $query['post_status'] = $atts['post_status'];
480
+ $query['suppress_filters'] = false;
481
 
482
  $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
483
  unset( $query );
485
  remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
486
 
487
  if ( empty( $actions ) ) {
488
+ return array();
489
+ }
490
 
491
+ $settings = array();
492
+ foreach ( $actions as $action ) {
493
  if ( count( $settings ) >= $limit ) {
494
+ continue;
495
+ }
496
 
497
  $action = $this->prepare_action( $action );
498
 
499
  $settings[ $action->ID ] = $action;
500
+ }
501
 
502
+ if ( 1 === $limit ) {
503
  $settings = reset( $settings );
504
+ }
505
 
506
+ return $settings;
507
  }
508
 
509
  public static function action_args( $form_id = 0, $limit = 99 ) {
526
  $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
527
  $action->post_excerpt = sanitize_title( $action->post_excerpt );
528
 
529
+ $default_values = $this->get_global_defaults();
530
 
531
+ // fill default values
532
+ $action->post_content += $default_values;
533
 
534
+ foreach ( $default_values as $k => $vals ) {
535
  if ( is_array( $vals ) && ! empty( $vals ) ) {
536
  if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
537
+ continue;
538
+ }
539
  $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
540
+ }
541
+ }
542
 
543
  if ( ! is_array( $action->post_content['event'] ) ) {
544
  $action->post_content['event'] = explode( ',', $action->post_content['event'] );
545
  }
546
 
547
+ return $action;
548
  }
549
 
550
  public function destroy( $form_id = false, $type = 'default' ) {
551
+ global $wpdb;
552
 
553
+ $this->form_id = $form_id;
554
 
555
+ $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
556
+ if ( $form_id ) {
557
+ $query['menu_order'] = $form_id;
558
+ }
559
+ if ( 'all' != $type ) {
560
+ $query['post_excerpt'] = $this->id_base;
561
+ }
562
 
563
+ $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
564
 
565
+ foreach ( $post_ids as $id ) {
566
  wp_delete_post( $id );
567
+ }
568
  self::clear_cache();
569
  }
570
 
582
  }
583
 
584
  public function get_global_defaults() {
585
+ $defaults = $this->get_defaults();
586
 
587
  if ( ! isset( $defaults['event'] ) ) {
588
  $defaults['event'] = array( 'create' );
589
+ }
590
 
591
  if ( ! isset( $defaults['conditions'] ) ) {
592
+ $defaults['conditions'] = array(
593
+ 'send_stop' => '',
594
+ 'any_all' => '',
595
+ );
596
+ }
597
 
598
+ return $defaults;
599
  }
600
 
601
  public function get_global_switch_fields() {
602
+ $switch = $this->get_switch_fields();
603
  $switch['conditions'] = array( 'hide_field' );
604
+ return $switch;
 
605
  }
606
 
607
  /**
608
  * Migrate settings from form->options into new action.
609
  */
610
  public function migrate_to_2( $form, $update = 'update' ) {
611
+ $action = $this->prepare_new( $form->id );
612
  $form->options = maybe_unserialize( $form->options );
613
 
614
+ // fill with existing options
615
+ foreach ( $action->post_content as $name => $val ) {
616
  if ( isset( $form->options[ $name ] ) ) {
617
  $action->post_content[ $name ] = $form->options[ $name ];
618
  unset( $form->options[ $name ] );
619
+ }
620
+ }
621
 
622
  $action = $this->migrate_values( $action, $form );
623
 
624
+ // check if action already exists
625
  $post_id = get_posts(
626
  array(
627
+ 'name' => $action->post_name,
628
+ 'post_type' => FrmFormActionsController::$action_post_type,
629
+ 'post_status' => $action->post_status,
630
+ 'numberposts' => 1,
631
  )
632
  );
633
 
636
  $post_id = $this->save_settings( $action );
637
  }
638
 
639
+ if ( $post_id && 'update' == $update ) {
640
+ global $wpdb;
641
  $form->options = maybe_serialize( $form->options );
642
 
643
+ // update form options
644
  $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
645
+ FrmForm::clear_form_cache();
646
+ }
647
 
648
+ return $post_id;
649
+ }
650
 
651
  public static function action_conditions_met( $action, $entry ) {
652
  $notification = $action->post_content;
653
+ $stop = false;
654
+ $met = array();
655
 
656
  if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
657
  return $stop;
692
  * Prepare the logic value for comparison against the entered value
693
  *
694
  * @since 2.01.02
 
695
  * @param array|string $logic_value
696
  */
697
  private static function prepare_logic_value( &$logic_value ) {
704
  }
705
  }
706
 
707
+
708
  /**
709
  * Get the value from a specific field and entry
710
  *
711
  * @since 2.01.02
 
712
  * @param object $entry
713
  * @param int $field_id
 
714
  * @return array|bool|mixed|string
715
  */
716
  private static function get_value_from_entry( $entry, $field_id ) {
718
 
719
  if ( isset( $entry->metas[ $field_id ] ) ) {
720
  $observed_value = $entry->metas[ $field_id ];
721
+ } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
722
+ $field = FrmField::getOne( $field_id );
723
  $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
724
  $entry,
725
  $field,
735
 
736
  public static function default_action_opts( $class = '' ) {
737
  return array(
738
+ 'classes' => 'frm_icon_font ' . $class,
739
+ 'active' => false,
740
+ 'limit' => 0,
741
  );
742
  }
743
 
744
  public static function trigger_labels() {
745
  $triggers = array(
746
+ 'draft' => __( 'Save Draft', 'formidable' ),
747
+ 'create' => __( 'Create', 'formidable' ),
748
+ 'update' => __( 'Update', 'formidable' ),
749
+ 'delete' => __( 'Delete', 'formidable' ),
750
+ 'import' => __( 'Import', 'formidable' ),
751
  );
 
752
  return apply_filters( 'frm_action_triggers', $triggers );
753
  }
754
  }
classes/models/FrmFormApi.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  class FrmFormApi {
4
 
5
- protected $license = '';
6
  protected $cache_key = '';
7
  protected $cache_timeout = '+6 hours';
8
 
@@ -67,7 +67,7 @@ class FrmFormApi {
67
 
68
  $response = wp_remote_get( $url );
69
  if ( is_array( $response ) && ! is_wp_error( $response ) ) {
70
- $addons = $response['body'];
71
  if ( ! empty( $addons ) ) {
72
  $addons = json_decode( $addons, true );
73
 
@@ -104,9 +104,7 @@ class FrmFormApi {
104
 
105
  /**
106
  * @since 3.06
107
- *
108
  * @param object $license_plugin The FrmAddon object
109
- *
110
  * @return array
111
  */
112
  public function get_addon_for_license( $license_plugin, $addons = array() ) {
@@ -114,7 +112,7 @@ class FrmFormApi {
114
  $addons = $this->get_api_info();
115
  }
116
  $download_id = $license_plugin->download_id;
117
- $plugin = array();
118
  if ( empty( $download_id ) && ! empty( $addons ) ) {
119
  foreach ( $addons as $addon ) {
120
  if ( strtolower( $license_plugin->plugin_name ) == strtolower( $addon['title'] ) ) {
@@ -135,7 +133,6 @@ class FrmFormApi {
135
  if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) ) {
136
  $updater = FrmProAppHelper::get_updater();
137
  $this->set_license( $updater->license );
138
-
139
  return $updater;
140
  }
141
 
@@ -184,7 +181,6 @@ class FrmFormApi {
184
  if ( ! empty( $this->license ) ) {
185
  $errors = $this->get_error_from_response();
186
  }
187
-
188
  return $errors;
189
  }
190
 
@@ -201,7 +197,6 @@ class FrmFormApi {
201
  $errors[] = $addons['error']['message'];
202
  do_action( 'frm_license_error', $addons['error'] );
203
  }
204
-
205
  return $errors;
206
  }
207
  }
2
 
3
  class FrmFormApi {
4
 
5
+ protected $license = '';
6
  protected $cache_key = '';
7
  protected $cache_timeout = '+6 hours';
8
 
67
 
68
  $response = wp_remote_get( $url );
69
  if ( is_array( $response ) && ! is_wp_error( $response ) ) {
70
+ $addons = $response['body'];
71
  if ( ! empty( $addons ) ) {
72
  $addons = json_decode( $addons, true );
73
 
104
 
105
  /**
106
  * @since 3.06
 
107
  * @param object $license_plugin The FrmAddon object
 
108
  * @return array
109
  */
110
  public function get_addon_for_license( $license_plugin, $addons = array() ) {
112
  $addons = $this->get_api_info();
113
  }
114
  $download_id = $license_plugin->download_id;
115
+ $plugin = array();
116
  if ( empty( $download_id ) && ! empty( $addons ) ) {
117
  foreach ( $addons as $addon ) {
118
  if ( strtolower( $license_plugin->plugin_name ) == strtolower( $addon['title'] ) ) {
133
  if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) ) {
134
  $updater = FrmProAppHelper::get_updater();
135
  $this->set_license( $updater->license );
 
136
  return $updater;
137
  }
138
 
181
  if ( ! empty( $this->license ) ) {
182
  $errors = $this->get_error_from_response();
183
  }
 
184
  return $errors;
185
  }
186
 
197
  $errors[] = $addons['error']['message'];
198
  do_action( 'frm_license_error', $addons['error'] );
199
  }
 
200
  return $errors;
201
  }
202
  }
classes/models/FrmFormMigrator.php CHANGED
@@ -49,8 +49,7 @@ abstract class FrmFormMigrator {
49
  Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>. <br/>
50
  Select the forms to import.
51
  </p>
52
- <form id="frm_form_importer" method="post"
53
- action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
54
  <?php wp_nonce_field( 'nonce', 'frm_ajax' ); ?>
55
  <input type="hidden" name="slug" value="<?php echo esc_attr( $this->slug ); ?>" />
56
  <input type="hidden" name="action" value="frm_import_<?php echo esc_attr( $this->slug ); ?>" />
@@ -58,14 +57,13 @@ abstract class FrmFormMigrator {
58
  <?php foreach ( $this->get_forms() as $form_id => $name ) { ?>
59
  <p>
60
  <label>
61
- <input type="checkbox" name="form_id[]"
62
- value="<?php echo esc_attr( $form_id ); ?>" checked="checked" />
63
  <?php
64
  echo esc_html( $name );
65
  $new_form_id = $this->is_imported( $form_id );
66
  ?>
67
  <?php if ( $new_form_id ) { ?>
68
- (<a href="<?php echo esc_url( FrmForm::get_edit_link( $new_form_id ) ); ?>">previously imported</a>)
69
  <?php } ?>
70
  </label>
71
  </p>
@@ -77,13 +75,11 @@ abstract class FrmFormMigrator {
77
 
78
  <p class="process-count">
79
  <i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
80
- Importing <span class="form-current">1</span> of <span class="form-total">0</span> forms
81
- from <?php echo esc_html( $this->name ); ?>.
82
  </p>
83
 
84
  <p class="process-completed" class="frm_hidden">
85
- The import process has finished! We have successfully imported
86
- <span class="forms-completed"></span> forms. You can review the results below.
87
  </p>
88
 
89
  <div class="status"></div>
@@ -128,9 +124,9 @@ abstract class FrmFormMigrator {
128
  */
129
  protected function import_form( $source_id ) {
130
 
131
- $source_form = $this->get_form( $source_id );
132
- $source_form_name = $this->get_form_name( $source_form );
133
- $source_fields = $this->get_form_fields( $source_id );
134
 
135
  // If form does not contain fields, bail.
136
  if ( empty( $source_fields ) ) {
@@ -185,15 +181,15 @@ abstract class FrmFormMigrator {
185
  continue;
186
  }
187
 
188
- $new_field = FrmFieldsHelper::setup_new_vars( $this->convert_field_type( $type ) );
189
- $new_field['name'] = $label;
190
  $new_field['field_order'] = $field_order;
191
- $new_field['original'] = $type;
192
 
193
  $this->prepare_field( $field, $new_field );
194
  $form['fields'][] = $new_field;
195
 
196
- $field_order ++;
197
  }
198
  }
199
 
@@ -235,7 +231,7 @@ abstract class FrmFormMigrator {
235
  }
236
 
237
  foreach ( $form['fields'] as $key => $new_field ) {
238
- $new_field['form_id'] = $form_id;
239
  $form['fields'][ $key ]['id'] = FrmField::create( $new_field );
240
  }
241
 
@@ -259,10 +255,10 @@ abstract class FrmFormMigrator {
259
 
260
  // Build and send final AJAX response!
261
  return array(
262
- 'name' => $form['name'],
263
- 'id' => $form_id,
264
- 'link' => esc_url_raw( FrmForm::get_edit_link( $form_id ) ),
265
- 'upgrade_omit' => $this->response['upgrade_omit'],
266
  );
267
  }
268
 
@@ -296,12 +292,11 @@ abstract class FrmFormMigrator {
296
  * @return int the ID of the created form or 0
297
  */
298
  private function is_imported( $source_id ) {
299
- $imported = $this->get_tracked_import();
300
  $new_form_id = 0;
301
  if ( isset( $imported[ $this->slug ] ) && in_array( $source_id, $imported[ $this->slug ] ) ) {
302
  $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) );
303
  }
304
-
305
  return $new_form_id;
306
  }
307
 
@@ -316,7 +311,6 @@ abstract class FrmFormMigrator {
316
 
317
  private function is_unsupported_field( $type ) {
318
  $fields = $this->unsupported_field_types();
319
-
320
  return in_array( $type, $fields, true );
321
  }
322
 
@@ -331,7 +325,6 @@ abstract class FrmFormMigrator {
331
 
332
  private function should_skip_field( $type ) {
333
  $skip_pro_fields = $this->skip_pro_fields();
334
-
335
  return ( ! FrmAppHelper::pro_is_installed() && in_array( $type, $skip_pro_fields, true ) );
336
  }
337
 
@@ -339,7 +332,7 @@ abstract class FrmFormMigrator {
339
  * Replace 3rd-party form provider tags/shortcodes with our own Tags.
340
  *
341
  * @param string $string String to process the smart tag in.
342
- * @param array $fields List of fields for the form.
343
  *
344
  * @return string
345
  */
@@ -362,7 +355,6 @@ abstract class FrmFormMigrator {
362
 
363
  /**
364
  * @param object|array $source_form
365
- *
366
  * @return string
367
  */
368
  protected function get_form_name( $source_form ) {
@@ -371,7 +363,6 @@ abstract class FrmFormMigrator {
371
 
372
  /**
373
  * @param object|array|int $source_form
374
- *
375
  * @return array
376
  */
377
  protected function get_form_fields( $source_form ) {
@@ -380,7 +371,6 @@ abstract class FrmFormMigrator {
380
 
381
  /**
382
  * @param object|array $field
383
- *
384
  * @return string
385
  */
386
  protected function get_field_type( $field ) {
@@ -393,7 +383,7 @@ abstract class FrmFormMigrator {
393
  * @return string
394
  */
395
  protected function get_field_label( $field ) {
396
- $type = $this->get_field_type( $field );
397
  $label = sprintf(
398
  /* translators: %1$s - field type */
399
  esc_html__( '%1$s Field', 'formidable' ),
49
  Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>. <br/>
50
  Select the forms to import.
51
  </p>
52
+ <form id="frm_form_importer" method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
 
53
  <?php wp_nonce_field( 'nonce', 'frm_ajax' ); ?>
54
  <input type="hidden" name="slug" value="<?php echo esc_attr( $this->slug ); ?>" />
55
  <input type="hidden" name="action" value="frm_import_<?php echo esc_attr( $this->slug ); ?>" />
57
  <?php foreach ( $this->get_forms() as $form_id => $name ) { ?>
58
  <p>
59
  <label>
60
+ <input type="checkbox" name="form_id[]" value="<?php echo esc_attr( $form_id ); ?>" checked="checked" />
 
61
  <?php
62
  echo esc_html( $name );
63
  $new_form_id = $this->is_imported( $form_id );
64
  ?>
65
  <?php if ( $new_form_id ) { ?>
66
+ (<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $new_form_id ) ); ?>">previously imported</a>)
67
  <?php } ?>
68
  </label>
69
  </p>
75
 
76
  <p class="process-count">
77
  <i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
78
+ Importing <span class="form-current">1</span> of <span class="form-total">0</span> forms from <?php echo esc_html( $this->name ); ?>.
 
79
  </p>
80
 
81
  <p class="process-completed" class="frm_hidden">
82
+ The import process has finished! We have successfully imported <span class="forms-completed"></span> forms. You can review the results below.
 
83
  </p>
84
 
85
  <div class="status"></div>
124
  */
125
  protected function import_form( $source_id ) {
126
 
127
+ $source_form = $this->get_form( $source_id );
128
+ $source_form_name = $this->get_form_name( $source_form );
129
+ $source_fields = $this->get_form_fields( $source_id );
130
 
131
  // If form does not contain fields, bail.
132
  if ( empty( $source_fields ) ) {
181
  continue;
182
  }
183
 
184
+ $new_field = FrmFieldsHelper::setup_new_vars( $this->convert_field_type( $type ) );
185
+ $new_field['name'] = $label;
186
  $new_field['field_order'] = $field_order;
187
+ $new_field['original'] = $type;
188
 
189
  $this->prepare_field( $field, $new_field );
190
  $form['fields'][] = $new_field;
191
 
192
+ $field_order++;
193
  }
194
  }
195
 
231
  }
232
 
233
  foreach ( $form['fields'] as $key => $new_field ) {
234
+ $new_field['form_id'] = $form_id;
235
  $form['fields'][ $key ]['id'] = FrmField::create( $new_field );
236
  }
237
 
255
 
256
  // Build and send final AJAX response!
257
  return array(
258
+ 'name' => $form['name'],
259
+ 'id' => $form_id,
260
+ 'link' => esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ) ),
261
+ 'upgrade_omit' => $this->response['upgrade_omit'],
262
  );
263
  }
264
 
292
  * @return int the ID of the created form or 0
293
  */
294
  private function is_imported( $source_id ) {
295
+ $imported = $this->get_tracked_import();
296
  $new_form_id = 0;
297
  if ( isset( $imported[ $this->slug ] ) && in_array( $source_id, $imported[ $this->slug ] ) ) {
298
  $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) );
299
  }
 
300
  return $new_form_id;
301
  }
302
 
311
 
312
  private function is_unsupported_field( $type ) {
313
  $fields = $this->unsupported_field_types();
 
314
  return in_array( $type, $fields, true );
315
  }
316
 
325
 
326
  private function should_skip_field( $type ) {
327
  $skip_pro_fields = $this->skip_pro_fields();
 
328
  return ( ! FrmAppHelper::pro_is_installed() && in_array( $type, $skip_pro_fields, true ) );
329
  }
330
 
332
  * Replace 3rd-party form provider tags/shortcodes with our own Tags.
333
  *
334
  * @param string $string String to process the smart tag in.
335
+ * @param array $fields List of fields for the form.
336
  *
337
  * @return string
338
  */
355
 
356
  /**
357
  * @param object|array $source_form
 
358
  * @return string
359
  */
360
  protected function get_form_name( $source_form ) {
363
 
364
  /**
365
  * @param object|array|int $source_form
 
366
  * @return array
367
  */
368
  protected function get_form_fields( $source_form ) {
371
 
372
  /**
373
  * @param object|array $field
 
374
  * @return string
375
  */
376
  protected function get_field_type( $field ) {
383
  * @return string
384
  */
385
  protected function get_field_label( $field ) {
386
+ $type = $this->get_field_type( $field );
387
  $label = sprintf(
388
  /* translators: %1$s - field type */
389
  esc_html__( '%1$s Field', 'formidable' ),
classes/models/FrmMigrate.php CHANGED
@@ -12,10 +12,10 @@ class FrmMigrate {
12
  }
13
 
14
  global $wpdb;
15
- $this->fields = $wpdb->prefix . 'frm_fields';
16
- $this->forms = $wpdb->prefix . 'frm_forms';
17
- $this->entries = $wpdb->prefix . 'frm_items';
18
- $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
19
  }
20
 
21
  public function upgrade() {
@@ -74,11 +74,11 @@ class FrmMigrate {
74
  return $wpdb->get_charset_collate();
75
  }
76
 
77
- private function create_tables() {
78
- $charset_collate = $this->collation();
79
- $sql = array();
80
 
81
- /* Create/Upgrade Fields Table */
82
  $sql[] = 'CREATE TABLE ' . $this->fields . ' (
83
  id BIGINT(20) NOT NULL auto_increment,
84
  field_key varchar(100) default NULL,
@@ -97,7 +97,7 @@ class FrmMigrate {
97
  UNIQUE KEY field_key (field_key)
98
  )';
99
 
100
- /* Create/Upgrade Forms Table */
101
  $sql[] = 'CREATE TABLE ' . $this->forms . ' (
102
  id int(11) NOT NULL auto_increment,
103
  form_key varchar(100) default NULL,
@@ -115,7 +115,7 @@ class FrmMigrate {
115
  UNIQUE KEY form_key (form_key)
116
  )';
117
 
118
- /* Create/Upgrade Items Table */
119
  $sql[] = 'CREATE TABLE ' . $this->entries . ' (
120
  id BIGINT(20) NOT NULL auto_increment,
121
  item_key varchar(100) default NULL,
@@ -138,7 +138,7 @@ class FrmMigrate {
138
  UNIQUE KEY item_key (item_key)
139
  )';
140
 
141
- /* Create/Upgrade Meta Table */
142
  $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
143
  id BIGINT(20) NOT NULL auto_increment,
144
  meta_value longtext default NULL,
@@ -150,7 +150,7 @@ class FrmMigrate {
150
  KEY item_id (item_id)
151
  )';
152
 
153
- foreach ( $sql as $q ) {
154
  if ( function_exists( 'dbDelta' ) ) {
155
  dbDelta( $q . $charset_collate . ';' );
156
  } else {
@@ -158,8 +158,8 @@ class FrmMigrate {
158
  $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok.
159
  }
160
  unset( $q );
161
- }
162
- }
163
 
164
  private function maybe_create_contact_form() {
165
  $form_exists = FrmForm::get_id_by_key( 'contact-form' );
@@ -197,7 +197,7 @@ class FrmMigrate {
197
  $old_db_version = get_option( 'frm_db_version' );
198
  }
199
  if ( strpos( $old_db_version, '-' ) ) {
200
- $last_upgrade = explode( '-', $old_db_version );
201
  $old_db_version = (int) $last_upgrade[1];
202
  }
203
 
@@ -206,7 +206,7 @@ class FrmMigrate {
206
  return;
207
  }
208
 
209
- $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97 );
210
  foreach ( $migrations as $migration ) {
211
  if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
212
  $function_name = 'migrate_to_' . $migration;
@@ -215,13 +215,13 @@ class FrmMigrate {
215
  }
216
  }
217
 
218
- public function uninstall() {
219
  if ( ! current_user_can( 'administrator' ) ) {
220
- $frm_settings = FrmAppHelper::get_settings();
221
  wp_die( esc_html( $frm_settings->admin_permission ) );
222
- }
223
 
224
- global $wpdb, $wp_roles;
225
 
226
  $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok.
227
  $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok.
@@ -234,12 +234,12 @@ class FrmMigrate {
234
  delete_option( 'frm_lite_settings_upgrade' );
235
  delete_option( 'frm-usage-uuid' );
236
 
237
- // Delete roles.
238
- $frm_roles = FrmAppHelper::frm_capabilities();
239
- $roles = get_editable_roles();
240
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
241
- foreach ( $roles as $role => $details ) {
242
- $wp_roles->remove_cap( $role, $frm_role );
243
  unset( $role, $details );
244
  }
245
  unset( $frm_role, $frm_role_description );
@@ -267,69 +267,8 @@ class FrmMigrate {
267
  $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
268
 
269
  do_action( 'frm_after_uninstall' );
270
-
271
- return true;
272
- }
273
-
274
- /**
275
- * Move default_blank and clear_on_focus to placeholder.
276
- *
277
- * @since 4.0
278
- */
279
- private function migrate_to_97() {
280
- $this->migrate_to_placeholder( 'clear_on_focus' );
281
- $this->migrate_to_placeholder( 'default_blank' );
282
- }
283
-
284
- /**
285
- * Move clear_on_focus or default_blank to placeholder.
286
- *
287
- * @since 4.0
288
- */
289
- private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
290
- $query = array(
291
- 'field_options like' => '"' . $type . '";s:1:"1";',
292
- );
293
-
294
- $fields = FrmDb::get_results( $this->fields, $query, 'id, default_value, field_options, options' );
295
-
296
- foreach ( $fields as $field ) {
297
- $field_options = maybe_unserialize( $field->field_options );
298
- if ( empty( $field_options[ $type ] ) || empty( $field->default_value ) ) {
299
- continue;
300
- }
301
-
302
- $field_options['placeholder'] = $field->default_value;
303
- unset( $field_options['default_blank'] );
304
- unset( $field_options['clear_on_focus'] );
305
-
306
- // If a dropdown placeholder was used, remove the option so it won't be included twice.
307
- $options = maybe_unserialize( $field->options );
308
- if ( $type === 'default_blank' ) {
309
- foreach ( $options as $opt_key => $opt ) {
310
- if ( is_array( $opt ) ) {
311
- $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
312
- }
313
-
314
- if ( $opt == $field->default_value ) {
315
- unset( $options[ $opt_key ] );
316
- break;
317
- }
318
- }
319
- }
320
-
321
- FrmField::update(
322
- $field->id,
323
- array(
324
- 'field_options' => $field_options,
325
- 'default_value' => '',
326
- 'options' => $options,
327
- )
328
- );
329
-
330
- unset( $field );
331
- }
332
- }
333
 
334
  /**
335
  * Delete uneeded default templates
@@ -354,7 +293,7 @@ class FrmMigrate {
354
 
355
  foreach ( (array) $fields as $f ) {
356
  $f->field_options = maybe_unserialize( $f->field_options );
357
- $size = $f->field_options['size'];
358
  $this->maybe_convert_migrated_size( $size );
359
 
360
  if ( $size === $f->field_options['size'] ) {
@@ -376,24 +315,10 @@ class FrmMigrate {
376
  }
377
 
378
  private function get_fields_with_size() {
379
- $field_types = array(
380
- 'textarea',
381
- 'text',
382
- 'number',
383
- 'email',
384
- 'url',
385
- 'rte',
386
- 'date',
387
- 'phone',
388
- 'password',
389
- 'image',
390
- 'tag',
391
- 'file',
392
- );
393
-
394
  $query = array(
395
- 'type' => $field_types,
396
- 'field_options like' => 's:4:"size";',
397
  'field_options not like' => 's:4:"size";s:0:',
398
  );
399
 
@@ -439,7 +364,6 @@ class FrmMigrate {
439
  }
440
 
441
  $pixel_conversion = 9;
442
-
443
  $size = round( (int) $int_size / $pixel_conversion );
444
  }
445
 
@@ -452,7 +376,7 @@ class FrmMigrate {
452
  private function migrate_to_25() {
453
  // get the style that was created with the style migration
454
  $frm_style = new FrmStyle();
455
- $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
456
  if ( empty( $styles ) ) {
457
  return;
458
  }
@@ -461,7 +385,6 @@ class FrmMigrate {
461
  if ( $style->post_content['field_width'] == '400px' ) {
462
  $style->post_content['field_width'] = '100%';
463
  $frm_style->save( (array) $style );
464
-
465
  return;
466
  }
467
  }
@@ -523,47 +446,46 @@ class FrmMigrate {
523
 
524
  private function convert_character_to_px( &$size ) {
525
  $pixel_conversion = 9;
526
-
527
  $size = round( $pixel_conversion * (int) $size );
528
  $size .= 'px';
529
  }
530
 
531
- /**
532
- * Migrate post and email notification settings into actions
533
- */
534
- private function migrate_to_16() {
535
- $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
536
-
537
- /**
538
- * Old email settings format:
539
- * email_to: Email or field id
540
- * also_email_to: array of fields ids
541
- * reply_to: Email, field id, 'custom'
542
- * cust_reply_to: string
543
- * reply_to_name: field id, 'custom'
544
- * cust_reply_to_name: string
545
- * plain_text: 0|1
546
- * email_message: string or ''
547
- * email_subject: string or ''
548
- * inc_user_info: 0|1
549
- * update_email: 0, 1, 2
550
- *
551
- * Old autoresponder settings format:
552
- * auto_responder: 0|1
553
- * ar_email_message: string or ''
554
- * ar_email_to: field id
555
- * ar_plain_text: 0|1
556
- * ar_reply_to_name: string
557
- * ar_reply_to: string
558
- * ar_email_subject: string
559
- * ar_update_email: 0, 1, 2
560
- *
561
- * New email settings:
562
- * post_content: json settings
563
- * post_title: form id
564
- * post_excerpt: message
565
- */
566
- foreach ( $forms as $form ) {
567
  if ( $form->is_template && $form->default_template ) {
568
  // don't migrate the default templates since the email will be added anyway
569
  continue;
@@ -572,19 +494,19 @@ class FrmMigrate {
572
  // Format form options
573
  $form_options = maybe_unserialize( $form->options );
574
 
575
- // Migrate settings to actions
576
- FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
577
- }
578
- }
579
 
580
- private function migrate_to_11() {
581
- global $wpdb;
582
 
583
  $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
584
 
585
- $sending = __( 'Sending', 'formidable' );
586
- $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
587
- $old_default_html = <<<DEFAULT_HTML
588
  <div class="frm_submit">
589
  [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
590
  <input type="submit" value="[button_label]" [button_action] />
@@ -594,21 +516,21 @@ DEFAULT_HTML;
594
  unset( $sending, $img );
595
 
596
  $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
597
- $draft_link = FrmFormsHelper::get_draft_link();
598
  foreach ( $forms as $form ) {
599
  $form->options = maybe_unserialize( $form->options );
600
  if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
601
- continue;
602
- }
603
 
604
- if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
605
- $form->options['submit_html'] = $new_default_html;
606
  $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
607
- } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
608
  $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
609
  $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
610
- }
611
  unset( $form );
612
- }
613
- }
614
  }
12
  }
13
 
14
  global $wpdb;
15
+ $this->fields = $wpdb->prefix . 'frm_fields';
16
+ $this->forms = $wpdb->prefix . 'frm_forms';
17
+ $this->entries = $wpdb->prefix . 'frm_items';
18
+ $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
19
  }
20
 
21
  public function upgrade() {
74
  return $wpdb->get_charset_collate();
75
  }
76
 
77
+ private function create_tables() {
78
+ $charset_collate = $this->collation();
79
+ $sql = array();
80
 
81
+ /* Create/Upgrade Fields Table */
82
  $sql[] = 'CREATE TABLE ' . $this->fields . ' (
83
  id BIGINT(20) NOT NULL auto_increment,
84
  field_key varchar(100) default NULL,
97
  UNIQUE KEY field_key (field_key)
98
  )';
99
 
100
+ /* Create/Upgrade Forms Table */
101
  $sql[] = 'CREATE TABLE ' . $this->forms . ' (
102
  id int(11) NOT NULL auto_increment,
103
  form_key varchar(100) default NULL,
115
  UNIQUE KEY form_key (form_key)
116
  )';
117
 
118
+ /* Create/Upgrade Items Table */
119
  $sql[] = 'CREATE TABLE ' . $this->entries . ' (
120
  id BIGINT(20) NOT NULL auto_increment,
121
  item_key varchar(100) default NULL,
138
  UNIQUE KEY item_key (item_key)
139
  )';
140
 
141
+ /* Create/Upgrade Meta Table */
142
  $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
143
  id BIGINT(20) NOT NULL auto_increment,
144
  meta_value longtext default NULL,
150
  KEY item_id (item_id)
151
  )';
152
 
153
+ foreach ( $sql as $q ) {
154
  if ( function_exists( 'dbDelta' ) ) {
155
  dbDelta( $q . $charset_collate . ';' );
156
  } else {
158
  $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok.
159
  }
160
  unset( $q );
161
+ }
162
+ }
163
 
164
  private function maybe_create_contact_form() {
165
  $form_exists = FrmForm::get_id_by_key( 'contact-form' );
197
  $old_db_version = get_option( 'frm_db_version' );
198
  }
199
  if ( strpos( $old_db_version, '-' ) ) {
200
+ $last_upgrade = explode( '-', $old_db_version );
201
  $old_db_version = (int) $last_upgrade[1];
202
  }
203
 
206
  return;
207
  }
208
 
209
+ $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90 );
210
  foreach ( $migrations as $migration ) {
211
  if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
212
  $function_name = 'migrate_to_' . $migration;
215
  }
216
  }
217
 
218
+ public function uninstall() {
219
  if ( ! current_user_can( 'administrator' ) ) {
220
+ $frm_settings = FrmAppHelper::get_settings();
221
  wp_die( esc_html( $frm_settings->admin_permission ) );
222
+ }
223
 
224
+ global $wpdb, $wp_roles;
225
 
226
  $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok.
227
  $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok.
234
  delete_option( 'frm_lite_settings_upgrade' );
235
  delete_option( 'frm-usage-uuid' );
236
 
237
+ //delete roles
238
+ $frm_roles = FrmAppHelper::frm_capabilities();
239
+ $roles = get_editable_roles();
240
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
241
+ foreach ( $roles as $role => $details ) {
242
+ $wp_roles->remove_cap( $role, $frm_role );
243
  unset( $role, $details );
244
  }
245
  unset( $frm_role, $frm_role_description );
267
  $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
268
 
269
  do_action( 'frm_after_uninstall' );
270
+ return true;
271
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
  /**
274
  * Delete uneeded default templates
293
 
294
  foreach ( (array) $fields as $f ) {
295
  $f->field_options = maybe_unserialize( $f->field_options );
296
+ $size = $f->field_options['size'];
297
  $this->maybe_convert_migrated_size( $size );
298
 
299
  if ( $size === $f->field_options['size'] ) {
315
  }
316
 
317
  private function get_fields_with_size() {
318
+ $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  $query = array(
320
+ 'type' => $field_types,
321
+ 'field_options like' => 's:4:"size";',
322
  'field_options not like' => 's:4:"size";s:0:',
323
  );
324
 
364
  }
365
 
366
  $pixel_conversion = 9;
 
367
  $size = round( (int) $int_size / $pixel_conversion );
368
  }
369
 
376
  private function migrate_to_25() {
377
  // get the style that was created with the style migration
378
  $frm_style = new FrmStyle();
379
+ $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
380
  if ( empty( $styles ) ) {
381
  return;
382
  }
385
  if ( $style->post_content['field_width'] == '400px' ) {
386
  $style->post_content['field_width'] = '100%';
387
  $frm_style->save( (array) $style );
 
388
  return;
389
  }
390
  }
446
 
447
  private function convert_character_to_px( &$size ) {
448
  $pixel_conversion = 9;
 
449
  $size = round( $pixel_conversion * (int) $size );
450
  $size .= 'px';
451
  }
452
 
453
+ /**
454
+ * Migrate post and email notification settings into actions
455
+ */
456
+ private function migrate_to_16() {
457
+ $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
458
+
459
+ /**
460
+ * Old email settings format:
461
+ * email_to: Email or field id
462
+ * also_email_to: array of fields ids
463
+ * reply_to: Email, field id, 'custom'
464
+ * cust_reply_to: string
465
+ * reply_to_name: field id, 'custom'
466
+ * cust_reply_to_name: string
467
+ * plain_text: 0|1
468
+ * email_message: string or ''
469
+ * email_subject: string or ''
470
+ * inc_user_info: 0|1
471
+ * update_email: 0, 1, 2
472
+ *
473
+ * Old autoresponder settings format:
474
+ * auto_responder: 0|1
475
+ * ar_email_message: string or ''
476
+ * ar_email_to: field id
477
+ * ar_plain_text: 0|1
478
+ * ar_reply_to_name: string
479
+ * ar_reply_to: string
480
+ * ar_email_subject: string
481
+ * ar_update_email: 0, 1, 2
482
+ *
483
+ * New email settings:
484
+ * post_content: json settings
485
+ * post_title: form id
486
+ * post_excerpt: message
487
+ */
488
+ foreach ( $forms as $form ) {
489
  if ( $form->is_template && $form->default_template ) {
490
  // don't migrate the default templates since the email will be added anyway
491
  continue;
494
  // Format form options
495
  $form_options = maybe_unserialize( $form->options );
496
 
497
+ // Migrate settings to actions
498
+ FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
499
+ }
500
+ }
501
 
502
+ private function migrate_to_11() {
503
+ global $wpdb;
504
 
505
  $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
506
 
507
+ $sending = __( 'Sending', 'formidable' );
508
+ $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
509
+ $old_default_html = <<<DEFAULT_HTML
510
  <div class="frm_submit">
511
  [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
512
  <input type="submit" value="[button_label]" [button_action] />
516
  unset( $sending, $img );
517
 
518
  $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
519
+ $draft_link = FrmFormsHelper::get_draft_link();
520
  foreach ( $forms as $form ) {
521
  $form->options = maybe_unserialize( $form->options );
522
  if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
523
+ continue;
524
+ }
525
 
526
+ if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
527
+ $form->options['submit_html'] = $new_default_html;
528
  $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
529
+ } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
530
  $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
531
  $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
532
+ }
533
  unset( $form );
534
+ }
535
+ }
536
  }
classes/models/FrmNotification.php CHANGED
@@ -73,7 +73,6 @@ class FrmNotification {
73
  */
74
  public static function remove_mandrill_br() {
75
  _deprecated_function( __FUNCTION__, '2.03.04', 'FrmEmailHelper::remove_mandrill_br' );
76
-
77
  return FrmEmailHelper::remove_mandrill_br();
78
  }
79
 
73
  */
74
  public static function remove_mandrill_br() {
75
  _deprecated_function( __FUNCTION__, '2.03.04', 'FrmEmailHelper::remove_mandrill_br' );
 
76
  return FrmEmailHelper::remove_mandrill_br();
77
  }
78
 
classes/models/FrmPersonalData.php CHANGED
@@ -4,7 +4,7 @@ class FrmPersonalData {
4
 
5
  private $limit = 200;
6
 
7
- private $page = 1;
8
 
9
  public function __construct() {
10
  add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_data_eraser' ) );
@@ -15,9 +15,7 @@ class FrmPersonalData {
15
  * Add options to the WordPress personal data exporter
16
  *
17
  * @since 3.02
18
- *
19
  * @param array $exporters
20
- *
21
  * @return array
22
  */
23
  public function register_exporter( $exporters ) {
@@ -25,7 +23,6 @@ class FrmPersonalData {
25
  'exporter_friendly_name' => __( 'Formidable Forms Exporter', 'formidable' ),
26
  'callback' => array( $this, 'export_data' ),
27
  );
28
-
29
  return $exporters;
30
  }
31
 
@@ -33,9 +30,7 @@ class FrmPersonalData {
33
  * Add options to the WordPress personal data eraser
34
  *
35
  * @since 3.02
36
- *
37
  * @param array $erasers
38
- *
39
  * @return array
40
  */
41
  public function register_data_eraser( $erasers ) {
@@ -70,7 +65,6 @@ class FrmPersonalData {
70
  }
71
 
72
  $data_to_export['done'] = count( $entries ) < $this->limit;
73
-
74
  return $data_to_export;
75
  }
76
 
@@ -90,7 +84,7 @@ class FrmPersonalData {
90
  }
91
 
92
  $this->page = absint( $page );
93
- $entries = $this->get_user_entries( $email );
94
  if ( empty( $entries ) ) {
95
  return $data_removed;
96
  }
@@ -117,7 +111,6 @@ class FrmPersonalData {
117
  * or with a field value that matches the email address
118
  *
119
  * @param string $email
120
- *
121
  * @return array of entry ids
122
  */
123
  private function get_user_entries( $email ) {
@@ -127,7 +120,6 @@ class FrmPersonalData {
127
  );
128
 
129
  $user = get_user_by( 'email', $email );
130
-
131
  $entries_by_email = FrmDb::get_col( 'frm_item_metas', array( 'meta_value' => $email ), 'item_id', $query_args );
132
 
133
  if ( empty( $user ) ) {
@@ -141,19 +133,16 @@ class FrmPersonalData {
141
 
142
  $entry_ids = array_merge( (array) $entries_by_user, (array) $entries_by_email );
143
  $entry_ids = array_unique( array_filter( $entry_ids ) );
144
-
145
  return $entry_ids;
146
  }
147
 
148
  private function get_current_page() {
149
  $start = ( $this->page - 1 ) * $this->limit;
150
-
151
  return FrmDb::esc_limit( $start . ',' . $this->limit );
152
  }
153
 
154
  /**
155
  * @param int $entry
156
- *
157
  * @return array
158
  */
159
  private function prepare_entry_data( $entry ) {
4
 
5
  private $limit = 200;
6
 
7
+ private $page = 1;
8
 
9
  public function __construct() {
10
  add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_data_eraser' ) );
15
  * Add options to the WordPress personal data exporter
16
  *
17
  * @since 3.02
 
18
  * @param array $exporters
 
19
  * @return array
20
  */
21
  public function register_exporter( $exporters ) {
23
  'exporter_friendly_name' => __( 'Formidable Forms Exporter', 'formidable' ),
24
  'callback' => array( $this, 'export_data' ),
25
  );
 
26
  return $exporters;
27
  }
28
 
30
  * Add options to the WordPress personal data eraser
31
  *
32
  * @since 3.02
 
33
  * @param array $erasers
 
34
  * @return array
35
  */
36
  public function register_data_eraser( $erasers ) {
65
  }
66
 
67
  $data_to_export['done'] = count( $entries ) < $this->limit;
 
68
  return $data_to_export;
69
  }
70
 
84
  }
85
 
86
  $this->page = absint( $page );
87
+ $entries = $this->get_user_entries( $email );
88
  if ( empty( $entries ) ) {
89
  return $data_removed;
90
  }
111
  * or with a field value that matches the email address
112
  *
113
  * @param string $email
 
114
  * @return array of entry ids
115
  */
116
  private function get_user_entries( $email ) {
120
  );
121
 
122
  $user = get_user_by( 'email', $email );
 
123
  $entries_by_email = FrmDb::get_col( 'frm_item_metas', array( 'meta_value' => $email ), 'item_id', $query_args );
124
 
125
  if ( empty( $user ) ) {
133
 
134
  $entry_ids = array_merge( (array) $entries_by_user, (array) $entries_by_email );
135
  $entry_ids = array_unique( array_filter( $entry_ids ) );
 
136
  return $entry_ids;
137
  }
138
 
139
  private function get_current_page() {
140
  $start = ( $this->page - 1 ) * $this->limit;
 
141
  return FrmDb::esc_limit( $start . ',' . $this->limit );
142
  }
143
 
144
  /**
145
  * @param int $entry
 
146
  * @return array
147
  */
148
  private function prepare_entry_data( $entry ) {
classes/models/FrmReviews.php CHANGED
@@ -53,8 +53,8 @@ class FrmReviews {
53
  update_user_meta( $user_id, $this->option_name, $default );
54
  }
55
 
56
- $review = array_merge( $default, (array) $review );
57
- $review['asked'] = (int) $review['asked'];
58
  $this->review_status = $review;
59
  }
60
 
@@ -62,14 +62,13 @@ class FrmReviews {
62
  * Maybe show review request
63
  *
64
  * @since 3.04.03
65
- *
66
  * @param int $asked
67
  */
68
  private function review() {
69
 
70
  // show the review request 3 times, depending on the number of entries
71
  $show_intervals = array( 50, 200, 500 );
72
- $asked = $this->review_status['asked'];
73
 
74
  if ( ! isset( $show_intervals[ $asked ] ) ) {
75
  return;
@@ -84,7 +83,6 @@ class FrmReviews {
84
  // check the entry count again in a week
85
  $this->review_status['time'] = time();
86
  update_user_meta( $user->ID, $this->option_name, $this->review_status );
87
-
88
  return;
89
  }
90
 
@@ -124,7 +122,7 @@ class FrmReviews {
124
  wp_die();
125
  }
126
 
127
- $dismissed = FrmAppHelper::get_post_param( 'link', 'no', 'sanitize_text_field' );
128
  $review['time'] = time();
129
  $review['dismissed'] = $dismissed === 'done' ? true : 'later';
130
  $review['asked'] = isset( $review['asked'] ) ? $review['asked'] + 1 : 1;
53
  update_user_meta( $user_id, $this->option_name, $default );
54
  }
55
 
56
+ $review = array_merge( $default, (array) $review );
57
+ $review['asked'] = (int) $review['asked'];
58
  $this->review_status = $review;
59
  }
60
 
62
  * Maybe show review request
63
  *
64
  * @since 3.04.03
 
65
  * @param int $asked
66
  */
67
  private function review() {
68
 
69
  // show the review request 3 times, depending on the number of entries
70
  $show_intervals = array( 50, 200, 500 );
71
+ $asked = $this->review_status['asked'];
72
 
73
  if ( ! isset( $show_intervals[ $asked ] ) ) {
74
  return;
83
  // check the entry count again in a week
84
  $this->review_status['time'] = time();
85
  update_user_meta( $user->ID, $this->option_name, $this->review_status );
 
86
  return;
87
  }
88
 
122
  wp_die();
123
  }
124
 
125
+ $dismissed = FrmAppHelper::get_post_param( 'link', 'no', 'sanitize_text_field' );
126
  $review['time'] = time();
127
  $review['dismissed'] = $dismissed === 'done' ? true : 'later';
128
  $review['asked'] = isset( $review['asked'] ) ? $review['asked'] + 1 : 1;
classes/models/FrmSettings.php CHANGED
@@ -1,33 +1,33 @@
1
  <?php
2
 
3
  class FrmSettings {
4
- public $option_name = 'frm_options';
5
- public $menu;
6
- public $mu_menu;
7
- public $use_html;
8
- public $jquery_css;
9
- public $accordion_js;
10
  public $fade_form;
11
  public $old_css;
12
 
13
- public $success_msg;
14
- public $blank_msg;
15
- public $unique_msg;
16
- public $invalid_msg;
17
- public $failed_msg;
18
- public $submit_value;
19
- public $login_msg;
20
- public $admin_permission;
21
-
22
- public $email_to;
23
- public $load_style;
24
- public $custom_style;
25
-
26
- public $pubkey;
27
- public $privkey;
28
- public $re_lang;
29
  public $re_type;
30
- public $re_msg;
31
  public $re_multi;
32
 
33
  public $no_ips;
@@ -45,146 +45,145 @@ class FrmSettings {
45
  $settings = $this->translate_settings( $settings );
46
  }
47
 
48
- foreach ( $settings as $setting_name => $setting ) {
49
- $this->{$setting_name} = $setting;
50
  unset( $setting_name, $setting );
51
- }
52
 
53
- $this->set_default_options();
54
 
55
  $this->maybe_filter_for_form( $args );
56
- }
57
 
58
  private function translate_settings( $settings ) {
59
- if ( $settings ) { //workaround for W3 total cache conflict
60
  return unserialize( serialize( $settings ) );
61
- }
62
 
63
  $settings = get_option( $this->option_name );
64
  if ( is_object( $settings ) ) {
65
  set_transient( $this->option_name, $settings );
66
-
67
  return $settings;
68
  }
69
 
70
- // If unserializing didn't work
71
- if ( $settings ) { //workaround for W3 total cache conflict
72
  $settings = unserialize( serialize( $settings ) );
73
- } else {
74
- $settings = $this;
75
- }
76
 
77
  update_option( $this->option_name, $settings );
78
  set_transient( $this->option_name, $settings );
79
 
80
- return $settings;
81
- }
82
 
83
- /**
84
- * @return array
85
- */
86
  public function default_options() {
87
- return array(
88
- 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
89
- 'mu_menu' => 0,
90
- 'use_html' => true,
91
- 'jquery_css' => false,
92
- 'accordion_js' => false,
93
- 'fade_form' => false,
94
- 'old_css' => true,
95
-
96
- 're_multi' => 1,
97
-
98
- 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
99
- 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
100
- 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
101
- 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
102
- 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
103
- 'submit_value' => __( 'Submit', 'formidable' ),
104
- 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
105
- 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
106
-
107
- 'email_to' => '[admin_email]',
108
  'no_ips' => 0,
109
  'tracking' => FrmAppHelper::pro_is_installed(),
110
- );
111
- }
112
 
113
  private function set_default_options() {
114
- $this->fill_recaptcha_settings();
115
 
116
  if ( ! isset( $this->load_style ) ) {
117
  if ( ! isset( $this->custom_style ) ) {
118
- $this->custom_style = true;
119
- }
120
 
121
- $this->load_style = 'all';
122
- }
123
 
124
- $this->fill_with_defaults();
125
 
126
- if ( is_multisite() && is_admin() ) {
127
  $mu_menu = get_site_option( 'frm_admin_menu_name' );
128
  if ( $mu_menu && ! empty( $mu_menu ) ) {
129
- $this->menu = $mu_menu;
130
- $this->mu_menu = 1;
131
- }
132
- }
133
 
134
  $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
135
  foreach ( $frm_roles as $frm_role => $frm_role_description ) {
136
  if ( ! isset( $this->$frm_role ) ) {
137
- $this->$frm_role = 'administrator';
138
- }
139
- }
140
- }
141
 
142
  public function fill_with_defaults( $params = array() ) {
143
- $settings = $this->default_options();
144
 
145
- foreach ( $settings as $setting => $default ) {
146
  if ( isset( $params[ 'frm_' . $setting ] ) ) {
147
  $this->{$setting} = $params[ 'frm_' . $setting ];
148
  } elseif ( ! isset( $this->{$setting} ) ) {
149
- $this->{$setting} = $default;
150
- }
151
 
152
  if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
153
  $this->{$setting} = $default;
154
  }
155
 
156
  unset( $setting, $default );
157
- }
158
- }
159
 
160
- private function fill_recaptcha_settings() {
161
- $privkey = '';
162
  $re_lang = '';
163
 
164
  if ( ! isset( $this->pubkey ) ) {
165
  // get the options from the database
166
  $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
167
- $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
168
- $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
169
- $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
170
  }
171
 
172
  if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
173
- $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
174
- }
175
 
176
  if ( ! isset( $this->privkey ) ) {
177
- $this->privkey = $privkey;
178
- }
179
 
180
  if ( ! isset( $this->re_lang ) ) {
181
- $this->re_lang = $re_lang;
182
- }
183
 
184
  if ( ! isset( $this->re_type ) ) {
185
  $this->re_type = '';
186
  }
187
- }
188
 
189
  /**
190
  * Get values that may be shown on the front-end without an override in the form settings.
@@ -214,9 +213,9 @@ class FrmSettings {
214
  }
215
  }
216
 
217
- public function validate( $params, $errors ) {
218
- return apply_filters( 'frm_validate_settings', $errors, $params );
219
- }
220
 
221
  public function update( $params ) {
222
  $this->fill_with_defaults( $params );
@@ -230,51 +229,51 @@ class FrmSettings {
230
 
231
  $this->update_roles( $params );
232
 
233
- do_action( 'frm_update_settings', $params );
234
 
235
  if ( function_exists( 'get_filesystem_method' ) ) {
236
  // save styling settings in case fallback setting changes
237
  $frm_style = new FrmStyle();
238
  $frm_style->update( 'default' );
239
  }
240
- }
241
 
242
  private function update_settings( $params ) {
243
- $this->pubkey = trim( $params['frm_pubkey'] );
244
- $this->privkey = $params['frm_privkey'];
245
- $this->re_type = $params['frm_re_type'];
246
- $this->re_lang = $params['frm_re_lang'];
247
 
248
- $this->load_style = $params['frm_load_style'];
249
 
250
  $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking' );
251
  foreach ( $checkboxes as $set ) {
252
  $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
253
  }
254
- }
255
 
256
  private function update_roles( $params ) {
257
- global $wp_roles;
258
 
259
- $frm_roles = FrmAppHelper::frm_capabilities();
260
- $roles = get_editable_roles();
261
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
262
- $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
263
 
264
- // Make sure administrators always have permissions
265
- if ( ! in_array( 'administrator', $this->$frm_role ) ) {
266
  array_push( $this->$frm_role, 'administrator' );
267
- }
268
 
269
- foreach ( $roles as $role => $details ) {
270
  if ( in_array( $role, $this->$frm_role ) ) {
271
- $wp_roles->add_cap( $role, $frm_role );
272
- } else {
273
- $wp_roles->remove_cap( $role, $frm_role );
274
- }
275
- }
276
  }
277
- }
278
 
279
  public function store() {
280
  // Save the posted value in the database
1
  <?php
2
 
3
  class FrmSettings {
4
+ public $option_name = 'frm_options';
5
+ public $menu;
6
+ public $mu_menu;
7
+ public $use_html;
8
+ public $jquery_css;
9
+ public $accordion_js;
10
  public $fade_form;
11
  public $old_css;
12
 
13
+ public $success_msg;
14
+ public $blank_msg;
15
+ public $unique_msg;
16
+ public $invalid_msg;
17
+ public $failed_msg;
18
+ public $submit_value;
19
+ public $login_msg;
20
+ public $admin_permission;
21
+
22
+ public $email_to;
23
+ public $load_style;
24
+ public $custom_style;
25
+
26
+ public $pubkey;
27
+ public $privkey;
28
+ public $re_lang;
29
  public $re_type;
30
+ public $re_msg;
31
  public $re_multi;
32
 
33
  public $no_ips;
45
  $settings = $this->translate_settings( $settings );
46
  }
47
 
48
+ foreach ( $settings as $setting_name => $setting ) {
49
+ $this->{$setting_name} = $setting;
50
  unset( $setting_name, $setting );
51
+ }
52
 
53
+ $this->set_default_options();
54
 
55
  $this->maybe_filter_for_form( $args );
56
+ }
57
 
58
  private function translate_settings( $settings ) {
59
+ if ( $settings ) { //workaround for W3 total cache conflict
60
  return unserialize( serialize( $settings ) );
61
+ }
62
 
63
  $settings = get_option( $this->option_name );
64
  if ( is_object( $settings ) ) {
65
  set_transient( $this->option_name, $settings );
 
66
  return $settings;
67
  }
68
 
69
+ // If unserializing didn't work
70
+ if ( $settings ) { //workaround for W3 total cache conflict
71
  $settings = unserialize( serialize( $settings ) );
72
+ } else {
73
+ $settings = $this;
74
+ }
75
 
76
  update_option( $this->option_name, $settings );
77
  set_transient( $this->option_name, $settings );
78
 
79
+ return $settings;
80
+ }
81
 
82
+ /**
83
+ * @return array
84
+ */
85
  public function default_options() {
86
+ return array(
87
+ 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
88
+ 'mu_menu' => 0,
89
+ 'use_html' => true,
90
+ 'jquery_css' => false,
91
+ 'accordion_js' => false,
92
+ 'fade_form' => false,
93
+ 'old_css' => true,
94
+
95
+ 're_multi' => 1,
96
+
97
+ 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
98
+ 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
99
+ 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
100
+ 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
101
+ 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
102
+ 'submit_value' => __( 'Submit', 'formidable' ),
103
+ 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
104
+ 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
105
+
106
+ 'email_to' => '[admin_email]',
107
  'no_ips' => 0,
108
  'tracking' => FrmAppHelper::pro_is_installed(),
109
+ );
110
+ }
111
 
112
  private function set_default_options() {
113
+ $this->fill_recaptcha_settings();
114
 
115
  if ( ! isset( $this->load_style ) ) {
116
  if ( ! isset( $this->custom_style ) ) {
117
+ $this->custom_style = true;
118
+ }
119
 
120
+ $this->load_style = 'all';
121
+ }
122
 
123
+ $this->fill_with_defaults();
124
 
125
+ if ( is_multisite() && is_admin() ) {
126
  $mu_menu = get_site_option( 'frm_admin_menu_name' );
127
  if ( $mu_menu && ! empty( $mu_menu ) ) {
128
+ $this->menu = $mu_menu;
129
+ $this->mu_menu = 1;
130
+ }
131
+ }
132
 
133
  $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
134
  foreach ( $frm_roles as $frm_role => $frm_role_description ) {
135
  if ( ! isset( $this->$frm_role ) ) {
136
+ $this->$frm_role = 'administrator';
137
+ }
138
+ }
139
+ }
140
 
141
  public function fill_with_defaults( $params = array() ) {
142
+ $settings = $this->default_options();
143
 
144
+ foreach ( $settings as $setting => $default ) {
145
  if ( isset( $params[ 'frm_' . $setting ] ) ) {
146
  $this->{$setting} = $params[ 'frm_' . $setting ];
147
  } elseif ( ! isset( $this->{$setting} ) ) {
148
+ $this->{$setting} = $default;
149
+ }
150
 
151
  if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
152
  $this->{$setting} = $default;
153
  }
154
 
155
  unset( $setting, $default );
156
+ }
157
+ }
158
 
159
+ private function fill_recaptcha_settings() {
160
+ $privkey = '';
161
  $re_lang = '';
162
 
163
  if ( ! isset( $this->pubkey ) ) {
164
  // get the options from the database
165
  $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
166
+ $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
167
+ $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
168
+ $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
169
  }
170
 
171
  if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
172
+ $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
173
+ }
174
 
175
  if ( ! isset( $this->privkey ) ) {
176
+ $this->privkey = $privkey;
177
+ }
178
 
179
  if ( ! isset( $this->re_lang ) ) {
180
+ $this->re_lang = $re_lang;
181
+ }
182
 
183
  if ( ! isset( $this->re_type ) ) {
184
  $this->re_type = '';
185
  }
186
+ }
187
 
188
  /**
189
  * Get values that may be shown on the front-end without an override in the form settings.
213
  }
214
  }
215
 
216
+ public function validate( $params, $errors ) {
217
+ return apply_filters( 'frm_validate_settings', $errors, $params );
218
+ }
219
 
220
  public function update( $params ) {
221
  $this->fill_with_defaults( $params );
229
 
230
  $this->update_roles( $params );
231
 
232
+ do_action( 'frm_update_settings', $params );
233
 
234
  if ( function_exists( 'get_filesystem_method' ) ) {
235
  // save styling settings in case fallback setting changes
236
  $frm_style = new FrmStyle();
237
  $frm_style->update( 'default' );
238
  }
239
+ }
240
 
241
  private function update_settings( $params ) {
242
+ $this->pubkey = trim( $params['frm_pubkey'] );
243
+ $this->privkey = $params['frm_privkey'];
244
+ $this->re_type = $params['frm_re_type'];
245
+ $this->re_lang = $params['frm_re_lang'];
246
 
247
+ $this->load_style = $params['frm_load_style'];
248
 
249
  $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking' );
250
  foreach ( $checkboxes as $set ) {
251
  $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
252
  }
253
+ }
254
 
255
  private function update_roles( $params ) {
256
+ global $wp_roles;
257
 
258
+ $frm_roles = FrmAppHelper::frm_capabilities();
259
+ $roles = get_editable_roles();
260
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
261
+ $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
262
 
263
+ // Make sure administrators always have permissions
264
+ if ( ! in_array( 'administrator', $this->$frm_role ) ) {
265
  array_push( $this->$frm_role, 'administrator' );
266
+ }
267
 
268
+ foreach ( $roles as $role => $details ) {
269
  if ( in_array( $role, $this->$frm_role ) ) {
270
+ $wp_roles->add_cap( $role, $frm_role );
271
+ } else {
272
+ $wp_roles->remove_cap( $role, $frm_role );
273
+ }
274
+ }
275
  }
276
+ }
277
 
278
  public function store() {
279
  // Save the posted value in the database
classes/models/FrmStyle.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  class FrmStyle {
4
  public $number = false; // Unique ID number of the current instance.
5
  public $id = 0; // the id of the post
@@ -8,108 +7,105 @@ class FrmStyle {
8
  * @param int|string $id The id of the stylsheet or 'default'
9
  */
10
  public function __construct( $id = 0 ) {
11
- $this->id = $id;
12
- }
13
 
14
- public function get_new() {
15
  $this->id = 0;
16
 
17
- $max_slug_value = 2147483647;
18
- $min_slug_value = 37; // we want to have at least 2 characters in the slug
19
- $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
20
-
21
- $style = array(
22
- 'post_type' => FrmStylesController::$post_type,
23
- 'ID' => '',
24
- 'post_title' => __( 'New Style', 'formidable' ),
25
- 'post_name' => $key,
26
- 'post_content' => $this->get_defaults(),
27
- 'menu_order' => '',
28
- 'post_status' => 'publish',
29
- );
30
 
31
- return (object) $style;
32
- }
 
 
 
 
 
 
 
 
 
 
33
 
34
  public function save( $settings ) {
35
  return FrmDb::save_settings( $settings, 'frm_styles' );
36
- }
37
 
38
  public function duplicate( $id ) {
39
- // duplicating is a pro feature
40
- }
41
 
42
- public function update( $id = 'default' ) {
43
- $all_instances = $this->get_all();
44
 
45
- if ( empty( $id ) ) {
46
- $new_style = (array) $this->get_new();
47
- $all_instances[] = $new_style;
48
- }
49
 
50
- $action_ids = array();
51
 
52
- foreach ( $all_instances as $number => $new_instance ) {
53
- $new_instance = stripslashes_deep( (array) $new_instance );
54
- $this->id = $new_instance['ID'];
55
- if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
56
  $all_instances[ $number ] = $new_instance;
57
 
58
  if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
59
- // this style was set to default, so remove default setting on previous default style
60
- $new_instance['menu_order'] = 0;
61
- $action_ids[] = $this->save( $new_instance );
62
- }
63
 
64
- // don't continue if not saving this style
65
- continue;
66
- }
67
 
68
- $new_instance['post_title'] = isset( $_POST['frm_style_setting']['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ) : '';
69
- $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? wp_unslash( $_POST['frm_style_setting']['post_content'] ) : '';
70
- $new_instance['post_type'] = FrmStylesController::$post_type;
71
- $new_instance['post_status'] = 'publish';
72
- $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
73
 
74
  if ( empty( $id ) ) {
75
- $new_instance['post_name'] = $new_instance['post_title'];
76
- }
77
 
78
- $default_settings = $this->get_defaults();
79
 
80
- foreach ( $default_settings as $setting => $default ) {
81
  if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
82
  $new_instance['post_content'][ $setting ] = $default;
83
  }
84
 
85
  if ( $this->is_color( $setting ) ) {
86
  $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
87
- } elseif ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) )
88
- && ! isset( $new_instance['post_content'][ $setting ] )
89
- ) {
90
  $new_instance['post_content'][ $setting ] = 0;
91
- } elseif ( $setting == 'font' ) {
92
- $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
93
- }
94
- }
95
 
96
  $all_instances[ $number ] = $new_instance;
97
 
98
  $action_ids[] = $this->save( $new_instance );
99
 
100
- }
101
 
102
- $this->save_settings();
103
 
104
- return $action_ids;
105
- }
106
 
107
  /**
108
  * @since 3.01.01
109
  */
110
  private function is_color( $setting ) {
111
  $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
112
-
113
  return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors );
114
  }
115
 
@@ -119,20 +115,19 @@ class FrmStyle {
119
  public function get_color_settings() {
120
  $defaults = $this->get_defaults();
121
  $settings = array_keys( $defaults );
122
-
123
  return array_filter( $settings, array( $this, 'is_color' ) );
124
  }
125
 
126
- /**
127
- * Create static css file
128
- */
129
  public function save_settings() {
130
  $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
131
  update_option( 'frm_last_style_update', date( 'njGi' ) );
132
 
133
  if ( ! is_file( $filename ) ) {
134
- return;
135
- }
136
 
137
  $this->clear_cache();
138
 
@@ -153,13 +148,13 @@ class FrmStyle {
153
  private function get_css_content( $filename ) {
154
  $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
155
 
156
- $saving = true;
157
  $frm_style = $this;
158
 
159
- ob_start();
160
- include( $filename );
161
  $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
162
- ob_end_clean();
163
 
164
  return $css;
165
  }
@@ -180,84 +175,83 @@ class FrmStyle {
180
 
181
  public function destroy( $id ) {
182
  return wp_delete_post( $id );
183
- }
184
-
185
- public function get_one() {
186
- if ( 'default' == $this->id ) {
187
- $style = $this->get_default_style();
188
- if ( $style ) {
189
- $this->id = $style->ID;
190
- } else {
191
- $this->id = 0;
192
- }
193
-
194
- return $style;
195
- }
196
 
197
  $style = get_post( $this->id );
198
 
199
- if ( ! $style ) {
200
- return $style;
201
- }
202
 
203
  $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
204
 
205
- $default_values = $this->get_defaults();
206
 
207
  // fill default values
208
  $style->post_content = $this->override_defaults( $style->post_content );
209
  $style->post_content = wp_parse_args( $style->post_content, $default_values );
210
 
211
- return $style;
212
- }
213
 
214
- public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
215
- $post_atts = array(
216
  'post_type' => FrmStylesController::$post_type,
217
  'post_status' => 'publish',
218
  'numberposts' => $limit,
219
  'orderby' => $orderby,
220
  'order' => $order,
221
- );
222
 
223
  $temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
224
 
225
  if ( empty( $temp_styles ) ) {
226
- global $wpdb;
227
- // make sure there wasn't a conflict with the query
228
- $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
229
  $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
230
 
231
  if ( empty( $temp_styles ) ) {
232
- // create a new style if there are none
233
- $new = $this->get_new();
234
  $new->post_title = __( 'Formidable Style', 'formidable' );
235
- $new->post_name = $new->post_title;
236
- $new->menu_order = 1;
237
- $new = $this->save( (array) $new );
238
  $this->update( 'default' );
239
 
240
- $post_atts['include'] = $new;
241
 
242
- $temp_styles = get_posts( $post_atts );
243
- }
244
- }
245
 
246
- $default_values = $this->get_defaults();
247
- $default_style = false;
248
-
249
- $styles = array();
250
- foreach ( $temp_styles as $style ) {
251
- $this->id = $style->ID;
252
- if ( $style->menu_order ) {
253
- if ( $default_style ) {
254
- // only return one default
255
- $style->menu_order = 0;
256
- } else {
257
- // check for a default style
258
- $default_style = $style->ID;
259
- }
260
- }
261
 
262
  $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
263
 
@@ -266,198 +260,196 @@ class FrmStyle {
266
  $style->post_content = wp_parse_args( $style->post_content, $default_values );
267
 
268
  $styles[ $style->ID ] = $style;
269
- }
270
 
271
- if ( ! $default_style ) {
272
  $default_style = reset( $styles );
273
-
274
  $styles[ $default_style->ID ]->menu_order = 1;
275
- }
276
 
277
- return $styles;
278
- }
279
 
280
  public function get_default_style( $styles = null ) {
281
  if ( ! isset( $styles ) ) {
282
  $styles = $this->get_all( 'menu_order', 'DESC', 1 );
283
- }
284
 
285
- foreach ( $styles as $style ) {
286
- if ( $style->menu_order ) {
287
- return $style;
288
- }
289
- }
290
- }
291
 
292
  public function override_defaults( $settings ) {
293
  if ( ! is_array( $settings ) ) {
294
- return $settings;
295
- }
296
 
297
  $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
298
 
299
  if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
300
- $settings['form_desc_size'] = $settings['description_font_size'];
301
- $settings['form_desc_color'] = $settings['description_color'];
302
- $settings['title_color'] = $settings['label_color'];
303
- }
304
 
305
  if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
306
- $settings['section_color'] = $settings['label_color'];
307
- $settings['section_border_color'] = $settings['border_color'];
308
- }
309
 
310
  if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
311
- $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
312
- $settings['submit_hover_color'] = $settings['submit_text_color'];
313
- $settings['submit_hover_border_color'] = $settings['submit_border_color'];
314
 
315
- $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
316
- $settings['submit_active_color'] = $settings['submit_text_color'];
317
- $settings['submit_active_border_color'] = $settings['submit_border_color'];
318
- }
319
 
320
- return apply_filters( 'frm_override_default_styles', $settings );
321
  }
322
 
323
  public function get_defaults() {
324
  $defaults = array(
325
- 'theme_css' => 'ui-lightness',
326
- 'theme_name' => 'UI Lightness',
327
 
328
  'center_form' => '',
329
- 'form_width' => '100%',
330
- 'form_align' => 'left',
331
- 'direction' => is_rtl() ? 'rtl' : 'ltr',
332
- 'fieldset' => '0px',
333
- 'fieldset_color' => '000000',
334
- 'fieldset_padding' => '0 0 15px 0',
335
- 'fieldset_bg_color' => '',
336
-
337
- 'title_size' => '20px',
338
- 'title_color' => '444444',
339
- 'title_margin_top' => '10px',
340
- 'title_margin_bottom' => '10px',
341
- 'form_desc_size' => '14px',
342
- 'form_desc_color' => '666666',
343
- 'form_desc_margin_top' => '10px',
344
  'form_desc_margin_bottom' => '25px',
345
 
346
- 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
347
- 'font_size' => '14px',
348
- 'label_color' => '444444',
349
- 'weight' => 'bold',
350
- 'position' => 'none',
351
- 'align' => 'left',
352
- 'width' => '150px',
353
- 'required_color' => 'B94A48',
354
- 'required_weight' => 'bold',
355
- 'label_padding' => '0 0 3px 0',
356
-
357
- 'description_font_size' => '12px',
358
- 'description_color' => '666666',
359
- 'description_weight' => 'normal',
360
- 'description_style' => 'normal',
361
- 'description_align' => 'left',
362
- 'description_margin' => '0',
363
-
364
- 'field_font_size' => '14px',
365
- 'field_height' => '32px',
366
- 'line_height' => 'normal',
367
- 'field_width' => '100%',
368
- 'auto_width' => false,
369
- 'field_pad' => '6px 10px',
370
- 'field_margin' => '20px',
371
- 'field_weight' => 'normal',
372
- 'text_color' => '555555',
373
- //'border_color_hv' => 'cccccc',
374
- 'border_color' => 'cccccc',
375
- 'field_border_width' => '1px',
376
- 'field_border_style' => 'solid',
377
-
378
- 'bg_color' => 'ffffff',
379
- //'bg_color_hv' => 'ffffff',
380
- 'remove_box_shadow' => '',
381
- 'bg_color_active' => 'ffffff',
382
- 'border_color_active' => '66afe9',
383
  'remove_box_shadow_active' => '',
384
- 'text_color_error' => '444444',
385
- 'bg_color_error' => 'ffffff',
386
- 'border_color_error' => 'B94A48',
387
- 'border_width_error' => '1px',
388
- 'border_style_error' => 'solid',
389
- 'bg_color_disabled' => 'ffffff',
390
- 'border_color_disabled' => 'E5E5E5',
391
- 'text_color_disabled' => 'A1A1A1',
392
-
393
- 'radio_align' => 'block',
394
- 'check_align' => 'block',
395
- 'check_font_size' => '13px',
396
- 'check_label_color' => '444444',
397
- 'check_weight' => 'normal',
398
-
399
- 'section_font_size' => '18px',
400
- 'section_color' => '444444',
401
- 'section_weight' => 'bold',
402
- 'section_pad' => '15px 0 3px 0',
403
- 'section_mar_top' => '15px',
404
- 'section_mar_bottom' => '12px',
405
- 'section_bg_color' => '',
406
- 'section_border_color' => 'e8e8e8',
407
- 'section_border_width' => '2px',
408
- 'section_border_style' => 'solid',
409
- 'section_border_loc' => '-top',
410
- 'collapse_icon' => '6',
411
- 'collapse_pos' => 'after',
412
- 'repeat_icon' => '1',
413
-
414
- 'submit_style' => false,
415
- 'submit_font_size' => '14px',
416
- 'submit_width' => 'auto',
417
- 'submit_height' => 'auto',
418
- 'submit_bg_color' => 'ffffff',
419
- 'submit_border_color' => 'cccccc',
420
- 'submit_border_width' => '1px',
421
- 'submit_text_color' => '444444',
422
- 'submit_weight' => 'normal',
423
- 'submit_border_radius' => '4px',
424
- 'submit_bg_img' => '',
425
- 'submit_margin' => '10px',
426
- 'submit_padding' => '6px 11px',
427
- 'submit_shadow_color' => 'eeeeee',
428
- 'submit_hover_bg_color' => 'efefef',
429
- 'submit_hover_color' => '444444',
430
- 'submit_hover_border_color' => 'cccccc',
431
- 'submit_active_bg_color' => 'efefef',
432
- 'submit_active_color' => '444444',
433
- 'submit_active_border_color' => 'cccccc',
434
-
435
- 'border_radius' => '4px',
436
- 'error_bg' => 'F2DEDE',
437
- 'error_border' => 'EBCCD1',
438
- 'error_text' => 'B94A48',
439
- 'error_font_size' => '14px',
440
-
441
- 'success_bg_color' => 'DFF0D8',
442
- 'success_border_color' => 'D6E9C6',
443
- 'success_text_color' => '468847',
444
- 'success_font_size' => '14px',
445
-
446
- 'important_style' => false,
447
-
448
- 'progress_bg_color' => 'dddddd',
449
- 'progress_active_color' => 'ffffff',
450
  'progress_active_bg_color' => '008ec2',
451
- 'progress_color' => 'ffffff',
452
- 'progress_border_color' => 'dfdfdf',
453
- 'progress_border_size' => '2px',
454
- 'progress_size' => '30px',
455
 
456
- 'custom_css' => '',
457
  );
458
-
459
  return apply_filters( 'frm_default_style_settings', $defaults );
460
- }
461
 
462
  public function get_field_name( $field_name, $post_field = 'post_content' ) {
463
  return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
@@ -465,15 +457,15 @@ class FrmStyle {
465
 
466
  public static function get_bold_options() {
467
  return array(
468
- 100 => 100,
469
- 200 => 200,
470
- 300 => 300,
471
  'normal' => __( 'normal', 'formidable' ),
472
- 500 => 500,
473
- 600 => 600,
474
- 'bold' => __( 'bold', 'formidable' ),
475
- 800 => 800,
476
- 900 => 900,
477
  );
478
  }
479
 
@@ -483,13 +475,12 @@ class FrmStyle {
483
  public function force_balanced_quotation( $value ) {
484
  $balanced_characters = array( '"', "'" );
485
  foreach ( $balanced_characters as $char ) {
486
- $char_count = substr_count( $value, $char );
487
  $is_balanced = $char_count % 2 == 0;
488
  if ( ! $is_balanced ) {
489
  $value .= $char;
490
  }
491
  }
492
-
493
  return $value;
494
  }
495
  }
1
  <?php
 
2
  class FrmStyle {
3
  public $number = false; // Unique ID number of the current instance.
4
  public $id = 0; // the id of the post
7
  * @param int|string $id The id of the stylsheet or 'default'
8
  */
9
  public function __construct( $id = 0 ) {
10
+ $this->id = $id;
11
+ }
12
 
13
+ public function get_new() {
14
  $this->id = 0;
15
 
16
+ $max_slug_value = 2147483647;
17
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
+ $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
 
 
 
 
 
 
 
 
 
 
19
 
20
+ $style = array(
21
+ 'post_type' => FrmStylesController::$post_type,
22
+ 'ID' => '',
23
+ 'post_title' => __( 'New Style', 'formidable' ),
24
+ 'post_name' => $key,
25
+ 'post_content' => $this->get_defaults(),
26
+ 'menu_order' => '',
27
+ 'post_status' => 'publish',
28
+ );
29
+
30
+ return (object) $style;
31
+ }
32
 
33
  public function save( $settings ) {
34
  return FrmDb::save_settings( $settings, 'frm_styles' );
35
+ }
36
 
37
  public function duplicate( $id ) {
38
+ // duplicating is a pro feature
39
+ }
40
 
41
+ public function update( $id = 'default' ) {
42
+ $all_instances = $this->get_all();
43
 
44
+ if ( empty( $id ) ) {
45
+ $new_style = (array) $this->get_new();
46
+ $all_instances[] = $new_style;
47
+ }
48
 
49
+ $action_ids = array();
50
 
51
+ foreach ( $all_instances as $number => $new_instance ) {
52
+ $new_instance = stripslashes_deep( (array) $new_instance );
53
+ $this->id = $new_instance['ID'];
54
+ if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
55
  $all_instances[ $number ] = $new_instance;
56
 
57
  if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
58
+ // this style was set to default, so remove default setting on previous default style
59
+ $new_instance['menu_order'] = 0;
60
+ $action_ids[] = $this->save( $new_instance );
61
+ }
62
 
63
+ // don't continue if not saving this style
64
+ continue;
65
+ }
66
 
67
+ $new_instance['post_title'] = isset( $_POST['frm_style_setting']['post_title'] ) ? sanitize_text_field( $_POST['frm_style_setting']['post_title'] ) : '';
68
+ $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $_POST['frm_style_setting']['post_content'] : '';
69
+ $new_instance['post_type'] = FrmStylesController::$post_type;
70
+ $new_instance['post_status'] = 'publish';
71
+ $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
72
 
73
  if ( empty( $id ) ) {
74
+ $new_instance['post_name'] = $new_instance['post_title'];
75
+ }
76
 
77
+ $default_settings = $this->get_defaults();
78
 
79
+ foreach ( $default_settings as $setting => $default ) {
80
  if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
81
  $new_instance['post_content'][ $setting ] = $default;
82
  }
83
 
84
  if ( $this->is_color( $setting ) ) {
85
  $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
86
+ } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
 
 
87
  $new_instance['post_content'][ $setting ] = 0;
88
+ } else if ( $setting == 'font' ) {
89
+ $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
90
+ }
91
+ }
92
 
93
  $all_instances[ $number ] = $new_instance;
94
 
95
  $action_ids[] = $this->save( $new_instance );
96
 
97
+ }
98
 
99
+ $this->save_settings();
100
 
101
+ return $action_ids;
102
+ }
103
 
104
  /**
105
  * @since 3.01.01
106
  */
107
  private function is_color( $setting ) {
108
  $extra_colors = array( 'error_bg', 'error_border', 'error_text' );
 
109
  return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors );
110
  }
111
 
115
  public function get_color_settings() {
116
  $defaults = $this->get_defaults();
117
  $settings = array_keys( $defaults );
 
118
  return array_filter( $settings, array( $this, 'is_color' ) );
119
  }
120
 
121
+ /**
122
+ * Create static css file
123
+ */
124
  public function save_settings() {
125
  $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
126
  update_option( 'frm_last_style_update', date( 'njGi' ) );
127
 
128
  if ( ! is_file( $filename ) ) {
129
+ return;
130
+ }
131
 
132
  $this->clear_cache();
133
 
148
  private function get_css_content( $filename ) {
149
  $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n";
150
 
151
+ $saving = true;
152
  $frm_style = $this;
153
 
154
+ ob_start();
155
+ include( $filename );
156
  $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
157
+ ob_end_clean();
158
 
159
  return $css;
160
  }
175
 
176
  public function destroy( $id ) {
177
  return wp_delete_post( $id );
178
+ }
179
+
180
+ public function get_one() {
181
+ if ( 'default' == $this->id ) {
182
+ $style = $this->get_default_style();
183
+ if ( $style ) {
184
+ $this->id = $style->ID;
185
+ } else {
186
+ $this->id = 0;
187
+ }
188
+ return $style;
189
+ }
 
190
 
191
  $style = get_post( $this->id );
192
 
193
+ if ( ! $style ) {
194
+ return $style;
195
+ }
196
 
197
  $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
198
 
199
+ $default_values = $this->get_defaults();
200
 
201
  // fill default values
202
  $style->post_content = $this->override_defaults( $style->post_content );
203
  $style->post_content = wp_parse_args( $style->post_content, $default_values );
204
 
205
+ return $style;
206
+ }
207
 
208
+ public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
209
+ $post_atts = array(
210
  'post_type' => FrmStylesController::$post_type,
211
  'post_status' => 'publish',
212
  'numberposts' => $limit,
213
  'orderby' => $orderby,
214
  'order' => $order,
215
+ );
216
 
217
  $temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
218
 
219
  if ( empty( $temp_styles ) ) {
220
+ global $wpdb;
221
+ // make sure there wasn't a conflict with the query
222
+ $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
223
  $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
224
 
225
  if ( empty( $temp_styles ) ) {
226
+ // create a new style if there are none
227
+ $new = $this->get_new();
228
  $new->post_title = __( 'Formidable Style', 'formidable' );
229
+ $new->post_name = $new->post_title;
230
+ $new->menu_order = 1;
231
+ $new = $this->save( (array) $new );
232
  $this->update( 'default' );
233
 
234
+ $post_atts['include'] = $new;
235
 
236
+ $temp_styles = get_posts( $post_atts );
237
+ }
238
+ }
239
 
240
+ $default_values = $this->get_defaults();
241
+ $default_style = false;
242
+
243
+ $styles = array();
244
+ foreach ( $temp_styles as $style ) {
245
+ $this->id = $style->ID;
246
+ if ( $style->menu_order ) {
247
+ if ( $default_style ) {
248
+ // only return one default
249
+ $style->menu_order = 0;
250
+ } else {
251
+ // check for a default style
252
+ $default_style = $style->ID;
253
+ }
254
+ }
255
 
256
  $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
257
 
260
  $style->post_content = wp_parse_args( $style->post_content, $default_values );
261
 
262
  $styles[ $style->ID ] = $style;
263
+ }
264
 
265
+ if ( ! $default_style ) {
266
  $default_style = reset( $styles );
 
267
  $styles[ $default_style->ID ]->menu_order = 1;
268
+ }
269
 
270
+ return $styles;
271
+ }
272
 
273
  public function get_default_style( $styles = null ) {
274
  if ( ! isset( $styles ) ) {
275
  $styles = $this->get_all( 'menu_order', 'DESC', 1 );
276
+ }
277
 
278
+ foreach ( $styles as $style ) {
279
+ if ( $style->menu_order ) {
280
+ return $style;
281
+ }
282
+ }
283
+ }
284
 
285
  public function override_defaults( $settings ) {
286
  if ( ! is_array( $settings ) ) {
287
+ return $settings;
288
+ }
289
 
290
  $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
291
 
292
  if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
293
+ $settings['form_desc_size'] = $settings['description_font_size'];
294
+ $settings['form_desc_color'] = $settings['description_color'];
295
+ $settings['title_color'] = $settings['label_color'];
296
+ }
297
 
298
  if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
299
+ $settings['section_color'] = $settings['label_color'];
300
+ $settings['section_border_color'] = $settings['border_color'];
301
+ }
302
 
303
  if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
304
+ $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
305
+ $settings['submit_hover_color'] = $settings['submit_text_color'];
306
+ $settings['submit_hover_border_color'] = $settings['submit_border_color'];
307
 
308
+ $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
309
+ $settings['submit_active_color'] = $settings['submit_text_color'];
310
+ $settings['submit_active_border_color'] = $settings['submit_border_color'];
311
+ }
312
 
313
+ return apply_filters( 'frm_override_default_styles', $settings );
314
  }
315
 
316
  public function get_defaults() {
317
  $defaults = array(
318
+ 'theme_css' => 'ui-lightness',
319
+ 'theme_name' => 'UI Lightness',
320
 
321
  'center_form' => '',
322
+ 'form_width' => '100%',
323
+ 'form_align' => 'left',
324
+ 'direction' => is_rtl() ? 'rtl' : 'ltr',
325
+ 'fieldset' => '0px',
326
+ 'fieldset_color' => '000000',
327
+ 'fieldset_padding' => '0 0 15px 0',
328
+ 'fieldset_bg_color' => '',
329
+
330
+ 'title_size' => '20px',
331
+ 'title_color' => '444444',
332
+ 'title_margin_top' => '10px',
333
+ 'title_margin_bottom' => '10px',
334
+ 'form_desc_size' => '14px',
335
+ 'form_desc_color' => '666666',
336
+ 'form_desc_margin_top' => '10px',
337
  'form_desc_margin_bottom' => '25px',
338
 
339
+ 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
340
+ 'font_size' => '14px',
341
+ 'label_color' => '444444',
342
+ 'weight' => 'bold',
343
+ 'position' => 'none',
344
+ 'align' => 'left',
345
+ 'width' => '150px',
346
+ 'required_color' => 'B94A48',
347
+ 'required_weight' => 'bold',
348
+ 'label_padding' => '0 0 3px 0',
349
+
350
+ 'description_font_size' => '12px',
351
+ 'description_color' => '666666',
352
+ 'description_weight' => 'normal',
353
+ 'description_style' => 'normal',
354
+ 'description_align' => 'left',
355
+ 'description_margin' => '0',
356
+
357
+ 'field_font_size' => '14px',
358
+ 'field_height' => '32px',
359
+ 'line_height' => 'normal',
360
+ 'field_width' => '100%',
361
+ 'auto_width' => false,
362
+ 'field_pad' => '6px 10px',
363
+ 'field_margin' => '20px',
364
+ 'field_weight' => 'normal',
365
+ 'text_color' => '555555',
366
+ //'border_color_hv' => 'cccccc',
367
+ 'border_color' => 'cccccc',
368
+ 'field_border_width' => '1px',
369
+ 'field_border_style' => 'solid',
370
+
371
+ 'bg_color' => 'ffffff',
372
+ //'bg_color_hv' => 'ffffff',
373
+ 'remove_box_shadow' => '',
374
+ 'bg_color_active' => 'ffffff',
375
+ 'border_color_active' => '66afe9',
376
  'remove_box_shadow_active' => '',
377
+ 'text_color_error' => '444444',
378
+ 'bg_color_error' => 'ffffff',
379
+ 'border_color_error' => 'B94A48',
380
+ 'border_width_error' => '1px',
381
+ 'border_style_error' => 'solid',
382
+ 'bg_color_disabled' => 'ffffff',
383
+ 'border_color_disabled' => 'E5E5E5',
384
+ 'text_color_disabled' => 'A1A1A1',
385
+
386
+ 'radio_align' => 'block',
387
+ 'check_align' => 'block',
388
+ 'check_font_size' => '13px',
389
+ 'check_label_color' => '444444',
390
+ 'check_weight' => 'normal',
391
+
392
+ 'section_font_size' => '18px',
393
+ 'section_color' => '444444',
394
+ 'section_weight' => 'bold',
395
+ 'section_pad' => '15px 0 3px 0',
396
+ 'section_mar_top' => '15px',
397
+ 'section_mar_bottom' => '12px',
398
+ 'section_bg_color' => '',
399
+ 'section_border_color' => 'e8e8e8',
400
+ 'section_border_width' => '2px',
401
+ 'section_border_style' => 'solid',
402
+ 'section_border_loc' => '-top',
403
+ 'collapse_icon' => '6',
404
+ 'collapse_pos' => 'after',
405
+ 'repeat_icon' => '1',
406
+
407
+ 'submit_style' => false,
408
+ 'submit_font_size' => '14px',
409
+ 'submit_width' => 'auto',
410
+ 'submit_height' => 'auto',
411
+ 'submit_bg_color' => 'ffffff',
412
+ 'submit_border_color' => 'cccccc',
413
+ 'submit_border_width' => '1px',
414
+ 'submit_text_color' => '444444',
415
+ 'submit_weight' => 'normal',
416
+ 'submit_border_radius' => '4px',
417
+ 'submit_bg_img' => '',
418
+ 'submit_margin' => '10px',
419
+ 'submit_padding' => '6px 11px',
420
+ 'submit_shadow_color' => 'eeeeee',
421
+ 'submit_hover_bg_color' => 'efefef',
422
+ 'submit_hover_color' => '444444',
423
+ 'submit_hover_border_color' => 'cccccc',
424
+ 'submit_active_bg_color' => 'efefef',
425
+ 'submit_active_color' => '444444',
426
+ 'submit_active_border_color' => 'cccccc',
427
+
428
+ 'border_radius' => '4px',
429
+ 'error_bg' => 'F2DEDE',
430
+ 'error_border' => 'EBCCD1',
431
+ 'error_text' => 'B94A48',
432
+ 'error_font_size' => '14px',
433
+
434
+ 'success_bg_color' => 'DFF0D8',
435
+ 'success_border_color' => 'D6E9C6',
436
+ 'success_text_color' => '468847',
437
+ 'success_font_size' => '14px',
438
+
439
+ 'important_style' => false,
440
+
441
+ 'progress_bg_color' => 'dddddd',
442
+ 'progress_active_color' => 'ffffff',
443
  'progress_active_bg_color' => '008ec2',
444
+ 'progress_color' => 'ffffff',
445
+ 'progress_border_color' => 'dfdfdf',
446
+ 'progress_border_size' => '2px',
447
+ 'progress_size' => '30px',
448
 
449
+ 'custom_css' => '',
450
  );
 
451
  return apply_filters( 'frm_default_style_settings', $defaults );
452
+ }
453
 
454
  public function get_field_name( $field_name, $post_field = 'post_content' ) {
455
  return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
457
 
458
  public static function get_bold_options() {
459
  return array(
460
+ 100 => 100,
461
+ 200 => 200,
462
+ 300 => 300,
463
  'normal' => __( 'normal', 'formidable' ),
464
+ 500 => 500,
465
+ 600 => 600,
466
+ 'bold' => __( 'bold', 'formidable' ),
467
+ 800 => 800,
468
+ 900 => 900,
469
  );
470
  }
471
 
475
  public function force_balanced_quotation( $value ) {
476
  $balanced_characters = array( '"', "'" );
477
  foreach ( $balanced_characters as $char ) {
478
+ $char_count = substr_count( $value, $char );
479
  $is_balanced = $char_count % 2 == 0;
480
  if ( ! $is_balanced ) {
481
  $value .= $char;
482
  }
483
  }
 
484
  return $value;
485
  }
486
  }
classes/models/FrmTableHTMLGenerator.php CHANGED
@@ -47,6 +47,7 @@ class FrmTableHTMLGenerator {
47
  */
48
  private $td_style = '';
49
 
 
50
  /**
51
  * FrmTableHTMLGenerator constructor.
52
  *
@@ -61,6 +62,7 @@ class FrmTableHTMLGenerator {
61
  $this->init_direction( $atts );
62
  $this->init_table_style();
63
  $this->init_td_style();
 
64
  }
65
 
66
  /**
@@ -71,7 +73,7 @@ class FrmTableHTMLGenerator {
71
  * @param array $atts
72
  */
73
  private function init_style_settings( $atts ) {
74
- $style_settings = array(
75
  'border_color' => 'dddddd',
76
  'bg_color' => 'f7f7f7',
77
  'text_color' => '444444',
@@ -90,8 +92,6 @@ class FrmTableHTMLGenerator {
90
  $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
91
  }
92
  }
93
-
94
- $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : '';
95
  }
96
 
97
  /**
@@ -132,10 +132,6 @@ class FrmTableHTMLGenerator {
132
  $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
133
 
134
  }
135
-
136
- if ( ! empty( $this->style_settings['class'] ) ) {
137
- $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"';
138
- }
139
  }
140
 
141
  /**
@@ -209,7 +205,7 @@ class FrmTableHTMLGenerator {
209
 
210
  if ( $this->type === 'shortcode' ) {
211
  $tr_style = ' style="[frm-alt-color]"';
212
- } elseif ( $this->use_inline_style ) {
213
  $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"';
214
  } else {
215
  $tr_style = '';
@@ -262,17 +258,13 @@ class FrmTableHTMLGenerator {
262
  * @return string
263
  */
264
  public function generate_two_cell_table_row( $label, $value ) {
265
- $row = '<tr' . $this->tr_style();
266
- if ( $value === '' ) {
267
- $row .= ' class="frm-empty-row"';
268
- }
269
- $row .= '>';
270
 
271
  if ( 'rtl' == $this->direction ) {
272
- $first = $value;
273
  $second = $label;
274
  } else {
275
- $first = $label;
276
  $second = $value;
277
  }
278
 
47
  */
48
  private $td_style = '';
49
 
50
+
51
  /**
52
  * FrmTableHTMLGenerator constructor.
53
  *
62
  $this->init_direction( $atts );
63
  $this->init_table_style();
64
  $this->init_td_style();
65
+
66
  }
67
 
68
  /**
73
  * @param array $atts
74
  */
75
  private function init_style_settings( $atts ) {
76
+ $style_settings = array(
77
  'border_color' => 'dddddd',
78
  'bg_color' => 'f7f7f7',
79
  'text_color' => '444444',
92
  $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
93
  }
94
  }
 
 
95
  }
96
 
97
  /**
132
  $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
133
 
134
  }
 
 
 
 
135
  }
136
 
137
  /**
205
 
206
  if ( $this->type === 'shortcode' ) {
207
  $tr_style = ' style="[frm-alt-color]"';
208
+ } else if ( $this->use_inline_style ) {
209
  $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"';
210
  } else {
211
  $tr_style = '';
258
  * @return string
259
  */
260
  public function generate_two_cell_table_row( $label, $value ) {
261
+ $row = '<tr' . $this->tr_style() . '>';
 
 
 
 
262
 
263
  if ( 'rtl' == $this->direction ) {
264
+ $first = $value;
265
  $second = $label;
266
  } else {
267
+ $first = $label;
268
  $second = $value;
269
  }
270
 
classes/models/fields/FrmFieldCaptcha.php CHANGED
@@ -31,8 +31,8 @@ class FrmFieldCaptcha extends FrmFieldType {
31
  return array(
32
  'required' => false,
33
  'invalid' => true,
 
34
  'captcha_size' => true,
35
- 'default' => false,
36
  );
37
  }
38
 
@@ -41,7 +41,6 @@ class FrmFieldCaptcha extends FrmFieldType {
41
  */
42
  protected function new_field_settings() {
43
  $frm_settings = FrmAppHelper::get_settings();
44
-
45
  return array(
46
  'invalid' => $frm_settings->re_msg,
47
  );
@@ -76,8 +75,8 @@ class FrmFieldCaptcha extends FrmFieldType {
76
  return '';
77
  }
78
 
79
- $class_prefix = $this->class_prefix();
80
- $captcha_size = $this->captcha_size();
81
  $allow_mutiple = $frm_settings->re_multi;
82
 
83
  $html = '<div id="' . esc_attr( $args['html_id'] ) . '" class="' . esc_attr( $class_prefix ) . 'g-recaptcha" data-sitekey="' . esc_attr( $frm_settings->pubkey ) . '" data-size="' . esc_attr( $captcha_size ) . '" data-theme="' . esc_attr( $this->field['captcha_theme'] ) . '"';
@@ -99,7 +98,7 @@ class FrmFieldCaptcha extends FrmFieldType {
99
  protected function api_url() {
100
  $api_js_url = 'https://www.google.com/recaptcha/api.js?';
101
 
102
- $frm_settings = FrmAppHelper::get_settings();
103
  $allow_mutiple = $frm_settings->re_multi;
104
  if ( $allow_mutiple ) {
105
  $api_js_url .= '&onload=frmRecaptcha&render=explicit';
@@ -119,13 +118,11 @@ class FrmFieldCaptcha extends FrmFieldType {
119
  } else {
120
  $class_prefix = '';
121
  }
122
-
123
  return $class_prefix;
124
  }
125
 
126
  protected function allow_multiple() {
127
  $frm_settings = FrmAppHelper::get_settings();
128
-
129
  return $frm_settings->re_multi;
130
  }
131
 
@@ -133,7 +130,6 @@ class FrmFieldCaptcha extends FrmFieldType {
133
  // for reverse compatibility
134
  $frm_settings = FrmAppHelper::get_settings();
135
  $captcha_size = ( $this->field['captcha_size'] == 'default' ) ? 'normal' : $this->field['captcha_size'];
136
-
137
  return ( $frm_settings->re_type == 'invisible' ) ? 'invisible' : $captcha_size;
138
  }
139
 
@@ -145,27 +141,25 @@ class FrmFieldCaptcha extends FrmFieldType {
145
  }
146
 
147
  if ( ! isset( $_POST['g-recaptcha-response'] ) ) {
148
- // If captcha is missing, check if it was already verified.
149
- $checked = FrmAppHelper::get_param( 'recaptcha_checked', '', 'post', 'sanitize_text_field' );
150
- if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $checked, 'frm_ajax' ) ) {
151
- // There was no captcha submitted.
152
  $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' );
153
  }
154
-
155
  return $errors;
156
  }
157
 
158
  $frm_settings = FrmAppHelper::get_settings();
159
 
160
- $resp = $this->send_api_check( $frm_settings );
161
  $response = json_decode( wp_remote_retrieve_body( $resp ), true );
162
 
163
  if ( isset( $response['success'] ) && ! $response['success'] ) {
164
  // What happens when the CAPTCHA was entered incorrectly
165
- $invalid_message = FrmField::get_option( $this->field, 'invalid' );
166
  $errors[ 'field' . $args['id'] ] = ( $invalid_message == '' ? $frm_settings->re_msg : $invalid_message );
167
  } elseif ( is_wp_error( $resp ) ) {
168
- $error_string = $resp->get_error_message();
169
  $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' );
170
  $errors[ 'field' . $args['id'] ] .= ' ' . $error_string;
171
  }
@@ -190,9 +184,9 @@ class FrmFieldCaptcha extends FrmFieldType {
190
 
191
  protected function send_api_check( $frm_settings ) {
192
  $arg_array = array(
193
- 'body' => array(
194
  'secret' => $frm_settings->privkey,
195
- 'response' => FrmAppHelper::get_param( 'g-recaptcha-response', '', 'post', 'sanitize_text_field' ),
196
  'remoteip' => FrmAppHelper::get_ip_address(),
197
  ),
198
  );
31
  return array(
32
  'required' => false,
33
  'invalid' => true,
34
+ 'default_blank' => false,
35
  'captcha_size' => true,
 
36
  );
37
  }
38
 
41
  */
42
  protected function new_field_settings() {
43
  $frm_settings = FrmAppHelper::get_settings();
 
44
  return array(
45
  'invalid' => $frm_settings->re_msg,
46
  );
75
  return '';
76
  }
77
 
78
+ $class_prefix = $this->class_prefix();
79
+ $captcha_size = $this->captcha_size();
80
  $allow_mutiple = $frm_settings->re_multi;
81
 
82
  $html = '<div id="' . esc_attr( $args['html_id'] ) . '" class="' . esc_attr( $class_prefix ) . 'g-recaptcha" data-sitekey="' . esc_attr( $frm_settings->pubkey ) . '" data-size="' . esc_attr( $captcha_size ) . '" data-theme="' . esc_attr( $this->field['captcha_theme'] ) . '"';
98
  protected function api_url() {
99
  $api_js_url = 'https://www.google.com/recaptcha/api.js?';
100
 
101
+ $frm_settings = FrmAppHelper::get_settings();
102
  $allow_mutiple = $frm_settings->re_multi;
103
  if ( $allow_mutiple ) {
104
  $api_js_url .= '&onload=frmRecaptcha&render=explicit';
118
  } else {
119
  $class_prefix = '';
120
  }
 
121
  return $class_prefix;
122
  }
123
 
124
  protected function allow_multiple() {
125
  $frm_settings = FrmAppHelper::get_settings();
 
126
  return $frm_settings->re_multi;
127
  }
128
 
130
  // for reverse compatibility
131
  $frm_settings = FrmAppHelper::get_settings();
132
  $captcha_size = ( $this->field['captcha_size'] == 'default' ) ? 'normal' : $this->field['captcha_size'];
 
133
  return ( $frm_settings->re_type == 'invisible' ) ? 'invisible' : $captcha_size;
134
  }
135
 
141
  }
142
 
143
  if ( ! isset( $_POST['g-recaptcha-response'] ) ) {
144
+ // If captcha is missing, check if it was already verified
145
+ if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) {
146
+ // There was no captcha submitted
 
147
  $errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' );
148
  }
 
149
  return $errors;
150
  }
151
 
152
  $frm_settings = FrmAppHelper::get_settings();
153
 
154
+ $resp = $this->send_api_check( $frm_settings );
155
  $response = json_decode( wp_remote_retrieve_body( $resp ), true );
156
 
157
  if ( isset( $response['success'] ) && ! $response['success'] ) {
158
  // What happens when the CAPTCHA was entered incorrectly
159
+ $invalid_message = FrmField::get_option( $this->field, 'invalid' );
160
  $errors[ 'field' . $args['id'] ] = ( $invalid_message == '' ? $frm_settings->re_msg : $invalid_message );
161
  } elseif ( is_wp_error( $resp ) ) {
162
+ $error_string = $resp->get_error_message();
163
  $errors[ 'field' . $args['id'] ] = __( 'There was a problem verifying your recaptcha', 'formidable' );
164
  $errors[ 'field' . $args['id'] ] .= ' ' . $error_string;
165
  }
184
 
185
  protected function send_api_check( $frm_settings ) {
186
  $arg_array = array(
187
+ 'body' => array(
188
  'secret' => $frm_settings->privkey,
189
+ 'response' => $_POST['g-recaptcha-response'], // WPCS: CSRF ok.
190
  'remoteip' => FrmAppHelper::get_ip_address(),
191
  ),
192
  );
classes/models/fields/FrmFieldCheckbox.php CHANGED
@@ -30,7 +30,13 @@ class FrmFieldCheckbox extends FrmFieldType {
30
  }
31
 
32
  protected function include_form_builder_file() {
33
- return $this->include_front_form_file();
 
 
 
 
 
 
34
  }
35
 
36
  protected function new_field_settings() {
@@ -46,7 +52,6 @@ class FrmFieldCheckbox extends FrmFieldType {
46
 
47
  protected function extra_field_opts() {
48
  $form_id = $this->get_field_column( 'form_id' );
49
-
50
  return array(
51
  'align' => FrmStylesController::get_style_val( 'check_align', ( empty( $form_id ) ? 'default' : $form_id ) ),
52
  );
30
  }
31
 
32
  protected function include_form_builder_file() {
33
+ return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-multiple.php';
34
+ }
35
+
36
+ protected function field_settings_for_type() {
37
+ return array(
38
+ 'default_blank' => false,
39
+ );
40
  }
41
 
42
  protected function new_field_settings() {
52
 
53
  protected function extra_field_opts() {
54
  $form_id = $this->get_field_column( 'form_id' );
 
55
  return array(
56
  'align' => FrmStylesController::get_style_val( 'check_align', ( empty( $form_id ) ? 'default' : $form_id ) ),
57
  );
classes/models/fields/FrmFieldEmail.php CHANGED
@@ -38,7 +38,6 @@ class FrmFieldEmail extends FrmFieldType {
38
  if ( $args['value'] != '' && ! is_email( $args['value'] ) ) {
39
  $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
40
  }
41
-
42
  return $errors;
43
  }
44
  }
38
  if ( $args['value'] != '' && ! is_email( $args['value'] ) ) {
39
  $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
40
  }
 
41
  return $errors;
42
  }
43
  }
classes/models/fields/FrmFieldHTML.php CHANGED
@@ -17,17 +17,6 @@ class FrmFieldHTML extends FrmFieldType {
17
  */
18
  protected $has_input = false;
19
 
20
- /**
21
- * @since 4.0
22
- * @param array $args - Includes 'field', 'display', and 'values'
23
- */
24
- public function show_primary_options( $args ) {
25
- $field = $args['field'];
26
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/html-content.php' );
27
-
28
- parent::show_primary_options( $args );
29
- }
30
-
31
  public function default_html() {
32
  return '<div id="frm_field_[id]_container" class="frm_form_field form-field">[description]</div>';
33
  }
@@ -38,11 +27,10 @@ class FrmFieldHTML extends FrmFieldType {
38
  protected function after_replace_html_shortcodes( $args, $html ) {
39
  FrmFieldsHelper::run_wpautop( array( 'wpautop' => true ), $html );
40
  $pre_filter = $html;
41
- $html = apply_filters( 'frm_get_default_value', $html, (object) $this->field, false );
42
  if ( $pre_filter === $html ) {
43
  $html = do_shortcode( $html );
44
  }
45
-
46
  return $html;
47
  }
48
 
17
  */
18
  protected $has_input = false;
19
 
 
 
 
 
 
 
 
 
 
 
 
20
  public function default_html() {
21
  return '<div id="frm_field_[id]_container" class="frm_form_field form-field">[description]</div>';
22
  }
27
  protected function after_replace_html_shortcodes( $args, $html ) {
28
  FrmFieldsHelper::run_wpautop( array( 'wpautop' => true ), $html );
29
  $pre_filter = $html;
30
+ $html = apply_filters( 'frm_get_default_value', $html, (object) $this->field, false );
31
  if ( $pre_filter === $html ) {
32
  $html = do_shortcode( $html );
33
  }
 
34
  return $html;
35
  }
36
 
classes/models/fields/FrmFieldHidden.php CHANGED
@@ -30,10 +30,8 @@ class FrmFieldHidden extends FrmFieldType {
30
  protected $holds_email_values = true;
31
 
32
  protected function field_settings_for_type() {
33
- $settings = parent::field_settings_for_type();
34
  $settings['css'] = false;
35
- $settings['default'] = true;
36
-
37
  return $settings;
38
  }
39
 
30
  protected $holds_email_values = true;
31
 
32
  protected function field_settings_for_type() {
33
+ $settings = parent::field_settings_for_type();
34
  $settings['css'] = false;
 
 
35
  return $settings;
36
  }
37
 
classes/models/fields/FrmFieldNumber.php CHANGED
@@ -72,6 +72,7 @@ class FrmFieldNumber extends FrmFieldType {
72
  return $errors;
73
  }
74
 
 
75
  /**
76
  * IE fallback for number fields
77
  * Remove the comma when HTML5 isn't supported
@@ -92,7 +93,6 @@ class FrmFieldNumber extends FrmFieldType {
92
  if ( ! is_numeric( $value ) ) {
93
  $value = (float) $value;
94
  }
95
-
96
  return $value;
97
  }
98
  }
72
  return $errors;
73
  }
74
 
75
+
76
  /**
77
  * IE fallback for number fields
78
  * Remove the comma when HTML5 isn't supported
93
  if ( ! is_numeric( $value ) ) {
94
  $value = (float) $value;
95
  }
 
96
  return $value;
97
  }
98
  }
classes/models/fields/FrmFieldPhone.php CHANGED
@@ -29,7 +29,6 @@ class FrmFieldPhone extends FrmFieldType {
29
 
30
  protected function html5_input_type() {
31
  $frm_settings = FrmAppHelper::get_settings();
32
-
33
  return $frm_settings->use_html ? 'tel' : 'text';
34
  }
35
  }
29
 
30
  protected function html5_input_type() {
31
  $frm_settings = FrmAppHelper::get_settings();
 
32
  return $frm_settings->use_html ? 'tel' : 'text';
33
  }
34
  }
classes/models/fields/FrmFieldRadio.php CHANGED
@@ -30,12 +30,17 @@ class FrmFieldRadio extends FrmFieldType {
30
  }
31
 
32
  protected function include_form_builder_file() {
33
- return $this->include_front_form_file();
 
 
 
 
 
 
34
  }
35
 
36
  protected function extra_field_opts() {
37
  $form_id = $this->get_field_column( 'form_id' );
38
-
39
  return array(
40
  'align' => FrmStylesController::get_style_val( 'radio_align', ( empty( $form_id ) ? 'default' : $form_id ) ),
41
  );
30
  }
31
 
32
  protected function include_form_builder_file() {
33
+ return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-multiple.php';
34
+ }
35
+
36
+ protected function field_settings_for_type() {
37
+ return array(
38
+ 'default_blank' => false,
39
+ );
40
  }
41
 
42
  protected function extra_field_opts() {
43
  $form_id = $this->get_field_column( 'form_id' );
 
44
  return array(
45
  'align' => FrmStylesController::get_style_val( 'radio_align', ( empty( $form_id ) ? 'default' : $form_id ) ),
46
  );
classes/models/fields/FrmFieldSelect.php CHANGED
@@ -18,12 +18,11 @@ class FrmFieldSelect extends FrmFieldType {
18
  protected $holds_email_values = true;
19
 
20
  protected function include_form_builder_file() {
21
- return $this->include_front_form_file();
22
  }
23
 
24
  protected function field_settings_for_type() {
25
  return array(
26
- 'clear_on_focus' => true,
27
  'size' => true,
28
  );
29
  }
@@ -39,14 +38,6 @@ class FrmFieldSelect extends FrmFieldType {
39
  );
40
  }
41
 
42
- /**
43
- * @since 4.0
44
- * @param array $args - Includes 'field', 'display', and 'values'
45
- */
46
- public function show_extra_field_choices( $args ) {
47
- $this->auto_width_setting( $args );
48
- }
49
-
50
  protected function include_front_form_file() {
51
  return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/front-end/dropdown-field.php';
52
  }
@@ -59,7 +50,6 @@ class FrmFieldSelect extends FrmFieldType {
59
  if ( FrmField::is_option_true( $this->field, 'multiple' ) ) {
60
  $value = $this->get_multi_opts_for_import( $value );
61
  }
62
-
63
  return $value;
64
  }
65
  }
18
  protected $holds_email_values = true;
19
 
20
  protected function include_form_builder_file() {
21
+ return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/dropdown-field.php';
22
  }
23
 
24
  protected function field_settings_for_type() {
25
  return array(
 
26
  'size' => true,
27
  );
28
  }
38
  );
39
  }
40
 
 
 
 
 
 
 
 
 
41
  protected function include_front_form_file() {
42
  return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/front-end/dropdown-field.php';
43
  }
50
  if ( FrmField::is_option_true( $this->field, 'multiple' ) ) {
51
  $value = $this->get_multi_opts_for_import( $value );
52
  }
 
53
  return $value;
54
  }
55
  }
classes/models/fields/FrmFieldTextarea.php CHANGED
@@ -28,10 +28,10 @@ class FrmFieldTextarea extends FrmFieldType {
28
  * @param string $name
29
  */
30
  public function show_on_form_builder( $name = '' ) {
31
- $size = FrmField::get_option( $this->field, 'size' );
32
  $size_html = $size ? ' style="width:' . esc_attr( $size . ( is_numeric( $size ) ? 'px' : '' ) ) . '";' : '';
33
 
34
- $max = FrmField::get_option( $this->field, 'max' );
35
  $default_value = FrmAppHelper::esc_textarea( force_balance_tags( $this->get_field_column( 'default_value' ) ) );
36
 
37
  echo '<textarea name="' . esc_attr( $this->html_name( $name ) ) . '" ' . // WPCS: XSS ok.
28
  * @param string $name
29
  */
30
  public function show_on_form_builder( $name = '' ) {
31
+ $size = FrmField::get_option( $this->field, 'size' );
32
  $size_html = $size ? ' style="width:' . esc_attr( $size . ( is_numeric( $size ) ? 'px' : '' ) ) . '";' : '';
33
 
34
+ $max = FrmField::get_option( $this->field, 'max' );
35
  $default_value = FrmAppHelper::esc_textarea( force_balance_tags( $this->get_field_column( 'default_value' ) ) );
36
 
37
  echo '<textarea name="' . esc_attr( $this->html_name( $name ) ) . '" ' . // WPCS: XSS ok.
classes/models/fields/FrmFieldType.php CHANGED
@@ -80,7 +80,6 @@ abstract class FrmFieldType {
80
  if ( property_exists( $this, $key ) ) {
81
  $value = $this->{$key};
82
  }
83
-
84
  return $value;
85
  }
86
 
@@ -108,7 +107,6 @@ abstract class FrmFieldType {
108
  } elseif ( is_array( $this->field ) && isset( $this->field[ $column ] ) ) {
109
  $field_val = $this->field[ $column ];
110
  }
111
-
112
  return $field_val;
113
  }
114
 
@@ -175,7 +173,6 @@ DEFAULT_HTML;
175
  } else {
176
  $for = '';
177
  }
178
-
179
  return $for;
180
  }
181
 
@@ -185,7 +182,7 @@ DEFAULT_HTML;
185
  * @param string $name
186
  */
187
  public function show_on_form_builder( $name = '' ) {
188
- $field = FrmFieldsHelper::setup_edit_vars( $this->field );
189
  $include_file = $this->include_form_builder_file();
190
 
191
  if ( ! empty( $include_file ) ) {
@@ -206,11 +203,8 @@ DEFAULT_HTML;
206
  protected function include_on_form_builder( $name, $field ) {
207
  $field_name = $this->html_name( $name );
208
  $html_id = $this->html_id();
209
- $read_only = $field['read_only'];
210
-
211
- $field['html_name'] = $field_name;
212
- $field['html_id'] = $html_id;
213
- $field['default_value'] = maybe_unserialize( $field['default_value'] );
214
 
215
  $display = $this->display_field_settings();
216
  include( $this->include_form_builder_file() );
@@ -224,49 +218,44 @@ DEFAULT_HTML;
224
  }
225
 
226
  protected function builder_text_field( $name = '' ) {
227
- $read_only = FrmField::get_option( $this->field, 'read_only' );
228
-
229
- return '<input type="text" name="' . esc_attr( $this->html_name( $name ) ) . '" id="' . esc_attr( $this->html_id() ) . '" value="' . esc_attr( $this->get_field_column( 'default_value' ) ) . '" placeholder="' . esc_attr( FrmField::get_option( $this->field, 'placeholder' ) ) . '" ' . ( $read_only ? ' readonly="readonly" disabled="disabled"' : '' ) . ' />';
230
  }
231
 
232
  protected function html_name( $name = '' ) {
233
  $prefix = empty( $name ) ? 'item_meta' : $name;
234
-
235
  return $prefix . '[' . $this->get_field_column( 'id' ) . ']';
236
  }
237
 
238
  protected function html_id( $plus = '' ) {
239
  return apply_filters( 'frm_field_get_html_id', 'field_' . $this->get_field_column( 'field_key' ) . $plus, $this->field );
240
- }
241
 
242
  public function display_field_settings() {
243
- $default_settings = $this->default_field_settings();
244
  $field_type_settings = $this->field_settings_for_type();
245
-
246
  return array_merge( $default_settings, $field_type_settings );
247
  }
248
 
249
  protected function default_field_settings() {
250
  return array(
251
- 'type' => $this->type,
252
- 'label' => true,
253
- 'required' => true,
254
- 'unique' => false,
255
- 'read_only' => false,
256
- 'description' => true,
257
- 'options' => true,
258
  'label_position' => true,
259
- 'invalid' => false,
260
- 'size' => false,
261
- 'clear_on_focus' => false, // Shows the placeholder option.
262
- 'css' => true,
263
- 'conf_field' => false,
264
- 'max' => true,
265
- 'range' => false,
266
- 'captcha_size' => false,
267
- 'format' => false,
268
- 'show_image' => false,
269
- 'default' => true,
270
  );
271
  }
272
 
@@ -275,16 +264,15 @@ DEFAULT_HTML;
275
  if ( ! $this->has_input ) {
276
  $settings = $this->no_input_settings();
277
  }
278
-
279
  return $settings;
280
  }
281
 
282
  private function no_input_settings() {
283
  return array(
 
284
  'required' => false,
285
  'description' => false,
286
  'label_position' => false,
287
- 'default' => false,
288
  );
289
  }
290
 
@@ -299,7 +287,6 @@ DEFAULT_HTML;
299
  'name',
300
  'description',
301
  'default_value',
302
- 'placeholder',
303
  'required_indicator',
304
  'invalid',
305
  'blank',
@@ -309,7 +296,6 @@ DEFAULT_HTML;
309
 
310
  public function form_builder_classes( $display_type ) {
311
  $classes = 'form-field edit_form_item frm_field_box frm_top_container frm_not_divider edit_field_type_' . $display_type;
312
-
313
  return $this->alter_builder_classes( $classes );
314
  }
315
 
@@ -324,66 +310,11 @@ DEFAULT_HTML;
324
  do_action( 'frm_' . $field['type'] . '_field_options_form', $field, $display, $values );
325
  }
326
 
327
- /**
328
- * @since 4.0
329
- * @param array $args - Includes 'field', 'display', and 'values'
330
- */
331
- public function show_primary_options( $args ) {
332
- do_action( 'frm_' . $args['field']['type'] . '_primary_field_options', $args );
333
- }
334
-
335
- /**
336
- * This is called for any fields with set options (radio, checkbox, select, dynamic, lookup).
337
- *
338
- * @since 4.0
339
- * @param array $args - Includes 'field', 'display', and 'values'
340
- */
341
- public function show_extra_field_choices( $args ) {
342
- return;
343
- }
344
-
345
- /**
346
- * This is called right after the default value settings.
347
- *
348
- * @since 4.0
349
- * @param array $args - Includes 'field', 'display'.
350
- */
351
- public function show_after_default( $args ) {
352
- return;
353
- }
354
-
355
- /**
356
- * @since 4.0
357
- */
358
- public function default_value_to_string( &$default_value ) {
359
- if ( ! is_array( $default_value ) ) {
360
- return;
361
- }
362
-
363
- if ( empty( array_filter( $default_value ) ) ) {
364
- $default_value = '';
365
- } else {
366
- $default_value = implode( $default_value, ',' );
367
- }
368
- }
369
-
370
- /**
371
- * @since 4.0
372
- * @param array $args - Includes 'field', 'display', and 'values'
373
- */
374
- protected function auto_width_setting( $args ) {
375
- $use_style = ( ! isset( $args['values']['custom_style'] ) || $args['values']['custom_style'] );
376
- if ( $use_style ) {
377
- $field = $args['field'];
378
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/automatic-width.php' );
379
- }
380
- }
381
-
382
  /** New field **/
383
 
384
  public function get_new_field_defaults() {
385
  $frm_settings = FrmAppHelper::get_settings();
386
- $field = array(
387
  'name' => $this->get_new_field_name(),
388
  'description' => '',
389
  'type' => $this->type,
@@ -397,7 +328,6 @@ DEFAULT_HTML;
397
  );
398
 
399
  $field_options = $this->new_field_settings();
400
-
401
  return array_merge( $field, $field_options );
402
  }
403
 
@@ -406,7 +336,7 @@ DEFAULT_HTML;
406
  $message = '';
407
  } else {
408
  $frm_settings = FrmAppHelper::get_settings();
409
- $message = $frm_settings->unique_msg;
410
  }
411
 
412
  return $message;
@@ -417,7 +347,6 @@ DEFAULT_HTML;
417
  if ( $field_name == '' ) {
418
  $invalid = __( 'This field is invalid', 'formidable' );
419
  } else {
420
- /* translators: %s: The field name. */
421
  $invalid = sprintf( __( '%s is invalid', 'formidable' ), $field_name );
422
  }
423
 
@@ -442,31 +371,30 @@ DEFAULT_HTML;
442
  }
443
 
444
  public function get_default_field_options() {
445
- $opts = array(
446
- 'size' => '',
447
- 'max' => '',
448
- 'label' => '',
449
- 'blank' => '',
450
  'required_indicator' => '*',
451
- 'invalid' => '',
452
- 'separate_value' => 0,
453
- 'clear_on_focus' => 0,
454
- 'classes' => '',
455
- 'custom_html' => '',
456
- 'minnum' => 1,
457
- 'maxnum' => 10,
458
- 'step' => 1,
459
- 'format' => '',
460
- 'placeholder' => '',
461
  );
462
  $field_opts = $this->extra_field_opts();
463
- $opts = array_merge( $opts, $field_opts );
464
 
465
  $filter_args = array(
466
  'field' => $this->field,
467
  'type' => $this->type,
468
  );
469
-
470
  return apply_filters( 'frm_default_field_options', $opts, $filter_args );
471
  }
472
 
@@ -484,7 +412,6 @@ DEFAULT_HTML;
484
  */
485
  public function prepare_front_field( $values, $atts ) {
486
  $values['value'] = $this->prepare_field_value( $values['value'], $atts );
487
-
488
  return $values;
489
  }
490
 
@@ -539,21 +466,20 @@ DEFAULT_HTML;
539
  $args = $this->fill_display_field_values( $args );
540
 
541
  if ( $this->has_html ) {
542
- $args['html'] = $this->before_replace_html_shortcodes( $args, $this->field['custom_html'] );
543
- $args['errors'] = is_array( $args['errors'] ) ? $args['errors'] : array();
544
  $args['field_obj'] = $this;
545
 
546
  $label = FrmFieldsHelper::label_position( $this->field['label'], $this->field, $args['form'] );
547
  $this->set_field_column( 'label', $label );
548
 
549
  $html_shortcode = new FrmFieldFormHtml( $args );
550
- $html = $html_shortcode->get_html();
551
- $html = $this->after_replace_html_shortcodes( $args, $html );
552
  $html_shortcode->remove_collapse_shortcode( $html );
553
  } else {
554
  $html = $this->include_front_field_input( $args, array() );
555
  }
556
-
557
  return $html;
558
  }
559
 
@@ -572,19 +498,13 @@ DEFAULT_HTML;
572
  }
573
 
574
  public function get_container_class() {
575
- $is_radio = FrmField::is_radio( $this->field );
576
  $is_checkbox = FrmField::is_checkbox( $this->field );
577
- $align = FrmField::get_option( $this->field, 'align' );
578
 
579
  $class = '';
580
  if ( ! empty( $align ) && ( $is_radio || $is_checkbox ) ) {
581
- if ( 'inline' === $align ) {
582
- $class .= ' horizontal_radio';
583
- } elseif ( 'block' === $align ) {
584
- $class .= ' vertical_radio';
585
- } else {
586
- $class .= ' ' . $align;
587
- }
588
  }
589
 
590
  return $class;
@@ -600,7 +520,7 @@ DEFAULT_HTML;
600
  * @since 3.02
601
  */
602
  protected function add_input_class() {
603
- $input_class = FrmField::get_option( $this->field, 'input_class' );
604
  $extra_classes = $this->get_input_class();
605
  if ( ! empty( $extra_classes ) ) {
606
  $input_class .= ' ' . $extra_classes;
@@ -658,10 +578,10 @@ DEFAULT_HTML;
658
 
659
  $hidden = $this->maybe_include_hidden_values( $args );
660
 
661
- $field = $this->field;
662
- $html_id = $args['html_id'];
663
  $field_name = $args['field_name'];
664
- $read_only = FrmField::is_read_only( $this->field ) && ! FrmAppHelper::is_admin();
665
  unset( $args['form'] ); // lighten up on memory usage
666
 
667
  ob_start();
@@ -683,7 +603,6 @@ DEFAULT_HTML;
683
 
684
  protected function html5_input_type() {
685
  $frm_settings = FrmAppHelper::get_settings();
686
-
687
  return $frm_settings->use_html ? $this->type : 'text';
688
  }
689
 
@@ -725,12 +644,11 @@ DEFAULT_HTML;
725
  }
726
 
727
  protected function maybe_include_hidden_values( $args ) {
728
- $hidden = '';
729
  $is_read_only = FrmField::is_read_only( $this->field ) && ! FrmAppHelper::is_admin();
730
  if ( $is_read_only && $this->show_readonly_hidden() ) {
731
  $hidden = $this->show_hidden_values( $args );
732
  }
733
-
734
  return $hidden;
735
  }
736
 
@@ -752,7 +670,7 @@ DEFAULT_HTML;
752
 
753
  protected function show_hidden_values( $args ) {
754
  $selected_value = isset( $args['field_value'] ) ? $args['field_value'] : $this->field['value'];
755
- $hidden = '';
756
  if ( is_array( $selected_value ) ) {
757
  $args['save_array'] = true;
758
  foreach ( $selected_value as $selected ) {
@@ -760,7 +678,7 @@ DEFAULT_HTML;
760
  }
761
  } else {
762
  $args['save_array'] = $this->is_readonly_array();
763
- $hidden .= $this->show_single_hidden( $selected_value, $args );
764
  }
765
 
766
  return $hidden;
@@ -769,7 +687,7 @@ DEFAULT_HTML;
769
  protected function show_single_hidden( $selected, $args ) {
770
  if ( $args['save_array'] ) {
771
  $args['field_name'] .= '[]';
772
- $id = '';
773
  } else {
774
  $id = ' id="' . esc_attr( $args['html_id'] ) . '"';
775
  }
@@ -781,17 +699,17 @@ DEFAULT_HTML;
781
  * @since 3.0
782
  */
783
  protected function get_select_box( $values ) {
784
- $options = $this->get_field_column( 'options' );
785
  $selected = $values['field_value'];
786
 
787
  if ( isset( $values['combo_name'] ) ) {
788
- $options = $options[ $values['combo_name'] ];
789
  $selected = ( is_array( $selected ) && isset( $selected[ $values['combo_name'] ] ) ) ? $selected[ $values['combo_name'] ] : '';
790
  }
791
 
792
  $input = $this->select_tag( $values );
793
 
794
- foreach ( $options as $option ) {
795
  $input .= '<option value="' . esc_attr( $option ) . '" ' . selected( $selected, $option, false ) . '>';
796
  $input .= esc_html( $option );
797
  $input .= '</option>';
@@ -805,14 +723,13 @@ DEFAULT_HTML;
805
  * @since 3.0
806
  */
807
  protected function select_tag( $values ) {
808
- $field = isset( $values['field'] ) ? $values['field'] : $this->field;
809
- $input_html = $this->get_field_input_html_hook( $field );
810
  $select_atts = $this->get_select_atributes( $values );
811
- $select = '';
812
  foreach ( $select_atts as $name => $value ) {
813
  $select .= $name . '="' . esc_attr( $value ) . '" ';
814
  }
815
-
816
  return '<select ' . $select . $input_html . '>';
817
  }
818
 
@@ -820,16 +737,16 @@ DEFAULT_HTML;
820
  * @since 3.0
821
  */
822
  protected function get_select_atributes( $values ) {
823
- $readonly = ( FrmField::is_read_only( $this->field ) && ! FrmAppHelper::is_admin() );
824
  $select_atts = array();
825
  if ( ! $readonly ) {
826
  if ( isset( $values['combo_name'] ) ) {
827
  $values['field_name'] .= '[' . $values['combo_name'] . ']';
828
- $values['html_id'] .= '_' . $values['combo_name'];
829
  }
830
 
831
  $select_atts['name'] = $values['field_name'];
832
- $select_atts['id'] = $values['html_id'];
833
  }
834
 
835
  return $select_atts;
@@ -840,13 +757,13 @@ DEFAULT_HTML;
840
  }
841
 
842
  protected function fill_display_field_values( $args = array() ) {
843
- $defaults = array(
844
  'field_name' => 'item_meta[' . $this->get_field_column( 'id' ) . ']',
845
  'field_id' => $this->get_field_column( 'id' ),
846
  'field_plus_id' => '',
847
  'section_id' => '',
848
  );
849
- $args = wp_parse_args( $args, $defaults );
850
  $args['html_id'] = $this->html_id( $args['field_plus_id'] );
851
 
852
  if ( FrmField::is_multiple_select( $this->field ) ) {
@@ -889,7 +806,6 @@ DEFAULT_HTML;
889
 
890
  /**
891
  * @param array $args
892
- *
893
  * @return array
894
  */
895
  public function validate( $args ) {
@@ -901,7 +817,6 @@ DEFAULT_HTML;
901
  if ( FrmAppHelper::pro_is_installed() ) {
902
  $exists = FrmProEntryMetaHelper::value_exists( $this->get_field_column( 'id' ), $value, $entry_id );
903
  }
904
-
905
  return $exists;
906
  }
907
 
@@ -937,11 +852,10 @@ DEFAULT_HTML;
937
  if ( isset( $atts['show'] ) && $atts['show'] && isset( $value[ $atts['show'] ] ) ) {
938
  $value = $value[ $atts['show'] ];
939
  } elseif ( ! isset( $atts['return_array'] ) || ! $atts['return_array'] ) {
940
- $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
941
  $value = implode( $sep, $value );
942
  }
943
  }
944
-
945
  return $value;
946
  }
947
 
@@ -949,7 +863,7 @@ DEFAULT_HTML;
949
  $defaults = array(
950
  'sep' => ', ',
951
  );
952
- $atts = wp_parse_args( $atts, $defaults );
953
  }
954
 
955
  /**
@@ -993,7 +907,6 @@ DEFAULT_HTML;
993
  *
994
  * @param $value
995
  * @param $atts
996
- *
997
  * @internal param array $meta_value
998
  * @internal param object $field
999
  * @internal param array $saved_entries
@@ -1002,7 +915,7 @@ DEFAULT_HTML;
1002
  */
1003
  protected function get_new_child_ids( $value, $atts ) {
1004
  $saved_entries = $atts['ids'];
1005
- $new_value = array();
1006
  foreach ( (array) $value as $old_child_id ) {
1007
  if ( isset( $saved_entries[ $old_child_id ] ) ) {
1008
  $new_value[] = $saved_entries[ $old_child_id ];
80
  if ( property_exists( $this, $key ) ) {
81
  $value = $this->{$key};
82
  }
 
83
  return $value;
84
  }
85
 
107
  } elseif ( is_array( $this->field ) && isset( $this->field[ $column ] ) ) {
108
  $field_val = $this->field[ $column ];
109
  }
 
110
  return $field_val;
111
  }
112
 
173
  } else {
174
  $for = '';
175
  }
 
176
  return $for;
177
  }
178
 
182
  * @param string $name
183
  */
184
  public function show_on_form_builder( $name = '' ) {
185
+ $field = FrmFieldsHelper::setup_edit_vars( $this->field );
186
  $include_file = $this->include_form_builder_file();
187
 
188
  if ( ! empty( $include_file ) ) {
203
  protected function include_on_form_builder( $name, $field ) {
204
  $field_name = $this->html_name( $name );
205
  $html_id = $this->html_id();
206
+ $field['html_name'] = $field_name;
207
+ $field['html_id'] = $html_id;
 
 
 
208
 
209
  $display = $this->display_field_settings();
210
  include( $this->include_form_builder_file() );
218
  }
219
 
220
  protected function builder_text_field( $name = '' ) {
221
+ return '<input type="text" name="' . esc_attr( $this->html_name( $name ) ) . '" id="' . esc_attr( $this->html_id() ) . '" value="' . esc_attr( $this->get_field_column( 'default_value' ) ) . '" class="dyn_default_value" />';
 
 
222
  }
223
 
224
  protected function html_name( $name = '' ) {
225
  $prefix = empty( $name ) ? 'item_meta' : $name;
 
226
  return $prefix . '[' . $this->get_field_column( 'id' ) . ']';
227
  }
228
 
229
  protected function html_id( $plus = '' ) {
230
  return apply_filters( 'frm_field_get_html_id', 'field_' . $this->get_field_column( 'field_key' ) . $plus, $this->field );
231
+ }
232
 
233
  public function display_field_settings() {
234
+ $default_settings = $this->default_field_settings();
235
  $field_type_settings = $this->field_settings_for_type();
 
236
  return array_merge( $default_settings, $field_type_settings );
237
  }
238
 
239
  protected function default_field_settings() {
240
  return array(
241
+ 'type' => $this->type,
242
+ 'required' => true,
243
+ 'unique' => false,
244
+ 'read_only' => false,
245
+ 'description' => true,
246
+ 'options' => true,
 
247
  'label_position' => true,
248
+ 'invalid' => false,
249
+ 'size' => false,
250
+ 'clear_on_focus' => false,
251
+ 'default_blank' => true,
252
+ 'css' => true,
253
+ 'conf_field' => false,
254
+ 'max' => true,
255
+ 'range' => false,
256
+ 'captcha_size' => false,
257
+ 'format' => false,
258
+ 'show_image' => false,
259
  );
260
  }
261
 
264
  if ( ! $this->has_input ) {
265
  $settings = $this->no_input_settings();
266
  }
 
267
  return $settings;
268
  }
269
 
270
  private function no_input_settings() {
271
  return array(
272
+ 'default_blank' => false,
273
  'required' => false,
274
  'description' => false,
275
  'label_position' => false,
 
276
  );
277
  }
278
 
287
  'name',
288
  'description',
289
  'default_value',
 
290
  'required_indicator',
291
  'invalid',
292
  'blank',
296
 
297
  public function form_builder_classes( $display_type ) {
298
  $classes = 'form-field edit_form_item frm_field_box frm_top_container frm_not_divider edit_field_type_' . $display_type;
 
299
  return $this->alter_builder_classes( $classes );
300
  }
301
 
310
  do_action( 'frm_' . $field['type'] . '_field_options_form', $field, $display, $values );
311
  }
312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  /** New field **/
314
 
315
  public function get_new_field_defaults() {
316
  $frm_settings = FrmAppHelper::get_settings();
317
+ $field = array(
318
  'name' => $this->get_new_field_name(),
319
  'description' => '',
320
  'type' => $this->type,
328
  );
329
 
330
  $field_options = $this->new_field_settings();
 
331
  return array_merge( $field, $field_options );
332
  }
333
 
336
  $message = '';
337
  } else {
338
  $frm_settings = FrmAppHelper::get_settings();
339
+ $message = $frm_settings->unique_msg;
340
  }
341
 
342
  return $message;
347
  if ( $field_name == '' ) {
348
  $invalid = __( 'This field is invalid', 'formidable' );
349
  } else {
 
350
  $invalid = sprintf( __( '%s is invalid', 'formidable' ), $field_name );
351
  }
352
 
371
  }
372
 
373
  public function get_default_field_options() {
374
+ $opts = array(
375
+ 'size' => '',
376
+ 'max' => '',
377
+ 'label' => '',
378
+ 'blank' => '',
379
  'required_indicator' => '*',
380
+ 'invalid' => '',
381
+ 'separate_value' => 0,
382
+ 'clear_on_focus' => 0,
383
+ 'default_blank' => 0,
384
+ 'classes' => '',
385
+ 'custom_html' => '',
386
+ 'minnum' => 1,
387
+ 'maxnum' => 10,
388
+ 'step' => 1,
389
+ 'format' => '',
390
  );
391
  $field_opts = $this->extra_field_opts();
392
+ $opts = array_merge( $opts, $field_opts );
393
 
394
  $filter_args = array(
395
  'field' => $this->field,
396
  'type' => $this->type,
397
  );
 
398
  return apply_filters( 'frm_default_field_options', $opts, $filter_args );
399
  }
400
 
412
  */
413
  public function prepare_front_field( $values, $atts ) {
414
  $values['value'] = $this->prepare_field_value( $values['value'], $atts );
 
415
  return $values;
416
  }
417
 
466
  $args = $this->fill_display_field_values( $args );
467
 
468
  if ( $this->has_html ) {
469
+ $args['html'] = $this->before_replace_html_shortcodes( $args, $this->field['custom_html'] );
470
+ $args['errors'] = is_array( $args['errors'] ) ? $args['errors'] : array();
471
  $args['field_obj'] = $this;
472
 
473
  $label = FrmFieldsHelper::label_position( $this->field['label'], $this->field, $args['form'] );
474
  $this->set_field_column( 'label', $label );
475
 
476
  $html_shortcode = new FrmFieldFormHtml( $args );
477
+ $html = $html_shortcode->get_html();
478
+ $html = $this->after_replace_html_shortcodes( $args, $html );
479
  $html_shortcode->remove_collapse_shortcode( $html );
480
  } else {
481
  $html = $this->include_front_field_input( $args, array() );
482
  }
 
483
  return $html;
484
  }
485
 
498
  }
499
 
500
  public function get_container_class() {
501
+ $is_radio = FrmField::is_radio( $this->field );
502
  $is_checkbox = FrmField::is_checkbox( $this->field );
503
+ $align = FrmField::get_option( $this->field, 'align' );
504
 
505
  $class = '';
506
  if ( ! empty( $align ) && ( $is_radio || $is_checkbox ) ) {
507
+ $class .= ( 'inline' === $align ) ? ' horizontal_radio' : ' vertical_radio';
 
 
 
 
 
 
508
  }
509
 
510
  return $class;
520
  * @since 3.02
521
  */
522
  protected function add_input_class() {
523
+ $input_class = FrmField::get_option( $this->field, 'input_class' );
524
  $extra_classes = $this->get_input_class();
525
  if ( ! empty( $extra_classes ) ) {
526
  $input_class .= ' ' . $extra_classes;
578
 
579
  $hidden = $this->maybe_include_hidden_values( $args );
580
 
581
+ $field = $this->field;
582
+ $html_id = $args['html_id'];
583
  $field_name = $args['field_name'];
584
+ $read_only = FrmField::is_read_only( $this->field ) && ! FrmAppHelper::is_admin();
585
  unset( $args['form'] ); // lighten up on memory usage
586
 
587
  ob_start();
603
 
604
  protected function html5_input_type() {
605
  $frm_settings = FrmAppHelper::get_settings();
 
606
  return $frm_settings->use_html ? $this->type : 'text';
607
  }
608
 
644
  }
645
 
646
  protected function maybe_include_hidden_values( $args ) {
647
+ $hidden = '';
648
  $is_read_only = FrmField::is_read_only( $this->field ) && ! FrmAppHelper::is_admin();
649
  if ( $is_read_only && $this->show_readonly_hidden() ) {
650
  $hidden = $this->show_hidden_values( $args );
651
  }
 
652
  return $hidden;
653
  }
654
 
670
 
671
  protected function show_hidden_values( $args ) {
672
  $selected_value = isset( $args['field_value'] ) ? $args['field_value'] : $this->field['value'];
673
+ $hidden = '';
674
  if ( is_array( $selected_value ) ) {
675
  $args['save_array'] = true;
676
  foreach ( $selected_value as $selected ) {
678
  }
679
  } else {
680
  $args['save_array'] = $this->is_readonly_array();
681
+ $hidden .= $this->show_single_hidden( $selected_value, $args );
682
  }
683
 
684
  return $hidden;
687
  protected function show_single_hidden( $selected, $args ) {
688
  if ( $args['save_array'] ) {
689
  $args['field_name'] .= '[]';
690
+ $id = '';
691
  } else {
692
  $id = ' id="' . esc_attr( $args['html_id'] ) . '"';
693
  }
699
  * @since 3.0
700
  */
701
  protected function get_select_box( $values ) {
702
+ $options = $this->get_field_column( 'options' );
703
  $selected = $values['field_value'];
704
 
705
  if ( isset( $values['combo_name'] ) ) {
706
+ $options = $options[ $values['combo_name'] ];
707
  $selected = ( is_array( $selected ) && isset( $selected[ $values['combo_name'] ] ) ) ? $selected[ $values['combo_name'] ] : '';
708
  }
709
 
710
  $input = $this->select_tag( $values );
711
 
712
+ foreach ( $options as $option ) {
713
  $input .= '<option value="' . esc_attr( $option ) . '" ' . selected( $selected, $option, false ) . '>';
714
  $input .= esc_html( $option );
715
  $input .= '</option>';
723
  * @since 3.0
724
  */
725
  protected function select_tag( $values ) {
726
+ $field = isset( $values['field'] ) ? $values['field'] : $this->field;
727
+ $input_html = $this->get_field_input_html_hook( $field );
728
  $select_atts = $this->get_select_atributes( $values );
729
+ $select = '';
730
  foreach ( $select_atts as $name => $value ) {
731
  $select .= $name . '="' . esc_attr( $value ) . '" ';
732
  }
 
733
  return '<select ' . $select . $input_html . '>';
734
  }
735
 
737
  * @since 3.0
738
  */
739
  protected function get_select_atributes( $values ) {
740
+ $readonly = ( FrmField::is_read_only( $this->field ) && ! FrmAppHelper::is_admin() );
741
  $select_atts = array();
742
  if ( ! $readonly ) {
743
  if ( isset( $values['combo_name'] ) ) {
744
  $values['field_name'] .= '[' . $values['combo_name'] . ']';
745
+ $values['html_id'] .= '_' . $values['combo_name'];
746
  }
747
 
748
  $select_atts['name'] = $values['field_name'];
749
+ $select_atts['id'] = $values['html_id'];
750
  }
751
 
752
  return $select_atts;
757
  }
758
 
759
  protected function fill_display_field_values( $args = array() ) {
760
+ $defaults = array(
761
  'field_name' => 'item_meta[' . $this->get_field_column( 'id' ) . ']',
762
  'field_id' => $this->get_field_column( 'id' ),
763
  'field_plus_id' => '',
764
  'section_id' => '',
765
  );
766
+ $args = wp_parse_args( $args, $defaults );
767
  $args['html_id'] = $this->html_id( $args['field_plus_id'] );
768
 
769
  if ( FrmField::is_multiple_select( $this->field ) ) {
806
 
807
  /**
808
  * @param array $args
 
809
  * @return array
810
  */
811
  public function validate( $args ) {
817
  if ( FrmAppHelper::pro_is_installed() ) {
818
  $exists = FrmProEntryMetaHelper::value_exists( $this->get_field_column( 'id' ), $value, $entry_id );
819
  }
 
820
  return $exists;
821
  }
822
 
852
  if ( isset( $atts['show'] ) && $atts['show'] && isset( $value[ $atts['show'] ] ) ) {
853
  $value = $value[ $atts['show'] ];
854
  } elseif ( ! isset( $atts['return_array'] ) || ! $atts['return_array'] ) {
855
+ $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
856
  $value = implode( $sep, $value );
857
  }
858
  }
 
859
  return $value;
860
  }
861
 
863
  $defaults = array(
864
  'sep' => ', ',
865
  );
866
+ $atts = wp_parse_args( $atts, $defaults );
867
  }
868
 
869
  /**
907
  *
908
  * @param $value
909
  * @param $atts
 
910
  * @internal param array $meta_value
911
  * @internal param object $field
912
  * @internal param array $saved_entries
915
  */
916
  protected function get_new_child_ids( $value, $atts ) {
917
  $saved_entries = $atts['ids'];
918
+ $new_value = array();
919
  foreach ( (array) $value as $old_child_id ) {
920
  if ( isset( $saved_entries[ $old_child_id ] ) ) {
921
  $new_value[] = $saved_entries[ $old_child_id ];
classes/models/fields/FrmFieldUrl.php CHANGED
@@ -36,10 +36,10 @@ class FrmFieldUrl extends FrmFieldType {
36
 
37
  protected function fill_default_atts( &$atts ) {
38
  $defaults = array(
39
- 'sep' => ', ',
40
  'html' => false,
41
  );
42
- $atts = wp_parse_args( $atts, $defaults );
43
 
44
  if ( $atts['html'] ) {
45
  $atts['sep'] = ' ';
@@ -74,7 +74,7 @@ class FrmFieldUrl extends FrmFieldType {
74
  $images = '';
75
  foreach ( (array) $value as $url ) {
76
  $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/';
77
- $is_image = preg_match( $image_regex, $url );
78
  if ( $is_image ) {
79
  $images .= '<img src="' . esc_attr( $url ) . '" class="frm_image_from_url" alt="" /> ';
80
  } else {
36
 
37
  protected function fill_default_atts( &$atts ) {
38
  $defaults = array(
39
+ 'sep' => ', ',
40
  'html' => false,
41
  );
42
+ $atts = wp_parse_args( $atts, $defaults );
43
 
44
  if ( $atts['html'] ) {
45
  $atts['sep'] = ' ';
74
  $images = '';
75
  foreach ( (array) $value as $url ) {
76
  $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/';
77
+ $is_image = preg_match( $image_regex, $url );
78
  if ( $is_image ) {
79
  $images .= '<img src="' . esc_attr( $url ) . '" class="frm_image_from_url" alt="" /> ';
80
  } else {
classes/models/fields/FrmFieldUserID.php CHANGED
@@ -39,11 +39,11 @@ class FrmFieldUserID extends FrmFieldType {
39
  public function prepare_field_html( $args ) {
40
  $args = $this->fill_display_field_values( $args );
41
 
42
- $user_ID = get_current_user_id();
43
- $user_ID = ( $user_ID ? $user_ID : '' );
44
  $posted_value = ( FrmAppHelper::is_admin() && $_POST && isset( $_POST['item_meta'][ $this->field['id'] ] ) ); // WPCS: CSRF ok.
45
- $updating = ( isset( $args['action'] ) && $args['action'] == 'update' );
46
- $value = ( is_numeric( $this->field['value'] ) || $posted_value || $updating ) ? $this->field['value'] : $user_ID;
47
 
48
  echo '<input type="hidden" name="' . esc_attr( $args['field_name'] ) . '" id="' . esc_attr( $args['html_id'] ) . '" value="' . esc_attr( $value ) . '" data-frmval="' . esc_attr( $value ) . '"/>' . "\n";
49
  }
@@ -73,7 +73,6 @@ class FrmFieldUserID extends FrmFieldType {
73
  */
74
  protected function prepare_display_value( $value, $atts ) {
75
  $user_info = $this->prepare_user_info_attribute( $atts );
76
-
77
  return FrmFieldsHelper::get_user_display_name( $value, $user_info, $atts );
78
  }
79
 
@@ -83,7 +82,6 @@ class FrmFieldUserID extends FrmFieldType {
83
  * From the get_display_name() function
84
  *
85
  * @since 3.0
86
- *
87
  * @param $atts
88
  *
89
  * @return string
39
  public function prepare_field_html( $args ) {
40
  $args = $this->fill_display_field_values( $args );
41
 
42
+ $user_ID = get_current_user_id();
43
+ $user_ID = ( $user_ID ? $user_ID : '' );
44
  $posted_value = ( FrmAppHelper::is_admin() && $_POST && isset( $_POST['item_meta'][ $this->field['id'] ] ) ); // WPCS: CSRF ok.
45
+ $updating = ( isset( $args['action'] ) && $args['action'] == 'update' );
46
+ $value = ( is_numeric( $this->field['value'] ) || $posted_value || $updating ) ? $this->field['value'] : $user_ID;
47
 
48
  echo '<input type="hidden" name="' . esc_attr( $args['field_name'] ) . '" id="' . esc_attr( $args['html_id'] ) . '" value="' . esc_attr( $value ) . '" data-frmval="' . esc_attr( $value ) . '"/>' . "\n";
49
  }
73
  */
74
  protected function prepare_display_value( $value, $atts ) {
75
  $user_info = $this->prepare_user_info_attribute( $atts );
 
76
  return FrmFieldsHelper::get_user_display_name( $value, $user_info, $atts );
77
  }
78
 
82
  * From the get_display_name() function
83
  *
84
  * @since 3.0
 
85
  * @param $atts
86
  *
87
  * @return string
classes/views/addons/list.php CHANGED
@@ -1,12 +1,6 @@
1
  <div class="frm_wrap" id="frm-addons-page">
2
- <?php
3
- FrmAppHelper::get_admin_header(
4
- array(
5
- 'label' => __( 'Formidable Add-Ons', 'formidable' ),
6
- )
7
- );
8
- ?>
9
- <div class="wrap">
10
 
11
  <?php include( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' ); ?>
12
 
@@ -20,45 +14,34 @@
20
  </div>
21
  <?php } ?>
22
  <h2>
23
- <?php echo esc_html( $addon['title'] ); ?>
24
  </h2>
25
- <p>
26
- <?php echo esc_html( $addon['excerpt'] ); ?>
27
- <?php if ( isset( $addon['docs'] ) && ! empty( $addon['docs'] ) && $addon['installed'] ) { ?>
28
- <br/><a href="<?php echo esc_url( $addon['docs'] ); ?>" target="_blank" aria-label="<?php esc_attr_e( 'View Docs', 'formidable' ); ?>">
29
- <?php esc_html_e( 'View Docs', 'formidable' ); ?>
30
- </a>
31
- <?php } ?>
32
- </p>
33
- <?php
34
- $plan_required = FrmFormsHelper::get_plan_required( $addon );
35
- FrmFormsHelper::show_plan_required( $addon, $pricing . '&utm_content=' . $addon['slug'] );
36
- ?>
37
  </div>
38
  <div class="plugin-card-bottom">
39
  <span class="addon-status">
40
  <?php
41
  printf(
42
- /* translators: %s: Status name */
43
  esc_html__( 'Status: %s', 'formidable' ),
44
  '<span class="addon-status-label">' . esc_html( $addon['status']['label'] ) . '</span>'
45
  );
46
  ?>
47
  </span>
48
  <?php if ( $addon['status']['type'] === 'installed' ) { ?>
49
- <a rel="<?php echo esc_attr( $addon['plugin'] ); ?>" class="button button-primary frm-button-primary frm-activate-addon <?php echo esc_attr( empty( $addon['activate_url'] ) ? 'frm_hidden' : '' ); ?>">
50
  <?php esc_html_e( 'Activate', 'formidable' ); ?>
51
  </a>
52
  <?php } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) { ?>
53
  <a class="frm-install-addon button button-primary frm-button-primary" rel="<?php echo esc_attr( $addon['url'] ); ?>" aria-label="<?php esc_attr_e( 'Install', 'formidable' ); ?>">
54
  <?php esc_html_e( 'Install', 'formidable' ); ?>
55
  </a>
56
- <?php } elseif ( ! empty( $license_type ) && $license_type === strtolower( $plan_required ) ) { ?>
57
- <a class="install-now button button-secondary frm-button-secondary" href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( 'addons', 'account/licenses/' ) . '&utm_content=' . $addon['slug'] ); ?>" target="_blank" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
58
- <?php esc_html_e( 'Renew Now', 'formidable' ); ?>
59
- </a>
60
  <?php } else { ?>
61
- <a class="install-now button button-secondary frm-button-secondary" href="<?php echo esc_url( $pricing . '&utm_content=' . $addon['slug'] ); ?>" target="_blank" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
62
  <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
63
  </a>
64
  <?php } ?>
1
  <div class="frm_wrap" id="frm-addons-page">
2
+ <div class="wrap">
3
+ <h1><?php esc_html_e( 'Formidable Add-Ons', 'formidable' ); ?></h1>
 
 
 
 
 
 
4
 
5
  <?php include( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' ); ?>
6
 
14
  </div>
15
  <?php } ?>
16
  <h2>
17
+ <?php echo esc_html( $addon['title'] ) ?>
18
  </h2>
19
+ <p><?php echo esc_html( $addon['excerpt'] ); ?></p>
20
+ <?php if ( isset( $addon['docs'] ) && ! empty( $addon['docs'] ) && $addon['installed'] ) { ?>
21
+ <a href="<?php echo esc_url( $addon['docs'] ); ?>" target="_blank" aria-label="<?php esc_attr_e( 'View Docs', 'formidable' ); ?>">
22
+ <?php esc_html_e( 'View Docs', 'formidable' ); ?>
23
+ </a>
24
+ <?php } ?>
 
 
 
 
 
 
25
  </div>
26
  <div class="plugin-card-bottom">
27
  <span class="addon-status">
28
  <?php
29
  printf(
 
30
  esc_html__( 'Status: %s', 'formidable' ),
31
  '<span class="addon-status-label">' . esc_html( $addon['status']['label'] ) . '</span>'
32
  );
33
  ?>
34
  </span>
35
  <?php if ( $addon['status']['type'] === 'installed' ) { ?>
36
+ <a rel="<?php echo esc_attr( $addon['plugin'] ) ?>" class="button button-primary frm-button-primary frm-activate-addon <?php echo esc_attr( empty( $addon['activate_url'] ) ? 'frm_hidden' : '' ); ?>">
37
  <?php esc_html_e( 'Activate', 'formidable' ); ?>
38
  </a>
39
  <?php } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) { ?>
40
  <a class="frm-install-addon button button-primary frm-button-primary" rel="<?php echo esc_attr( $addon['url'] ); ?>" aria-label="<?php esc_attr_e( 'Install', 'formidable' ); ?>">
41
  <?php esc_html_e( 'Install', 'formidable' ); ?>
42
  </a>
 
 
 
 
43
  <?php } else { ?>
44
+ <a class="install-now button button-primary frm-button-primary" href="<?php echo esc_url( $pricing . '&utm_content=' . $addon['slug'] ); ?>" target="_blank" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
45
  <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
46
  </a>
47
  <?php } ?>
classes/views/addons/settings.php CHANGED
@@ -1,5 +1,5 @@
1
  <div class="wrap">
2
- <h2 class="frm-h2"><?php esc_html_e( 'Plugin Licenses', 'formidable' ); ?></h2>
3
 
4
  <?php
5
 
@@ -14,18 +14,18 @@
14
  $icon_class = ( empty( $license ) ) ? 'frm_hidden' : '';
15
  ?>
16
 
17
- <div class="edd_frm_license_row frm_grid_container">
18
- <label class="frm4 frm_form_field" for="edd_<?php echo esc_attr( $slug ); ?>_license_key"><?php echo esc_html( $plugin->plugin_name ); ?></label>
19
- <div class="edd_frm_authorized frm8 frm_form_field <?php echo esc_attr( $activate == 'activate' ) ? 'frm_hidden' : ''; ?>">
20
  <span class="edd_frm_license"><?php esc_html_e( 'Good to go!', 'formidable' ); ?></span>
21
  <span class="frm_icon_font frm_action_icon frm_error_icon edd_frm_status_icon frm_inactive_icon"></span>
22
- <input type="button" class="button-secondary frm-button-secondary edd_frm_save_license" data-plugin="<?php echo esc_attr( $slug ); ?>" name="edd_<?php echo esc_attr( $slug ); ?>_license_deactivate" value="<?php esc_attr_e( 'Deactivate', 'formidable' ); ?>"/>
23
  <p class="frm_license_msg"></p>
24
  </div>
25
- <div class="edd_frm_unauthorized frm8 frm_form_field <?php echo esc_attr( $activate == 'deactivate' ) ? 'frm_hidden' : ''; ?>">
26
- <input id="edd_<?php echo esc_attr( $slug ); ?>_license_key" name="edd_<?php echo esc_attr( $slug ); ?>_license_key" type="text" class="frm_addon_license_key auto_width" value="" />
27
  <span class="frm_icon_font frm_action_icon frm_error_icon edd_frm_status_icon <?php echo esc_attr( $icon_class ); ?>"></span>
28
- <input type="button" class="button-secondary frm-button-secondary edd_frm_save_license" data-plugin="<?php echo esc_attr( $slug ); ?>" name="edd_<?php echo esc_attr( $slug ); ?>_license_activate" value="<?php esc_attr_e( 'Activate', 'formidable' ); ?>"/>
29
  <p class="frm_license_msg"></p>
30
  </div>
31
 
1
  <div class="wrap">
2
+ <h4><?php esc_html_e( 'Plugin Licenses', 'formidable' ); ?></h4>
3
 
4
  <?php
5
 
14
  $icon_class = ( empty( $license ) ) ? 'frm_hidden' : '';
15
  ?>
16
 
17
+ <div class="edd_frm_license_row">
18
+ <label class="frm_left_label" for="edd_<?php echo esc_attr( $slug ) ?>_license_key"><?php echo esc_html( $plugin->plugin_name ); ?></label>
19
+ <div class="edd_frm_authorized alignleft <?php echo esc_attr( $activate == 'activate' ) ? 'frm_hidden' : '' ?>">
20
  <span class="edd_frm_license"><?php esc_html_e( 'Good to go!', 'formidable' ); ?></span>
21
  <span class="frm_icon_font frm_action_icon frm_error_icon edd_frm_status_icon frm_inactive_icon"></span>
22
+ <input type="button" class="button-secondary edd_frm_save_license" data-plugin="<?php echo esc_attr( $slug ) ?>" name="edd_<?php echo esc_attr( $slug ) ?>_license_deactivate" value="<?php esc_attr_e( 'Deactivate', 'formidable' ) ?>"/>
23
  <p class="frm_license_msg"></p>
24
  </div>
25
+ <div class="edd_frm_unauthorized alignleft <?php echo esc_attr( $activate == 'deactivate' ) ? 'frm_hidden' : '' ?>">
26
+ <input id="edd_<?php echo esc_attr( $slug ) ?>_license_key" name="edd_<?php echo esc_attr( $slug ) ?>_license_key" type="text" class="regular-text frm_addon_license_key" value="" />
27
  <span class="frm_icon_font frm_action_icon frm_error_icon edd_frm_status_icon <?php echo esc_attr( $icon_class ); ?>"></span>
28
+ <input type="button" class="button-secondary edd_frm_save_license" data-plugin="<?php echo esc_attr( $slug ) ?>" name="edd_<?php echo esc_attr( $slug ) ?>_license_activate" value="<?php esc_attr_e( 'Activate', 'formidable' ) ?>"/>
29
  <p class="frm_license_msg"></p>
30
  </div>
31
 
classes/views/addons/upgrade_to_pro.php CHANGED
@@ -1,6 +1,6 @@
1
- <div class="frm_wrap wrap upgrade_to_pro frm-fields">
2
  <h1 class="frm_pro_heading">
3
- <img src="<?php echo esc_url( FrmAppHelper::plugin_url() ); ?>/images/logo.png" alt="Upgrade to Pro" />
4
  <span class="alignright">Take on bigger projects, earn more clients and grow your business.<br/>
5
  <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( FrmAppHelper::admin_upgrade_link( $link_parts ) ) ); ?>" target="_blank">Upgrade to Pro</a>.</span>
6
  <span class="clear"></span>
@@ -18,9 +18,9 @@
18
  <th></th>
19
  <?php foreach ( $pro_pricing as $price_info ) { ?>
20
  <th>
21
- <h3><?php echo esc_attr( ucfirst( $price_info['name'] ) ); ?></h3>
22
- <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( FrmAppHelper::admin_upgrade_link( $link_parts ) ) ); ?>" class="button-primary frm-button-primary" target="_blank">
23
- <?php esc_html_e( 'Get Started', 'formidable' ); ?>
24
  </a>
25
  </th>
26
  <?php } ?>
@@ -82,8 +82,8 @@
82
  }
83
  ?>
84
  </th>
85
- <td><i class="frm_icon_font <?php echo esc_attr( $feature['lite'] ? 'frm_checkmark_icon' : 'frm_close_icon' ); ?>"></i></td>
86
- <td><i class="frm_icon_font frm_checkmark_icon"></i></td>
87
  </tr>
88
  <?php } ?>
89
  <?php } ?>
1
+ <div class="wrap upgrade_to_pro">
2
  <h1 class="frm_pro_heading">
3
+ <img src="<?php echo esc_url( FrmAppHelper::plugin_url() ) ?>/images/logo.png" alt="Upgrade to Pro" />
4
  <span class="alignright">Take on bigger projects, earn more clients and grow your business.<br/>
5
  <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( FrmAppHelper::admin_upgrade_link( $link_parts ) ) ); ?>" target="_blank">Upgrade to Pro</a>.</span>
6
  <span class="clear"></span>
18
  <th></th>
19
  <?php foreach ( $pro_pricing as $price_info ) { ?>
20
  <th>
21
+ <h3><?php echo esc_attr( ucfirst( $price_info['name'] ) ) ?></h3>
22
+ <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( FrmAppHelper::admin_upgrade_link( $link_parts ) ) ); ?>" class="button-primary" target="_blank">
23
+ <?php esc_html_e( 'Get Started', 'formidable' ) ?>
24
  </a>
25
  </th>
26
  <?php } ?>
82
  }
83
  ?>
84
  </th>
85
+ <td><i class="frm_icon_font <?php echo esc_attr( $feature['lite'] ? 'frm_check_icon' : 'frm_cancel1_icon' ); ?>"></i></td>
86
+ <td><i class="frm_icon_font frm_check_icon"></i></td>
87
  </tr>
88
  <?php } ?>
89
  <?php } ?>
classes/views/frm-entries/_sidebar-shared-pub.php CHANGED
@@ -1,34 +1,27 @@
1
  <?php
2
  if ( ! isset( $entry ) ) {
3
- $entry = $record;
4
  } ?>
5
 
6
- <div class="misc-pub-section">
7
- <i class="frm_icon_font frm_calendar_icon"></i>
8
- <span id="timestamp">
9
- <?php
10
- $date_format = __( 'M j, Y @ G:i', 'formidable' );
11
- printf(
12
- /* translators: %1$s: The date */
13
- esc_html__( 'Submitted: %1$s', 'formidable' ),
14
- '<b>' . esc_html( FrmAppHelper::get_localized_date( $date_format, $entry->created_at ) ) . '</b>'
15
- );
16
  ?>
17
- </span>
18
  </div>
19
-
 
 
 
 
 
20
  <?php if ( $entry->updated_at && $entry->updated_at != $entry->created_at ) { ?>
21
- <div class="misc-pub-section">
22
- <i class="frm_icon_font frm_calendar_icon"></i>
23
- <span id="timestamp">
24
- <?php
25
- printf(
26
- /* translators: %1$s: The date */
27
- esc_html__( 'Updated: %1$s', 'formidable' ),
28
- '<b>' . esc_html( FrmAppHelper::get_localized_date( $date_format, $entry->updated_at ) ) . '</b>'
29
- );
30
- ?>
31
- </span>
32
  </div>
33
  <?php } ?>
34
 
1
  <?php
2
  if ( ! isset( $entry ) ) {
3
+ $entry = $record;
4
  } ?>
5
 
6
+ <div class="misc-pub-section curtime misc-pub-curtime">
7
+ <span id="timestamp">
8
+ <?php
9
+ $date_format = __( 'M j, Y @ G:i', 'formidable' );
10
+ printf( esc_html__( 'Published on: %1$s', 'formidable' ), '<b>' . esc_html( FrmAppHelper::get_localized_date( $date_format, $entry->created_at ) ) . '</b>' );
 
 
 
 
 
11
  ?>
12
+ </span>
13
  </div>
14
+ <?php if ( FrmAppHelper::get_param( 'frm_action' ) == 'show' ) { ?>
15
+ <div class="misc-pub-section frm_no_print">
16
+ <span class="dashicons dashicons-format-aside wp-media-buttons-icon"></span>
17
+ <a href="#" onclick="window.print();return false;"><?php esc_html_e( 'Print', 'formidable' ) ?></a>
18
+ </div>
19
+ <?php } ?>
20
  <?php if ( $entry->updated_at && $entry->updated_at != $entry->created_at ) { ?>
21
+ <div class="misc-pub-section curtime misc-pub-curtime">
22
+ <span id="timestamp">
23
+ <?php printf( esc_html__( 'Updated on: %1$s', 'formidable' ), '<b>' . esc_html( FrmAppHelper::get_localized_date( $date_format, $entry->updated_at ) ) . '</b>' ); ?>
24
+ </span>
 
 
 
 
 
 
 
25
  </div>
26
  <?php } ?>
27
 
classes/views/frm-entries/direct.php CHANGED
@@ -1,7 +1,7 @@
1
  <!DOCTYPE html>
2
  <html <?php language_attributes(); ?>>
3
  <head>
4
- <title><?php bloginfo( 'name' ); ?> | <?php echo esc_html( $form->name ); ?></title>
5
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7
  <?php wp_head(); ?>
1
  <!DOCTYPE html>
2
  <html <?php language_attributes(); ?>>
3
  <head>
4
+ <title><?php bloginfo( 'name' ); ?> | <?php echo esc_html( $form->name ) ?></title>
5
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7
  <?php wp_head(); ?>
classes/views/frm-entries/errors.php CHANGED
@@ -1,46 +1,46 @@
1
  <?php
2
  if ( isset( $include_extra_container ) ) { ?>
3
- <div class="<?php echo esc_attr( $include_extra_container ); ?>" id="frm_form_<?php echo esc_attr( $form->id ); ?>_container">
4
- <?php
5
  }
6
  if ( isset( $message ) && $message != '' ) {
7
- if ( FrmAppHelper::is_admin() ) {
8
- ?>
9
- <div id="message" class="frm_updated_message"><?php echo wp_kses_post( $message ); ?></div>
10
- <?php
11
  } else {
12
  FrmFormsHelper::maybe_get_scroll_js( $form->id );
13
 
14
  // we need to allow scripts here for javascript in the success message
15
  echo $message; // WPCS: XSS ok.
16
- }
17
  }
18
 
19
  if ( isset( $errors ) && is_array( $errors ) && ! empty( $errors ) ) {
20
 
21
  if ( isset( $form ) && is_object( $form ) ) {
22
- FrmFormsHelper::get_scroll_js( $form->id );
23
  }
24
  ?>
25
- <div class="<?php echo esc_attr( FrmFormsHelper::form_error_class() ); ?>">
26
- <?php
27
- $img = '';
28
- if ( ! FrmAppHelper::is_admin() ) {
29
- $img = apply_filters( 'frm_error_icon', $img );
30
- if ( $img && ! empty( $img ) ) {
31
- echo '<img src="' . esc_url( $img ) . '" alt="" />';
32
- }
33
- }
34
 
35
- FrmFormsHelper::show_errors( compact( 'img', 'errors', 'form' ) );
36
 
37
- ?>
38
  </div>
39
- <?php
40
  }
41
 
42
  if ( isset( $include_extra_container ) ) {
43
- ?>
44
  </div>
45
- <?php
46
  }
1
  <?php
2
  if ( isset( $include_extra_container ) ) { ?>
3
+ <div class="<?php echo esc_attr( $include_extra_container ) ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
4
+ <?php
5
  }
6
  if ( isset( $message ) && $message != '' ) {
7
+ if ( FrmAppHelper::is_admin() ) {
8
+ ?>
9
+ <div id="message" class="frm_updated_message"><?php echo wp_kses_post( $message ) ?></div>
10
+ <?php
11
  } else {
12
  FrmFormsHelper::maybe_get_scroll_js( $form->id );
13
 
14
  // we need to allow scripts here for javascript in the success message
15
  echo $message; // WPCS: XSS ok.
16
+ }
17
  }
18
 
19
  if ( isset( $errors ) && is_array( $errors ) && ! empty( $errors ) ) {
20
 
21
  if ( isset( $form ) && is_object( $form ) ) {
22
+ FrmFormsHelper::get_scroll_js( $form->id );
23
  }
24
  ?>
25
+ <div class="<?php echo esc_attr( FrmFormsHelper::form_error_class() ) ?>">
26
+ <?php
27
+ $img = '';
28
+ if ( ! FrmAppHelper::is_admin() ) {
29
+ $img = apply_filters( 'frm_error_icon', $img );
30
+ if ( $img && ! empty( $img ) ) {
31
+ echo '<img src="' . esc_url( $img ) . '" alt="" />';
32
+ }
33
+ }
34
 
35
+ FrmFormsHelper::show_errors( compact( 'img', 'errors', 'form' ) );
36
 
37
+ ?>
38
  </div>
39
+ <?php
40
  }
41
 
42
  if ( isset( $include_extra_container ) ) {
43
+ ?>
44
  </div>
45
+ <?php
46
  }
classes/views/frm-entries/form.php CHANGED
@@ -1,20 +1,11 @@
1
  <?php
2
  if ( empty( $values ) || ! isset( $values['fields'] ) || empty( $values['fields'] ) ) { ?>
3
  <div class="frm_forms <?php echo esc_attr( FrmFormsHelper::get_form_style_class( $form ) ); ?>" id="frm_form_<?php echo esc_attr( $form->id ); ?>_container">
4
- <div class="frm_error_style">
5
- <strong><?php esc_html_e( 'Oops!', 'formidable' ); ?></strong>
6
- <?php
7
- printf(
8
- /* translators: %1$s: HTML open link, %2$s: HTML close link */
9
- esc_html__( 'You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable' ),
10
- '<a href="' . esc_url( FrmForm::get_edit_link( $form->id ) ) . '">',
11
- '</a>'
12
- );
13
- ?>
14
- </div>
15
  </div>
16
- <?php
17
- return;
18
  }
19
 
20
  global $frm_vars;
@@ -35,10 +26,10 @@ $frm_hide_fields = FrmAppHelper::get_post_param( 'frm_hide_fields_' . $form->id,
35
  <input type="hidden" name="form_key" value="<?php echo esc_attr( $form->form_key ); ?>" />
36
  <input type="hidden" name="item_meta[0]" value="" />
37
  <?php wp_nonce_field( 'frm_submit_entry_nonce', 'frm_submit_entry_' . $form->id ); ?>
38
- <label for="frm_verify_<?php echo esc_attr( $form->id ); ?>" class="frm_screen_reader frm_hidden"><?php esc_html_e( 'If you are human, leave this field blank.', 'formidable' ); ?></label>
39
  <input type="text" class="frm_hidden frm_verify" id="frm_verify_<?php echo esc_attr( $form->id ); ?>" name="frm_verify" value="<?php echo esc_attr( FrmAppHelper::get_param( 'frm_verify', '', 'get', 'wp_kses_post' ) ); ?>" <?php FrmFormsHelper::maybe_hide_inline(); ?> />
40
  <?php if ( isset( $id ) ) { ?>
41
- <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
42
  <?php } ?>
43
  <?php
44
  if ( $values['fields'] ) {
@@ -47,14 +38,14 @@ if ( $values['fields'] ) {
47
 
48
  $frm_settings = FrmAppHelper::get_settings();
49
  if ( FrmAppHelper::is_admin() ) {
50
- ?>
51
  <div class="frm_form_field form-field">
52
- <label class="frm_primary_label"><?php esc_html_e( 'Entry Key', 'formidable' ); ?></label>
53
  <input type="text" name="item_key" value="<?php echo esc_attr( $values['item_key'] ); ?>" />
54
  </div>
55
  <?php } else { ?>
56
  <input type="hidden" name="item_key" value="<?php echo esc_attr( $values['item_key'] ); ?>" />
57
- <?php
58
  }
59
 
60
  do_action( 'frm_entry_form', $form, $form_action, $errors );
@@ -68,7 +59,7 @@ if ( isset( $frm_vars['div'] ) && $frm_vars['div'] ) {
68
 
69
  // close open collapsible toggle div
70
  if ( isset( $frm_vars['collapse_div'] ) && $frm_vars['collapse_div'] ) {
71
- echo "</div>\n";
72
  unset( $frm_vars['collapse_div'] );
73
  }
74
 
1
  <?php
2
  if ( empty( $values ) || ! isset( $values['fields'] ) || empty( $values['fields'] ) ) { ?>
3
  <div class="frm_forms <?php echo esc_attr( FrmFormsHelper::get_form_style_class( $form ) ); ?>" id="frm_form_<?php echo esc_attr( $form->id ); ?>_container">
4
+ <div class="frm_error_style"><strong><?php esc_html_e( 'Oops!', 'formidable' ) ?></strong> <?php printf( esc_html__( 'You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable' ), '<a href="' . esc_url( admin_url( '?page=formidable&frm_action=edit&id=' . $form->id ) ) . '">', '</a>' ) ?>
5
+ </div>
 
 
 
 
 
 
 
 
 
6
  </div>
7
+ <?php
8
+ return;
9
  }
10
 
11
  global $frm_vars;
26
  <input type="hidden" name="form_key" value="<?php echo esc_attr( $form->form_key ); ?>" />
27
  <input type="hidden" name="item_meta[0]" value="" />
28
  <?php wp_nonce_field( 'frm_submit_entry_nonce', 'frm_submit_entry_' . $form->id ); ?>
29
+ <label for="frm_verify_<?php echo esc_attr( $form->id ) ?>" class="frm_screen_reader frm_hidden"><?php esc_html_e( 'If you are human, leave this field blank.', 'formidable' ) ?></label>
30
  <input type="text" class="frm_hidden frm_verify" id="frm_verify_<?php echo esc_attr( $form->id ); ?>" name="frm_verify" value="<?php echo esc_attr( FrmAppHelper::get_param( 'frm_verify', '', 'get', 'wp_kses_post' ) ); ?>" <?php FrmFormsHelper::maybe_hide_inline(); ?> />
31
  <?php if ( isset( $id ) ) { ?>
32
+ <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
33
  <?php } ?>
34
  <?php
35
  if ( $values['fields'] ) {
38
 
39
  $frm_settings = FrmAppHelper::get_settings();
40
  if ( FrmAppHelper::is_admin() ) {
41
+ ?>
42
  <div class="frm_form_field form-field">
43
+ <label class="frm_primary_label"><?php esc_html_e( 'Entry Key', 'formidable' ) ?></label>
44
  <input type="text" name="item_key" value="<?php echo esc_attr( $values['item_key'] ); ?>" />
45
  </div>
46
  <?php } else { ?>
47
  <input type="hidden" name="item_key" value="<?php echo esc_attr( $values['item_key'] ); ?>" />
48
+ <?php
49
  }
50
 
51
  do_action( 'frm_entry_form', $form, $form_action, $errors );
59
 
60
  // close open collapsible toggle div
61
  if ( isset( $frm_vars['collapse_div'] ) && $frm_vars['collapse_div'] ) {
62
+ echo "</div>\n";
63
  unset( $frm_vars['collapse_div'] );
64
  }
65
 
classes/views/frm-entries/list.php CHANGED
@@ -1,47 +1,28 @@
1
  <div id="form_entries_page" class="frm_wrap frm_list_entry_page">
2
- <?php if ( $form ) { ?>
3
- <div class="frm_page_container">
4
- <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- <?php
7
- FrmAppHelper::get_admin_header(
8
- array(
9
- 'label' => __( 'Form Entries', 'formidable' ),
10
- 'form' => $form,
11
- 'close' => $form ? '?page=formidable-entries&form=' . $form->id : '',
12
- )
13
- );
14
- ?>
15
 
16
- <div class="wrap">
17
- <?php if ( $form ) { ?>
18
- <h2>
19
- <?php esc_html_e( 'Form Entries', 'formidable' ); ?>
20
- <?php
21
- FrmAppHelper::add_new_item_link(
22
- array(
23
- 'new_link' => FrmAppHelper::maybe_full_screen_link( admin_url( 'admin.php?page=formidable-entries&frm_action=new&form=' . $form->id ) ),
24
- )
25
- );
26
- ?>
27
- </h2>
28
- <?php } ?>
29
 
30
- <?php require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' ); ?>
31
-
32
- <form id="posts-filter" method="get">
33
- <input type="hidden" name="page" value="formidable-entries" />
34
- <input type="hidden" name="form" value="<?php echo esc_attr( $form ? $form->id : '' ); ?>" />
35
- <input type="hidden" name="frm_action" value="list" />
36
- <?php do_action( 'frm_entry_inside_h2', $form ); ?>
37
- <?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' ); ?>
38
-
39
- <?php FrmTipsHelper::pro_tip( 'get_entries_tip' ); ?>
40
-
41
- <?php $wp_list_table->display(); ?>
42
- </form>
43
- </div>
44
- <?php if ( $form ) { ?>
45
  </div>
46
- <?php } ?>
47
  </div>
1
  <div id="form_entries_page" class="frm_wrap frm_list_entry_page">
2
+ <?php
3
+ FrmAppHelper::get_admin_header(
4
+ array(
5
+ 'label' => __( 'Entries', 'formidable' ),
6
+ 'link_hook' => array(
7
+ 'hook' => 'frm_entry_inside_h2',
8
+ 'param' => $form,
9
+ ),
10
+ 'form' => $form,
11
+ )
12
+ );
13
+ ?>
14
+ <div class="wrap">
15
+ <form id="posts-filter" method="get">
16
+ <input type="hidden" name="page" value="formidable-entries" />
17
+ <input type="hidden" name="form" value="<?php echo esc_attr( $form ? $form->id : '' ); ?>" />
18
+ <input type="hidden" name="frm_action" value="list" />
19
+ <?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' ); ?>
20
 
21
+ <?php include( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' ); ?>
22
+ <?php FrmTipsHelper::pro_tip( 'get_entries_tip' ); ?>
 
 
 
 
 
 
 
23
 
24
+ <?php $wp_list_table->display(); ?>
25
+ </form>
 
 
 
 
 
 
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  </div>
 
28
  </div>
classes/views/frm-entries/new.php CHANGED
@@ -1,9 +1,9 @@
1
- <div class="frm_forms <?php echo esc_attr( FrmFormsHelper::get_form_style_class( $values ) ); ?>" id="frm_form_<?php echo esc_attr( $form->id ); ?>_container" <?php echo wp_strip_all_tags( apply_filters( 'frm_form_div_attributes', '', $form ) ); // WPCS: XSS ok. ?>>
2
  <?php if ( ! isset( $include_form_tag ) || $include_form_tag ) { ?>
3
- <form enctype="<?php echo esc_attr( apply_filters( 'frm_form_enctype', 'multipart/form-data', $form ) ); ?>" method="post" class="frm-show-form <?php do_action( 'frm_form_classes', $form ); ?>" id="form_<?php echo esc_attr( $form->form_key ); ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?> <?php echo wp_strip_all_tags( apply_filters( 'frm_form_attributes', '', $form ) ); // WPCS: XSS ok. ?>>
4
  <?php } else { ?>
5
- <div id="form_<?php echo esc_attr( $form->form_key ); ?>" class="frm-show-form <?php do_action( 'frm_form_classes', $form ); ?>" >
6
- <?php
7
  }
8
 
9
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
@@ -11,7 +11,7 @@ $form_action = 'create';
11
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/form.php' );
12
 
13
  if ( ! isset( $include_form_tag ) || $include_form_tag ) {
14
- ?>
15
  </form>
16
  <?php } else { ?>
17
  </div>
1
+ <div class="frm_forms <?php echo esc_attr( FrmFormsHelper::get_form_style_class( $values ) ); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container" <?php echo wp_strip_all_tags( apply_filters( 'frm_form_div_attributes', '', $form ) ); // WPCS: XSS ok. ?>>
2
  <?php if ( ! isset( $include_form_tag ) || $include_form_tag ) { ?>
3
+ <form enctype="<?php echo esc_attr( apply_filters( 'frm_form_enctype', 'multipart/form-data', $form ) ) ?>" method="post" class="frm-show-form <?php do_action( 'frm_form_classes', $form ) ?>" id="form_<?php echo esc_attr( $form->form_key ) ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?> <?php echo wp_strip_all_tags( apply_filters( 'frm_form_attributes', '', $form ) ); // WPCS: XSS ok. ?>>
4
  <?php } else { ?>
5
+ <div id="form_<?php echo esc_attr( $form->form_key ) ?>" class="frm-show-form <?php do_action( 'frm_form_classes', $form ) ?>" >
6
+ <?php
7
  }
8
 
9
  include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
11
  require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/form.php' );
12
 
13
  if ( ! isset( $include_form_tag ) || $include_form_tag ) {
14
+ ?>
15
  </form>
16
  <?php } else { ?>
17
  </div>
classes/views/frm-entries/no_entries.php CHANGED
@@ -1,45 +1,12 @@
1
  <div class="frmcenter frm_no_entries_form">
2
  <?php if ( $form && isset( $form->options['no_save'] ) && $form->options['no_save'] ) { ?>
3
- <h3><?php esc_html_e( 'This form is not set to save any entries.', 'formidable' ); ?></h3>
4
- <p>
5
- <?php
6
- printf(
7
- /* translators: %1$s: Start link HTML, %2$s: End link HTML, %3$s: Line break HTML */
8
- esc_html__( 'If you would like to save entries in this form, go to the %1$sform Settings%2$s page %3$s and uncheck the "Do not store any entries submitted from this form" box.', 'formidable' ),
9
- '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $form->id ) ) . '">',
10
- '</a>',
11
- '</br>'
12
- );
13
- ?>
14
- </p>
15
  <?php } elseif ( $form ) { ?>
16
- <div class="frm_no_entries_header">
17
- <?php
18
- /* translators: %s: The form name */
19
- printf( esc_html__( 'No Entries for form: %s', 'formidable' ), esc_html( $form->name ) );
20
- ?>
21
- </div>
22
- <p class="frm_no_entries_text">
23
- <?php
24
- printf(
25
- /* translators: %1$s: Start link HTML, %2$s: End link HTML, %3$s: Line break HTML */
26
- esc_html__( 'See the %1$sform documentation%2$s for instructions on publishing your form', 'formidable' ),
27
- '<a href="https://formidableforms.com/knowledgebase/publish-your-forms/?utm_source=WordPress&utm_medium=entries&utm_campaign=liteplugin" target="_blank">',
28
- '</a>'
29
- );
30
- ?>
31
- </p>
32
  <?php } else { ?>
33
  <div class="frm_no_entries_header"><?php esc_html_e( 'You have not created any forms yet.', 'formidable' ); ?></div>
34
- <p class="frm_no_entries_text">
35
- <?php
36
- printf(
37
- /* translators: %1$s: Start link HTML, %2$s: End link HTML, %3$s: Line break HTML */
38
- esc_html__( 'To view entries, you must first %1$sbuild a form%2$s', 'formidable' ),
39
- '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=add_new' ) ) . '">',
40
- '</a>'
41
- );
42
- ?>
43
- </p>
44
  <?php } ?>
45
  </div>
1
  <div class="frmcenter frm_no_entries_form">
2
  <?php if ( $form && isset( $form->options['no_save'] ) && $form->options['no_save'] ) { ?>
3
+ <h3><?php esc_html_e( 'This form is not set to save any entries.', 'formidable' ) ?></h3>
4
+ <p><?php printf( esc_html__( 'If you would like to save entries in this form, go to the %1$sform Settings%2$s page %3$s and uncheck the "Do not store any entries submitted from this form" box.', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $form->id ) ) . '">', '</a>', '</br>' ) ?></p>
 
 
 
 
 
 
 
 
 
 
5
  <?php } elseif ( $form ) { ?>
6
+ <div class="frm_no_entries_header"><?php printf( esc_html__( 'No Entries for form: %s', 'formidable' ), esc_html( $form->name ) ); ?></div>
7
+ <p class="frm_no_entries_text"><?php printf( esc_html__( 'See the %1$sform documentation%2$s for instructions on publishing your form', 'formidable' ), '<a href="https://formidableforms.com/knowledgebase/publish-your-forms/?utm_source=WordPress&utm_medium=entries&utm_campaign=liteplugin" target="_blank">', '</a>' ); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  <?php } else { ?>
9
  <div class="frm_no_entries_header"><?php esc_html_e( 'You have not created any forms yet.', 'formidable' ); ?></div>
10
+ <p class="frm_no_entries_text"><?php printf( esc_html__( 'To view entries, you must first %1$sbuild a form%2$s', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) . '">', '</a>' ); ?></p>
 
 
 
 
 
 
 
 
 
11
  <?php } ?>
12
  </div>
classes/views/frm-entries/show.php CHANGED
@@ -1,66 +1,85 @@
1
  <div id="form_show_entry_page" class="frm_wrap frm_single_entry_page">
2
- <div class="frm_page_container">
3
-
4
- <?php
5
- FrmAppHelper::get_admin_header(
6
- array(
7
- 'label' => __( 'View Entry', 'formidable' ),
8
- 'form' => $form,
9
- 'hide_title' => true,
10
- 'close' => '?page=formidable-entries&form=' . $form->id,
11
- )
12
- );
13
- ?>
14
-
15
- <div class="columns-2">
16
-
17
- <div id="post-body-content" class="frm-fields">
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  <div class="frm_form_fields">
20
  <div class="postbox">
21
- <a href="#" class="alignright frm-pre-hndle" data-frmtoggle=".frm-empty-row" data-toggletext="<?php esc_attr_e( 'Hide empty fields', 'formidable' ); ?>">
22
- <?php esc_html_e( 'Show empty fields', 'formidable' ); ?>
23
- </a>
24
- <h3 class="hndle">
25
- <span><?php esc_html_e( 'Entry', 'formidable' ); ?></span>
26
- <span class="frm-sub-label">
27
  <?php
28
- printf(
29
- /* translators: %d: Entry ID */
30
- esc_html__( '(ID %d)', 'formidable' ),
31
- esc_attr( $entry->id )
32
- );
33
- ?>
34
- </span>
35
- </h3>
36
- <?php
37
- echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok.
38
- array(
39
- 'id' => $entry->id,
40
- 'entry' => $entry,
41
- 'fields' => $fields,
42
- 'include_blank' => true,
43
- 'include_extras' => 'page, section',
44
- 'inline_style' => 0,
45
- 'class' => 'frm-alt-table',
46
- )
47
- );
48
- ?>
49
 
50
- <?php do_action( 'frm_show_entry', $entry ); ?>
51
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- <?php do_action( 'frm_after_show_entry', $entry ); ?>
54
- </div>
55
- </div>
 
 
 
 
 
 
 
56
 
57
- <div class="frm-right-panel">
58
- <?php
59
- do_action( 'frm_show_entry_sidebar', $entry );
60
- FrmEntriesController::entry_sidebar( $entry );
61
- ?>
62
- </div>
 
 
 
63
 
 
 
 
 
64
  </div>
65
  </div>
66
  </div>
 
 
1
  <div id="form_show_entry_page" class="frm_wrap frm_single_entry_page">
2
+ <div class="frm_forms">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ <div id="poststuff" class="frm_page_container">
5
+ <div id="post-body" class="metabox-holder columns-2">
6
+ <div id="post-body-content">
7
+ <?php
8
+ FrmAppHelper::get_admin_header(
9
+ array(
10
+ 'label' => __( 'View Entry', 'formidable' ),
11
+ 'link_hook' => array(
12
+ 'hook' => 'frm_entry_inside_h2',
13
+ 'param' => $form,
14
+ ),
15
+ 'form' => $form,
16
+ )
17
+ );
18
+ ?>
19
  <div class="frm_form_fields">
20
  <div class="postbox">
21
+ <h3 class="hndle"><span><?php esc_html_e( 'Entry', 'formidable' ) ?></span></h3>
22
+ <div class="inside">
23
+ <table class="form-table"><tbody>
 
 
 
24
  <?php
25
+ $first_h3 = 'frm_first_h3';
26
+ foreach ( $fields as $field ) {
27
+ if ( in_array( $field->type, array( 'captcha', 'html', 'end_divider', 'form' ), true ) ) {
28
+ continue;
29
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ if ( in_array( $field->type, array( 'break', 'divider' ), true ) ) {
32
+ ?>
33
+ </tbody></table>
34
+ <br/><h3 class="<?php echo esc_attr( $first_h3 ) ?>"><?php echo esc_html( $field->name ) ?></h3>
35
+ <table class="form-table"><tbody>
36
+ <?php
37
+ $first_h3 = '';
38
+ } else {
39
+ ?>
40
+ <tr>
41
+ <th scope="row"><?php echo esc_html( $field->name ) ?>:</th>
42
+ <td>
43
+ <?php
44
+ $embedded_field_id = ( $entry->form_id !== $field->form_id ) ? 'form' . $field->form_id : 0;
45
+ $atts = array(
46
+ 'type' => $field->type,
47
+ 'post_id' => $entry->post_id,
48
+ 'show_filename' => true,
49
+ 'show_icon' => true,
50
+ 'entry_id' => $entry->id,
51
+ 'embedded_field_id' => $embedded_field_id,
52
+ );
53
+ $display_value = FrmEntriesHelper::prepare_display_value( $entry, $field, $atts );
54
+ echo $display_value; // WPCS: XSS ok.
55
 
56
+ if ( is_email( $display_value ) && ! in_array( $display_value, $to_emails ) ) {
57
+ $to_emails[] = $display_value;
58
+ }
59
+ ?>
60
+ </td>
61
+ </tr>
62
+ <?php
63
+ }
64
+ }
65
+ ?>
66
 
67
+ <?php if ( $entry->parent_item_id ) { ?>
68
+ <tr><th><?php esc_html_e( 'Parent Entry ID', 'formidable' ) ?>:</th>
69
+ <td><?php echo absint( $entry->parent_item_id ) ?>
70
+ </td></tr>
71
+ <?php } ?>
72
+ </tbody></table>
73
+ <?php do_action( 'frm_show_entry', $entry ); ?>
74
+ </div>
75
+ </div>
76
 
77
+ <?php do_action( 'frm_after_show_entry', $entry ); ?>
78
+ </div>
79
+ </div>
80
+ <?php require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-show.php' ); ?>
81
  </div>
82
  </div>
83
  </div>
84
+ </div>
85
+ <br/>
classes/views/frm-entries/sidebar-shared.php CHANGED
@@ -1,135 +1,110 @@
1
- <div class="frm_with_icons frm_no_print">
2
- <h3>
3
- <?php esc_html_e( 'Entry Actions', 'formidable' ); ?>
4
- </h3>
5
- <div class="inside">
6
- <?php FrmEntriesHelper::actions_dropdown( compact( 'id', 'entry' ) ); ?>
7
- <?php do_action( 'frm_entry_major_pub', $entry ); ?>
8
- <div class="clear"></div>
9
 
10
- <?php if ( has_action( 'frm_show_entry_publish_box' ) ) { ?>
11
- <div id="minor-publishing" class="frm_remove_border">
12
- <div class="misc-pub-section">
13
- <?php do_action( 'frm_show_entry_publish_box', $entry ); ?>
14
- <div class="clear"></div>
15
- </div>
16
- </div>
17
  <?php } ?>
18
- </div>
19
- </div>
20
-
21
- <div class="frm_with_icons">
22
- <h3>
23
- <?php esc_html_e( 'Entry Details', 'formidable' ); ?>
24
  </h3>
25
- <div class="inside">
26
  <?php include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/_sidebar-shared-pub.php' ); ?>
27
 
28
- <?php if ( $entry->post_id ) { ?>
29
- <div class="misc-pub-section frm_no_print">
30
- <i aria-hidden="true" class="frm_icon_font frm_calendar_icon"></i>
31
- <?php esc_html_e( 'Post', 'formidable' ); ?>:
32
- <b><?php echo esc_html( get_the_title( $entry->post_id ) ); ?></b>
33
- <span>
34
- <a href="<?php echo esc_url( admin_url( 'post.php?post=' . $entry->post_id . '&action=edit' ) ); ?>">
35
- <?php esc_html_e( 'Edit', 'formidable' ); ?>
36
- </a>
37
- <a href="<?php echo esc_url( get_permalink( $entry->post_id ) ); ?>">
38
- <?php esc_html_e( 'View', 'formidable' ); ?>
39
- </a>
40
- </span>
41
- </div>
42
- <?php } ?>
43
 
44
- <div class="misc-pub-section">
45
- <i class="frm_icon_font frm_fingerprint_icon" aria-hidden="true"></i>
46
- <?php esc_html_e( 'Entry ID', 'formidable' ); ?>:
47
- <b><?php echo absint( $entry->id ); ?></b>
48
- </div>
49
 
50
- <div class="misc-pub-section">
51
- <i class="frm_icon_font frm_keyalt_icon" aria-hidden="true"></i>
52
- <?php esc_html_e( 'Entry Key', 'formidable' ); ?>:
53
- <b><?php echo esc_html( $entry->item_key ); ?></b>
54
- </div>
55
 
56
- <?php if ( $entry->parent_item_id ) { ?>
57
- <div class="misc-pub-section">
58
- <i class="frm_icon_font frm_sitemap_icon" aria-hidden="true"></i>
59
- <?php esc_html_e( 'Parent Entry ID', 'formidable' ); ?>:
60
- <b><?php echo esc_html( $entry->parent_item_id ); ?></b>
61
- </div>
62
- <?php } ?>
63
- </div>
64
- </div>
 
 
 
65
 
66
- <div class="frm_with_icons">
67
- <h3><?php esc_html_e( 'User Information', 'formidable' ); ?></h3>
68
- <div class="inside">
69
- <?php if ( $entry->user_id ) { ?>
70
- <div class="misc-pub-section">
71
- <i class="frm_icon_font frm_user_icon" aria-hidden="true"></i>
72
- <?php
73
- printf(
74
- /* translators: %1$s: User display name. */
75
- esc_html__( 'Created by: %1$s', 'formidable' ),
76
- FrmAppHelper::kses( FrmFieldsHelper::get_user_display_name( $entry->user_id, 'display_name', array( 'link' => true ) ), array( 'a' ) )
77
- ); // WPCS: XSS ok.
78
- ?>
79
- </div>
80
- <?php } ?>
81
 
82
- <?php if ( $entry->updated_by && $entry->updated_by != $entry->user_id ) { ?>
83
- <div class="misc-pub-section">
84
- <i class="frm_icon_font frm_user_icon" aria-hidden="true"></i>
85
- <?php
86
- printf(
87
- /* translators: %1$s: User display name. */
88
- esc_html__( 'Updated by: %1$s', 'formidable' ),
89
- FrmAppHelper::kses( FrmFieldsHelper::get_user_display_name( $entry->updated_by, 'display_name', array( 'link' => true ) ), array( 'a' ) )
90
- ); // WPCS: XSS ok.
91
- ?>
92
- </div>
93
- <?php } ?>
94
 
 
 
 
95
  <?php if ( ! empty( $entry->ip ) ) { ?>
96
- <div class="misc-pub-section">
97
- <i class="frm_icon_font frm_location_icon" aria-hidden="true"></i>
98
- <?php esc_html_e( 'IP Address:', 'formidable' ); ?>
99
- <b><?php echo esc_html( $entry->ip ); ?></b>
100
- </div>
101
  <?php } ?>
102
 
103
- <?php if ( isset( $browser ) ) { ?>
104
- <div class="misc-pub-section">
105
- <i class="frm_icon_font frm_browser_icon" aria-hidden="true"></i>
106
- <?php esc_html_e( 'Browser/OS:', 'formidable' ); ?>
107
- <b><?php echo wp_kses_post( $browser ); ?></b>
108
- </div>
109
- <?php } ?>
110
 
111
  <?php if ( isset( $data['referrer'] ) ) { ?>
112
- <div class="misc-pub-section frm_force_wrap">
113
- <i class="frm_icon_font frm_history_icon" aria-hidden="true"></i>
114
- <?php esc_html_e( 'Referrer:', 'formidable' ); ?>
115
- <?php echo wp_kses_post( str_replace( "\r\n", '<br/>', $data['referrer'] ) ); ?>
116
- </div>
117
- <?php } ?>
118
 
119
- <?php
120
- foreach ( (array) $data as $k => $d ) {
121
  if ( in_array( $k, array( 'browser', 'referrer' ) ) ) {
122
- continue;
123
- }
124
- ?>
125
- <div class="misc-pub-section">
126
- <i class="frm_icon_font frm_attach_file_icon" aria-hidden="true"></i>
127
- <?php echo esc_html( ucfirst( str_replace( '-', ' ', $k ) ) ); ?>:
128
- <b><?php echo wp_kses_post( implode( ', ', (array) $d ) ); ?></b>
129
- </div>
130
- <?php
131
  unset( $k, $d );
132
- }
133
- ?>
134
- </div>
135
  </div>
 
 
 
 
 
 
 
 
1
 
2
+ <div class="postbox frm_with_icons" >
3
+ <h3 class="hndle">
4
+ <span><?php esc_html_e( 'Entry Details', 'formidable' ) ?></span>
5
+ <?php if ( FrmAppHelper::get_param( 'frm_action' ) != 'show' ) { ?>
6
+ <a href="?page=formidable-entries&amp;frm_action=show&amp;id=<?php echo absint( $entry->id ); ?>" class="alignright">
7
+ <?php esc_html_e( 'View Entry', 'formidable' ) ?>
8
+ </a>
9
  <?php } ?>
 
 
 
 
 
 
10
  </h3>
11
+ <div class="inside">
12
  <?php include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/_sidebar-shared-pub.php' ); ?>
13
 
14
+ <?php if ( $entry->post_id ) { ?>
15
+ <div class="misc-pub-section frm_no_print">
16
+ <span class="dashicons dashicons-admin-post wp-media-buttons-icon"></span>
17
+ <?php esc_html_e( 'Post', 'formidable' ) ?>:
18
+ <b><?php echo esc_html( get_the_title( $entry->post_id ) ); ?></b>
19
+ <span>
20
+ <a href="<?php echo esc_url( admin_url( 'post.php?post=' . $entry->post_id . '&action=edit' ) ) ?>">
21
+ <?php esc_html_e( 'Edit', 'formidable' ) ?>
22
+ </a>
23
+ <a href="<?php echo esc_url( get_permalink( $entry->post_id ) ) ?>">
24
+ <?php esc_html_e( 'View', 'formidable' ) ?>
25
+ </a>
26
+ </span>
27
+ </div>
28
+ <?php } ?>
29
 
30
+ <div class="misc-pub-section">
31
+ <span class="dashicons dashicons-id wp-media-buttons-icon"></span>
32
+ <?php esc_html_e( 'Entry ID', 'formidable' ) ?>:
33
+ <b><?php echo absint( $entry->id ) ?></b>
34
+ </div>
35
 
36
+ <div class="misc-pub-section">
37
+ <span class="dashicons dashicons-post-status wp-media-buttons-icon"></span>
38
+ <?php esc_html_e( 'Entry Key', 'formidable' ) ?>:
39
+ <b><?php echo esc_html( $entry->item_key ) ?></b>
40
+ </div>
41
 
42
+ <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
43
+ <?php if ( $entry->user_id ) { ?>
44
+ <div class="misc-pub-section">
45
+ <span class="dashicons dashicons-admin-users wp-media-buttons-icon"></span>
46
+ <?php
47
+ printf(
48
+ esc_html__( 'Created by: %1$s', 'formidable' ),
49
+ FrmAppHelper::kses( FrmFieldsHelper::get_user_display_name( $entry->user_id, 'display_name', array( 'link' => true ) ), array( 'a' ) )
50
+ ); // WPCS: XSS ok.
51
+ ?>
52
+ </div>
53
+ <?php } ?>
54
 
55
+ <?php if ( $entry->updated_by && $entry->updated_by != $entry->user_id ) { ?>
56
+ <div class="misc-pub-section">
57
+ <span class="dashicons dashicons-admin-users wp-media-buttons-icon"></span>
58
+ <?php
59
+ printf(
60
+ esc_html__( 'Updated by: %1$s', 'formidable' ),
61
+ FrmAppHelper::kses( FrmFieldsHelper::get_user_display_name( $entry->updated_by, 'display_name', array( 'link' => true ) ), array( 'a' ) )
62
+ ); // WPCS: XSS ok.
63
+ ?>
64
+ </div>
65
+ <?php } ?>
66
+ <?php } ?>
 
 
 
67
 
68
+ </div>
69
+ </div>
 
 
 
 
 
 
 
 
 
 
70
 
71
+ <div class="postbox">
72
+ <h3 class="hndle"><span><?php esc_html_e( 'User Information', 'formidable' ) ?></span></h3>
73
+ <div class="inside">
74
  <?php if ( ! empty( $entry->ip ) ) { ?>
75
+ <div class="misc-pub-section">
76
+ <?php esc_html_e( 'IP Address', 'formidable' ) ?>:
77
+ <b><?php echo esc_html( $entry->ip ); ?></b>
78
+ </div>
 
79
  <?php } ?>
80
 
81
+ <?php if ( isset( $browser ) ) { ?>
82
+ <div class="misc-pub-section">
83
+ <b><?php esc_html_e( 'Browser/OS', 'formidable' ) ?></b>:<br/>
84
+ <?php echo wp_kses_post( $browser ); ?>
85
+ </div>
86
+ <?php } ?>
 
87
 
88
  <?php if ( isset( $data['referrer'] ) ) { ?>
89
+ <div class="misc-pub-section frm_force_wrap">
90
+ <b><?php esc_html_e( 'Referrer', 'formidable' ) ?></b>:<br/>
91
+ <?php echo wp_kses_post( str_replace( "\r\n", '<br/>', $data['referrer'] ) ); ?>
92
+ </div>
93
+ <?php } ?>
 
94
 
95
+ <?php
96
+ foreach ( (array) $data as $k => $d ) {
97
  if ( in_array( $k, array( 'browser', 'referrer' ) ) ) {
98
+ continue;
99
+ }
100
+ ?>
101
+ <div class="misc-pub-section">
102
+ <b><?php echo esc_html( ucfirst( str_replace( '-', ' ', $k ) ) ); ?></b>:
103
+ <?php echo wp_kses_post( implode( ', ', (array) $d ) ); ?>
104
+ </div>
105
+ <?php
 
106
  unset( $k, $d );
107
+ }
108
+ ?>
109
+ </div>
110
  </div>
classes/views/frm-entries/sidebar-show.php CHANGED
@@ -1,5 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
- _deprecated_file( esc_html( basename( __FILE__ ) ), '4.0' );
3
-
4
  do_action( 'frm_show_entry_sidebar', $entry );
5
  FrmEntriesController::entry_sidebar( $entry );
 
 
1
+ <div id="postbox-container-1" class="postbox-container frm-right-panel">
2
+ <div id="submitdiv" class="postbox frm-no-border frm_no_print">
3
+ <div class="inside">
4
+ <div class="submitbox">
5
+ <div id="major-publishing-actions">
6
+ <div class="alignleft">
7
+ <?php FrmEntriesHelper::actions_dropdown( compact( 'id', 'entry' ) ); ?>
8
+ </div>
9
+ <?php do_action( 'frm_entry_major_pub', $entry ); ?>
10
+ <div class="clear"></div>
11
+ </div>
12
+ <?php if ( has_action( 'frm_show_entry_publish_box' ) ) { ?>
13
+ <div id="minor-publishing" class="frm_remove_border">
14
+ <div class="misc-pub-section">
15
+ <?php do_action( 'frm_show_entry_publish_box', $entry ); ?>
16
+ <div class="clear"></div>
17
+ </div>
18
+ </div>
19
+ <?php } ?>
20
+ </div>
21
+ </div>
22
+ </div>
23
  <?php
 
 
24
  do_action( 'frm_show_entry_sidebar', $entry );
25
  FrmEntriesController::entry_sidebar( $entry );
26
+ ?>
27
+ </div>
classes/views/frm-fields/back-end/ajax-field-placeholder.php CHANGED
@@ -1,4 +1,4 @@
1
- <li id="frm_field_id_<?php echo esc_attr( $field_object->id ); ?>" class="<?php echo esc_attr( $li_classes ); ?> frm_field_loading" data-fid="<?php echo esc_attr( $field_object->id ); ?>" data-formid="<?php echo esc_attr( 'divider' == $field_object->type ? FrmField::get_option( $field_object, 'form_select' ) : $field_object->form_id ); ?>" data-ftype="<?php echo esc_attr( $display['type'] ); ?>">
2
- <span class="frm-wait frm_visible_spinner"></span>
3
  <span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars( json_encode( $field_object ) ); // WPCS: XSS ok. ?></span>
4
  </li>
1
+ <li id="frm_field_id_<?php echo esc_attr( $field_object->id ); ?>" class="<?php echo esc_attr( $li_classes ) ?> frm_field_loading" data-fid="<?php echo esc_attr( $field_object->id ) ?>" data-formid="<?php echo esc_attr( 'divider' == $field_object->type ? FrmField::get_option( $field_object, 'form_select' ) : $field_object->form_id ); ?>" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
2
+ <span class="spinner frm_visible_spinner"></span>
3
  <span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars( json_encode( $field_object ) ); // WPCS: XSS ok. ?></span>
4
  </li>
classes/views/frm-fields/back-end/automatic-width.php CHANGED
@@ -1,6 +1,9 @@
1
- <p class="frm6 frm_form_field frm_multiple_cont_<?php echo absint( $field['id'] ); ?>">
2
- <label for="size_<?php echo esc_attr( $field['id'] ); ?>">
3
- <input type="checkbox" name="field_options[size_<?php echo esc_attr( $field['id'] ); ?>]" id="size_<?php echo esc_attr( $field['id'] ); ?>" value="1" <?php echo FrmField::is_option_true( $field, 'size' ) ? 'checked="checked"' : ''; ?> />
4
- <?php esc_html_e( 'Automatic width', 'formidable' ); ?>
5
- </label>
6
- </p>
 
 
 
1
+ <tr>
2
+ <td class="frm_150_width"><label><?php esc_html_e( 'Field Size', 'formidable' ) ?></label></td>
3
+ <td>
4
+ <label for="size_<?php echo esc_attr( $field['id'] ) ?>">
5
+ <input type="checkbox" name="field_options[size_<?php echo esc_attr( $field['id'] ) ?>]" id="size_<?php echo esc_attr( $field['id'] ) ?>" value="1" <?php echo FrmField::is_option_true( $field, 'size' ) ? 'checked="checked"' : ''; ?> />
6
+ <?php esc_html_e( 'automatic width', 'formidable' ) ?>
7
+ </label>
8
+ </td>
9
+ </tr>
classes/views/frm-fields/back-end/bulk-options-overlay.php DELETED
@@ -1,35 +0,0 @@
1
- <div id="frm-bulk-modal" class="frm_hidden settings-lite-cta">
2
- <a href="#" class="dismiss alignright" title="<?php esc_attr_e( 'Close', 'formidable' ); ?>">
3
- <i class="frm_icon_font frm_close_icon" aria-label="<?php esc_attr_e( 'Close', 'formidable' ); ?>" aria-hidden="true"></i>
4
- </a>
5
- <h2>
6
- <?php esc_html_e( 'Bulk Edit Options', 'formidable' ); ?>
7
- </h2>
8
- <div class="frm_grid_container">
9
- <div class="frm8 frm_form_field">
10
- <p class="howto">
11
- <?php esc_html_e( 'Edit or add field options (one per line)', 'formidable' ); ?>
12
- </p>
13
- <textarea name="frm_bulk_options" id="frm_bulk_options"></textarea>
14
- <input type="hidden" value="" id="bulk-field-id" />
15
-
16
- <button class="button-primary frm-button-primary" id="frm-update-bulk-opts">
17
- <?php esc_attr_e( 'Update Options', 'formidable' ); ?>
18
- </button>
19
- </div>
20
- <div class="frm4 frm_form_field">
21
- <h3>
22
- <?php esc_html_e( 'Insert Presets', 'formidable' ); ?>
23
- </h3>
24
- <ul class="frm_prepop">
25
- <?php foreach ( $prepop as $label => $pop ) { ?>
26
- <li>
27
- <a href="#" class="frm-insert-preset" data-opts="<?php echo esc_attr( json_encode( $pop ) ); ?>">
28
- <?php echo esc_html( $label ); ?>
29
- </a>
30
- </li>
31
- <?php } ?>
32
- </ul>
33
- </div>
34
- </div>
35
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/dropdown-field.php CHANGED
@@ -10,8 +10,8 @@ if ( isset( $field['post_field'] ) && 'post_category' === $field['post_field'] &
10
  )
11
  );
12
  } else {
13
- ?>
14
- <select id="frm_dropdown_<?php echo esc_attr( $field['id'] ); ?>"
15
  name="<?php echo esc_attr( $field_name ) . ( FrmField::is_option_true( $field, 'multiple' ) ? '[]' : '' ); ?>" <?php echo FrmField::is_option_true( $field, 'size' ) ? 'class="auto_width"' : ''; ?> <?php echo FrmField::is_option_true( $field, 'multiple' ) ? 'multiple="multiple"' : ''; ?>>
16
  <?php
17
  foreach ( $field['options'] as $opt_key => $opt ) {
@@ -19,16 +19,22 @@ if ( isset( $field['post_field'] ) && 'post_category' === $field['post_field'] &
19
  $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
20
  $selected = ( $field['default_value'] === $field_val || FrmFieldsHelper::get_other_val( array( 'opt_key', 'field' ) ) ) ? ' selected="selected"' : '';
21
  ?>
22
- <option value="<?php echo esc_attr( $field_val ); ?>"<?php echo $selected; // WPCS: XSS ok. ?>><?php echo esc_html( $opt ); ?> </option>
23
  <?php } ?>
24
  </select>
25
  <?php } ?>
26
 
 
 
 
 
 
 
27
  <div class="clear"></div>
28
  <div class="frm-show-click frm_small_top_margin">
29
  <?php if ( ! isset( $field['post_field'] ) || 'post_category' !== $field['post_field'] ) { ?>
30
  <?php do_action( 'frm_add_multiple_opts_labels', $field ); ?>
31
- <ul id="frm_field_<?php echo esc_attr( $field['id'] ); ?>_opts" class="frm_sortable_field_opts<?php echo ( count( $field['options'] ) > 10 ) ? ' frm_field_opts_list' : ''; ?>">
32
  <?php FrmFieldsHelper::show_single_option( $field ); ?>
33
  </ul>
34
  <?php } ?>
10
  )
11
  );
12
  } else {
13
+ ?>
14
+ <select id="frm_dropdown_<?php echo esc_attr( $field['id'] ) ?>"
15
  name="<?php echo esc_attr( $field_name ) . ( FrmField::is_option_true( $field, 'multiple' ) ? '[]' : '' ); ?>" <?php echo FrmField::is_option_true( $field, 'size' ) ? 'class="auto_width"' : ''; ?> <?php echo FrmField::is_option_true( $field, 'multiple' ) ? 'multiple="multiple"' : ''; ?>>
16
  <?php
17
  foreach ( $field['options'] as $opt_key => $opt ) {
19
  $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
20
  $selected = ( $field['default_value'] === $field_val || FrmFieldsHelper::get_other_val( array( 'opt_key', 'field' ) ) ) ? ' selected="selected"' : '';
21
  ?>
22
+ <option value="<?php echo esc_attr( $field_val ) ?>"<?php echo $selected; // WPCS: XSS ok. ?>><?php echo esc_html( $opt ) ?> </option>
23
  <?php } ?>
24
  </select>
25
  <?php } ?>
26
 
27
+ <?php if ( $display['default_blank'] ) { ?>
28
+ <span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm_clear_on_focus frm-show-click">
29
+ <?php FrmFieldsHelper::show_default_blank_js( $field['default_blank'] ); ?>
30
+ </span>
31
+ <input type="hidden" name="field_options[default_blank_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['default_blank'] ) ?>" />
32
+ <?php } ?>
33
  <div class="clear"></div>
34
  <div class="frm-show-click frm_small_top_margin">
35
  <?php if ( ! isset( $field['post_field'] ) || 'post_category' !== $field['post_field'] ) { ?>
36
  <?php do_action( 'frm_add_multiple_opts_labels', $field ); ?>
37
+ <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts<?php echo ( count( $field['options'] ) > 10 ) ? ' frm_field_opts_list' : ''; ?>">
38
  <?php FrmFieldsHelper::show_single_option( $field ); ?>
39
  </ul>
40
  <?php } ?>
classes/views/frm-fields/back-end/field-captcha.php CHANGED
@@ -1,11 +1,8 @@
1
  <?php
2
  $frm_settings = FrmAppHelper::get_settings();
3
  if ( empty( $frm_settings->pubkey ) ) {
4
- ?>
5
- <div class="howto frm_no_captcha_text"><?php
6
- /* translators: %1$s: Link HTML, %2$s: End link */
7
- printf( esc_html__( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Secret Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>' );
8
- ?></div>
9
  <?php } ?>
10
- <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/recaptcha.png' ); ?>" class="recaptcha_placeholder" alt="reCaptcha"/>
11
- <input type="hidden" name="<?php echo esc_attr( $field_name ); ?>" value="1" />
1
  <?php
2
  $frm_settings = FrmAppHelper::get_settings();
3
  if ( empty( $frm_settings->pubkey ) ) {
4
+ ?>
5
+ <div class="howto frm_no_captcha_text"><?php printf( esc_html__( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Secret Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>' ); ?></div>
 
 
 
6
  <?php } ?>
7
+ <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/recaptcha.png' ) ?>" class="recaptcha_placeholder" alt="reCaptcha"/>
8
+ <input type="hidden" name="<?php echo esc_attr( $field_name ) ?>" value="1" />
classes/views/frm-fields/back-end/field-description.php DELETED
@@ -1,8 +0,0 @@
1
- <p>
2
- <label for="frm_description_<?php echo esc_attr( $field['id'] ); ?>">
3
- <?php esc_html_e( 'Field Description', 'formidable' ); ?>
4
- </label>
5
- <textarea name="field_options[description_<?php echo esc_attr( $field['id'] ); ?>]" class="frm_long_input" data-changeme="field_description_<?php echo esc_attr( $field['id'] ); ?>"><?php
6
- echo FrmAppHelper::esc_textarea( $field['description'] ); // WPCS: XSS ok.
7
- ?></textarea>
8
- </p>
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/field-hidden.php CHANGED
@@ -1,4 +1,4 @@
1
- <input type="text" id="<?php echo esc_attr( $html_id ); ?>" name="<?php echo esc_attr( $field_name ); ?>" value="<?php echo esc_attr( $field['default_value'] ); ?>" class="dyn_default_value" />
2
  <p class="howto frm_clear">
3
- <?php esc_html_e( 'Note: This field will not show in the form. Enter the value to be hidden.', 'formidable' ); ?>
4
  </p>
1
+ <input type="text" id="<?php echo esc_attr( $html_id ) ?>" name="<?php echo esc_attr( $field_name ) ?>" value="<?php echo esc_attr( $field['default_value'] ); ?>" class="dyn_default_value" />
2
  <p class="howto frm_clear">
3
+ <?php esc_html_e( 'Note: This field will not show in the form. Enter the value to be hidden.', 'formidable' ) ?>
4
  </p>
classes/views/frm-fields/back-end/field-html.php CHANGED
@@ -1,6 +1,6 @@
1
- <div class="frm-embed-field-placeholder">
2
- <div class="frm-embed-message">
3
- <?php esc_html_e( 'Custom HTML:', 'formidable' ); ?>
4
- <?php echo esc_html( FrmAppHelper::truncate( htmlentities( $field['description'] ), 60 ) ); ?>
5
- </div>
6
  </div>
1
+ <div class="frm_html_field_placeholder">
2
+ <div class="howto button-secondary frm_html_field">
3
+ <?php esc_html_e( 'This is a placeholder for your custom HTML.', 'formidable' ) ?><br/>
4
+ <?php esc_html_e( 'You can edit this content in the field settings.', 'formidable' ) ?>
5
+ </div>
6
  </div>
classes/views/frm-fields/back-end/field-multiple.php CHANGED
@@ -1,11 +1,13 @@
1
  <?php
2
-
3
- _deprecated_file( esc_html( basename( __FILE__ ) ), '4.0', null );
4
-
5
  if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
6
  $type = $field['type'];
7
  do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) );
8
  } else {
9
- $read_only = $field['read_only'];
10
- include( dirname( __FILE__ ) . '/' . $field['type'] . '-field.php' );
 
 
 
 
11
  }
1
  <?php
2
+ $field['default_value'] = maybe_unserialize( $field['default_value'] );
 
 
3
  if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
4
  $type = $field['type'];
5
  do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) );
6
  } else {
7
+ do_action( 'frm_add_multiple_opts_labels', $field );
8
+ ?>
9
+ <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts frm_clear<?php echo ( count( $field['options'] ) > 10 ) ? ' frm_field_opts_list' : ''; ?>">
10
+ <?php FrmFieldsHelper::show_single_option( $field ); ?>
11
+ </ul>
12
+ <?php
13
  }
classes/views/frm-fields/back-end/field-user-id.php CHANGED
@@ -1,4 +1,3 @@
1
- <span class="frm-with-left-icon">
2
- <i class="frm_icon_font frm_user_icon"></i>
3
- <input type="text" value="<?php esc_attr_e( 'User ID fields will not show in your form.', 'formidable' ); ?>" disabled />
4
- </span>
1
+ <p class="howto frm_clear">
2
+ <?php esc_html_e( 'Note: This field will not show in the form, but will link the user id to it as long as the user is logged in at the time of form submission.', 'formidable' ) ?>
3
+ </p>
 
classes/views/frm-fields/back-end/html-content.php CHANGED
@@ -1,8 +1,7 @@
1
- <p>
2
- <label>
3
- <?php esc_html_e( 'Content', 'formidable' ); ?>
4
- </label>
5
- <textarea name="field_options[description_<?php echo absint( $field['id'] ); ?>]" rows="8"><?php
6
  echo FrmAppHelper::esc_textarea( $field['description'] ); // WPCS: XSS ok.
7
  ?></textarea>
8
- </p>
 
1
+ <tr>
2
+ <td colspan="2"><?php esc_html_e( 'Content', 'formidable' ) ?><br/>
3
+ <textarea name="field_options[description_<?php echo absint( $field['id'] ) ?>]" class="frm_98_width" rows="8"><?php
 
 
4
  echo FrmAppHelper::esc_textarea( $field['description'] ); // WPCS: XSS ok.
5
  ?></textarea>
6
+ </td>
7
+ </tr>
classes/views/frm-fields/back-end/inline-modal.php DELETED
@@ -1,15 +0,0 @@
1
- <div class="frm-inline-modal postbox <?php echo esc_attr( $args['class'] . ( $args['show'] ? '' : ' frm_hidden' ) ); ?>" id="<?php echo esc_attr( $args['id'] ); ?>">
2
- <a href="#" class="dismiss alignright" title="<?php esc_attr_e( 'Close', 'formidable' ); ?>">
3
- <i class="frm_icon_font frm_close_icon" aria-label="<?php esc_attr_e( 'Close', 'formidable' ); ?>" aria-hidden="true"></i>
4
- </a>
5
- <ul class="frm-nav-tabs">
6
- <li class="frm-tabs">
7
- <a href="#">
8
- <?php echo esc_html( $args['title'] ); ?>
9
- </a>
10
- </li>
11
- </ul>
12
- <div class="inside">
13
- <?php call_user_func( $args['callback'], $args['args'] ); ?>
14
- </div>
15
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/input-mask-info.php DELETED
@@ -1,28 +0,0 @@
1
- <p class="howto">
2
- <?php esc_html_e( 'To create a custom input mask, you’ll need to use this specific set of symbols:', 'formidable' ); ?>
3
- </p>
4
- <p>
5
- 9 - <?php esc_html_e( 'Numeric', 'formidable' ); ?> (0-9)<br/>
6
- a - <?php esc_html_e( 'Alphabetical', 'formidable' ); ?> (a-z, A-Z)<br/>
7
- A - <?php esc_html_e( 'Uppercase alphabetical', 'formidable' ); ?> (A-Z)<br/>
8
- * - <?php esc_html_e( 'Alphanumeric', 'formidable' ); ?> (0-9, a-z, A-Z)<br/>
9
- & - <?php esc_html_e( 'Uppercase alphanumeric', 'formidable' ); ?> (0-9, A-Z)
10
- </p>
11
- <p>
12
- <?php esc_html_e( 'Example:', 'formidable' ); ?> 1 (999)-999-9999
13
- </p>
14
- <p>
15
- <a href="<?php
16
- echo esc_url(
17
- FrmAppHelper::admin_upgrade_link(
18
- array(
19
- 'medium' => 'builder',
20
- 'content' => 'inputmask',
21
- ),
22
- 'knowledgebase/format/'
23
- )
24
- );
25
- ?>" target="_blank" rel="noopener">
26
- <?php esc_html_e( 'See more examples and docs', 'formidable' ); ?>
27
- </a>
28
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/layout-classes.php DELETED
@@ -1,44 +0,0 @@
1
- <div id="frm-layout-classes">
2
- <p class="howto">
3
- <?php esc_html_e( 'Click on any box below to set the width for your selected field.', 'formidable' ); ?>
4
- </p>
5
- <ul class="frm_code_list frm_grid_container">
6
- <li class="frm_half frm_form_field">
7
- <a href="javascript:void(0);" data-code="frm_half" class="frm_insert_code show_frm_classes">
8
- 1/2
9
- </a>
10
- </li>
11
- <?php
12
- foreach ( FrmFormsHelper::grid_classes() as $c => $d ) {
13
- ?>
14
- <li class="<?php echo esc_attr( $c ); ?> frm_form_field">
15
- <a href="javascript:void(0);" data-code="<?php echo esc_attr( $c ); ?>" class="frm_insert_code show_frm_classes">
16
- <?php echo esc_html( FrmFormsHelper::style_class_label( $d, $c ) ); ?>
17
- </a>
18
- </li>
19
- <?php
20
- unset( $c, $d );
21
- }
22
- ?>
23
- </ul>
24
-
25
- <h4 class="frm-with-line">
26
- <span><?php esc_html_e( 'Other Style Classes', 'formidable' ); ?></span>
27
- </h4>
28
- <ul class="frm_code_list frm-full-hover">
29
- <?php
30
- foreach ( FrmFormsHelper::css_classes() as $c => $d ) {
31
- $title = ( ! empty( $d ) && is_array( $d ) && isset( $d['title'] ) ) ? $d['title'] : '';
32
- ?>
33
- <li>
34
- <a href="javascript:void(0);" data-code="<?php echo esc_attr( $c ); ?>" class="frm_insert_code show_frm_classes<?php echo esc_attr( ! empty( $title ) ? ' frm_help' : '' ); ?>" <?php echo ( ! empty( $title ) ? ' title="' . esc_attr( $title ) . '"' : '' ); ?>>
35
- <span><?php echo esc_html( $c ); ?></span>
36
- <?php echo esc_html( FrmFormsHelper::style_class_label( $d, $c ) ); ?>
37
- </a>
38
- </li>
39
- <?php
40
- unset( $c, $d );
41
- }
42
- ?>
43
- </ul>
44
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/max.php CHANGED
@@ -1,12 +1 @@
1
- <p class="frm6 frm_form_field">
2
- <label for="field_options_max_<?php echo esc_attr( $field['id'] ); ?>">
3
- <?php
4
- if ( 'textarea' === $field['type'] || 'rte' === $field['type'] ) {
5
- esc_html_e( 'Rows', 'formidable' );
6
- } else {
7
- esc_html_e( 'Max Characters', 'formidable' );
8
- }
9
- ?>
10
- </label>
11
- <input type="text" name="field_options[max_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['max'] ); ?>" id="field_options_max_<?php echo esc_attr( $field['id'] ); ?>" size="5" />
12
- </p>
1
+ <input type="text" name="field_options[max_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['max'] ); ?>" size="5" /> <span class="howto"><?php echo esc_html( ( 'textarea' === $field['type'] || 'rte' === $field['type'] ) ? __( 'rows high', 'formidable' ) : __( 'characters maximum', 'formidable' ) ) ?></span>
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/number-range.php CHANGED
@@ -1,19 +1,15 @@
1
- <p class="frm8 frm_first frm_form_field frm-number-range">
2
- <label for="frm_format_<?php echo esc_attr( $field['field_key'] ); ?>" class="frm_help" title="<?php esc_attr_e( 'Set the number range the field validation should allow. Browsers that support the HTML5 number field require a number range to determine the numbers seen when clicking the arrows next to the field.', 'formidable' ); ?>">
3
- <?php esc_html_e( 'Number Range', 'formidable' ); ?>
4
- </label>
5
- <span class="frm_grid_container">
6
- <span class="frm5 frm_form_field frm-range-min">
7
- <input type="text" name="field_options[minnum_<?php echo absint( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['minnum'] ); ?>" />
8
- </span>
9
- <span class="frm5 frm_last frm_form_field">
10
- <input type="text" name="field_options[maxnum_<?php echo absint( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['maxnum'] ); ?>" />
11
- </span>
12
- </span>
13
- </p>
14
- <p class="frm3 frm_last frm_form_field">
15
- <label for="frm_step_<?php echo esc_attr( $field['field_key'] ); ?>">
16
- <?php esc_html_e( 'Step', 'formidable' ); ?>
17
- </label>
18
- <input type="text" name="field_options[step_<?php echo absint( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['step'] ); ?>" id="frm_step_<?php echo esc_attr( $field['field_key'] ); ?>" />
19
- </p>
1
+ <tr>
2
+ <td style="width:150px">
3
+ <label><?php esc_html_e( 'Number Range', 'formidable' ) ?>
4
+ <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Set the number range the field validation should allow. Browsers that support the HTML5 number field require a number range to determine the numbers seen when clicking the arrows next to the field.', 'formidable' ) ?>" ></span>
5
+ </label>
6
+ </td>
7
+ <td>
8
+ <input type="text" name="field_options[minnum_<?php echo absint( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['minnum'] ); ?>" size="5" />
9
+ <span class="howto"><?php esc_html_e( 'minimum', 'formidable' ) ?></span>
10
+ <input type="text" name="field_options[maxnum_<?php echo absint( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['maxnum'] ); ?>" size="5" />
11
+ <span class="howto"><?php esc_html_e( 'maximum', 'formidable' ) ?></span>
12
+ <input type="text" name="field_options[step_<?php echo absint( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['step'] ); ?>" size="5" />
13
+ <span class="howto"><?php esc_html_e( 'step', 'formidable' ) ?></span>
14
+ </td>
15
+ </tr>
 
 
 
 
classes/views/frm-fields/back-end/pixels-wide.php CHANGED
@@ -1,16 +1,18 @@
1
- <p class="<?php echo esc_attr( $display_max ? 'frm6 frm_form_field' : '' ); ?>">
2
- <label for="field_options_size_<?php echo esc_attr( $field['id'] ); ?>">
3
- <?php esc_html_e( 'Field Size', 'formidable' ); ?>
4
- <span class="frm-sub-label">
5
- <?php esc_html_e( '(%, px, em)', 'formidable' ); ?>
 
 
 
 
 
6
  </span>
7
- </label>
8
-
9
- <input type="text" name="field_options[size_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['size'] ); ?>" size="5" id="field_options_size_<?php echo esc_attr( $field['id'] ); ?>" aria-describedby="howto_size_<?php echo esc_attr( $field['id'] ); ?>" />
10
- </p>
11
-
12
- <?php
13
- if ( $display_max ) {
14
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/max.php' );
15
- }
16
- ?>
1
+ <tr>
2
+ <td class="frm_150_width">
3
+ <label for="field_options_size_<?php echo esc_attr( $field['id'] ) ?>">
4
+ <?php esc_html_e( 'Field Size', 'formidable' ) ?>
5
+ </label>
6
+ </td>
7
+ <td>
8
+ <input type="text" name="field_options[size_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['size'] ); ?>" size="5" id="field_options_size_<?php echo esc_attr( $field['id'] ) ?>" aria-describedby="howto_size_<?php echo esc_attr( $field['id'] ) ?>" />
9
+ <span class="howto" id="howto_size_<?php echo esc_attr( $field['id'] ) ?>">
10
+ <?php esc_html_e( 'pixels wide', 'formidable' ) ?>
11
  </span>
12
+ <?php
13
+ if ( $display_max ) {
14
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/max.php' );
15
+ }
16
+ ?>
17
+ </td>
18
+ </tr>
 
 
 
classes/views/frm-fields/back-end/radio-field.php DELETED
@@ -1,48 +0,0 @@
1
- <?php
2
-
3
- if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' ) {
4
- $type = $field['type'];
5
- do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) );
6
- } elseif ( is_array( $field['options'] ) ) {
7
-
8
- foreach ( $field['options'] as $opt_key => $opt ) {
9
-
10
- $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field );
11
- $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
12
- ?>
13
- <div class="frm_radio">
14
- <label for="<?php echo esc_attr( $html_id . '-' . $opt_key ); ?>">
15
- <?php
16
-
17
- $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' ';
18
-
19
- $other_opt = false;
20
- $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked );
21
- ?>
22
- <input type="radio" name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>" <?php
23
- echo $checked; // WPCS: XSS ok.
24
- do_action( 'frm_field_input_html', $field );
25
- ?>/>
26
- <?php echo ' ' . FrmAppHelper::kses( $opt, 'all' ); // WPCS: XSS ok. ?>
27
- </label>
28
- <?php
29
- FrmFieldsHelper::include_other_input(
30
- array(
31
- 'other_opt' => $other_opt,
32
- 'read_only' => false,
33
- 'checked' => $checked,
34
- 'name' => $other_args['name'],
35
- 'value' => $other_args['value'],
36
- 'field' => $field,
37
- 'html_id' => $html_id,
38
- 'opt_key' => $opt_key,
39
- 'opt_label' => $opt,
40
- )
41
- );
42
-
43
- unset( $other_opt, $other_args );
44
- ?>
45
- </div>
46
- <?php
47
- }
48
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/settings.php DELETED
@@ -1,382 +0,0 @@
1
- <div class="frm-single-settings frm_hidden frm-fields" id="frm-single-settings-<?php echo esc_attr( $field['id'] ); ?>" data-fid="<?php echo esc_attr( $field['id'] ); ?>">
2
- <input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr( $field['id'] ); ?>" />
3
- <input type="hidden" name="field_options[field_order_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['field_order'] ); ?>"/>
4
-
5
- <div class="frm-sub-label alignright">
6
- (ID <?php echo esc_html( $field['id'] ); ?>)
7
- </div>
8
- <h3>
9
- <?php
10
- printf(
11
- /* translators: %s: Field type */
12
- esc_html__( '%s Field', 'formidable' ),
13
- esc_html( $all_field_types[ $field['type'] ]['name'] )
14
- );
15
- ?>
16
- </h3>
17
-
18
- <div class="frm_grid_container frm-collapse-me">
19
- <?php if ( $display['label'] ) { ?>
20
- <p>
21
- <label for="frm_name_<?php echo esc_attr( $field['id'] ); ?>">
22
- <?php echo esc_html( apply_filters( 'frm_builder_field_label', __( 'Field Label', 'formidable' ), $field ) ); ?>
23
- </label>
24
- <input type="text" name="field_options[name_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['name'] ); ?>" id="frm_name_<?php echo esc_attr( $field['id'] ); ?>" data-changeme="field_label_<?php echo esc_attr( $field['id'] ); ?>" />
25
- </p>
26
- <?php } else { ?>
27
- <input type="hidden" name="field_options[name_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['name'] ); ?>" id="frm_name_<?php echo esc_attr( $field['id'] ); ?>" />
28
- <?php } ?>
29
-
30
- <p>
31
- <?php if ( $display['required'] ) { ?>
32
- <label for="frm_req_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_inline_label">
33
- <input type="checkbox" id="frm_req_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_req_field" name="field_options[required_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['required'], 1 ); ?> />
34
- <?php esc_html_e( 'Required', 'formidable' ); ?>
35
- </label>
36
- <?php
37
- }
38
-
39
- if ( $display['unique'] ) {
40
- ?>
41
- <label for="frm_uniq_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.', 'formidable' ); ?>"><input type="checkbox" name="field_options[unique_<?php echo esc_attr( $field['id'] ); ?>]" id="frm_uniq_field_<?php echo esc_attr( $field['id'] ); ?>" value="1" <?php checked( $field['unique'], 1 ); ?> class="frm_mark_unique" />
42
- <?php esc_html_e( 'Unique', 'formidable' ); ?>
43
- </label>
44
- <?php
45
- }
46
-
47
- if ( $display['read_only'] ) {
48
- ?>
49
- <label for="frm_read_only_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ); ?>" >
50
- <input type="checkbox" id="frm_read_only_field_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[read_only_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['read_only'], 1 ); ?>/>
51
- <?php esc_html_e( 'Read Only', 'formidable' ); ?>
52
- </label>
53
- <?php
54
- }
55
-
56
- do_action( 'frm_field_options_form_top', $field, $display, $values );
57
- ?>
58
- </p>
59
-
60
- <?php
61
- if ( $display['range'] ) {
62
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/number-range.php' );
63
- }
64
-
65
- $field_obj->show_primary_options( compact( 'field', 'display', 'values' ) );
66
-
67
- ?>
68
- </div>
69
-
70
- <?php if ( ! empty( $display_type ) ) { ?>
71
- <h3>
72
- <?php
73
- printf(
74
- /* translators: %s: Field type */
75
- esc_html__( '%s Options', 'formidable' ),
76
- esc_html( $all_field_types[ $display['type'] ]['name'] )
77
- );
78
- ?>
79
- <i class="frm_icon_font frm_arrowdown6_icon"></i>
80
- </h3>
81
- <div class="frm_grid_container frm-collapse-me">
82
- <?php
83
- if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
84
- ?>
85
- <div class="frm-inline-message" id="frm_has_hidden_options_<?php echo esc_attr( $field['id'] ); ?>">
86
- <?php echo FrmFieldsHelper::get_term_link( $field['taxonomy'] ); // WPCS: XSS ok. ?>
87
- </div>
88
- <?php
89
- } elseif ( in_array( $field['type'], array( 'select', 'radio', 'checkbox' ) ) ) {
90
- $has_options = ! empty( $field['options'] );
91
- $short_name = FrmAppHelper::truncate( strip_tags( str_replace( '"', '&quot;', $field['name'] ) ), 20 );
92
-
93
- /* translators: %s: Field name */
94
- $option_title = sprintf( __( '%s Options', 'formidable' ), $short_name );
95
-
96
- ?>
97
- <a href="#" title="<?php echo esc_attr( $option_title ); ?>" class="frm-bulk-edit-link">
98
- <?php esc_html_e( 'Bulk Edit Options', 'formidable' ); ?>
99
- </a>
100
- <?php do_action( 'frm_add_multiple_opts_labels', $field ); ?>
101
- <ul id="frm_field_<?php echo esc_attr( $field['id'] ); ?>_opts" class="frm_sortable_field_opts frm_clear<?php echo ( count( $field['options'] ) > 10 ) ? ' frm_field_opts_list' : ''; ?> frm_add_remove" data-key="<?php echo esc_attr( $field['field_key'] ); ?>">
102
- <?php FrmFieldsHelper::show_single_option( $field ); ?>
103
- </ul>
104
- <a href="javascript:void(0);" data-opttype="single" class="frm_cb_button frm-small-add frm_add_opt frm6 frm_form_field" id="frm_add_opt_<?php echo esc_attr( $field['id'] ); ?>">
105
- <span class="frm_icon_font frm_add_tag"></span>
106
- <?php esc_html_e( 'Add Option', 'formidable' ); ?>
107
- </a>
108
-
109
- <?php
110
- }
111
-
112
- $field_obj->show_extra_field_choices( compact( 'field', 'display', 'values' ) );
113
- ?>
114
- </div>
115
- <?php
116
- }
117
-
118
- if ( $display['clear_on_focus'] ) {
119
- do_action( 'frm_extra_field_display_options', $field );
120
- }
121
-
122
- do_action( 'frm_before_field_options', $field );
123
-
124
- ?>
125
-
126
- <h3 class="frm-collapsed">
127
- <?php esc_html_e( 'Advanced', 'formidable' ); ?>
128
- <i class="frm_icon_font frm_arrowdown6_icon"></i>
129
- </h3>
130
- <div class="frm_grid_container frm-collapse-me">
131
- <?php
132
- if ( $display['description'] ) {
133
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-description.php' );
134
- }
135
- ?>
136
-
137
- <?php if ( $display['clear_on_focus'] ) { ?>
138
- <p>
139
- <label for="frm_placeholder_<?php echo esc_attr( $field['id'] ); ?>">
140
- <?php esc_html_e( 'Placeholder Text', 'formidable' ); ?>
141
- </label>
142
- <input type="text" name="field_options[placeholder_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['placeholder'] ); ?>" id="frm_placeholder_<?php echo esc_attr( $field['id'] ); ?>" data-changeme="field_<?php echo esc_attr( $field['field_key'] ); ?>" data-changeatt="placeholder" />
143
- </p>
144
- <?php } ?>
145
-
146
- <?php if ( $display['default'] ) { ?>
147
- <div class="frm-has-modal">
148
- <?php if ( count( $default_value_types ) > 1 ) { ?>
149
- <span class="frm-default-switcher">
150
- <?php foreach ( $default_value_types as $def_name => $link ) { ?>
151
- <a href="#" title="<?php echo esc_attr( $link['title'] ); ?>" class="<?php echo esc_attr( $link['class'] ); ?>" data-toggleclass="frm_hidden frm-open"
152
- <?php foreach ( $link['data'] as $data_key => $data_value ) { ?>
153
- data-<?php echo esc_attr( $data_key ); ?>="<?php echo esc_attr( $data_value . ( substr( $data_value, -1 ) === '-' ? $field['id'] : '' ) ); ?>"
154
- <?php } ?>
155
- <?php if ( isset( $link['data']['frmshow'] ) ) { ?>
156
- data-frmhide=".frm-inline-modal,.default-value-section-<?php echo esc_attr( $field['id'] ); ?>"
157
- <?php } ?>
158
- >
159
- <i class="<?php echo esc_attr( $link['icon'] ); ?>"></i>
160
- </a>
161
- <?php } ?>
162
- </span>
163
- <?php } ?>
164
-
165
- <p class="frm-has-modal default-value-section-<?php echo esc_attr( $field['id'] . ( isset( $default_value_types['default_value']['current'] ) ? '' : ' frm_hidden' ) ); ?>" id="default-value-for-<?php echo esc_attr( $field['id'] ); ?>">
166
- <label for="frm_default_value_<?php echo esc_attr( $field['id'] ); ?>">
167
- <?php esc_html_e( 'Default Value', 'formidable' ); ?>
168
- </label>
169
- <span class="frm-with-right-icon">
170
- <i class="frm-show-inline-modal frm_icon_font frm_more_horiz_solid_icon" data-open="frm-smart-values-box"></i>
171
- <?php
172
- if ( isset( $display['default_value'] ) && $display['default_value'] ) {
173
- $default_name = 'field_options[dyn_default_value_' . $field['id'] . ']';
174
- $default_value = isset( $field['dyn_default_value'] ) ? $field['dyn_default_value'] : '';
175
- } else {
176
- $default_name = 'default_value_' . $field['id'];
177
- $default_value = $field['default_value'];
178
- }
179
- $field_obj->default_value_to_string( $default_value );
180
- ?>
181
- <input type="text" name="<?php echo esc_attr( $default_name ); ?>" value="<?php echo esc_attr( $default_value ); ?>" id="frm_default_value_<?php echo esc_attr( $field['id'] ); ?>" class="default-value-field" />
182
- </span>
183
- </p>
184
- <?php do_action( 'frm_default_value_setting', compact( 'field', 'display', 'default_value_types' ) ); ?>
185
- </div>
186
- <?php } ?>
187
-
188
- <?php $field_obj->show_after_default( compact( 'field', 'display' ) ); ?>
189
-
190
- <?php if ( $display['css'] ) { ?>
191
- <p class="frm-has-modal">
192
- <label for="frm_classes_<?php echo esc_attr( $field['id'] ); ?>" class="frm_help" title="<?php esc_attr_e( 'Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable' ); ?>">
193
- <?php esc_html_e( 'CSS Layout Classes', 'formidable' ); ?>
194
- </label>
195
- <span class="frm-with-right-icon">
196
- <i class="frm-show-inline-modal frm_icon_font frm_more_horiz_solid_icon" data-open="frm-layout-classes-box"></i>
197
- <input type="text" name="field_options[classes_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['classes'] ); ?>" id="frm_classes_<?php echo esc_attr( $field['id'] ); ?>" />
198
- </span>
199
- </p>
200
- <?php } ?>
201
-
202
- <?php
203
- // Field Size
204
- if ( $display['size'] && ! in_array( $field['type'], array( 'select', 'data', 'time' ) ) ) {
205
- $display_max = $display['max'];
206
- include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/pixels-wide.php' );
207
- }
208
- ?>
209
-
210
- <?php if ( $display['show_image'] ) { ?>
211
- <p>
212
- <label for="frm_show_image_<?php echo esc_attr( $field['id'] ); ?>">
213
- <input type="checkbox" id="frm_show_image_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[show_image_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['show_image'], 1 ); ?> />
214
- <?php esc_html_e( 'If this URL points to an image, show to image on the entries listing page.', 'formidable' ); ?>
215
- </label>
216
- </p>
217
- <?php } ?>
218
-
219
- <?php if ( $display['captcha_size'] && $frm_settings->re_type !== 'invisible' ) { ?>
220
- <p class="frm6 frm_first frm_form_field">
221
- <label for="field_options_captcha_size_<?php echo esc_attr( $field['id'] ); ?>" class="frm_help" title="<?php esc_attr_e( 'Set the size of the captcha field. The compact option is best if your form is in a small area.', 'formidable' ); ?>">
222
- <?php esc_html_e( 'ReCaptcha Type', 'formidable' ); ?>
223
- </label>
224
- <select name="field_options[captcha_size_<?php echo esc_attr( $field['id'] ); ?>]" id="field_options_captcha_size_<?php echo esc_attr( $field['id'] ); ?>">
225
- <option value="normal" <?php selected( $field['captcha_size'], 'normal' ); ?>>
226
- <?php esc_html_e( 'Normal', 'formidable' ); ?>
227
- </option>
228
- <option value="compact" <?php selected( $field['captcha_size'], 'compact' ); ?>>
229
- <?php esc_html_e( 'Compact', 'formidable' ); ?>
230
- </option>
231
- </select>
232
- </p>
233
- <p class="frm6 frm_form_field">
234
- <label for="captcha_theme_<?php echo esc_attr( $field['field_key'] ); ?>">
235
- <?php esc_html_e( 'reCAPTCHA Color', 'formidable' ); ?>
236
- </label>
237
- <select name="field_options[captcha_theme_<?php echo esc_attr( $field['id'] ); ?>]" id="captcha_theme_<?php echo esc_attr( $field['field_key'] ); ?>">
238
- <option value="light" <?php selected( $field['captcha_theme'], 'light' ); ?>>
239
- <?php esc_html_e( 'Light', 'formidable' ); ?>
240
- </option>
241
- <option value="dark" <?php selected( $field['captcha_theme'], 'dark' ); ?>>
242
- <?php esc_html_e( 'Dark', 'formidable' ); ?>
243
- </option>
244
- </select>
245
- </p>
246
- <?php } ?>
247
-
248
- <?php
249
- if ( $display['format'] ) {
250
- FrmFieldsController::show_format_option( $field );
251
- }
252
- ?>
253
-
254
- <?php do_action( 'frm_field_options', compact( 'field', 'display', 'values' ) ); ?>
255
-
256
- <?php if ( $display['required'] ) { ?>
257
- <p class="frm6 frm_form_field frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>">
258
- <label>
259
- <?php esc_html_e( 'Required Field Indicator', 'formidable' ); ?>
260
- </label>
261
- <input type="text" name="field_options[required_indicator_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['required_indicator'] ); ?>" />
262
- </p>
263
- <?php } ?>
264
-
265
- <?php if ( $display['label_position'] ) { ?>
266
- <p class="frm6 frm_form_field">
267
- <label><?php esc_html_e( 'Label Position', 'formidable' ); ?></label>
268
- <select name="field_options[label_<?php echo esc_attr( $field['id'] ); ?>]">
269
- <option value=""<?php selected( $field['label'], '' ); ?>>
270
- <?php esc_html_e( 'Default', 'formidable' ); ?>
271
- </option>
272
- <?php
273
- foreach ( FrmStylesHelper::get_single_label_positions() as $pos => $pos_label ) {
274
- if ( ! $display['clear_on_focus'] && 'inside' === $pos ) {
275
- // Don't allow inside labels for fields without placeholders.
276
- continue;
277
- }
278
- ?>
279
- <option value="<?php echo esc_attr( $pos ); ?>"<?php selected( $field['label'], $pos ); ?>>
280
- <?php echo esc_html( $pos_label ); ?>
281
- </option>
282
- <?php } ?>
283
- </select>
284
- </p>
285
- <?php } ?>
286
-
287
- <p class="frm6 frm_form_field">
288
- <label for="field_options_field_key_<?php echo esc_attr( $field['id'] ); ?>" class="frm_help" title="<?php esc_attr_e( 'The field key can be used as an alternative to the field ID in many cases.', 'formidable' ); ?>">
289
- <?php esc_html_e( 'Field Key', 'formidable' ); ?>
290
- </label>
291
- <input type="text" name="field_options[field_key_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['field_key'] ); ?>" id="field_options_field_key_<?php echo esc_attr( $field['id'] ); ?>"/>
292
- </p>
293
-
294
- <?php if ( count( $field_types ) > 1 ) { ?>
295
- <p class="frm6 frm_form_field">
296
- <label for="field_options_type_<?php echo esc_attr( $field['id'] ); ?>">
297
- <?php esc_html_e( 'Field Type', 'formidable' ); ?>
298
- </label>
299
- <select name="field_options[type_<?php echo esc_attr( $field['id'] ); ?>]" id="field_options_type_<?php echo esc_attr( $field['id'] ); ?>">
300
- <?php foreach ( $field_types as $fkey => $ftype ) { ?>
301
- <option value="<?php echo esc_attr( $fkey ); ?>" <?php echo ( $fkey === $field['type'] ) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists( $fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>>
302
- <?php echo esc_html( is_array( $ftype ) ? $ftype['name'] : $ftype ); ?>
303
- </option>
304
- <?php
305
- unset( $fkey, $ftype );
306
- }
307
- ?>
308
- </select>
309
- </p>
310
- <?php } else { ?>
311
- <input type="hidden" id="field_options_type_<?php echo esc_attr( $field['id'] ); ?>" value="<?php echo esc_attr( $field['type'] ); ?>" />
312
- <?php } ?>
313
-
314
- <table class="form-table frm_no_top_margin">
315
- <?php $field_obj->show_options( $field, $display, $values ); ?>
316
- <?php do_action( 'frm_field_options_form', $field, $display, $values ); ?>
317
- </table>
318
- </div>
319
-
320
- <?php if ( $display['required'] || $display['invalid'] || $display['unique'] || $display['conf_field'] ) { ?>
321
- <?php
322
- $hidden_invalid = FrmField::is_field_type( $field, 'text' ) && ! FrmField::is_option_true( $field, 'format' );
323
- $has_validation = ( ( $display['invalid'] && ! $hidden_invalid ) || $field['required'] || FrmField::is_option_true( $field, 'unique' ) || FrmField::is_option_true( $field, 'conf_field' ) );
324
- ?>
325
- <div class="frm_validation_msg <?php echo esc_attr( $has_validation ? '' : 'frm_hidden' ); ?>">
326
- <h3 class="frm-collapsed">
327
- <?php esc_html_e( 'Validation Messages', 'formidable' ); ?>
328
- <i class="frm_icon_font frm_arrowdown6_icon"></i>
329
- </h3>
330
-
331
- <div class="frm_validation_box frm-collapse-me">
332
- <?php if ( $display['required'] ) { ?>
333
- <p class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>">
334
- <label for="field_options_blank_<?php echo esc_attr( $field['id'] ); ?>">
335
- <?php esc_html_e( 'Required', 'formidable' ); ?>
336
- </label>
337
- <input type="text" name="field_options[blank_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['blank'] ); ?>" id="field_options_blank_<?php echo esc_attr( $field['id'] ); ?>"/>
338
- </p>
339
- <?php } ?>
340
-
341
- <?php if ( $display['invalid'] ) { ?>
342
- <p class="frm_invalid_msg<?php echo esc_attr( $field['id'] . ( $hidden_invalid ? ' frm_hidden' : '' ) ); ?>">
343
- <label for="field_options_invalid_<?php echo esc_attr( $field['id'] ); ?>">
344
- <?php esc_html_e( 'Invalid Format', 'formidable' ); ?>
345
- </label>
346
- <input type="text" name="field_options[invalid_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['invalid'] ); ?>" id="field_options_invalid_<?php echo esc_attr( $field['id'] ); ?>"/>
347
- </p>
348
- <?php
349
- }
350
-
351
- if ( $display['unique'] ) {
352
- ?>
353
- <p class="frm_unique_details<?php echo esc_attr( $field['id'] . ( $field['unique'] ? '' : ' frm_hidden' ) ); ?>">
354
- <label for="field_options_unique_msg_<?php echo esc_attr( $field['id'] ); ?>">
355
- <?php esc_html_e( 'Unique', 'formidable' ); ?>
356
- </label>
357
- <input type="text" name="field_options[unique_msg_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['unique_msg'] ); ?>" id="field_options_unique_msg_<?php echo esc_attr( $field['id'] ); ?>" />
358
- </p>
359
- <?php
360
- }
361
-
362
- if ( $display['conf_field'] ) {
363
- ?>
364
- <p class="frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
365
- <label for="field_options_conf_msg_<?php echo esc_attr( $field['id'] ); ?>">
366
- <?php esc_html_e( 'Confirmation', 'formidable' ); ?>
367
- </label>
368
- <input type="text" name="field_options[conf_msg_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['conf_msg'] ); ?>" id="field_options_conf_msg_<?php echo esc_attr( $field['id'] ); ?>" />
369
- </p>
370
- <?php
371
- }
372
- ?>
373
- </div>
374
- </div>
375
- <?php } ?>
376
-
377
- <?php do_action( 'frm_after_field_options', compact( 'field', 'display', 'values' ) ); ?>
378
-
379
- <?php if ( $display['conf_field'] ) { ?>
380
- <input type="hidden" name="field_options[conf_desc_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['conf_desc'] ); ?>" />
381
- <?php } ?>
382
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/smart-values.php DELETED
@@ -1,18 +0,0 @@
1
- <div class="cta-inside">
2
- <p id="frm-upgrade-message">
3
- <?php
4
- /* translators: %s: Feature name */
5
- $message = __( '%s are not available on your plan. Did you know you can upgrade to PRO to unlock more awesome features?', 'formidable' );
6
- printf( esc_html( $message ), '<span class="frm_feature_label">Smart tags</span>' );
7
- ?>
8
- </p>
9
- <p>
10
- <a href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( $upgrade_link ) ); ?>" class="button button-primary frm-button-primary" target="_blank" rel="noopener noreferrer" id="frm-upgrade-modal-link">
11
- <?php esc_html_e( 'Upgrade to Pro', 'formidable' ); ?>
12
- </a>
13
-
14
- <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( FrmAppHelper::admin_upgrade_link( $upgrade_link, 'knowledgebase/install-formidable-forms/' ) ) ); ?>" target="_blank" class="frm-link-secondary alignright">
15
- <?php esc_html_e( 'Already purchased?', 'formidable' ); ?>
16
- </a>
17
- </p>
18
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/back-end/value-format.php CHANGED
@@ -1,9 +1,7 @@
1
- <p class="frm-has-modal">
2
- <label for="frm_format_<?php echo esc_attr( $field['field_key'] ); ?>" class="frm_help" title="<?php esc_attr_e( 'Insert the format you would like to accept. Use a regular expression starting with ^ or an exact format like (999)999-9999.', 'formidable' ); ?>">
3
- <?php esc_html_e( 'Format', 'formidable' ); ?>
4
- </label>
5
- <span class="frm-with-right-icon">
6
- <i class="frm-show-inline-modal frm_icon_font frm_more_horiz_solid_icon" data-open="frm-input-mask-box"></i>
7
- <input type="text" class="frm_long_input frm_format_opt" value="<?php echo esc_attr( $field['format'] ); ?>" name="field_options[format_<?php echo absint( $field['id'] ); ?>]" id="frm_format_<?php echo absint( $field['id'] ); ?>" />
8
- </span>
9
- </p>
1
+ <tr>
2
+ <td><label><?php esc_html_e( 'Format', 'formidable' ) ?></label>
3
+ <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Insert the format you would like to accept. Use a regular expression starting with ^ or an exact format like (999)999-9999.', 'formidable' ) ?>" ></span>
4
+ </td>
5
+ <td><input type="text" class="frm_long_input frm_format_opt" value="<?php echo esc_attr( $field['format'] ) ?>" name="field_options[format_<?php echo absint( $field['id'] ) ?>]" id="frm_format_<?php echo absint( $field['id'] ) ?>" />
6
+ </td>
7
+ </tr>
 
 
classes/views/frm-fields/front-end/checkbox-field.php CHANGED
@@ -1,11 +1,4 @@
1
  <?php
2
- /**
3
- * Show the checkbox field on the front-end.
4
- * Extra line breaks show as space on the front-end when
5
- * the form is double filtered and not minimized.
6
- *
7
- * @phpcs:disable Generic.WhiteSpace.ScopeIndent
8
- */
9
 
10
  if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
11
  $type = $field['type'];
@@ -26,35 +19,33 @@ if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' )
26
  $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key' ), $other_opt, $checked );
27
 
28
  ?>
29
- <div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ); ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key ) ); ?>"><?php
30
-
31
- if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
32
- ?><label for="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>"><?php
33
- }
34
-
35
- ?><input type="checkbox" name="<?php echo esc_attr( $field_name ); ?>[<?php echo esc_attr( $other_opt ? $opt_key : '' ); ?>]" id="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>"<?php
36
- echo $checked . ' '; // WPCS: XSS ok.
37
- do_action( 'frm_field_input_html', $field );
38
- ?> /><?php
39
-
40
- if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
41
- echo ' ' . FrmAppHelper::kses( $opt, 'all' ) . '</label>'; // WPCS: XSS ok.
42
- }
43
-
44
- $other_args = array(
45
- 'other_opt' => $other_opt,
46
- 'read_only' => $read_only,
47
- 'checked' => $checked,
48
- 'name' => $other_args['name'],
49
- 'value' => $other_args['value'],
50
- 'field' => $field,
51
- 'html_id' => $html_id,
52
- 'opt_key' => $opt_key,
53
- 'opt_label' => $opt,
54
- );
55
- FrmFieldsHelper::include_other_input( $other_args );
56
-
57
- unset( $other_opt, $other_args, $checked );
58
 
59
  ?></div>
60
  <?php
1
  <?php
 
 
 
 
 
 
 
2
 
3
  if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
4
  $type = $field['type'];
19
  $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key' ), $other_opt, $checked );
20
 
21
  ?>
22
+ <div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ) ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key ) ) ?>"><?php
23
+
24
+ if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
25
+ ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
26
+ }
27
+
28
+ ?><input type="checkbox" name="<?php echo esc_attr( $field_name ); ?>[<?php echo esc_attr( $other_opt ? $opt_key : '' ); ?>]" id="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>"<?php echo $checked; // WPCS: XSS ok. ?> <?php do_action( 'frm_field_input_html', $field ); ?> /><?php
29
+
30
+ if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
31
+ echo ' ' . FrmAppHelper::kses( $opt, 'all' ) . '</label>'; // WPCS: XSS ok.
32
+ }
33
+
34
+ FrmFieldsHelper::include_other_input(
35
+ array(
36
+ 'other_opt' => $other_opt,
37
+ 'read_only' => $read_only,
38
+ 'checked' => $checked,
39
+ 'name' => $other_args['name'],
40
+ 'value' => $other_args['value'],
41
+ 'field' => $field,
42
+ 'html_id' => $html_id,
43
+ 'opt_key' => $opt_key,
44
+ 'opt_label' => $opt,
45
+ )
46
+ );
47
+
48
+ unset( $other_opt, $other_args, $checked );
 
 
49
 
50
  ?></div>
51
  <?php
classes/views/frm-fields/front-end/dropdown-field.php CHANGED
@@ -15,17 +15,7 @@ if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' &&
15
  <select <?php do_action( 'frm_field_input_html', $field ); ?>>
16
  <?php } else { ?>
17
  <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id ); ?>" <?php do_action( 'frm_field_input_html', $field ); ?>>
18
- <?php
19
- }
20
-
21
- $placeholder = FrmField::get_option( $field, 'placeholder' );
22
- $skipped = false;
23
- if ( $placeholder !== '' ) {
24
- ?>
25
- <option value="">
26
- <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
27
- </option>
28
- <?php
29
  }
30
 
31
  $other_opt = false;
@@ -40,11 +30,6 @@ if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' &&
40
  $other_checked = true;
41
  }
42
  }
43
-
44
- if ( ! empty( $placeholder ) && $opt == '' && ! $skipped ) {
45
- $skipped = true;
46
- continue;
47
- }
48
  ?>
49
  <option value="<?php echo esc_attr( $field_val ); ?>" <?php echo $selected ? ' selected="selected"' : ''; ?> class="<?php echo esc_attr( FrmFieldsHelper::is_other_opt( $opt_key ) ? 'frm_other_trigger' : '' ); ?>">
50
  <?php echo esc_html( $opt == '' ? ' ' : $opt ); ?>
15
  <select <?php do_action( 'frm_field_input_html', $field ); ?>>
16
  <?php } else { ?>
17
  <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id ); ?>" <?php do_action( 'frm_field_input_html', $field ); ?>>
18
+ <?php
 
 
 
 
 
 
 
 
 
 
19
  }
20
 
21
  $other_opt = false;
30
  $other_checked = true;
31
  }
32
  }
 
 
 
 
 
33
  ?>
34
  <option value="<?php echo esc_attr( $field_val ); ?>" <?php echo $selected ? ' selected="selected"' : ''; ?> class="<?php echo esc_attr( FrmFieldsHelper::is_other_opt( $opt_key ) ? 'frm_other_trigger' : '' ); ?>">
35
  <?php echo esc_html( $opt == '' ? ' ' : $opt ); ?>
classes/views/frm-fields/front-end/radio-field.php CHANGED
@@ -1,11 +1,4 @@
1
  <?php
2
- /**
3
- * Show the radio field on the front-end.
4
- * Extra line breaks show as space on the front-end when
5
- * the form is double filtered and not minimized.
6
- *
7
- * @phpcs:disable Generic.WhiteSpace.ScopeIndent
8
- */
9
 
10
  if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
11
  $type = $field['type'];
@@ -19,40 +12,40 @@ if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' )
19
  $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field );
20
  $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
21
  ?>
22
- <div class="<?php echo esc_attr( apply_filters( 'frm_radio_class', 'frm_radio', $field, $field_val ) ); ?>"><?php
23
 
24
- if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
25
- ?><label for="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>"><?php
26
- }
27
- $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' ';
28
 
29
- $other_opt = false;
30
- $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked );
31
- ?>
32
- <input type="radio" name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>"
33
- <?php
34
- echo $checked . ' '; // WPCS: XSS ok.
35
- do_action( 'frm_field_input_html', $field );
36
- ?>/><?php
37
 
38
- if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
39
- echo ' ' . FrmAppHelper::kses( $opt, 'all' ) . '</label>'; // WPCS: XSS ok.
40
- }
41
 
42
- $other_args = array(
43
- 'other_opt' => $other_opt,
44
- 'read_only' => $read_only,
45
- 'checked' => $checked,
46
- 'name' => $other_args['name'],
47
- 'value' => $other_args['value'],
48
- 'field' => $field,
49
- 'html_id' => $html_id,
50
- 'opt_key' => $opt_key,
51
- 'opt_label' => $opt,
52
- );
53
- FrmFieldsHelper::include_other_input( $other_args );
 
54
 
55
- unset( $other_opt, $other_args );
56
  ?></div>
57
  <?php
58
  }
1
  <?php
 
 
 
 
 
 
 
2
 
3
  if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) {
4
  $type = $field['type'];
12
  $field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field );
13
  $opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field );
14
  ?>
15
+ <div class="<?php echo esc_attr( apply_filters( 'frm_radio_class', 'frm_radio', $field, $field_val ) ) ?>"><?php
16
 
17
+ if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
18
+ ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
19
+ }
20
+ $checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? 'checked="checked" ' : ' ';
21
 
22
+ $other_opt = false;
23
+ $other_args = FrmFieldsHelper::prepare_other_input( compact( 'field_name', 'opt_key', 'field' ), $other_opt, $checked );
24
+ ?>
25
+ <input type="radio" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php
26
+ echo $checked; // WPCS: XSS ok.
27
+ do_action( 'frm_field_input_html', $field );
28
+ ?>/><?php
 
29
 
30
+ if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) {
31
+ echo ' ' . FrmAppHelper::kses( $opt, 'all' ) . '</label>'; // WPCS: XSS ok.
32
+ }
33
 
34
+ FrmFieldsHelper::include_other_input(
35
+ array(
36
+ 'other_opt' => $other_opt,
37
+ 'read_only' => $read_only,
38
+ 'checked' => $checked,
39
+ 'name' => $other_args['name'],
40
+ 'value' => $other_args['value'],
41
+ 'field' => $field,
42
+ 'html_id' => $html_id,
43
+ 'opt_key' => $opt_key,
44
+ 'opt_label' => $opt,
45
+ )
46
+ );
47
 
48
+ unset( $other_opt, $other_args );
49
  ?></div>
50
  <?php
51
  }
classes/views/frm-fields/import_choices.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html <?php language_attributes(); ?>>
3
+ <head>
4
+ <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
+ <title><?php bloginfo( 'name' ); ?></title>
6
+ <?php
7
+ wp_admin_css( 'global' );
8
+ wp_admin_css();
9
+ wp_admin_css( 'colors' );
10
+ wp_admin_css( 'ie' );
11
+ if ( is_multisite() ) {
12
+ wp_admin_css( 'ms' );
13
+ }
14
+
15
+ do_action( 'admin_print_styles' );
16
+ do_action( 'admin_print_scripts' );
17
+
18
+ ?>
19
+ </head>
20
+ <body class="wp-admin no-js wp-core-ui frm_field_opts_popup <?php echo esc_attr( apply_filters( 'admin_body_class', '' ) . ' ' . $admin_body_class ); ?>">
21
+ <div class="frm_med_padding">
22
+ <p class="howto"><?php esc_html_e( 'Edit or add field options (one per line)', 'formidable' ) ?></p>
23
+ <ul class="frm_prepop">
24
+ <?php foreach ( $prepop as $label => $pop ) { ?>
25
+ <li>
26
+ <a href="javascript:void(0)" onclick="frmPrePop(<?php echo esc_attr( json_encode( $pop ) ) ?>); return false;">
27
+ <?php echo esc_html( $label ) ?>
28
+ </a>
29
+ </li>
30
+ <?php } ?>
31
+ </ul>
32
+ <textarea name="frm_bulk_options" id="frm_bulk_options">
33
+ <?php
34
+ $other_array = array();
35
+ foreach ( $field->options as $fkey => $fopt ) {
36
+ //If it is an other option, don't include it
37
+ if ( $fkey && strpos( $fkey, 'other' ) !== false ) {
38
+ continue;
39
+ }
40
+ if ( is_array( $fopt ) ) {
41
+ $label = ( isset( $fopt['label'] ) ) ? $fopt['label'] : reset( $fopt );
42
+ $value = ( isset( $fopt['value'] ) ) ? $fopt['value'] : $label;
43
+ if ( $label !== $value && FrmField::is_option_true( $field, 'separate_value' ) ) {
44
+ echo esc_textarea( "$label|$value\n" );
45
+ } else {
46
+ echo esc_textarea( $label . "\n" );
47
+ }
48
+ } else {
49
+ echo esc_textarea( $fopt . "\n" );
50
+ }
51
+ }
52
+ ?>
53
+ </textarea>
54
+
55
+ <p class="submit frm_clear">
56
+ <input type="button" onclick="frmUpdateBulkOpts(<?php echo (int) $field->id ?>)" class="button-primary" value="<?php esc_attr_e( 'Update Field Choices', 'formidable' ) ?>" />
57
+ </p>
58
+ </div>
59
+
60
+ </body>
61
+ </html>
classes/views/frm-fields/single-option.php CHANGED
@@ -1,15 +1,20 @@
1
- <li id="frm_delete_field_<?php echo esc_attr( $field['id'] . '-' . $opt_key ); ?>_container" data-optkey="<?php echo esc_attr( $opt_key ); ?>" class="frm_single_option <?php echo $opt_key === '000' ? 'frm_hidden frm_option_template' : ''; ?>">
2
- <i class="frm_icon_font frm_drag_icon frm-drag"></i>
 
 
 
3
 
4
- <input type="<?php echo esc_attr( $default_type ); ?>" name="<?php echo esc_attr( $field_name ); ?>" <?php echo ( isset( $checked ) && $checked ? 'checked="checked"' : '' ); ?> value="<?php echo esc_attr( $field_val ); ?>"/>
 
 
 
5
 
6
- <input type="text" name="field_options[options_<?php echo esc_attr( $field['id'] ); ?>][<?php echo esc_attr( $opt_key ); ?>][label]" value="<?php echo esc_attr( $opt ); ?>" class="field_<?php echo esc_attr( $field['id'] ); ?>_option <?php echo esc_attr( $field['separate_value'] ? 'frm_with_key' : '' ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ); ?>" />
7
-
8
- <a href="javascript:void(0)" class="frm_icon_font frm_remove_tag" data-fid="<?php echo esc_attr( $field['id'] ); ?>" data-removeid="frm_delete_field_<?php echo esc_attr( $field['id'] . '-' . $opt_key ); ?>_container" data-showlast="#frm_add_opt_<?php echo esc_attr( $field['id'] ); ?>"></a>
9
-
10
- <span class="frm_option_key frm-with-right-icon field_<?php echo esc_attr( $field['id'] ); ?>_option_key<?php echo esc_attr( $field['separate_value'] ? '' : ' frm_hidden' ); ?>">
11
- <input type="<?php echo esc_attr( $default_type ); ?>" class="frm_invisible" />
12
- <input type="text" name="field_options[options_<?php echo esc_attr( $field['id'] ); ?>][<?php echo esc_attr( $opt_key ); ?>][value]" id="field_key_<?php echo esc_attr( $field['id'] . '-' . $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>" placeholder="<?php esc_attr_e( 'Saved Value', 'formidable' ); ?>"/>
13
- <i class="frm_icon_font frm_save_icon"></i>
14
  </span>
15
  </li>
 
 
1
+ <li id="frm_delete_field_<?php echo esc_attr( $field['id'] . '-' . $opt_key ) ?>_container" class="frm_single_option">
2
+ <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon" data-fid="<?php echo esc_attr( $field['id'] ); ?>"> </a>
3
+ <?php if ( 'select' !== $field['type'] ) { ?>
4
+ <input type="<?php echo esc_attr( $field['type'] ); ?>" name="<?php echo esc_attr( $field_name . ( 'checkbox' === $field['type'] ? '[]' : '' ) ); ?>" value="<?php echo esc_attr( $field_val ) ?>"<?php echo esc_html( isset( $checked ) ? $checked : '' ); ?>/>
5
+ <?php } ?>
6
 
7
+ <label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo esc_attr( $field['separate_value'] ? 'frm_with_key' : '' ); ?>" id="<?php echo esc_attr( $html_id . '-' . $opt_key ) ?>"><?php
8
+ echo '' === $opt ? esc_html__( '(Blank)', 'formidable' ) : FrmAppHelper::kses( $opt, 'all' ); // WPCS: XSS ok.
9
+ ?></label>
10
+ <input type="hidden" name="field_options[options_<?php echo esc_attr( $field['id'] ) ?>][<?php echo esc_attr( $opt_key ) ?>][label]" value="<?php echo esc_attr( $opt ) ?>" />
11
 
12
+ <span class="frm_option_key field_<?php echo esc_attr( $field['id'] ) ?>_option_key<?php echo esc_attr( $field['separate_value'] ? '' : ' frm_hidden' ); ?>">
13
+ <label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo esc_attr( $field['id'] . '-' . $opt_key ) ?>"><?php
14
+ echo ( '' === $field_val ) ? esc_html__( '(Blank)', 'formidable' ) : FrmAppHelper::kses( $field_val, 'all' ); // WPCS: XSS ok.
15
+ ?></label>
16
+ <input type="hidden" name="field_options[options_<?php echo esc_attr( $field['id'] ) ?>][<?php echo esc_attr( $opt_key ) ?>][value]" value="<?php echo esc_attr( $field_val ) ?>" />
 
 
 
17
  </span>
18
  </li>
19
+ <?php
20
+ unset( $field_val, $opt, $opt_key );
classes/views/frm-form-actions/_action_icon.php DELETED
@@ -1,23 +0,0 @@
1
- <li class="frm-action <?php echo esc_attr( $group_class . ( isset( $data['data-upgrade'] ) ? ' frm-not-installed' : '' ) ); ?>">
2
- <a href="javascript:void(0)" class="<?php echo esc_attr( $classes ); ?>"
3
- title="<?php echo esc_attr( $action_control->action_options['tooltip'] ); ?>"
4
- data-limit="<?php echo esc_attr( $action_control->action_options['limit'] ); ?>"
5
- data-actiontype="<?php echo esc_attr( $action_control->id_base ); ?>"
6
- <?php
7
- foreach ( $data as $name => $value ) {
8
- echo esc_attr( $name ) . '="' . esc_attr( $value ) . '" ';
9
- }
10
- ?>
11
- >
12
- <span><i class="<?php echo esc_attr( $action_control->action_options['classes'] ); ?>"
13
- <?php
14
- if ( $action_control->action_options['color'] !== 'var(--primary-hover)' ) {
15
- ?>
16
- style="--primary-hover:<?php echo esc_attr( $action_control->action_options['color'] ); ?>"
17
- <?php
18
- }
19
- ?>
20
- ></i></span>
21
- <?php echo esc_html( str_replace( 'Add to ', '', $action_control->name ) ); ?>
22
- </a>
23
- </li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-form-actions/_action_inside.php CHANGED
@@ -1,14 +1,18 @@
1
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'post_excerpt', '' ) ); ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
2
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'ID', '' ) ); ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
3
 
4
- <div class="frm_grid_container frm_no_p_margin">
5
- <p class="frm6 frm_form_field">
6
- <label for="<?php echo esc_attr( $action_control->get_field_id( 'action_post_title' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'action_title' ); ?>>
7
- <?php esc_html_e( 'Action Name', 'formidable' ); ?>
8
- </label>
9
- <input type="text" name="<?php echo esc_attr( $action_control->get_field_name( 'post_title', '' ) ); ?>" value="<?php echo esc_attr( $form_action->post_title ); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip( 'action_title', 'open' ); ?>" id="<?php echo esc_attr( $action_control->get_field_id( 'action_post_title' ) ); ?>" />
10
- </p>
 
 
 
11
  <?php
 
12
 
13
  if ( ! isset( $action_control->action_options['event'] ) ) {
14
  $events = 'create';
@@ -20,34 +24,27 @@ if ( ! is_array( $action_control->action_options['event'] ) ) {
20
 
21
  if ( count( $action_control->action_options['event'] ) == 1 || $action_control->action_options['force_event'] ) {
22
  foreach ( $action_control->action_options['event'] as $e ) {
23
- ?>
24
- <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'event' ) ); ?>[]" value="<?php echo esc_attr( $e ); ?>" />
25
- <?php
26
  }
27
  } else {
28
- ?>
29
- <p class="frm6 frm_form_field">
30
- <label for="<?php echo esc_attr( $action_control->get_field_id( 'event' ) ); ?>">
31
- <?php esc_html_e( 'Trigger this action when', 'formidable' ); ?>
32
- </label>
33
  <select name="<?php echo esc_attr( $action_control->get_field_name( 'event' ) ); ?>[]" multiple="multiple" class="frm_multiselect" id="<?php echo esc_attr( $action_control->get_field_id( 'event' ) ); ?>">
34
  <?php
35
 
36
  $event_labels = FrmFormAction::trigger_labels();
37
  foreach ( $action_control->action_options['event'] as $event ) {
38
- ?>
39
- <option value="<?php echo esc_attr( $event ); ?>" <?php echo in_array( $event, (array) $form_action->post_content['event'] ) ? ' selected="selected"' : ''; ?> ><?php echo esc_html( isset( $event_labels[ $event ] ) ? $event_labels[ $event ] : $event ); ?></option>
40
  <?php } ?>
41
  </select>
42
  </p>
43
- <?php
44
- }
45
-
46
- ?>
47
- </div>
48
  <?php
49
-
50
- $action_control->form( $form_action, compact( 'form', 'action_key', 'values' ) );
51
 
52
  $pass_args = array(
53
  'form' => $form,
@@ -93,7 +90,7 @@ if ( $use_logging ) {
93
  ?>
94
  <p>
95
  <a href="javascript:void(0)" class="frm_show_upgrade" data-upgrade="<?php esc_attr_e( 'Form action logs', 'formidable' ); ?>" data-medium="action-logs" data-oneclick="<?php echo esc_attr( json_encode( $upgrading ) ); ?>">
96
- <i class="frm_icon_font frm_tooltip_solid_icon"></i>
97
  <?php esc_html_e( 'Install logging to get more information on API requests.', 'formidable' ); ?>
98
  </a>
99
  </p>
@@ -101,10 +98,7 @@ if ( $use_logging ) {
101
  }
102
  }
103
  ?>
104
- <span class="alignright frm_action_id frm-sub-label <?php echo esc_attr( empty( $form_action->ID ) ? 'frm_hidden' : '' ); ?>">
105
- <?php
106
- /* translators: %1$s: The ID of the form action. */
107
- printf( esc_html__( 'Action ID: %1$s', 'formidable' ), esc_attr( $form_action->ID ) );
108
- ?>
109
  </span>
110
  <div style="clear:both;"></div>
1
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'post_excerpt', '' ) ); ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
2
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'ID', '' ) ); ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
3
 
4
+ <table class="form-table">
5
+ <tr>
6
+ <th>
7
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'action_title' ); ?>><?php esc_html_e( 'Label', 'formidable' ); ?></label>
8
+ </th>
9
+ <td>
10
+ <input type="text" name="<?php echo esc_attr( $action_control->get_field_name( 'post_title', '' ) ); ?>" value="<?php echo esc_attr( $form_action->post_title ); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip( 'action_title', 'open' ); ?>" id="<?php echo esc_attr( $action_control->get_field_id( 'action_post_title' ) ); ?>" />
11
+ </td>
12
+ </tr>
13
+ </table>
14
  <?php
15
+ $action_control->form( $form_action, compact( 'form', 'action_key', 'values' ) );
16
 
17
  if ( ! isset( $action_control->action_options['event'] ) ) {
18
  $events = 'create';
24
 
25
  if ( count( $action_control->action_options['event'] ) == 1 || $action_control->action_options['force_event'] ) {
26
  foreach ( $action_control->action_options['event'] as $e ) {
27
+ ?>
28
+ <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'event' ) ); ?>[]" value="<?php echo esc_attr( $e ); ?>" />
29
+ <?php
30
  }
31
  } else {
32
+ ?>
33
+ <h3><?php esc_html_e( 'Action Triggers', 'formidable' ); ?></h3>
34
+ <p>
35
+ <label class="frm_left_label"><?php esc_html_e( 'Trigger this action after', 'formidable' ) ?></label>
 
36
  <select name="<?php echo esc_attr( $action_control->get_field_name( 'event' ) ); ?>[]" multiple="multiple" class="frm_multiselect" id="<?php echo esc_attr( $action_control->get_field_id( 'event' ) ); ?>">
37
  <?php
38
 
39
  $event_labels = FrmFormAction::trigger_labels();
40
  foreach ( $action_control->action_options['event'] as $event ) {
41
+ ?>
42
+ <option value="<?php echo esc_attr( $event ) ?>" <?php echo in_array( $event, (array) $form_action->post_content['event'] ) ? ' selected="selected"' : ''; ?> ><?php echo esc_html( isset( $event_labels[ $event ] ) ? $event_labels[ $event ] : $event ); ?></option>
43
  <?php } ?>
44
  </select>
45
  </p>
 
 
 
 
 
46
  <?php
47
+ }
 
48
 
49
  $pass_args = array(
50
  'form' => $form,
90
  ?>
91
  <p>
92
  <a href="javascript:void(0)" class="frm_show_upgrade" data-upgrade="<?php esc_attr_e( 'Form action logs', 'formidable' ); ?>" data-medium="action-logs" data-oneclick="<?php echo esc_attr( json_encode( $upgrading ) ); ?>">
93
+ <i class="dashicons dashicons-info"></i>
94
  <?php esc_html_e( 'Install logging to get more information on API requests.', 'formidable' ); ?>
95
  </a>
96
  </p>
98
  }
99
  }
100
  ?>
101
+ <span class="alignright frm_action_id <?php echo esc_attr( empty( $form_action->ID ) ? 'frm_hidden' : '' ); ?>">
102
+ <?php printf( esc_html__( 'Action ID: %1$s', 'formidable' ), esc_attr( $form_action->ID ) ); ?>
 
 
 
103
  </span>
104
  <div style="clear:both;"></div>
classes/views/frm-form-actions/_email_settings.php CHANGED
@@ -1,86 +1,90 @@
1
- <p class="frm_has_shortcodes frm_to_row frm_email_row">
2
- <label for="<?php echo esc_attr( $this->get_field_id( 'email_to' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'email_to' ); ?>>
3
- <?php esc_html_e( 'To', 'formidable' ); ?>
4
- </label>
5
- <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'email_to' ) ); ?>" value="<?php echo esc_attr( $form_action->post_content['email_to'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip( 'email_to', 'open' ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'email_to' ) ); ?>" />
6
- </p>
7
-
8
- <p class="frm_bcc_cc_container">
9
- <a href="javascript:void(0)" class="button frm_email_buttons frm_cc_button <?php echo esc_attr( ! empty( $form_action->post_content['cc'] ) ? 'frm_hidden' : '' ); ?>" data-emailrow="cc">
10
- <?php esc_html_e( 'CC', 'formidable' ); ?>
11
- </a>
12
- <a href="javascript:void(0)" class="button frm_email_buttons frm_bcc_button <?php echo esc_attr( ! empty( $form_action->post_content['bcc'] ) ? 'frm_hidden' : '' ); ?>" data-emailrow="bcc">
13
- <?php esc_html_e( 'BCC', 'formidable' ); ?>
14
- </a>
15
- </p>
16
-
17
- <p class="frm_has_shortcodes frm_cc_row frm_email_row<?php echo empty( $form_action->post_content['cc'] ) ? ' frm_hidden' : ''; ?>" >
18
- <label for="<?php echo esc_attr( $this->get_field_id( 'cc' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'cc' ); ?>>
19
- <?php esc_html_e( 'CC', 'formidable' ); ?>
20
  <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="cc"></a>
21
- </label>
22
-
23
- <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'cc' ) ); ?>" value="<?php echo esc_attr( $form_action->post_content['cc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip( 'cc', 'open' ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'cc' ) ); ?>" />
24
- </p>
25
-
26
- <p class="frm_has_shortcodes frm_bcc_row frm_email_row<?php echo empty( $form_action->post_content['bcc'] ) ? ' frm_hidden' : ''; ?>" >
27
- <label for="<?php echo esc_attr( $this->get_field_id( 'bcc' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'bcc' ); ?>>
28
- <?php esc_html_e( 'BCC', 'formidable' ); ?>
 
29
  <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="bcc"></a>
30
- </label>
31
-
32
- <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'bcc' ) ); ?>" value="<?php echo esc_attr( $form_action->post_content['bcc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip( 'bcc', 'open' ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'bcc' ) ); ?>" />
33
- </p>
34
-
35
- <p class="frm_has_shortcodes frm_from_row frm_email_row">
36
- <label for="<?php echo esc_attr( $this->get_field_id( 'from' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'from' ); ?>>
37
- <?php esc_html_e( 'From', 'formidable' ); ?>
38
- </label>
39
-
40
- <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'from' ) ); ?>" value="<?php echo esc_attr( $form_action->post_content['from'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip( 'from', 'open' ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'from' ) ); ?>" />
41
- </p>
42
-
43
- <p class="frm_reply_to_container">
44
- <a href="javascript:void(0)" class="button frm_email_buttons frm_reply_to_button <?php echo ( ! empty( $form_action->post_content['reply_to'] ) ? 'frm_hidden' : '' ); ?>" data-emailrow="reply_to">
45
- <?php esc_html_e( 'Reply To', 'formidable' ); ?>
46
- </a>
47
- </p>
48
-
49
- <p class="frm_has_shortcodes frm_reply_to_row frm_email_row<?php echo empty( $form_action->post_content['reply_to'] ) ? ' frm_hidden' : ''; ?>">
50
- <label for="<?php echo esc_attr( $this->get_field_id( 'reply_to' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'reply_to' ); ?>>
51
- <?php esc_html_e( 'Reply To', 'formidable' ); ?>
52
  <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="reply_to"></a>
53
- </label>
54
-
55
- <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'reply_to' ) ); ?>" value="<?php echo esc_attr( $form_action->post_content['reply_to'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip( 'reply_to', 'open' ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'reply_to' ) ); ?>" />
56
- </p>
57
-
58
- <p class="frm_has_shortcodes">
59
- <label for="<?php echo esc_attr( $this->get_field_id( 'email_subject' ) ); ?>" <?php FrmAppHelper::maybe_add_tooltip( 'email_subject', '', $form->name ); ?>>
60
- <?php esc_html_e( 'Subject', 'formidable' ); ?>
61
- </label>
62
- <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'email_subject' ) ); ?>" class="frm_not_email_subject large-text <?php FrmAppHelper::maybe_add_tooltip( 'email_subject', 'open', $form->name ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'email_subject' ) ); ?>" size="55" value="<?php echo esc_attr( $form_action->post_content['email_subject'] ); ?>" />
63
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- <p class="frm_has_shortcodes">
66
- <label for="<?php echo esc_attr( $this->get_field_id( 'email_message' ) ); ?>">
67
- <?php esc_html_e( 'Message', 'formidable' ); ?>
68
- </label>
69
- <textarea name="<?php echo esc_attr( $this->get_field_name( 'email_message' ) ); ?>" class="frm_not_email_message frm_long_input" id="<?php echo esc_attr( $this->get_field_id( 'email_message' ) ); ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea( $form_action->post_content['email_message'] ); // WPCS: XSS ok. ?></textarea>
70
- </p>
71
 
72
- <label for="<?php echo esc_attr( $this->get_field_id( 'inc_user_info' ) ); ?>">
73
- <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'inc_user_info' ) ); ?>" class="frm_not_inc_user_info" id="<?php echo esc_attr( $this->get_field_id( 'inc_user_info' ) ); ?>" value="1" <?php checked( $form_action->post_content['inc_user_info'], 1 ); ?> />
74
- <?php if ( FrmAppHelper::ips_saved() ) { ?>
75
- <?php esc_html_e( 'Append IP Address, Browser, and Referring URL to message', 'formidable' ); ?>
76
- <?php } else { ?>
77
- <?php esc_html_e( 'Append Browser and Referring URL to message', 'formidable' ); ?>
78
- <?php } ?>
79
- </label>
 
80
 
81
- <p>
82
- <label for="<?php echo esc_attr( $this->get_field_id( 'plain_text' ) ); ?>">
83
- <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'plain_text' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'plain_text' ) ); ?>" value="1" <?php checked( $form_action->post_content['plain_text'], 1 ); ?> />
84
- <?php esc_html_e( 'Send Emails in Plain Text', 'formidable' ); ?>
85
- </label>
86
- </p>
 
 
1
+ <table class="form-table frm-no-margin">
2
+ <tr class="frm_to_row frm_email_row">
3
+ <th>
4
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'email_to' ) ?>><?php esc_html_e( 'To', 'formidable' ) ?></label>
5
+ </th>
6
+ <td>
7
+ <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'email_to' ) ) ?>" value="<?php echo esc_attr( $form_action->post_content['email_to'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip( 'email_to', 'open' ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'email_to' ) ) ?>" />
8
+ </td>
9
+ <td class="frm_bcc_cc_container">
10
+ <a href="javascript:void(0)" class="button frm_email_buttons frm_cc_button <?php echo esc_attr( ! empty( $form_action->post_content['cc'] ) ? 'frm_hidden' : '' ); ?>" data-emailrow="cc"><?php esc_html_e( 'CC', 'formidable' ) ?></a>
11
+ <a href="javascript:void(0)" class="button frm_email_buttons frm_bcc_button <?php echo esc_attr( ! empty( $form_action->post_content['bcc'] ) ? 'frm_hidden' : '' ); ?>" data-emailrow="bcc"><?php esc_html_e( 'BCC', 'formidable' ) ?></a>
12
+ </td>
13
+ </tr>
14
+ <tr class="frm_cc_row frm_email_row<?php echo empty( $form_action->post_content['cc'] ) ? ' frm_hidden' : ''; ?>" >
15
+ <th>
16
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'cc' ) ?>><?php esc_html_e( 'CC', 'formidable' ) ?></label>
17
+ </th>
18
+ <td class="frm_right_addon">
19
+ <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'cc' ) ) ?>" value="<?php echo esc_attr( $form_action->post_content['cc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip( 'cc', 'open' ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'cc' ) ) ?>" />
20
  <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="cc"></a>
21
+ </td>
22
+ <td></td>
23
+ </tr>
24
+ <tr class="frm_bcc_row frm_email_row<?php echo empty( $form_action->post_content['bcc'] ) ? ' frm_hidden' : ''; ?>" >
25
+ <th>
26
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'bcc' ) ?>><?php esc_html_e( 'BCC', 'formidable' ) ?></label>
27
+ </th>
28
+ <td class="frm_right_addon">
29
+ <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'bcc' ) ) ?>" value="<?php echo esc_attr( $form_action->post_content['bcc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip( 'bcc', 'open' ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'bcc' ) ) ?>" />
30
  <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="bcc"></a>
31
+ </td>
32
+ <td></td>
33
+ </tr>
34
+ <tr class="frm_reply_to_row frm_email_row<?php echo empty( $form_action->post_content['reply_to'] ) ? ' frm_hidden' : ''; ?>">
35
+ <th>
36
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'reply_to' ) ?>><?php esc_html_e( 'Reply to', 'formidable' ) ?></label>
37
+ </th>
38
+ <td class="frm_right_addon">
39
+ <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'reply_to' ) ) ?>" value="<?php echo esc_attr( $form_action->post_content['reply_to'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip( 'reply_to', 'open' ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'reply_to' ) ) ?>" />
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="reply_to"></a>
41
+ </td>
42
+ <td></td>
43
+ </tr>
44
+ <tr class="frm_from_row frm_email_row">
45
+ <th>
46
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'from' ) ?>>
47
+ <?php esc_html_e( 'From', 'formidable' ) ?>
48
+ </label>
49
+ </th>
50
+ <td>
51
+ <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'from' ) ) ?>" value="<?php echo esc_attr( $form_action->post_content['from'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip( 'from', 'open' ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'from' ) ) ?>" />
52
+ </td>
53
+ <td>
54
+ <a href="javascript:void(0)" class="button frm_email_buttons frm_reply_to_button <?php echo ( ! empty( $form_action->post_content['reply_to'] ) ? 'frm_hidden' : '' ) ?>" data-emailrow="reply_to"><?php esc_html_e( 'Reply To', 'formidable' ) ?></a>
55
+ </td>
56
+ </tr>
57
+ </table>
58
+ <table class="form-table frm-no-margin">
59
+ <tr>
60
+ <td colspan="3" class="frm_no_top_padding">
61
+ <p>
62
+ <label <?php FrmAppHelper::maybe_add_tooltip( 'email_subject', '', $form->name ) ?>>
63
+ <?php esc_html_e( 'Subject', 'formidable' ) ?>
64
+ </label><br/>
65
+ <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'email_subject' ) ) ?>" class="frm_not_email_subject large-text <?php FrmAppHelper::maybe_add_tooltip( 'email_subject', 'open', $form->name ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'email_subject' ) ) ?>" size="55" value="<?php echo esc_attr( $form_action->post_content['email_subject'] ); ?>" />
66
+ </p>
67
 
68
+ <p>
69
+ <label><?php esc_html_e( 'Message', 'formidable' ) ?> </label><br/>
70
+ <textarea name="<?php echo esc_attr( $this->get_field_name( 'email_message' ) ); ?>" class="frm_not_email_message large-text" id="<?php echo esc_attr( $this->get_field_id( 'email_message' ) ); ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea( $form_action->post_content['email_message'] ); // WPCS: XSS ok. ?></textarea>
71
+ </p>
 
 
72
 
73
+ <h4><?php esc_html_e( 'Options', 'formidable' ) ?> </h4>
74
+ <label for="<?php echo esc_attr( $this->get_field_id( 'inc_user_info' ) ) ?>">
75
+ <input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'inc_user_info' ) ) ?>" class="frm_not_inc_user_info" id="<?php echo esc_attr( $this->get_field_id( 'inc_user_info' ) ) ?>" value="1" <?php checked( $form_action->post_content['inc_user_info'], 1 ); ?> />
76
+ <?php if ( FrmAppHelper::ips_saved() ) { ?>
77
+ <?php esc_html_e( 'Append IP Address, Browser, and Referring URL to message', 'formidable' ) ?>
78
+ <?php } else { ?>
79
+ <?php esc_html_e( 'Append Browser and Referring URL to message', 'formidable' ) ?>
80
+ <?php } ?>
81
+ </label>
82
 
83
+ <p>
84
+ <label for="<?php echo esc_attr( $this->get_field_id( 'plain_text' ) ) ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'plain_text' ) ) ?>" id="<?php echo esc_attr( $this->get_field_id( 'plain_text' ) ) ?>" value="1" <?php checked( $form_action->post_content['plain_text'], 1 ); ?> />
85
+ <?php esc_html_e( 'Send Emails in Plain Text', 'formidable' ) ?>
86
+ </label>
87
+ </p>
88
+ </td>
89
+ </tr>
90
+ </table>
classes/views/frm-form-actions/default_actions.php CHANGED
@@ -2,8 +2,8 @@
2
  // add post action
3
  class FrmDefPostAction extends FrmFormAction {
4
  public function __construct() {
5
- $action_ops = FrmFormAction::default_action_opts( 'frm_wordpress_icon frm-inverse frm_show_upgrade' );
6
- $action_ops['color'] = 'rgb(0,160,210)';
7
 
8
  parent::__construct( 'wppost', __( 'Create Post', 'formidable' ), $action_ops );
9
  }
@@ -13,8 +13,7 @@ class FrmDefPostAction extends FrmFormAction {
13
  class FrmDefRegAction extends FrmFormAction {
14
  public function __construct() {
15
  $action_ops = FrmFormAction::default_action_opts( 'frm_register_icon frm_show_upgrade' );
16
- $action_ops['plugin'] = 'registration';
17
- $action_ops['color'] = 'var(--pink)';
18
  parent::__construct( 'register', __( 'Register User', 'formidable' ), $action_ops );
19
  }
20
  }
@@ -22,10 +21,8 @@ class FrmDefRegAction extends FrmFormAction {
22
  // add paypal action
23
  class FrmDefPayPalAction extends FrmFormAction {
24
  public function __construct() {
25
- $action_ops = FrmFormAction::default_action_opts( 'frm_paypal_icon frm-inverse frm_show_upgrade' );
26
- $action_ops['color'] = 'var(--primary-hover)';
27
-
28
- parent::__construct( 'paypal', 'PayPal', $action_ops );
29
  }
30
  }
31
 
@@ -33,18 +30,15 @@ class FrmDefPayPalAction extends FrmFormAction {
33
  class FrmDefAweberAction extends FrmFormAction {
34
  public function __construct() {
35
  $action_ops = FrmFormAction::default_action_opts( 'frm_aweber_icon frm_show_upgrade' );
36
- $action_ops['color'] = 'var(--green)';
37
- parent::__construct( 'aweber', 'AWeber', $action_ops );
38
  }
39
  }
40
 
41
  // add mailchimp action
42
  class FrmDefMlcmpAction extends FrmFormAction {
43
  public function __construct() {
44
- $action_ops = FrmFormAction::default_action_opts( 'frm_mailchimp_icon frm_show_upgrade frm-inverse' );
45
- $action_ops['color'] = 'var(--dark-grey)';
46
-
47
- parent::__construct( 'mailchimp', 'MailChimp', $action_ops );
48
  }
49
  }
50
 
@@ -59,73 +53,15 @@ class FrmDefTwilioAction extends FrmFormAction {
59
  // add payment action
60
  class FrmDefHrsAction extends FrmFormAction {
61
  public function __construct() {
62
- $action_ops = FrmFormAction::default_action_opts( 'frm_stripe_icon frm_credit_card_alt_icon frm_show_upgrade' );
63
- $action_ops['color'] = 'var(--green)';
64
  $action_ops['plugin'] = 'stripe';
65
- parent::__construct( 'payment', __( 'eCommerce', 'formidable' ), $action_ops );
66
- }
67
- }
68
-
69
- class FrmDefActiveCampaignAction extends FrmFormAction {
70
- public function __construct() {
71
- $action_ops = FrmFormAction::default_action_opts( 'frm_activecampaign_icon frm_show_upgrade' );
72
- $action_ops['color'] = 'var(--primary-hover)';
73
- parent::__construct( 'activecampaign', 'ActiveCampaign', $action_ops );
74
- }
75
- }
76
-
77
- class FrmDefSalesforceAction extends FrmFormAction {
78
- public function __construct() {
79
- $action_ops = FrmFormAction::default_action_opts( 'frm_salesforce_icon frm-inverse frm_show_upgrade' );
80
- $action_ops['color'] = 'var(--primary-color)';
81
- parent::__construct( 'salesforce', 'Salesforce', $action_ops );
82
- }
83
- }
84
-
85
- class FrmDefConstContactAction extends FrmFormAction {
86
- public function __construct() {
87
- $action_ops = FrmFormAction::default_action_opts( 'frm_constant_contact_icon frm_show_upgrade' );
88
- $action_ops['color'] = 'rgb(0,160,210)';
89
- parent::__construct( 'constantcontact', 'Constant Contact', $action_ops );
90
- }
91
- }
92
-
93
- class FrmDefGetResponseAction extends FrmFormAction {
94
- public function __construct() {
95
- $action_ops = FrmFormAction::default_action_opts( 'frm_getresponse_icon frm_show_upgrade' );
96
- $action_ops['color'] = '#00baff';
97
- parent::__construct( 'getresponse', 'GetResponse', $action_ops );
98
- }
99
- }
100
-
101
- class FrmDefHubspotAction extends FrmFormAction {
102
- public function __construct() {
103
- $action_ops = FrmFormAction::default_action_opts( 'frm_hubspot_icon frm_show_upgrade' );
104
- $action_ops['color'] = 'var(--orange)';
105
- parent::__construct( 'hubspot', 'Hubspot', $action_ops );
106
- }
107
- }
108
-
109
- class FrmDefHighriseAction extends FrmFormAction {
110
- public function __construct() {
111
- $action_ops = FrmFormAction::default_action_opts( 'frm_building_icon frm_show_upgrade' );
112
- $action_ops['color'] = 'var(--purple)';
113
- parent::__construct( 'highrise', 'Highrise', $action_ops );
114
- }
115
- }
116
-
117
- class FrmDefMailpoetAction extends FrmFormAction {
118
- public function __construct() {
119
- $action_ops = FrmFormAction::default_action_opts( 'frm_mailpoet_icon frm_show_upgrade' );
120
- $action_ops['color'] = 'var(--orange)';
121
- parent::__construct( 'mailpoet', 'MailPoet', $action_ops );
122
  }
123
  }
124
 
125
  class FrmDefApiAction extends FrmFormAction {
126
  public function __construct() {
127
  $action_ops = FrmFormAction::default_action_opts( 'frm_feed_icon frm_show_upgrade' );
128
- $action_ops['color'] = 'var(--purple)';
129
  parent::__construct( 'api', __( 'Send API data', 'formidable' ), $action_ops );
130
  }
131
  }
2
  // add post action
3
  class FrmDefPostAction extends FrmFormAction {
4
  public function __construct() {
5
+ $action_ops = FrmFormAction::default_action_opts();
6
+ $action_ops['classes'] = 'ab-icon frm_dashicon_font dashicons-before frm_show_upgrade';
7
 
8
  parent::__construct( 'wppost', __( 'Create Post', 'formidable' ), $action_ops );
9
  }
13
  class FrmDefRegAction extends FrmFormAction {
14
  public function __construct() {
15
  $action_ops = FrmFormAction::default_action_opts( 'frm_register_icon frm_show_upgrade' );
16
+ $action_ops['plugin'] = 'registration';
 
17
  parent::__construct( 'register', __( 'Register User', 'formidable' ), $action_ops );
18
  }
19
  }
21
  // add paypal action
22
  class FrmDefPayPalAction extends FrmFormAction {
23
  public function __construct() {
24
+ $action_ops = FrmFormAction::default_action_opts( 'frm_paypal_icon frm_show_upgrade' );
25
+ parent::__construct( 'paypal', __( 'PayPal Payment', 'formidable' ), $action_ops );
 
 
26
  }
27
  }
28
 
30
  class FrmDefAweberAction extends FrmFormAction {
31
  public function __construct() {
32
  $action_ops = FrmFormAction::default_action_opts( 'frm_aweber_icon frm_show_upgrade' );
33
+ parent::__construct( 'aweber', __( 'Aweber', 'formidable' ), $action_ops );
 
34
  }
35
  }
36
 
37
  // add mailchimp action
38
  class FrmDefMlcmpAction extends FrmFormAction {
39
  public function __construct() {
40
+ $action_ops = FrmFormAction::default_action_opts( 'frm_mailchimp_icon frm_show_upgrade' );
41
+ parent::__construct( 'mailchimp', __( 'MailChimp', 'formidable' ), $action_ops );
 
 
42
  }
43
  }
44
 
53
  // add payment action
54
  class FrmDefHrsAction extends FrmFormAction {
55
  public function __construct() {
56
+ $action_ops = FrmFormAction::default_action_opts( 'frm_stripe_icon frm_credit-card-alt_icon frm_show_upgrade' );
 
57
  $action_ops['plugin'] = 'stripe';
58
+ parent::__construct( 'payment', __( 'Credit Card Payment', 'formidable' ), $action_ops );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
  }
61
 
62
  class FrmDefApiAction extends FrmFormAction {
63
  public function __construct() {
64
  $action_ops = FrmFormAction::default_action_opts( 'frm_feed_icon frm_show_upgrade' );
 
65
  parent::__construct( 'api', __( 'Send API data', 'formidable' ), $action_ops );
66
  }
67
  }
classes/views/frm-form-actions/email_action.php CHANGED
@@ -4,16 +4,16 @@ class FrmEmailAction extends FrmFormAction {
4
 
5
  public function __construct() {
6
  $action_ops = array(
7
- 'classes' => 'frm_icon_font frm_email_solid_icon',
8
- 'active' => true,
9
  'event' => array( 'create' ),
10
- 'limit' => 99,
11
- 'priority' => 10,
12
- 'color' => 'rgb(49, 119, 199)',
13
  );
14
  $action_ops = apply_filters( 'frm_email_control_settings', $action_ops );
15
 
16
- parent::__construct( 'email', __( 'Send Email', 'formidable' ), $action_ops );
17
  }
18
 
19
  public function form( $form_action, $args = array() ) {
@@ -23,17 +23,17 @@ class FrmEmailAction extends FrmFormAction {
23
  }
24
 
25
  public function get_defaults() {
26
- return array(
27
- 'email_to' => '[admin_email]',
28
- 'cc' => '',
29
- 'bcc' => '',
30
- 'from' => '[sitename] <[admin_email]>',
31
- 'reply_to' => '',
32
- 'email_subject' => '',
33
- 'email_message' => '[default-message]',
34
- 'inc_user_info' => 0,
35
- 'plain_text' => 0,
36
  'event' => array( 'create' ),
37
- );
38
  }
39
  }
4
 
5
  public function __construct() {
6
  $action_ops = array(
7
+ 'classes' => 'frm_email_icon frm_icon_font',
8
+ 'active' => true,
9
  'event' => array( 'create' ),
10
+ 'limit' => 99,
11
+ 'priority' => 10,
12
+ 'ajax_load' => false,
13
  );
14
  $action_ops = apply_filters( 'frm_email_control_settings', $action_ops );
15
 
16
+ parent::__construct( 'email', __( 'Email Notification', 'formidable' ), $action_ops );
17
  }
18
 
19
  public function form( $form_action, $args = array() ) {
23
  }
24
 
25
  public function get_defaults() {
26
+ return array(
27
+ 'email_to' => '[admin_email]',
28
+ 'cc' => '',
29
+ 'bcc' => '',
30
+ 'from' => '[sitename] <[admin_email]>',
31
+ 'reply_to' => '',
32
+ 'email_subject' => '',
33
+ 'email_message' => '[default-message]',
34
+ 'inc_user_info' => 0,
35
+ 'plain_text' => 0,
36
  'event' => array( 'create' ),
37
+ );
38
  }
39
  }
classes/views/frm-form-actions/form_action.php CHANGED
@@ -5,42 +5,41 @@ $form_action = apply_filters( 'frm_form_action_settings', $form_action, $form_ac
5
  $form_action = apply_filters( 'frm_form_' . $form_action->post_excerpt . '_action_settings', $form_action );
6
 
7
  ?>
8
- <div id="frm_form_action_<?php echo esc_attr( $action_key ); ?>" class="widget frm_form_action_settings frm_single_<?php echo esc_attr( $form_action->post_excerpt ); ?>_settings <?php echo esc_attr( $form_action->post_status === 'publish' ? '' : 'frm_disabled_action' ); ?>" data-actionkey="<?php echo esc_attr( $action_key ); ?>">
9
- <div class="widget-top">
10
- <div class="widget-title-action">
11
- <button type="button" class="widget-action hide-if-no-js" aria-expanded="false">
12
- <i class="frm_icon_font frm_arrow_right_icon" aria-hidden="true"></i>
13
- </button>
14
- </div>
15
- <span class="frm_email_icons alignright">
16
  <?php if ( $action_control->action_options['limit'] > 2 ) { ?>
17
- <a href="javascript:void(0)" class="frm_icon_font frm_clone_solid_icon frm_duplicate_form_action" title="<?php esc_attr_e( 'Duplicate', 'formidable' ); ?>"> </a>
18
  <?php } ?>
19
- <a href="javascript:void(0)" data-removeid="frm_form_action_<?php echo esc_attr( $action_key ); ?>" class="frm_icon_font frm_delete_icon frm_remove_form_action" data-frmverify="<?php echo esc_attr( 'Really?', 'formidable' ); ?>" title="<?php esc_attr_e( 'Delete', 'formidable' ); ?>"> </a>
20
 
21
  <label class="frm_toggle">
22
  <input type="checkbox" value="publish" name="<?php echo esc_attr( $action_control->get_field_name( 'post_status', '' ) ); ?>" <?php checked( $form_action->post_status, 'publish' ); ?> />
23
  <span class="frm_toggle_slider"></span>
24
  <span class="frm_toggle_on">ON</span>
25
- <span class="frm_toggle_off">OFF</span>
26
  </label>
27
- </span>
28
- <div class="widget-title">
29
- <h4><span class="frm_form_action_icon <?php echo esc_attr( $action_control->action_options['classes'] ); ?>"></span>
30
- <?php echo esc_html( $form_action->post_title ); ?>
31
- </h4>
32
- </div>
33
- </div>
34
- <div class="widget-inside">
35
- <?php
36
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
37
- // only load settings if they are just added or are open
38
  include( dirname( __FILE__ ) . '/_action_inside.php' );
39
- } else {
40
  // include hidden settings so action won't get lost on update
41
  ?>
42
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'post_excerpt', '' ) ); ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
43
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'ID', '' ) ); ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
44
  <?php } ?>
45
- </div>
46
  </div>
5
  $form_action = apply_filters( 'frm_form_' . $form_action->post_excerpt . '_action_settings', $form_action );
6
 
7
  ?>
8
+ <div id="frm_form_action_<?php echo esc_attr( $action_key ) ?>" class="widget frm_form_action_settings frm_single_<?php echo esc_attr( $form_action->post_excerpt ) ?>_settings" data-actionkey="<?php echo esc_attr( $action_key ) ?>">
9
+ <div class="widget-top">
10
+ <div class="widget-title-action">
11
+ <button type="button" class="widget-action hide-if-no-js" aria-expanded="false">
12
+ <span class="toggle-indicator" aria-hidden="true"></span>
13
+ </button>
14
+ </div>
15
+ <span class="frm_email_icons alignright">
16
  <?php if ( $action_control->action_options['limit'] > 2 ) { ?>
17
+ <a href="javascript:void(0)" class="frm_icon_font frm_duplicate_icon frm_duplicate_form_action" title="<?php esc_attr_e( 'Duplicate', 'formidable' ); ?>"> </a>
18
  <?php } ?>
19
+ <a href="javascript:void(0)" data-removeid="frm_form_action_<?php echo esc_attr( $action_key ) ?>" class="frm_icon_font frm_delete_icon frm_remove_form_action" data-frmverify="<?php echo esc_attr( 'Really?', 'formidable' ) ?>" title="<?php esc_attr_e( 'Delete', 'formidable' ); ?>"> </a>
20
 
21
  <label class="frm_toggle">
22
  <input type="checkbox" value="publish" name="<?php echo esc_attr( $action_control->get_field_name( 'post_status', '' ) ); ?>" <?php checked( $form_action->post_status, 'publish' ); ?> />
23
  <span class="frm_toggle_slider"></span>
24
  <span class="frm_toggle_on">ON</span>
 
25
  </label>
26
+ </span>
27
+ <div class="widget-title">
28
+ <h4><span class="frm_form_action_icon <?php echo esc_attr( $action_control->action_options['classes'] ) ?>"></span>
29
+ <?php echo esc_html( $form_action->post_title ); ?>
30
+ </h4>
31
+ </div>
32
+ </div>
33
+ <div class="widget-inside frm_hidden">
34
+ <?php
35
+ if ( defined( 'DOING_AJAX' ) || ! $action_control->action_options['ajax_load'] ) {
36
+ // only load settings if they are just added or are open
37
  include( dirname( __FILE__ ) . '/_action_inside.php' );
38
+ } else {
39
  // include hidden settings so action won't get lost on update
40
  ?>
41
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'post_excerpt', '' ) ); ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
42
  <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'ID', '' ) ); ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
43
  <?php } ?>
44
+ </div>
45
  </div>
classes/views/frm-form-actions/settings.php DELETED
@@ -1,80 +0,0 @@
1
- <p class="howto">
2
- <?php esc_html_e( 'Add form actions to your form to perform tasks when an entry is created, updated, imported, and more.', 'formidable' ); ?>
3
- </p>
4
-
5
- <?php FrmTipsHelper::pro_tip( 'get_form_action_tip', 'p' ); ?>
6
-
7
- <div id="frm_email_addon_menu" class="frm-limited-actions">
8
- <?php
9
- FrmAppHelper::show_search_box(
10
- array(
11
- 'input_id' => 'actions',
12
- 'placeholder' => __( 'Search Form Actions', 'formidable' ),
13
- 'tosearch' => 'frm-action',
14
- )
15
- );
16
- ?>
17
- <h3 class="frm-no-border">
18
- <?php esc_html_e( 'Form Actions', 'formidable' ); ?>
19
- <span class="frm-sub-label">
20
- <?php esc_html_e( '(click an action to add it to your form)', 'formidable' ); ?>
21
- </span>
22
- </h3>
23
- <?php
24
- $displayed_actions = array();
25
- foreach ( $groups as $group_name => $group ) {
26
- if ( ! empty( $group['name'] ) ) {
27
- ?>
28
- <h3 class="frm-group-heading"><?php echo esc_html( $group['name'] ); ?></h3>
29
- <?php
30
- }
31
-
32
- if ( ! isset( $group['actions'] ) ) {
33
- $group['actions'] = array();
34
- }
35
- ?>
36
- <ul class="frm_actions_list">
37
- <?php
38
- foreach ( $action_controls as $action_control ) {
39
- if ( in_array( $action_control->id_base, $displayed_actions ) || ! in_array( $action_control->id_base, $group['actions'] ) ) {
40
- continue;
41
- }
42
-
43
- $displayed_actions[] = $action_control->id_base;
44
- FrmFormActionsController::show_action_icon_link( $action_control, $allowed );
45
- unset( $actions_icon, $classes );
46
- }
47
-
48
- foreach ( $group['actions'] as $action ) {
49
- if ( ! in_array( $action, $displayed_actions ) ) {
50
- ?>
51
- <li class="frm-action frm-not-installed">
52
- <a href="javascript:void(0)" class="frm-single-action frm_show_upgrade">
53
- <span>
54
- <i class="frm_icon_font frm_plus_icon"
55
- <?php if ( isset( $group['color'] ) ) { ?>
56
- style="--primary-hover:<?php echo esc_attr( $group['color'] ); ?>"
57
- <?php } ?>></i>
58
- </span>
59
- <?php echo esc_html( $action ); ?>
60
- </a>
61
- </li>
62
- <?php
63
- }
64
- }
65
- ?>
66
- </ul>
67
- <?php
68
- }
69
- ?>
70
- <div class="clear"></div>
71
- <a href="#" id="frm-show-groups">
72
- <?php esc_html_e( 'Show all form actions', 'formidable' ); ?>
73
- </a>
74
- <a href="#" id="frm-hide-groups">
75
- <?php esc_html_e( 'Hide extra form actions', 'formidable' ); ?>
76
- </a>
77
- <div class="clear"></div>
78
- </div>
79
-
80
- <?php FrmFormActionsController::list_actions( $form, $values ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-forms/_publish_box.php CHANGED
@@ -1,23 +1,31 @@
1
- <?php
2
- if ( 'settings' == FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ) ) {
3
- $class = 'frm_submit_settings_btn';
4
- } else {
5
- $class = 'frm_submit_' . ( ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_' ) . 'ajax';
6
- }
7
- ?>
8
- <button class="frm_submit_form button-primary frm-button-primary frm_button_submit <?php echo esc_attr( $class ); ?>" type="button" id="frm_submit_side_top" >
9
- <?php esc_html_e( 'Update', 'formidable' ); ?>
10
- </button>
11
 
12
- <div id="frm-preview-action">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  <?php if ( ( ! isset( $hide_preview ) || ! $hide_preview ) && isset( $values['form_key'] ) ) { ?>
14
  <div class="preview dropdown">
15
- <a href="#" id="frm-previewDrop" class="frm-dropdown-toggle button frm-button-secondary" data-toggle="dropdown">
16
- <?php esc_html_e( 'Preview', 'formidable' ); ?>
17
- <i class="frmfont frm_arrowdown4_icon"></i>
18
- </a>
19
 
20
- <ul class="frm-dropdown-menu <?php echo esc_attr( is_rtl() ? 'pull-left' : 'pull-right' ); ?>" role="menu" aria-labelledby="frm-previewDrop">
21
  <li>
22
  <a href="<?php echo esc_url( FrmFormsHelper::get_direct_link( $values['form_key'] ) ); ?>" target="_blank">
23
  <?php esc_html_e( 'On Blank Page', 'formidable' ); ?>
@@ -32,5 +40,11 @@ if ( 'settings' == FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ) )
32
  </div>
33
  <?php } ?>
34
  </div>
 
 
 
 
35
 
36
- <div class="clear"></div>
 
 
1
+ <div id="submitdiv" class="postbox frm-no-border">
2
+ <div class="inside">
3
+ <div class="submitbox" id="submitpost">
 
 
 
 
 
 
 
4
 
5
+ <div id="major-publishing-actions">
6
+ <div id="publishing-action" class="<?php echo esc_attr( 'draft' === $values['status'] ? 'frm-is-draft' : '' ); ?>">
7
+ <div class="alignleft">
8
+ <?php FrmFormsHelper::actions_dropdown( $values ) ?>
9
+ </div>
10
+
11
+ <?php if ( 'draft' == $values['status'] ) { ?>
12
+ <button class="frm_submit_form frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary frm_button_submit" type="button" id="save-post" ><?php esc_html_e( 'Save Draft', 'formidable' ); ?></button>
13
+ <?php } ?>
14
+ <?php if ( 'settings' == FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ) ) { ?>
15
+ <button class="frm_submit_form frm_submit_settings_btn button-primary frm_button_submit" type="button" id="frm_submit_side_top" >
16
+ <?php esc_html_e( 'Update', 'formidable' ); ?>
17
+ </button>
18
+ <?php } else { ?>
19
+ <button class="frm_submit_form frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary frm_button_submit" type="button" id="frm_submit_side_top">
20
+ <?php echo esc_html( isset( $button ) ? $button : __( 'Update', 'formidable' ) ); ?>
21
+ </button>
22
+ <?php } ?>
23
+ <div id="frm-preview-action">
24
  <?php if ( ( ! isset( $hide_preview ) || ! $hide_preview ) && isset( $values['form_key'] ) ) { ?>
25
  <div class="preview dropdown">
26
+ <a href="#" id="frm-previewDrop" class="frm-dropdown-toggle button frm-button-primary" data-toggle="dropdown"><?php esc_html_e( 'Preview', 'formidable' ); ?> <b class="caret"></b></a>
 
 
 
27
 
28
+ <ul class="frm-dropdown-menu <?php echo esc_attr( is_rtl() ? 'pull-left' : 'pull-right' ) ?>" role="menu" aria-labelledby="frm-previewDrop">
29
  <li>
30
  <a href="<?php echo esc_url( FrmFormsHelper::get_direct_link( $values['form_key'] ) ); ?>" target="_blank">
31
  <?php esc_html_e( 'On Blank Page', 'formidable' ); ?>
40
  </div>
41
  <?php } ?>
42
  </div>
43
+ </div>
44
+
45
+ <div class="clear"></div>
46
+ </div><!-- #major-publishing-actions -->
47
 
48
+ </div>
49
+ </div>
50
+ </div>
classes/views/frm-forms/actions-dropdown.php CHANGED
@@ -1,17 +1,17 @@
1
- <div class="frm_actions_dropdown dropdown <?php echo esc_attr( is_rtl() ? 'pull-right' : 'pull-left' ); ?>">
2
- <a href="#" id="frm-actionsDrop" class="frm-dropdown-toggle frm_icon_font frm_option_icon" data-toggle="dropdown" title="<?php esc_attr_e( 'Show options', 'formidable' ); ?>"></a>
3
  <ul class="frm-dropdown-menu frm-on-top" role="menu" aria-labelledby="frm-actionsDrop">
4
  <?php foreach ( $links as $link ) { ?>
5
  <li>
6
  <a href="<?php echo esc_url( $link['url'] ); ?>" tabindex="-1" <?php
7
- if ( isset( $link['data'] ) ) {
8
- foreach ( $link['data'] as $data => $value ) {
9
- echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
 
10
  }
11
- }
12
- ?> >
13
- <span class="<?php echo esc_attr( $link['icon'] ); ?>"></span>
14
- <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
15
  </a>
16
  </li>
17
  <?php } ?>
1
+ <div class="frm_actions_dropdown dropdown <?php echo esc_attr( is_rtl() ? 'pull-right' : 'pull-left' ) ?>">
2
+ <a href="#" id="frm-actionsDrop" class="frm-dropdown-toggle frm_icon_font frm-option-icon" data-toggle="dropdown" title="<?php esc_attr_e( 'Show options', 'formidable' ) ?>"></a>
3
  <ul class="frm-dropdown-menu frm-on-top" role="menu" aria-labelledby="frm-actionsDrop">
4
  <?php foreach ( $links as $link ) { ?>
5
  <li>
6
  <a href="<?php echo esc_url( $link['url'] ); ?>" tabindex="-1" <?php
7
+ if ( isset( $link['data'] ) ) {
8
+ foreach ( $link['data'] as $data => $value ) {
9
+ echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
10
+ }
11
  }
12
+ ?> >
13
+ <span class="<?php echo esc_attr( $link['icon'] ) ?>"></span>
14
+ <span class="frm_link_label"><?php echo esc_html( $link['label'] ) ?></span>
 
15
  </a>
16
  </li>
17
  <?php } ?>
classes/views/frm-forms/add-new.php CHANGED
@@ -18,7 +18,7 @@
18
  <p><?php esc_html_e( 'Build anything you can imagine.', 'formidable' ); ?></p>
19
  </div>
20
  <div class="plugin-card-bottom">
21
- <a class="button button-primary frm-button-primary frm-new-form-button" href="#">
22
  <?php esc_html_e( 'Create Blank Form', 'formidable' ); ?>
23
  </a>
24
  </div>
@@ -57,8 +57,3 @@
57
  <div class="clear"></div>
58
  </div>
59
  </div>
60
-
61
- <?php
62
- $type = 'form';
63
- include( dirname( __FILE__ ) . '/new-form-overlay.php' );
64
- ?>
18
  <p><?php esc_html_e( 'Build anything you can imagine.', 'formidable' ); ?></p>
19
  </div>
20
  <div class="plugin-card-bottom">
21
+ <a class="button button-primary frm-button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ); ?>">
22
  <?php esc_html_e( 'Create Blank Form', 'formidable' ); ?>
23
  </a>
24
  </div>
57
  <div class="clear"></div>
58
  </div>
59
  </div>
 
 
 
 
 
classes/views/frm-forms/add_field.php CHANGED
@@ -1,87 +1,368 @@
1
- <li id="frm_field_id_<?php echo esc_attr( $field['id'] ); ?>" class="<?php echo esc_attr( $li_classes ); ?>" data-fid="<?php echo esc_attr( $field['id'] ); ?>" data-formid="<?php echo esc_attr( 'divider' == $field['type'] ? $field['form_select'] : $field['form_id'] ); ?>" data-ftype="<?php echo esc_attr( $display['type'] ); ?>" data-type="<?php echo esc_attr( $field['type'] ); ?>">
2
  <?php if ( $field['type'] == 'divider' ) { ?>
3
  <div class="divider_section_only">
4
  <?php } ?>
5
 
 
 
 
 
6
  <?php do_action( 'frm_extra_field_actions', $field['id'] ); ?>
 
 
 
 
 
 
 
 
 
7
 
8
- <div id="field_<?php echo esc_attr( $field['id'] ); ?>_inner_container" class="frm_inner_field_container">
9
- <div class="frm-field-action-icons frm-show-hover">
 
10
 
11
- <?php if ( $field['type'] === 'divider' ) { ?>
12
- <a href="#" class="frm-collapse-section frm-hover-icon frm_icon_font frm_arrowdown6_icon" title="<?php esc_attr_e( 'Expand/Collapse Section', 'formidable' ); ?>"></a>
13
- <?php } ?>
14
 
15
- <a href="#" class="frm_bstooltip frm-move frm-hover-icon frm_icon_font frm_move_icon" title="<?php esc_attr_e( 'Move Field', 'formidable' ); ?>"> </a>
16
- <a href="#" class="frm_bstooltip frm-hover-icon frm_icon_font frm_delete_icon frm_delete_field" title="<?php esc_attr_e( 'Delete Field', 'formidable' ); ?>"> </a>
17
- <a href="#" class="frm_bstooltip frm-hover-icon frm_icon_font frm_clone_icon" title="<?php ( $field['type'] === 'divider' ) ? esc_attr_e( 'Duplicate Section', 'formidable' ) : esc_attr_e( 'Duplicate Field', 'formidable' ); ?>"> </a>
 
18
 
19
- <div class="frm-sub-label alignright">
20
- (ID <?php echo esc_html( $field['id'] ); ?>)
21
- </div>
22
- </div>
23
-
24
- <label class="frm_primary_label" id="field_label_<?php echo esc_attr( $field['id'] ); ?>">
25
- <?php echo FrmAppHelper::kses( force_balance_tags( $field['name'] ), 'all' ); // WPCS: XSS ok. ?>
26
- <span class="frm_required">
27
- <?php
28
- if ( FrmField::is_required( $field ) ) {
29
- echo esc_html( $field['required_indicator'] );
30
- }
31
- ?>
32
- </span>
33
- <span class="frm-sub-label frm-collapsed-label">
34
- <?php esc_html_e( '(Collapsed)', 'formidable' ); ?>
35
- </span>
36
- </label>
37
-
38
- <div class="frm_form_fields" data-ftype="<?php echo esc_attr( $display['type'] ); ?>">
39
- <?php $field_obj->show_on_form_builder(); ?>
40
- <div class="clear"></div>
41
- </div>
42
- <?php if ( $display['description'] || in_array( $field['type'], array( 'address', 'credit_card' ) ) ) { ?>
43
- <div class="description" id="field_description_<?php echo esc_attr( $field['id'] ); ?>">
44
- <?php echo FrmAppHelper::kses( force_balance_tags( $field['description'] ), 'all' ); // WPCS: XSS ok. ?>
45
- </div>
46
- <?php } ?>
47
  </div>
48
  <?php if ( $display['conf_field'] ) { ?>
49
- <div id="frm_conf_field_<?php echo esc_attr( $field['id'] ); ?>_container" class="frm_conf_field_container frm_form_fields frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
50
- <div id="frm_conf_field_<?php echo esc_attr( $field['id'] ); ?>_inner_container" class="frm_inner_conf_container">
51
- <label class="frm_primary_label">&nbsp;</label>
52
  <div class="frm_form_fields">
53
- <input type="text" id="conf_field_<?php echo esc_attr( $field['field_key'] ); ?>" name="field_options[conf_input_<?php echo esc_attr( $field['id'] ); ?>]" placeholder="<?php echo esc_attr( $field['conf_input'] ); ?>" class="dyn_default_value" />
54
  </div>
55
- <div id="conf_field_description_<?php echo esc_attr( $field['id'] ); ?>" class="description"><?php
56
- echo FrmAppHelper::kses( force_balance_tags( $field['conf_desc'] ), 'all' ); // WPCS: XSS ok.
57
  ?></div>
 
58
  </div>
 
 
 
 
 
59
  </div>
60
  <div class="clear"></div>
 
 
 
 
 
 
61
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
- FrmFieldsController::load_single_field_settings( compact( 'field', 'field_obj', 'values', 'display' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  if ( 'divider' === $field['type'] ) {
67
- ?>
68
  </div>
69
  <div class="frm_no_section_fields">
70
- <i class="frm-large-plus frm_icon_font frm_plus2_icon"></i>
71
- <p class="howto"><?php esc_html_e( 'Your section has no fields. Drag fields here to add them to this section.', 'formidable' ); ?></p>
72
  </div>
73
  <ul class="start_divider frm_sorting">
74
- <?php
75
  } elseif ( 'end_divider' === $field['type'] ) {
76
- ?>
77
  </ul>
78
- <?php
79
  }
80
 
81
  if ( $field['type'] !== 'divider' ) {
82
- ?>
83
  </li>
84
- <?php
85
  }
86
-
87
- ?>
1
+ <li id="frm_field_id_<?php echo esc_attr( $field['id'] ); ?>" class="<?php echo esc_attr( $li_classes ) ?>" data-fid="<?php echo esc_attr( $field['id'] ) ?>" data-formid="<?php echo esc_attr( 'divider' == $field['type'] ? $field['form_select'] : $field['form_id'] ); ?>" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
2
  <?php if ( $field['type'] == 'divider' ) { ?>
3
  <div class="divider_section_only">
4
  <?php } ?>
5
 
6
+ <a href="javascript:void(0);" class="frm_bstooltip alignright frm-show-hover frm-move frm-hover-icon frm_icon_font frm_move_icon" title="<?php esc_attr_e( 'Move Field', 'formidable' ) ?>"> </a>
7
+ <a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_delete_icon frm_delete_field" title="<?php esc_attr_e( 'Delete Field', 'formidable' ) ?>"> </a>
8
+ <a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_duplicate_icon" title="<?php ( $field['type'] === 'divider' ) ? esc_attr_e( 'Duplicate Section', 'formidable' ) : esc_attr_e( 'Duplicate Field', 'formidable' ) ?>"> </a>
9
+ <input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr( $field['id'] ) ?>" />
10
  <?php do_action( 'frm_extra_field_actions', $field['id'] ); ?>
11
+ <?php if ( $display['required'] ) { ?>
12
+ <span id="require_field_<?php echo esc_attr( $field['id'] ); ?>">
13
+ <a href="javascript:void(0);" class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int) $field['required'] ?>" id="req_field_<?php echo esc_attr( $field['id'] ); ?>" title="Click to Mark as <?php echo FrmField::is_required( $field ) ? 'not ' : ''; ?>Required"></a>
14
+ </span>
15
+ <?php } ?>
16
+ <label class="<?php echo esc_attr( $field['type'] === 'end_divider' ? '' : 'frm_ipe_field_label' ); ?> frm_primary_label <?php echo esc_attr( $field['type'] === 'break' ? 'button' : '' ); ?>" id="field_label_<?php echo esc_attr( $field['id'] ); ?>"><?php
17
+ echo ( $field['name'] === '' ) ? esc_html__( '(no label)', 'formidable' ) : FrmAppHelper::kses( force_balance_tags( $field['name'] ), 'all' ); // WPCS: XSS ok.
18
+ ?></label>
19
+ <input type="hidden" name="field_options[name_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['name'] ); ?>" />
20
 
21
+ <div id="field_<?php echo esc_attr( $field['id'] ) ?>_inner_container" class="frm_inner_field_container">
22
+ <div class="frm_form_fields" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
23
+ <?php
24
 
25
+ $field_obj->show_on_form_builder();
 
 
26
 
27
+ if ( $display['clear_on_focus'] ) {
28
+ FrmFieldsHelper::clear_on_focus_html( $field, $display );
29
+ do_action( 'frm_extra_field_display_options', $field );
30
+ }
31
 
32
+ ?>
33
+ <div class="clear"></div>
34
+ </div>
35
+ <?php if ( $display['description'] ) { ?>
36
+ <div class="frm_ipe_field_desc description <?php echo esc_attr( $field['description'] === '' ? 'frm-show-click' : '' ); ?>" id="field_description_<?php echo esc_attr( $field['id'] ); ?>"><?php
37
+ echo ( $field['description'] === '' ) ? esc_html__( '(Click to add description)', 'formidable' ) : FrmAppHelper::kses( force_balance_tags( $field['description'] ), 'all' ); // WPCS: XSS ok.
38
+ ?></div>
39
+ <input type="hidden" name="field_options[description_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['description'] ); ?>" />
40
+
41
+ <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </div>
43
  <?php if ( $display['conf_field'] ) { ?>
44
+ <div id="frm_conf_field_<?php echo esc_attr( $field['id'] ) ?>_container" class="frm_conf_field_container frm_form_fields frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
45
+ <div id="frm_conf_field_<?php echo esc_attr( $field['id'] ) ?>_inner_container" class="frm_inner_conf_container">
 
46
  <div class="frm_form_fields">
47
+ <input type="text" id="conf_field_<?php echo esc_attr( $field['field_key'] ) ?>" name="field_options[conf_input_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_input'] ); ?>" class="dyn_default_value" />
48
  </div>
49
+ <div id="conf_field_description_<?php echo esc_attr( $field['id'] ) ?>" class="frm_ipe_field_conf_desc description <?php echo ( $field['conf_desc'] === '' ) ? 'frm-show-click' : '' ?>"><?php
50
+ echo ( $field['conf_desc'] === '' ) ? esc_html__( '(Click to add description)', 'formidable' ) : FrmAppHelper::kses( force_balance_tags( $field['conf_desc'] ), 'all' ); // WPCS: XSS ok.
51
  ?></div>
52
+ <input type="hidden" name="field_options[conf_desc_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_desc'] ); ?>" />
53
  </div>
54
+ <?php if ( $display['clear_on_focus'] ) { ?>
55
+ <div class="alignleft">
56
+ <?php FrmFieldsHelper::clear_on_focus_html( $field, $display, '_conf' ); ?>
57
+ </div>
58
+ <?php } ?>
59
  </div>
60
  <div class="clear"></div>
61
+ <?php
62
+ }
63
+
64
+ if ( in_array( $field['type'], array( 'select', 'radio', 'checkbox' ) ) ) {
65
+ ?>
66
+ <div class="frm-show-click frm_small_top_margin">
67
  <?php
68
+
69
+ if ( isset( $field['post_field'] ) && $field['post_field'] === 'post_category' ) {
70
+ echo '<p class="howto" id="frm_has_hidden_options_' . esc_attr( $field['id'] ) . '">' . FrmFieldsHelper::get_term_link( $field['taxonomy'] ) . '</p>'; // WPCS: XSS ok.
71
+ } elseif ( ! isset( $field['post_field'] ) || ! in_array( $field['post_field'], array( 'post_category' ) ) ) {
72
+ ?>
73
+ <div id="frm_add_field_<?php echo esc_attr( $field['id'] ); ?>">
74
+ <a href="javascript:void(0);" data-opttype="single" class="button frm_cb_button frm_add_opt" data-clicks="0"><?php esc_html_e( 'Add Option', 'formidable' ) ?></a>
75
+
76
+ <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
77
+ <a href="javascript:void(0);" id="other_button_<?php echo esc_attr( $field['id'] ); ?>" data-opttype="other" data-ftype="<?php echo esc_attr( $field['type'] ) ?>" class="button frm_cb_button frm_add_opt<?php echo ( in_array( $field['type'], array( 'radio', 'select' ) ) && $field['other'] == true ? ' frm_hidden' : '' ); ?>" data-clicks="0">
78
+ <?php esc_html_e( 'Add "Other"', 'formidable' ) ?>
79
+ </a>
80
+ <input type="hidden" value="<?php echo esc_attr( $field['other'] ); ?>" id="other_input_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[other_<?php echo esc_attr( $field['id'] ); ?>]">
81
+ <?php
82
+ }
83
+
84
+ if ( ! isset( $field['post_field'] ) || $field['post_field'] != 'post_category' ) {
85
+ ?>
86
+ <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=frm_import_choices&field_id=' . $field['id'] . '&TB_iframe=1' ) ) ?>" title="<?php echo esc_attr( FrmAppHelper::truncate( strip_tags( str_replace( '"', '&quot;', $field['name'] ) ), 20 ) . ' ' . __( 'Field Choices', 'formidable' ) ); ?>" class="thickbox frm_orange">
87
+ <?php esc_html_e( 'Bulk Edit Options', 'formidable' ); ?>
88
+ </a>
89
+ <?php } ?>
90
+ </div>
91
+ <?php
92
+ }
93
+ ?>
94
+ </div>
95
+ <?php
96
  }
97
 
98
+ do_action( 'frm_before_field_options', $field );
99
+
100
+ if ( $display['options'] ) {
101
+ ?>
102
+ <div class="widget">
103
+ <div class="widget-top">
104
+ <div class="widget-title-action">
105
+ <button type="button" class="widget-action hide-if-no-js" aria-expanded="false">
106
+ <span class="toggle-indicator" aria-hidden="true"></span>
107
+ </button>
108
+ </div>
109
+ <div class="widget-title">
110
+ <h3><?php esc_html_e( 'Field Settings', 'formidable' ) ?> (ID <?php echo (int) $field['id'] ?>)</h3>
111
+ </div>
112
+ </div>
113
+ <div class="widget-inside">
114
+ <table class="form-table frm_clear_none">
115
+ <?php $field_types = FrmFieldsHelper::get_field_types( $field['type'] ); ?>
116
+ <tr><td class="frm_150_width"><label><?php esc_html_e( 'Field Type', 'formidable' ) ?></label></td>
117
+ <td>
118
+ <select <?php echo ( count( $field_types ) === 1 ? 'disabled="disabled"' : 'name="field_options[type_' . esc_attr( $field['id'] ) . ']"' ); ?>>
119
+ <?php foreach ( $field_types as $fkey => $ftype ) { ?>
120
+ <option value="<?php echo esc_attr( $fkey ) ?>" <?php echo ( $fkey === $field['type'] ) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists( $fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>>
121
+ <?php echo esc_html( is_array( $ftype ) ? $ftype['name'] : $ftype ); ?>
122
+ </option>
123
+ <?php
124
+ unset( $fkey, $ftype );
125
+ }
126
+ ?>
127
+ </select>
128
+
129
+ <?php if ( $display['required'] ) { ?>
130
+ <label for="frm_req_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label">
131
+ <input type="checkbox" id="frm_req_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_req_field" name="field_options[required_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php checked( $field['required'], 1 ) ?> />
132
+ <?php esc_html_e( 'Required', 'formidable' ); ?>
133
+ </label>
134
+ <?php
135
+ }
136
+
137
+ if ( $display['unique'] ) {
138
+ if ( ! isset( $field['unique'] ) ) {
139
+ $field['unique'] = false;
140
+ }
141
+ ?>
142
+ <label for="frm_uniq_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.', 'formidable' ) ?>"><input type="checkbox" name="field_options[unique_<?php echo esc_attr( $field['id'] ) ?>]" id="frm_uniq_field_<?php echo esc_attr( $field['id'] ) ?>" value="1" <?php checked( $field['unique'], 1 ); ?> class="frm_mark_unique" />
143
+ <?php esc_html_e( 'Unique', 'formidable' ); ?>
144
+ </label>
145
+ <?php
146
+ }
147
+
148
+ if ( $display['read_only'] ) {
149
+ if ( ! isset( $field['read_only'] ) ) {
150
+ $field['read_only'] = false;
151
+ }
152
+ ?>
153
+ <label for="frm_read_only_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ) ?>" >
154
+ <input type="checkbox" id="frm_read_only_field_<?php echo esc_attr( $field['id'] ) ?>" name="field_options[read_only_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php checked( $field['read_only'], 1 ) ?>/>
155
+ <?php esc_html_e( 'Read Only', 'formidable' ); ?>
156
+ </label>
157
+ <?php
158
+ }
159
+
160
+ do_action( 'frm_field_options_form_top', $field, $display, $values );
161
+
162
+ if ( $display['required'] ) {
163
+ ?>
164
+ <div class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>">
165
+ <span class="howto"><?php esc_html_e( 'Indicate required field with', 'formidable' ); ?></span>
166
+ <input type="text" name="field_options[required_indicator_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['required_indicator'] ); ?>" />
167
+ </div>
168
+ <?php } ?>
169
+ </td>
170
+ </tr>
171
+ <tr>
172
+ <td class="frm_150_width">
173
+ <div class="hide-if-no-js edit-slug-box frm_help" title="<?php esc_attr_e( 'The field key can be used as an alternative to the field ID in many cases.', 'formidable' ) ?>">
174
+ <?php esc_html_e( 'Field Key', 'formidable' ); ?>
175
+ </div>
176
+ </td>
177
+ <td>
178
+ <input type="text" name="field_options[field_key_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['field_key'] ); ?>" />
179
+ </td>
180
+ </tr>
181
+
182
+ <?php if ( $display['css'] ) { ?>
183
+ <tr><td><label><?php esc_html_e( 'CSS layout classes', 'formidable' ) ?></label>
184
+ <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable' ) ?>" ></span>
185
+ </td>
186
+ <td><input type="text" name="field_options[classes_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['classes'] ) ?>" id="frm_classes_<?php echo esc_attr( $field['id'] ) ?>" class="frm_classes frm_long_input" />
187
+ </td>
188
+ </tr>
189
+ <?php } ?>
190
+
191
+ <?php if ( $display['label_position'] ) { ?>
192
+ <tr>
193
+ <td class="frm_150_width"><label><?php esc_html_e( 'Label Position', 'formidable' ) ?></label></td>
194
+ <td>
195
+ <select name="field_options[label_<?php echo esc_attr( $field['id'] ) ?>]">
196
+ <option value=""<?php selected( $field['label'], '' ); ?>>
197
+ <?php esc_html_e( 'Default', 'formidable' ) ?>
198
+ </option>
199
+ <?php foreach ( FrmStylesHelper::get_single_label_positions() as $pos => $pos_label ) { ?>
200
+ <?php
201
+ if ( ! $display['clear_on_focus'] && 'inside' === $pos ) {
202
+ // don't allow inside labels for fields without placeholders
203
+ continue;
204
+ }
205
+ ?>
206
+ <option value="<?php echo esc_attr( $pos ) ?>"<?php selected( $field['label'], $pos ); ?>>
207
+ <?php echo esc_html( $pos_label ) ?>
208
+ </option>
209
+ <?php } ?>
210
+ </select>
211
+ </td>
212
+ </tr>
213
+ <?php
214
+ }
215
+
216
+ // Field Size
217
+ if ( $display['size'] ) {
218
+ if ( in_array( $field['type'], array( 'select', 'time', 'data' ) ) ) {
219
+ if ( ! isset( $values['custom_style'] ) || $values['custom_style'] ) {
220
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/automatic-width.php' );
221
+ }
222
+ } else {
223
+ $display_max = $display['max'];
224
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/pixels-wide.php' );
225
+ }
226
+ }
227
+
228
+ if ( $display['show_image'] ) {
229
+ ?>
230
+ <tr>
231
+ <td class="frm_150_width">
232
+ <label><?php esc_html_e( 'Show URL image', 'formidable' ) ?></label>
233
+ </td>
234
+ <td>
235
+ <label for="frm_show_image_<?php echo esc_attr( $field['id'] ) ?>">
236
+ <input type="checkbox" id="frm_show_image_<?php echo esc_attr( $field['id'] ) ?>" name="field_options[show_image_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php checked( $field['show_image'], 1 ) ?> />
237
+ <?php esc_html_e( 'If this URL points to an image, show to image on the entries listing page.', 'formidable' ); ?>
238
+ </label>
239
+ </td>
240
+ </tr>
241
+ <?php
242
+ }
243
+
244
+ if ( $display['captcha_size'] && $frm_settings->re_type !== 'invisible' ) {
245
+ ?>
246
+ <tr><td><label><?php esc_html_e( 'ReCaptcha Type', 'formidable' ) ?></label>
247
+ <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Set the size of the captcha field. The compact option is best if your form is in a small area.', 'formidable' ) ?>" ></span>
248
+ </td>
249
+ <td>
250
+ <select name="field_options[captcha_size_<?php echo esc_attr( $field['id'] ) ?>]">
251
+ <option value="normal" <?php selected( $field['captcha_size'], 'normal' ); ?>>
252
+ <?php esc_html_e( 'Normal', 'formidable' ) ?>
253
+ </option>
254
+ <option value="compact" <?php selected( $field['captcha_size'], 'compact' ); ?>>
255
+ <?php esc_html_e( 'Compact', 'formidable' ) ?>
256
+ </option>
257
+ </select>
258
+ </td>
259
+ </tr>
260
+ <tr>
261
+ <td>
262
+ <label for="captcha_theme_<?php echo esc_attr( $field['field_key'] ) ?>">
263
+ <?php esc_html_e( 'reCAPTCHA Color', 'formidable' ) ?>
264
+ </label>
265
+ </td>
266
+ <td>
267
+ <select name="field_options[captcha_theme_<?php echo esc_attr( $field['id'] ) ?>]" id="captcha_theme_<?php echo esc_attr( $field['field_key'] ) ?>">
268
+ <option value="light" <?php selected( $field['captcha_theme'], 'light' ); ?>>
269
+ <?php esc_html_e( 'Light', 'formidable' ) ?>
270
+ </option>
271
+ <option value="dark" <?php selected( $field['captcha_theme'], 'dark' ); ?>>
272
+ <?php esc_html_e( 'Dark', 'formidable' ) ?>
273
+ </option>
274
+ </select>
275
+ </td>
276
+ </tr>
277
+ <?php
278
+ }
279
+
280
+ if ( $display['format'] ) {
281
+ FrmFieldsController::show_format_option( $field );
282
+ }
283
+
284
+ if ( $display['range'] ) {
285
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/number-range.php' );
286
+ } elseif ( $field['type'] == 'html' ) {
287
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/html-content.php' );
288
+ }
289
+
290
+ $field_obj->show_options( $field, $display, $values );
291
+ do_action( 'frm_field_options_form', $field, $display, $values );
292
+
293
+ if ( $display['required'] || $display['invalid'] || $display['unique'] || $display['conf_field'] ) {
294
+ ?>
295
+ <tr class="frm_validation_msg <?php echo ( $display['invalid'] || $field['required'] || FrmField::is_option_true( $field, 'unique' ) || FrmField::is_option_true( $field, 'conf_field' ) ) ? '' : 'frm_hidden'; ?>">
296
+ <td colspan="2">
297
+ <div class="menu-settings">
298
+ <h3 class="frm_no_bg"><?php esc_html_e( 'Validation', 'formidable' ) ?></h3>
299
+
300
+ <div class="frm_validation_box">
301
+ <?php
302
+ if ( $display['required'] ) {
303
+ ?>
304
+ <p class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>"><label><?php esc_html_e( 'Required', 'formidable' ) ?></label>
305
+ <input type="text" name="field_options[blank_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['blank'] ); ?>" />
306
+ </p>
307
+ <?php
308
+ }
309
+
310
+ if ( $display['invalid'] ) {
311
+ $hidden = FrmField::is_field_type( $field, 'text' ) && ! FrmField::is_option_true( $field, 'format' );
312
+ ?>
313
+ <p class="frm_invalid_msg<?php echo esc_attr( $field['id'] . ( $hidden ? ' frm_hidden' : '' ) ); ?>">
314
+ <label><?php esc_html_e( 'Invalid Format', 'formidable' ) ?></label>
315
+ <input type="text" name="field_options[invalid_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['invalid'] ); ?>" />
316
+ </p>
317
+ <?php
318
+ }
319
+
320
+ if ( $display['unique'] ) {
321
+ ?>
322
+ <p class="frm_unique_details<?php echo esc_attr( $field['id'] . ( $field['unique'] ? '' : ' frm_hidden' ) ); ?>">
323
+ <label><?php esc_html_e( 'Unique', 'formidable' ) ?></label>
324
+ <input type="text" name="field_options[unique_msg_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['unique_msg'] ); ?>" />
325
+ </p>
326
+ <?php
327
+ }
328
+
329
+ if ( $display['conf_field'] ) {
330
+ ?>
331
+ <p class="frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
332
+ <label><?php esc_html_e( 'Confirmation', 'formidable' ) ?></label>
333
+ <input type="text" name="field_options[conf_msg_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_msg'] ); ?>" />
334
+ </p>
335
+ <?php
336
+ }
337
+ ?>
338
+ </div>
339
+ </div>
340
+ </td>
341
+ </tr>
342
+ <?php } ?>
343
+
344
+ </table>
345
+ </div>
346
+ </div>
347
+ <?php
348
+ }
349
 
350
  if ( 'divider' === $field['type'] ) {
351
+ ?>
352
  </div>
353
  <div class="frm_no_section_fields">
354
+ <p class="howto"><?php esc_html_e( 'Drag fields from your form or the sidebar into this section', 'formidable' ) ?></p>
 
355
  </div>
356
  <ul class="start_divider frm_sorting">
357
+ <?php
358
  } elseif ( 'end_divider' === $field['type'] ) {
359
+ ?>
360
  </ul>
361
+ <?php
362
  }
363
 
364
  if ( $field['type'] !== 'divider' ) {
365
+ ?>
366
  </li>
367
+ <?php
368
  }
 
 
classes/views/frm-forms/add_field_links.php CHANGED
@@ -1,14 +1,25 @@
1
- <div class="frm-right-panel">
2
- <div class="frm_field_list">
3
- <ul id="frm-nav-tabs" class="frm-nav-tabs">
4
- <li class="frm-tabs">
5
- <a href="#frm-insert-fields" id="frm_insert_fields_tab">
6
- <?php esc_html_e( 'Add Fields', 'formidable' ); ?>
7
- </a>
 
 
 
 
 
 
 
 
 
 
 
8
  </li>
9
  <li class="hide-if-no-js">
10
- <a href="#frm-options-panel" id="frm-options-panel-tab">
11
- <?php esc_html_e( 'Field Options', 'formidable' ); ?>
12
  </a>
13
  </li>
14
  <?php do_action( 'frm_extra_form_instruction_tabs' ); ?>
@@ -16,26 +27,23 @@
16
 
17
  <div id="frm-insert-fields" class="tabs-panel">
18
  <ul class="field_type_list">
19
- <?php
20
- foreach ( $frm_field_selection as $field_key => $field_type ) {
21
- $field_label = FrmFormsHelper::get_field_link_name( $field_type );
22
- ?>
23
- <li class="frmbutton <?php echo esc_attr( ' frm_t' . $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>">
24
- <a href="#" class="frm_add_field frm_animate_bg" title="<?php echo esc_html( $field_label ); ?>">
25
- <i class="<?php echo esc_attr( FrmFormsHelper::get_field_link_icon( $field_type ) ); ?> frm_animate_bg"></i>
26
- <span><?php echo esc_html( $field_label ); ?></span>
27
- </a>
28
- </li>
29
- <?php
30
- unset( $field_key, $field_type );
31
- }
32
- ?>
33
  </ul>
34
  <div class="clear"></div>
35
  <?php FrmTipsHelper::pro_tip( 'get_builder_tip' ); ?>
36
- <h3 class="frm-with-line">
37
- <span><?php esc_html_e( 'Advanced Fields', 'formidable' ); ?></span>
38
- </h3>
39
  <ul class="field_type_list">
40
  <?php
41
 
@@ -43,6 +51,7 @@ $no_allow_class = apply_filters( 'frm_noallow_class', 'frm_noallow' );
43
  if ( $no_allow_class === 'frm_noallow' ) {
44
  $no_allow_class .= ' frm_show_upgrade';
45
  }
 
46
 
47
  foreach ( FrmField::pro_field_selection() as $field_key => $field_type ) {
48
 
@@ -51,120 +60,123 @@ foreach ( FrmField::pro_field_selection() as $field_key => $field_type ) {
51
  }
52
 
53
  if ( is_array( $field_type ) && isset( $field_type['types'] ) ) {
54
- _deprecated_argument( 'Field with sub types', '4.0' );
55
  $field_label = $field_type['name'];
56
 
57
- ?>
58
- <li class="frmbutton <?php echo esc_attr( $no_allow_class . ' frm_t' . $field_key ); ?> dropdown" id="<?php echo esc_attr( $field_key ); ?>">
59
- <a href="#" id="frm-<?php echo esc_attr( $field_key ); ?>Drop" class="frm-dropdown-toggle" data-toggle="dropdown" title="<?php echo esc_html( $field_label ); ?>">
60
- <i class="<?php echo esc_attr( FrmFormsHelper::get_field_link_icon( $field_type ) ); ?> frm_animate_bg"></i>
61
- <span><?php echo esc_html( $field_label ); ?> <b class="caret"></b></span>
62
  </a>
63
 
64
- <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-<?php echo esc_attr( $field_key ); ?>Drop">
65
  <?php foreach ( $field_type['types'] as $k => $type ) { ?>
66
- <li class="frm_t<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>|<?php echo esc_attr( $k ); ?>">
67
  <?php echo FrmAppHelper::kses( apply_filters( 'frmpro_field_links', $type, $id, $field_key . '|' . $k ), array( 'a', 'i', 'span' ) ); // WPCS: XSS ok. ?>
68
  </li>
69
- <?php
70
  unset( $k, $type );
71
  }
72
  ?>
73
  </ul>
74
  </li>
75
- <?php
76
- } else {
77
- $field_label = '<i class="' . esc_attr( FrmFormsHelper::get_field_link_icon( $field_type ) ) . ' frm_animate_bg"></i>';
78
- $field_name = FrmFormsHelper::get_field_link_name( $field_type );
79
- $field_label .= ' <span>' . $field_name . '</span>';
80
-
81
- /* translators: %s: Field name */
82
- $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
83
 
84
- // If the individual field isn't allowed, disable it.
85
- $run_filter = true;
86
- $single_no_allow = ' ';
87
- $install_data = '';
88
- $requires = '';
89
- if ( strpos( $field_type['icon'], ' frm_show_upgrade' ) ) {
90
- $single_no_allow .= 'frm_show_upgrade';
91
- $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
92
- $run_filter = false;
93
- if ( isset( $field_type['addon'] ) ) {
94
- $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
95
- if ( isset( $upgrading['url'] ) ) {
96
- $install_data = json_encode( $upgrading );
97
- }
98
- $requires = FrmFormsHelper::get_plan_required( $upgrading );
99
- }
100
- }
101
- ?>
102
- <li class="frmbutton <?php echo esc_attr( $no_allow_class . $single_no_allow . ' frm_t' . str_replace( '|', '-', $field_key ) ); ?>" id="<?php echo esc_attr( $field_key ); ?>" data-upgrade="<?php echo esc_attr( $upgrade_label ); ?>" data-medium="builder" data-oneclick="<?php echo esc_attr( $install_data ); ?>" data-content="<?php echo esc_attr( $field_key ); ?>" data-requires="<?php echo esc_attr( $requires ); ?>">
103
- <?php
104
- if ( $run_filter ) {
105
- echo FrmAppHelper::kses( apply_filters( 'frmpro_field_links', $field_label, $id, $field_key ), array( 'a', 'i', 'span' ) ); // WPCS: XSS ok.
106
- } else {
107
- echo FrmAppHelper::kses( $field_label, array( 'i', 'span' ) ); // WPCS: XSS ok.
108
- }
109
- ?>
110
  </li>
111
- <?php
112
- }
113
 
114
- unset( $field_key, $field_type, $field_label );
115
- }
116
- ?>
117
  </ul>
118
  <div class="clear"></div>
119
  </div>
120
  <?php do_action( 'frm_extra_form_instructions' ); ?>
121
 
122
- <div id="frm-options-panel" class="tabs-panel frm_hidden">
123
- <div class="frm-single-settings">
124
- <div class="frm-embed-field-placeholder">
125
- <div class="frm-embed-message">
126
- <?php esc_html_e( 'Select a field to see the options', 'formidable' ); ?>
127
- </div>
128
- </div>
129
- </div>
130
- <form method="post" id="new_fields">
131
- <input type="hidden" name="frm_action" value="update" />
132
- <input type="hidden" name="action" value="update" />
133
- <input type="hidden" name="id" id="form_id" value="<?php echo esc_attr( $values['id'] ); ?>" />
134
- <?php wp_nonce_field( 'frm_save_form_nonce', 'frm_save_form' ); ?>
135
- <input type="hidden" id="frm-end-form-marker" name="frm_end" value="1" />
136
-
137
  <?php
138
- FrmFieldsHelper::inline_modal(
139
- array(
140
- 'title' => __( 'Smart Default Values', 'formidable' ),
141
- 'callback' => array( 'FrmFieldsHelper', 'smart_values' ),
142
- 'id' => 'frm-smart-values-box',
143
- )
144
- );
145
-
146
- FrmFieldsHelper::inline_modal(
147
- array(
148
- 'title' => __( 'Add Layout Classes', 'formidable' ),
149
- 'callback' => array( 'FrmFieldsHelper', 'layout_classes' ),
150
- 'id' => 'frm-layout-classes-box',
151
- )
152
- );
153
-
154
- FrmFieldsHelper::inline_modal(
155
- array(
156
- 'title' => __( 'Input Mask Format', 'formidable' ),
157
- 'callback' => array( 'FrmFieldsHelper', 'input_mask' ),
158
- 'id' => 'frm-input-mask-box',
159
- )
160
- );
161
  ?>
162
- </form>
 
 
 
 
 
 
 
 
 
 
163
  </div>
164
  </div>
 
165
 
166
  <form method="post" id="frm_js_build_form">
167
  <input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
168
- <button class="frm_submit_form frm_submit_<?php echo esc_attr( ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_' ); ?>ajax frm_hidden frm_button_submit" type="button" id="frm_submit_side"><?php esc_html_e( 'Update', 'formidable' ); ?></button>
169
  </form>
 
 
 
170
  </div>
1
+ <div id="postbox-container-1" class="postbox-container frm-right-panel">
2
+ <div id="frm_position_ele"></div>
3
+ <div id="frm-fixed" class="frm-mobile-fixed">
4
+ <?php
5
+ $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
6
+ $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
7
+ $button = ( 'new' === $action || 'duplicate' === $action ) ? __( 'Create', 'formidable' ) : __( 'Update', 'formidable' );
8
+
9
+ include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
10
+ ?>
11
+
12
+ <div id="frm_set_height_ele"></div>
13
+ <div id="frm-fixed-panel">
14
+ <div class="frm-ltr frm_field_list">
15
+ <div id="taxonomy-linkcategory" class="categorydiv">
16
+ <ul id="category-tabs" class="category-tabs frm-category-tabs">
17
+ <li class="tabs">
18
+ <a href="#frm-insert-fields" id="frm_insert_fields_tab"><?php esc_html_e( 'Fields', 'formidable' ); ?></a>
19
  </li>
20
  <li class="hide-if-no-js">
21
+ <a href="#frm-layout-classes" id="frm_layout_classes_tab" class="frm_help" title="<?php esc_attr_e( 'Open the Field Settings and click on the CSS Layout Classes option to enable this tab', 'formidable' ) ?>">
22
+ <?php esc_html_e( 'Layout', 'formidable' ); ?>
23
  </a>
24
  </li>
25
  <?php do_action( 'frm_extra_form_instruction_tabs' ); ?>
27
 
28
  <div id="frm-insert-fields" class="tabs-panel">
29
  <ul class="field_type_list">
30
+ <?php
31
+ foreach ( $frm_field_selection as $field_key => $field_type ) {
32
+ $field_label = FrmFormsHelper::get_field_link_name( $field_type );
33
+ ?>
34
+ <li class="frmbutton button <?php echo esc_attr( ' frm_t' . $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>">
35
+ <a href="#" class="frm_add_field frm_animate_bg" title="<?php echo esc_html( $field_label ) ?>">
36
+ <i class="<?php echo esc_attr( FrmFormsHelper::get_field_link_icon( $field_type ) ) ?> frm_animate_bg"></i>
37
+ <span><?php echo esc_html( $field_label ) ?></span>
38
+ </a>
39
+ </li>
40
+ <?php
41
+ unset( $field_key, $field_type );
42
+ }
43
+ ?>
44
  </ul>
45
  <div class="clear"></div>
46
  <?php FrmTipsHelper::pro_tip( 'get_builder_tip' ); ?>
 
 
 
47
  <ul class="field_type_list">
48
  <?php
49
 
51
  if ( $no_allow_class === 'frm_noallow' ) {
52
  $no_allow_class .= ' frm_show_upgrade';
53
  }
54
+ FrmAppController::include_upgrade_overlay();
55
 
56
  foreach ( FrmField::pro_field_selection() as $field_key => $field_type ) {
57
 
60
  }
61
 
62
  if ( is_array( $field_type ) && isset( $field_type['types'] ) ) {
 
63
  $field_label = $field_type['name'];
64
 
65
+ ?>
66
+ <li class="frmbutton button <?php echo esc_attr( $no_allow_class . ' frm_t' . $field_key ) ?> dropdown" id="<?php echo esc_attr( $field_key ) ?>">
67
+ <a href="#" id="frm-<?php echo esc_attr( $field_key ) ?>Drop" class="frm-dropdown-toggle" data-toggle="dropdown" title="<?php echo esc_html( $field_label ) ?>">
68
+ <i class="<?php echo esc_attr( FrmFormsHelper::get_field_link_icon( $field_type ) ) ?> frm_animate_bg"></i>
69
+ <span><?php echo esc_html( $field_label ) ?> <b class="caret"></b></span>
70
  </a>
71
 
72
+ <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-<?php echo esc_attr( $field_key ) ?>Drop">
73
  <?php foreach ( $field_type['types'] as $k => $type ) { ?>
74
+ <li class="frm_t<?php echo esc_attr( $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>|<?php echo esc_attr( $k ) ?>">
75
  <?php echo FrmAppHelper::kses( apply_filters( 'frmpro_field_links', $type, $id, $field_key . '|' . $k ), array( 'a', 'i', 'span' ) ); // WPCS: XSS ok. ?>
76
  </li>
77
+ <?php
78
  unset( $k, $type );
79
  }
80
  ?>
81
  </ul>
82
  </li>
83
+ <?php
84
+ } else {
85
+ $field_label = '<i class="' . esc_attr( FrmFormsHelper::get_field_link_icon( $field_type ) ) . ' frm_animate_bg"></i>';
86
+ $field_name = FrmFormsHelper::get_field_link_name( $field_type );
87
+ $field_label .= ' <span>' . $field_name . '</span>';
88
+ $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
 
 
89
 
90
+ // If the individual field isn't allowed, disable it.
91
+ $run_filter = true;
92
+ $single_no_allow = ' ';
93
+ $install_data = '';
94
+ if ( strpos( $field_type['icon'], ' frm_show_upgrade' ) ) {
95
+ $single_no_allow .= 'frm_show_upgrade';
96
+ $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
97
+ $run_filter = false;
98
+ if ( isset( $field_type['addon'] ) ) {
99
+ $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
100
+ if ( isset( $upgrading['url'] ) ) {
101
+ $install_data = json_encode( $upgrading );
102
+ }
103
+ }
104
+ }
105
+ ?>
106
+ <li class="frmbutton button <?php echo esc_attr( $no_allow_class . $single_no_allow . ' frm_t' . str_replace( '|', '-', $field_key ) ) ?>" id="<?php echo esc_attr( $field_key ) ?>" data-upgrade="<?php echo esc_attr( $upgrade_label ); ?>" data-medium="builder" data-oneclick="<?php echo esc_attr( $install_data ); ?>" data-content="<?php echo esc_attr( $field_key ); ?>">
107
+ <?php
108
+ if ( $run_filter ) {
109
+ echo FrmAppHelper::kses( apply_filters( 'frmpro_field_links', $field_label, $id, $field_key ), array( 'a', 'i', 'span' ) ); // WPCS: XSS ok.
110
+ } else {
111
+ echo FrmAppHelper::kses( $field_label, array( 'i', 'span' ) ); // WPCS: XSS ok.
112
+ }
113
+ ?>
 
 
114
  </li>
115
+ <?php
116
+ }
117
 
118
+ unset( $field_key, $field_type, $field_label );
119
+ }
120
+ ?>
121
  </ul>
122
  <div class="clear"></div>
123
  </div>
124
  <?php do_action( 'frm_extra_form_instructions' ); ?>
125
 
126
+ <div id="frm-layout-classes" class="tabs-panel">
127
+ <ul>
128
+ <li class="frm_show_inactive">
129
+ <?php esc_html_e( 'Click inside the "CSS layout classes" field option in any field to enable the options below.', 'formidable' ); ?>
130
+ </li>
131
+ <li class="frm_show_active frm_hidden">
132
+ <?php esc_html_e( 'Click on any box below to set the width for your selected field.', 'formidable' ); ?>
133
+ </li>
134
+ </ul>
135
+ <ul class="frm_code_list frm_grid_container">
136
+ <li class="frm_half frm_form_field">
137
+ <a href="javascript:void(0);" data-code="frm_half" class="frm_insert_code show_frm_classes">
138
+ 1/2
139
+ </a>
140
+ </li>
141
  <?php
142
+ foreach ( FrmFormsHelper::grid_classes() as $c => $d ) {
143
+ ?>
144
+ <li class="<?php echo esc_attr( $c ) ?> frm_form_field">
145
+ <a href="javascript:void(0);" data-code="<?php echo esc_attr( $c ) ?>" class="frm_insert_code show_frm_classes">
146
+ <?php echo esc_html( FrmFormsHelper::style_class_label( $d, $c ) ); ?>
147
+ </a>
148
+ </li>
149
+ <?php
150
+ unset( $c, $d );
151
+ }
152
+ ?>
153
+ </ul>
154
+ <ul class="frm_code_list">
155
+ <?php
156
+ $col = 'one';
157
+ foreach ( FrmFormsHelper::css_classes() as $c => $d ) {
158
+ $title = ( ! empty( $d ) && is_array( $d ) && isset( $d['title'] ) ) ? $d['title'] : '';
 
 
 
 
 
 
159
  ?>
160
+ <li class="frm_col_<?php echo esc_attr( $col ) ?>">
161
+ <a href="javascript:void(0);" data-code="<?php echo esc_attr( $c ) ?>" class="frmbutton button frm_insert_code show_frm_classes<?php echo esc_attr( ! empty( $title ) ? ' frm_help' : '' ); ?>" <?php echo ( ! empty( $title ) ? ' title="' . esc_attr( $title ) . '"' : '' ); ?>>
162
+ <?php echo esc_html( FrmFormsHelper::style_class_label( $d, $c ) ); ?>
163
+ </a>
164
+ </li>
165
+ <?php
166
+ $col = ( 'one' === $col ) ? 'two' : 'one';
167
+ unset( $c, $d );
168
+ }
169
+ ?>
170
+ </ul>
171
  </div>
172
  </div>
173
+ </div>
174
 
175
  <form method="post" id="frm_js_build_form">
176
  <input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
177
+ <button class="frm_submit_form frm_submit_<?php echo esc_attr( ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_' ); ?>ajax frm_hidden frm_button_submit" type="button" id="frm_submit_side"><?php echo esc_html( $button ); ?></button>
178
  </form>
179
+
180
+ </div>
181
+ </div>
182
  </div>
classes/views/frm-forms/edit.php CHANGED
@@ -1,36 +1,44 @@
1
  <div id="frm_builder_page" class="frm_wrap">
2
- <div class="frm_page_container">
 
 
 
3
 
4
  <?php
5
  FrmAppHelper::get_admin_header(
6
  array(
7
- 'label' => __( 'Build Form', 'formidable' ),
 
8
  'form' => $form,
 
9
  'hide_title' => true,
10
- 'publish' => array( 'FrmFormsController::form_publish_button', compact( 'values' ) ),
11
  )
12
  );
 
 
 
13
  ?>
14
 
15
- <div class="columns-2">
16
- <?php require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field_links.php' ); ?>
17
- <div id="post-body-content">
18
 
19
- <div class="frm_form_builder with_frm_style">
 
 
 
20
 
21
- <p class="frm_hidden frm-no-margin">
22
- <button class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary">
23
- <?php esc_attr_e( 'Update', 'formidable' ); ?>"
24
- </button>
25
- </p>
26
 
27
- <form method="post">
28
- <?php require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/form.php' ); ?>
29
- </form>
30
 
31
- </div>
32
- </div>
33
 
34
- </div>
35
- </div>
 
 
 
36
  </div>
1
  <div id="frm_builder_page" class="frm_wrap">
2
+ <div id="poststuff" class="frm_page_container">
3
+
4
+ <div id="post-body" class="metabox-holder columns-2">
5
+ <div id="post-body-content">
6
 
7
  <?php
8
  FrmAppHelper::get_admin_header(
9
  array(
10
+ 'label' => ( $form->is_template ? __( 'Templates', 'formidable' ) : __( 'Build Form', 'formidable' ) ),
11
+ 'is_template' => $values['is_template'],
12
  'form' => $form,
13
+ 'new_link' => '?page=formidable&frm_action=new',
14
  'hide_title' => true,
 
15
  )
16
  );
17
+
18
+ // Add form messages
19
+ require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
20
  ?>
21
 
22
+ <div class="frm_form_builder with_frm_style">
 
 
23
 
24
+ <p class="frm_hidden frm-no-margin">
25
+ <input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
26
+ <span class="frm-loading-img"></span>
27
+ </p>
28
 
29
+ <form method="post" id="frm_build_form">
30
+ <input type="hidden" name="frm_action" value="update" />
31
+ <input type="hidden" name="action" value="update" />
32
+ <input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
 
33
 
34
+ <?php require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/form.php' ); ?>
 
 
35
 
36
+ </form>
37
+ <?php FrmFormsHelper::builder_submit_button( $values ); ?>
38
 
39
+ </div>
40
+ </div>
41
+ <?php require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field_links.php' ); ?>
42
+ </div>
43
+ </div>
44
  </div>
classes/views/frm-forms/form.php CHANGED
@@ -1,44 +1,50 @@
1
- <div id="frm_form_editor_container">
 
 
2
 
3
- <?php
4
- // Add form messages.
5
- require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
6
- ?>
7
 
8
- <div id="frm-fake-page" class="frm_hidden">
9
- <div class="frm-page-break">
10
- <div class="frm-collapse-page button frm-button-secondary">
11
- <?php
12
- /* translators: %s: The page number */
13
- printf( esc_html__( 'Page %s', 'formidable' ), '<span class="frm-page-num">1</span>' );
14
- ?>
15
- <i class="frm_icon_font frm_arrowdown6_icon"></i>
16
- </div>
17
- </div>
18
  </div>
19
 
20
- <ul id="frm-show-fields" class="frm_sorting inside">
21
- <?php
22
- if ( isset( $values['fields'] ) && ! empty( $values['fields'] ) ) {
23
- $values['count'] = 0;
24
- foreach ( $values['fields'] as $field ) {
25
- $values['count']++;
26
- FrmFieldsController::load_single_field( $field, $values );
27
- unset( $field );
28
- }
29
- }
30
- ?>
31
- </ul>
32
-
33
  <div class="frm_no_fields <?php echo ( isset( $values['fields'] ) && ! empty( $values['fields'] ) ) ? 'frm_hidden' : ''; ?>">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- <div class="frm_drag_inst">
36
- <?php esc_html_e( 'Add Fields Here', 'formidable' ); ?>
37
- </div>
38
- <p>
39
- <?php esc_html_e( 'Click or drag a field from the sidebar to add it to your form', 'formidable' ); ?>
40
- </p>
41
- <div class="clear"></div>
42
- </div>
43
  </div>
44
- <?php FrmFieldsHelper::bulk_options_overlay(); ?>
1
+ <?php wp_nonce_field( 'frm_save_form_nonce', 'frm_save_form' ); ?>
2
+ <input type="hidden" name="status" value="<?php echo esc_attr( $values['status'] ); ?>" />
3
+ <input type="hidden" name="new_status" value="" />
4
 
5
+ <div id="frm_form_editor_container">
 
 
 
6
 
7
+ <div class="postbox">
8
+ <div id="titlediv" class="inside">
9
+ <input type="text" name="name" value="<?php echo esc_attr( $form->name ); ?>" id="title" placeholder="<?php esc_attr_e( 'Enter title here', 'formidable' ); ?>" />
 
 
 
 
 
 
 
10
  </div>
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  <div class="frm_no_fields <?php echo ( isset( $values['fields'] ) && ! empty( $values['fields'] ) ) ? 'frm_hidden' : ''; ?>">
13
+ <div class="alignleft sketch1">
14
+ <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/sketch_arrow1.png' ); ?>" alt="" />
15
+ </div>
16
+ <div class="alignleft sketch1_text">
17
+ <?php esc_html_e( '1. Name your form', 'formidable' ) ?>
18
+ </div>
19
+
20
+ <div class="alignright sketch2">
21
+ <?php esc_html_e( '2. Click or drag a field to add it to your form', 'formidable' ); ?>
22
+ <div class="clear"></div>
23
+ <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/sketch_arrow2.png' ); ?>" alt="" />
24
+ </div>
25
+ <div class="clear"></div>
26
+
27
+ <div class="frm_drag_inst"><?php esc_html_e( 'Add Fields Here', 'formidable' ) ?></div>
28
+
29
+ <div class="alignleft sketch3">
30
+ <div class="alignright"><?php esc_html_e( '3. Save your form', 'formidable' ) ?></div>
31
+ <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/sketch_arrow3.png' ); ?>" alt="" />
32
+ </div>
33
+ <div class="clear"></div>
34
+ </div>
35
+ <ul id="new_fields" class="frm_sorting inside">
36
+ <?php
37
+ if ( isset( $values['fields'] ) && ! empty( $values['fields'] ) ) {
38
+ $values['count'] = 0;
39
+ foreach ( $values['fields'] as $field ) {
40
+ $values['count']++;
41
+ FrmFieldsController::load_single_field( $field, $values );
42
+ unset( $field );
43
+ }
44
+ }
45
+ ?>
46
+ </ul>
47
+ <input type="hidden" name="frm_end" value="1" />
48
+ </div>
49
 
 
 
 
 
 
 
 
 
50
  </div>
 
classes/views/frm-forms/insert_form_popup.php CHANGED
@@ -1,59 +1,50 @@
 
1
  <div id="frm_insert_form" class="frm_hidden hidden">
2
- <div id="frm_popup_content">
3
- <div class="media-modal wp-core-ui">
4
- <a href="#" class="media-modal-close">
5
- <span class="media-modal-icon">
6
- <span class="screen-reader-text"><?php esc_html_e( 'Close panel', 'formidable' ); ?></span>
7
- </span>
8
- </a>
9
-
10
- <div class="media-modal-content">
11
- <div class="media-frame mode-select wp-core-ui hide-router">
12
-
13
- <div id="frm_insert_form_content">
14
-
15
- <div class="media-frame-menu">
16
- <div class="media-menu">
17
- <?php foreach ( $shortcodes as $shortcode => $labels ) { ?>
18
- <a href="#" class="media-menu-item frm_switch_sc" id="sc-link-<?php echo esc_attr( $shortcode ); ?>">
19
- <?php echo esc_html( $labels['name'] ); ?>
20
- <span class="howto"><?php echo esc_html( $labels['label'] ); ?></span>
21
- </a>
22
- <?php } ?>
23
- <div class="clear"></div>
24
- </div>
25
- </div>
26
-
27
- <div class="media-frame-title">
28
- <h1><?php esc_html_e( 'Insert a Form', 'formidable' ); ?>
29
- <span class="spinner"></span>
30
- <span class="frm_icon_font frm_arrowdown4_icon"></span>
31
- </h1>
32
- </div>
33
-
34
- <div class="media-frame-content">
35
- <div class="attachments-browser">
36
- <div id="frm_shortcode_options" class="media-embed">
37
-
38
- </div>
39
- </div>
40
- </div>
41
-
42
- <div class="media-frame-toolbar">
43
- <div class="media-toolbar">
44
- <div class="media-toolbar-secondary">
45
- <input type="text" value="" id="frm_complete_shortcode"/>
46
- </div>
47
- <div class="media-toolbar-primary search-form">
48
- <a href="javascript:void(0);" class="button-primary button media-button-group" id="frm_insert_shortcode">
49
- <?php esc_html_e( 'Insert into Post', 'formidable' ); ?>
50
- </a>
51
- </div>
52
- </div>
53
- </div>
54
- </div>
55
- </div>
56
- </div>
57
- </div>
58
- </div>
1
+
2
  <div id="frm_insert_form" class="frm_hidden hidden">
3
+ <div id="frm_popup_content">
4
+ <div class="media-modal wp-core-ui">
5
+ <a href="#" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text"><?php esc_html_e( 'Close panel', 'formidable' ); ?></span></span></a>
6
+
7
+ <div class="media-modal-content">
8
+ <div class="media-frame mode-select wp-core-ui hide-router">
9
+
10
+ <div id="frm_insert_form_content">
11
+
12
+ <div class="media-frame-menu">
13
+ <div class="media-menu">
14
+ <?php foreach ( $shortcodes as $shortcode => $labels ) { ?>
15
+ <a href="#" class="media-menu-item frm_switch_sc" id="sc-link-<?php echo esc_attr( $shortcode ) ?>">
16
+ <?php echo esc_html( $labels['name'] ) ?>
17
+ <span class="howto"><?php echo esc_html( $labels['label'] ) ?></span>
18
+ </a>
19
+ <?php } ?>
20
+ <div class="clear"></div>
21
+ </div>
22
+ </div>
23
+
24
+ <div class="media-frame-title"><h1><?php esc_html_e( 'Insert