Formidable Forms – Form Builder for WordPress - Version 2.0

Version Description

  • Move visual form styler to free version
  • Added multiple emails to free version
  • Added BCC, CC, and reply to options to emails
  • Replaced the reCaptcha with the new no-captcha recaptcha
  • Allow multiple roles to be selected for the permissions on the global settings page
  • Updated the UI
  • Added a trash can for forms as well as draft forms
  • Extra security with sanitizing output and prepare database queries extra just to be sure
  • Switch to frm_first frm_last frm_half classes for more flexibility
  • Added more responsiveness to the styling classes
  • Change the field width option from characters to pixels
  • Change the user browser info into a more easily readable format, and include it in the lite version
  • Add (hidden) legend tag for accessibility
  • Fix preview page with 2015 theme
  • Reduce duplicate entry check to 1 minute
  • Remove a bunch of upgrade messages in the lite version
  • Reduce size of indexed db columns for utf8mb4 in WordPress 4.2
  • Pro: Added multiple form styling templates, more styling options, and updated the default styling
  • Pro: Added repeatable fields and embedded forms
  • Pro: Created form actions and consolidated notifications and add-ons
  • Pro: All form actions can use conditional logic
  • Pro: Added confirmation fields
  • Pro: Added read-only radio and check box fields
  • Pro: View pagination will automatically take on Genesis theme styling
  • Pro: Entire sections can be moved and duplicated
  • Pro: Add frm_repeat_start_rows filter to allow the form to start with multiple rows in a repeating section
  • Pro: Make the query work for custom code returning a string query on the frm_where_filter hook for reverse compatibility
  • Pro: Escape all quotes in CSV
  • Pro: Don't require dynamic fields with no options
  • Pro: Remove stray div in the calendar view
  • Pro: Remove 'no files selected' text if files are selected
  • Pro: Add decimal option to calculations
  • Pro: Add starts with, ends with, and group by options in View filters
  • Pro: Add IP option to view filters
  • Pro: Added entry ID to view order options
  • Pro: Added hooks: frm_selectable_dates, frm_main_feedback, frm_allowed_times, frm_view_order, frm_csv_headers, frm_map_csv_field
  • Pro: Allow min or max in the graph shortcode to be equal to 0
  • Pro: Keep users on current page when they click "Save Draft"
  • Pro: Add pending for post status options in the post settings
  • Pro: Include JS with form when editing in place
  • Pro: Fix displaying stats accuracy with partial stars
  • Pro: Enqueued scripts right before they are printed for easier integration with more popup plugins
  • Pro: Allow slashes in Phone Number Format option
  • Pro: Allow default templates to be deleted
  • Pro: Reduce the baseline memory load
  • Pro: Load the form styling on view pages when set to only load styling on applicable pages
  • Pro: Change deletelink so it deletes with ajax
  • Pro: Add [user_role] shortcode for current user's role
  • Pro: Add read-only option to Dynamic fields
  • Pro: Add single row and multiple row options to Dynamic Radio and Checkbox fields
  • Pro: Allow arrays in View filters
  • Pro: Allow drafts to be searched with the frm-search form
  • Pro: Fix sql error when searching by Hebrew characters
  • Pro: Allow the use of field keys in the frm-stats shortcode
  • Pro: Force tooltip wrapping in graphs
  • Pro: Improve frm_total class for number fields
  • Lots of other small features, bug fixes, and code cleanup. Too many little features to list!
Download this release

Release Info

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

Code changes from version 1.07.11 to 2.0

Files changed (74) hide show
  1. classes/controllers/FrmAppController.php +340 -371
  2. classes/controllers/FrmEntriesController.php +593 -368
  3. classes/controllers/FrmFieldsController.php +560 -382
  4. classes/controllers/FrmFormActionsController.php +355 -0
  5. classes/controllers/FrmFormsController.php +839 -580
  6. classes/controllers/FrmHooksController.php +200 -0
  7. classes/controllers/FrmSettingsController.php +41 -60
  8. classes/controllers/FrmStatisticsController.php +15 -27
  9. classes/controllers/FrmStylesController.php +434 -0
  10. classes/controllers/FrmXMLController.php +188 -220
  11. classes/helpers/FrmAppHelper.php +1497 -602
  12. classes/helpers/FrmEntriesHelper.php +664 -134
  13. classes/helpers/FrmEntriesListHelper.php +264 -0
  14. classes/helpers/FrmFieldsHelper.php +1001 -333
  15. classes/helpers/FrmFormActionsHelper.php +107 -0
  16. classes/helpers/FrmFormsHelper.php +480 -189
  17. classes/helpers/FrmFormsListHelper.php +370 -0
  18. classes/helpers/FrmListHelper.php +9 -206
  19. classes/helpers/FrmStylesHelper.php +193 -0
  20. classes/helpers/FrmXMLHelper.php +806 -118
  21. classes/models/FrmDb.php +543 -207
  22. classes/models/FrmEntry.php +569 -337
  23. classes/models/FrmEntryMeta.php +258 -180
  24. classes/models/FrmField.php +359 -175
  25. classes/models/FrmForm.php +392 -176
  26. classes/models/FrmFormAction.php +529 -0
  27. classes/models/FrmNotification.php +344 -92
  28. classes/models/FrmSettings.php +186 -94
  29. classes/models/FrmStyle.php +437 -0
  30. classes/recaptchalib.php +0 -274
  31. classes/views/frm-entries/_sidebar-shared-pub.php +21 -0
  32. classes/views/frm-entries/direct.php +7 -11
  33. classes/views/frm-entries/errors.php +42 -31
  34. classes/views/frm-entries/form.php +30 -33
  35. classes/views/frm-entries/frm-entry.php +0 -52
  36. classes/views/frm-entries/list.php +29 -26
  37. classes/views/frm-entries/new.php +8 -8
  38. classes/views/frm-entries/no_entries.php +17 -47
  39. classes/views/frm-entries/show.php +74 -0
  40. classes/views/frm-entries/sidebar-shared.php +84 -0
  41. classes/views/frm-entries/sidebar-show.php +38 -0
  42. classes/views/frm-fields/import_choices.php +30 -58
  43. classes/views/frm-fields/input.php +114 -65
  44. classes/views/frm-fields/radio.php +19 -9
  45. classes/views/frm-fields/show-build.php +64 -0
  46. classes/views/frm-fields/show.php +4 -1
  47. classes/views/frm-fields/single-option.php +11 -15
  48. classes/views/frm-form-actions/_action_inside.php +57 -0
  49. classes/views/frm-form-actions/_email_settings.php +64 -0
  50. classes/views/frm-form-actions/default_actions.php +65 -0
  51. classes/views/frm-form-actions/email_action.php +40 -0
  52. classes/views/frm-form-actions/form_action.php +40 -0
  53. classes/views/frm-forms/_publish_box.php +110 -0
  54. classes/views/frm-forms/add_field.php +252 -233
  55. classes/views/frm-forms/add_field_links.php +150 -104
  56. classes/views/frm-forms/default-templates.php +0 -47
  57. classes/views/frm-forms/edit.php +26 -31
  58. classes/views/frm-forms/form.php +42 -14
  59. classes/views/frm-forms/insert_form_popup.php +46 -66
  60. classes/views/frm-forms/list.php +18 -11
  61. classes/views/frm-forms/mb_html_tab.php +30 -31
  62. classes/views/frm-forms/mb_insert_fields.php +4 -20
  63. classes/views/frm-forms/new-field-js.php +1 -1
  64. classes/views/frm-forms/new-selection.php +0 -56
  65. classes/views/frm-forms/new.php +20 -35
  66. classes/views/frm-forms/notification.php +0 -94
  67. classes/views/frm-forms/settings.php +189 -129
  68. classes/views/frm-forms/shortcode_opts.php +41 -0
  69. classes/views/frm-forms/sidebar-settings.php +9 -31
  70. classes/views/frm-settings/form.php +121 -112
  71. classes/views/frm-settings/license_box.php +6 -6
  72. classes/views/frm-settings/styling_tab.php +0 -4
  73. classes/views/frm-statistics/list.php +11 -9
  74. classes/views/frm-statistics/list_displays.php +8 -7
classes/controllers/FrmAppController.php CHANGED
@@ -1,482 +1,451 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
6
-
7
- if(class_exists('FrmAppController'))
8
- return;
9
-
10
- class FrmAppController{
11
- public static function load_hooks(){
12
- add_action('admin_menu', 'FrmAppController::menu', 1);
13
- add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
14
- add_filter('plugin_action_links_formidable/formidable.php', 'FrmAppController::settings_link', 10, 2 );
15
- add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
16
- add_action('admin_notices', 'FrmAppController::pro_get_started_headline');
17
- add_filter('the_content', 'FrmAppController::page_route', 10);
18
- add_action('plugins_loaded', 'FrmAppController::load_lang');
19
- add_action('init', 'FrmAppController::front_head');
20
- add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
21
- add_action('admin_init', 'FrmAppController::admin_js', 11);
22
- register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::install');
23
- add_action('wp_ajax_frm_install', 'FrmAppController::install');
24
- add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall');
25
- add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize');
26
-
27
- // Used to process standalone requests
28
- add_action('init', 'FrmAppController::parse_standalone_request', 40);
29
- // Update the session data
30
- add_action('init', 'FrmAppController::referer_session', 1);
31
- }
32
-
33
- public static function menu(){
34
- global $frm_vars, $frm_settings;
35
-
36
- if ( current_user_can('administrator') && !current_user_can('frm_view_forms') ) {
37
- global $current_user;
38
- $frm_roles = FrmAppHelper::frm_capabilities();
39
- foreach($frm_roles as $frm_role => $frm_role_description)
40
- $current_user->add_cap( $frm_role );
41
- unset($frm_roles);
42
- unset($frm_role);
43
- unset($frm_role_description);
44
- }
45
-
46
- $count = count(get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ));
47
- $pos = ((int)$count > 0) ? '22.7' : '29.3';
48
- $pos = apply_filters('frm_menu_position', $pos);
49
-
50
- if(current_user_can('frm_view_forms')){
51
- add_menu_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
52
- }else if(current_user_can('frm_view_entries') and $frm_vars['pro_is_installed']){
53
- add_menu_page('Formidable', $frm_settings->menu, 'frm_view_entries', 'formidable', 'FrmProEntriesController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
54
  }
55
-
56
- add_filter('admin_body_class', 'FrmAppController::wp_admin_body_class');
 
 
 
 
 
57
  }
58
-
59
- public static function load_wp_admin_style(){
60
- wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version());
61
  }
62
-
63
- public static function get_form_nav($id, $show_nav=false){
64
  global $pagenow, $frm_vars;
65
-
66
- $show_nav = FrmAppHelper::get_param('show_nav', $show_nav);
67
- if(!$show_nav)
68
  return;
69
-
70
- $current_page = (isset($_GET['page'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None');
71
- if($id and is_numeric($id)){
72
- $frm_form = new FrmForm();
73
- $form = $frm_form->getOne($id);
74
- unset($frm_form);
75
- }else{
76
- $form = false;
77
  }
78
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
80
  }
81
 
82
  // Adds a settings link to the plugins page
83
- public static function settings_link($links, $file){
84
- $settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>';
85
- array_unshift($links, $settings);
86
-
87
  return $links;
88
  }
89
-
90
  public static function update_action_links( $actions, $plugin ) {
91
-
92
- if ( 'formidable/formidable.php' != $plugin )
93
  return $actions;
94
-
95
- global $frm_vars;
96
-
97
- $db_version = get_option('frm_db_version');
98
- $pro_db_version = $frm_vars['pro_is_installed'] ? get_option('frmpro_db_version') : false;
99
-
100
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
101
- ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
102
-
103
- return sprintf( '<a href="%s">%s</a>', add_query_arg(array('upgraded' => 'true'), menu_page_url( 'formidable', 0 )), __( 'Click here to complete the upgrade', 'formidable' ) );
104
-
105
- } else {
106
- return $actions;
107
  }
 
 
108
  }
109
 
110
- public static function pro_get_started_headline(){
111
- if ( isset($_GET['page']) && 'formidable' == $_GET['page'] && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) {
112
  self::install();
113
  ?>
114
- <div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div>
115
  <?php
116
  return;
117
  }
118
-
119
  // Don't display this error as we're upgrading the thing... cmon
120
- if(isset($_GET['action']) and $_GET['action'] == 'upgrade-plugin')
121
  return;
122
-
123
- if ( is_multisite() && !current_user_can('administrator') ) {
 
124
  return;
125
  }
126
-
127
- if(!isset($_GET['activate'])){
128
- global $frm_vars;
129
- $db_version = get_option('frm_db_version');
130
- $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false;
131
- if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
132
- ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
 
 
 
 
 
 
 
 
133
  ?>
134
- <div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or', 'formidable'); ?> <a id="frm_install_link" href="javascript:void(0)"><?php _e('Update Now', 'formidable') ?></a></div>
135
- <script type="text/javascript">
136
- jQuery(document).ready(function($){ $('#frm_install_link').click(frm_install_now); });
137
- function frm_install_now(){
138
- jQuery('#frm_install_message').html('<div style="line-height:24px;"><?php _e("Please wait while your site updates.", "formidable") ?><div class="spinner frm_spinner" style="float:left;display:block;"></div></div>');
139
- jQuery.ajax({
140
- type:"POST",url:ajaxurl,data:"action=frm_install",
141
- success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
142
- });
143
- }
144
- </script>
145
  <?php
146
  }
147
  }
148
-
149
- if ( self::pro_is_authorized() && !self::pro_is_installed()) {
 
 
 
150
  // user is authorized, but running free version
151
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
152
  ?>
153
- <div class="error" style="padding:7px;"><?php echo apply_filters('frm_pro_update_msg', sprintf(__('This site has been previously authorized to run Formidable Pro.<br/>%1$sInstall the pro version%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable'), '<a href="'. $inst_install_url .'" target="_blank">', '</a>', '<a href="javascript:void(0)" onclick="frm_deauthorize_now()" class="frm_deauthorize_link">', '</a>'), $inst_install_url); ?></div>
154
- <script type="text/javascript">
155
- function frm_deauthorize_now(){
156
- if(!confirm("<?php esc_attr_e('Are you sure you want to deauthorize Formidable Pro on this site?', 'formidable') ?>"))
157
- return false;
158
- jQuery('.frm_deauthorize_link').html('<span class="spinner" style="display:inline-block;margin-top:0;float:none;"></span>');
159
- jQuery.ajax({type:'POST',url:ajaxurl,data:'action=frm_deauthorize&nonce='+wp_create_nonce('frm_ajax'),
160
- success:function(msg){jQuery('.error').fadeOut('slow');}
161
- });
162
- return false;
163
- }
164
- </script>
165
- <?php
166
  }
167
  }
168
-
169
- public static function admin_js(){
170
  global $pagenow;
171
-
172
- if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) {
 
173
  return;
174
  }
175
-
176
- wp_enqueue_script('jquery');
177
- wp_enqueue_script('jquery-ui-core');
178
- wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.0.3');
179
-
180
- if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
181
- ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
182
- ) {
183
- $version = FrmAppHelper::plugin_version();
184
- add_filter('admin_body_class', 'FrmAppController::admin_body_class');
185
-
186
- wp_enqueue_script('jquery-ui-sortable');
187
- wp_enqueue_script('jquery-ui-draggable');
188
- wp_enqueue_script('admin-widgets');
189
- wp_enqueue_style('widgets');
190
- wp_enqueue_script('formidable');
191
- wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() .'/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version, true);
192
- self::localize_script('admin');
193
-
194
- wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version);
 
 
 
 
 
 
 
 
 
195
  add_thickbox();
196
-
197
- wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
198
- wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
199
-
200
-
201
- }else if($pagenow == 'post.php' or ($pagenow == 'post-new.php' and isset($_REQUEST['post_type']) and $_REQUEST['post_type'] == 'frm_display')){
202
- if(isset($_REQUEST['post_type'])){
203
- $post_type = $_REQUEST['post_type'];
204
- }else if(isset($_REQUEST['post']) and !empty($_REQUEST['post'])){
205
- $post = get_post($_REQUEST['post']);
206
- if(!$post)
207
  return;
 
208
  $post_type = $post->post_type;
209
- }else{
210
  return;
211
  }
212
-
213
- if($post_type == 'frm_display'){
214
- $version = FrmAppHelper::plugin_version();
215
- wp_enqueue_script('jquery-ui-draggable');
216
- wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version);
217
- wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url(). '/css/frm_admin.css', array(), $version);
218
- self::localize_script('admin');
219
  }
 
 
220
  }
221
  }
222
-
223
- public static function admin_body_class($classes){
224
  global $wp_version;
225
-
226
  //we only need this class on Formidable pages
227
- if(version_compare( $wp_version, '3.4.9', '>'))
228
  $classes .= ' frm_35_trigger';
229
-
 
230
  return $classes;
231
  }
232
-
233
- public static function wp_admin_body_class($classes){
234
  global $wp_version;
235
  //we need this class everywhere in the admin for the menu
236
- if(version_compare( $wp_version, '3.7.2', '>'))
237
  $classes .= ' frm_38_trigger';
238
-
 
239
  return $classes;
240
  }
241
-
242
- public static function load_lang(){
243
- load_plugin_textdomain('formidable', false, 'formidable/languages/' );
244
  }
245
-
246
- public static function front_head(){
247
- global $frm_settings;
248
 
249
- if (is_multisite()){
250
- global $frm_vars;
251
- $old_db_version = get_option('frm_db_version');
252
- $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
254
- ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
255
- self::install($old_db_version);
256
  }
257
  }
258
-
259
  $version = FrmAppHelper::plugin_version();
260
- wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true);
261
- wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true);
262
- wp_register_script('recaptcha-ajax', 'http'. (is_ssl() ? 's' : '').'://www.google.com/recaptcha/api/js/recaptcha_ajax.js', '', true);
263
-
264
- if ( is_admin() && !defined('DOING_AJAX') ) {
265
  // don't load this in back-end
266
  return;
267
  }
268
-
269
- self::localize_script('front');
270
-
271
- wp_enqueue_script('jquery');
272
-
273
- $style = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
274
- if($style){
275
- foreach((array)$style as $k => $file){
276
- wp_register_style($k, $file, array(), $version);
277
  if ( 'all' == $frm_settings->load_style ) {
278
- wp_enqueue_style($k);
279
  }
280
- unset($k, $file);
281
  }
282
  }
283
- unset($style);
284
-
285
- if ( $frm_settings->load_style == 'all' ) {
286
  global $frm_vars;
287
  $frm_vars['css_loaded'] = true;
288
  }
289
  }
290
-
291
- public static function localize_script($location){
 
 
 
292
  wp_localize_script('formidable', 'frm_js', array(
293
  'ajax_url' => admin_url( 'admin-ajax.php' ),
294
  'images_url' => FrmAppHelper::plugin_url() .'/images',
295
- 'loading' => __('Loading&hellip;'),
296
- 'remove' => __('Remove', 'formidable'),
297
- 'offset' => apply_filters('frm_scroll_offset', 4),
 
 
298
  ));
299
-
300
- if($location == 'admin'){
301
- global $frm_settings;
302
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
303
- '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'),
304
- 'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '',
305
- 'desc' => __('(Click here to add a description or instructions)', 'formidable'),
306
- 'blank' => __('(Blank)', 'formidable'),
307
- 'saving' => esc_attr(__('Saving', 'formidable')),
308
- 'saved' => esc_attr(__('Saved', 'formidable')),
309
- 'ok' => __('OK'),
310
- 'cancel' => __('Cancel', 'formidable'),
311
- 'clear_default' => __('Clear default value when typing', 'formidable'),
312
- 'no_clear_default' => __('Do not clear default value when typing', 'formidable'),
313
- 'valid_default' => __('Default value will pass form validation', 'formidable'),
314
- 'no_valid_default' => __('Default value will NOT pass form validation', 'formidable'),
315
- 'deauthorize' => __('Are you sure you want to deactivate Formidable Pro on this site?', 'formidable'),
316
- 'confirm' => __('Are you sure?', 'formidable'),
 
 
 
317
  'default_unique' => $frm_settings->unique_msg,
318
- 'import_complete' => __('Import Complete', 'formidable'),
319
- 'updating' => __('Please wait while your site updates.', 'formidable'),
320
- 'nonce' => wp_create_nonce('frm_ajax'),
321
- ));
 
 
 
 
 
 
322
  }
323
  }
324
-
325
- public static function footer_js($location='footer'){
326
- global $frm_settings, $frm_vars;
327
-
328
- if($frm_vars['load_css'] and (!is_admin() or defined('DOING_AJAX')) and ($frm_settings->load_style != 'none')){
329
- if(isset($frm_vars['css_loaded']) && $frm_vars['css_loaded'])
330
- $css = apply_filters('get_frm_stylesheet', array());
331
- else
332
- $css = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
333
-
334
- if(!empty($css)){
335
- echo "\n".'<script type="text/javascript">';
336
- foreach((array)$css as $css_key => $file){
337
- echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\''. ($css_key + (isset($frm_vars['css_loaded']) ? $frm_vars['css_loaded'] : false)) .'-css\' href=\''. $file. '\' type=\'text/css\' media=\'all\' /%3E"));';
338
- //wp_enqueue_style($css_key);
339
- unset($css_key);
340
- unset($file);
341
- }
342
- unset($css);
343
 
344
- echo '</script>'."\n";
 
 
 
 
 
 
 
 
 
 
 
345
  }
346
  }
347
 
348
- if((!is_admin() or defined('DOING_AJAX')) and $location != 'header' and !empty($frm_vars['forms_loaded'])) //load formidable js
349
- FrmAppHelper::load_scripts(array('formidable'));
 
 
 
350
  }
351
-
352
- public static function install($old_db_version=false){
353
- global $frmdb;
354
- $frmdb->upgrade($old_db_version);
 
 
355
  }
356
-
357
- public static function uninstall(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  check_ajax_referer( 'frm_ajax', 'nonce' );
359
-
360
- if ( current_user_can('administrator') ) {
361
- global $frmdb;
362
  $frmdb->uninstall();
363
  echo true;
364
  } else {
365
- global $frm_settings;
366
- wp_die($frm_settings->admin_permission);
367
  }
368
- die();
369
  }
370
-
 
 
 
 
 
 
 
 
 
371
  // Routes for wordpress pages -- we're just replacing content here folks.
372
- public static function page_route($content){
373
- global $post, $frm_settings;
374
 
375
- if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
 
376
  $content = FrmFormsController::page_preview();
377
  }
378
 
379
  return $content;
380
  }
381
-
382
- public static function referer_session() {
383
- global $frm_settings;
384
-
385
- if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) {
386
- return;
387
- }
388
-
389
- // keep the page history below 100
390
- $max = 100;
391
-
392
- if ( !isset($_SESSION) )
393
- session_start();
394
-
395
- if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) )
396
- $_SESSION['frm_http_pages'] = array("http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
397
-
398
- if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) )
399
- $_SESSION['frm_http_referer'] = array();
400
-
401
- if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) {
402
- if (! isset($_SERVER['HTTP_REFERER'])){
403
- $direct = __('Type-in or bookmark', 'formidable');
404
- if(!in_array($direct, $_SESSION['frm_http_referer']))
405
- $_SESSION['frm_http_referer'][] = $direct;
406
- }else{
407
- $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
408
- }
409
- }
410
-
411
- if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']))
412
- $_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
413
-
414
- //keep the page history below the max
415
- if(count($_SESSION['frm_http_pages']) > $max){
416
- foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
417
- if(count($_SESSION['frm_http_pages']) <= $max)
418
- break;
419
-
420
- unset($_SESSION['frm_http_pages'][$pkey]);
421
- }
422
- }
423
  }
424
 
425
- public static function parse_standalone_request(){
426
- $plugin = FrmAppHelper::get_param('plugin');
427
- $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
428
- $action = FrmAppHelper::get_param($action);
429
- $controller = FrmAppHelper::get_param('controller');
430
-
431
- if( !empty($plugin) and $plugin == 'formidable' and !empty($controller) ){
432
- _deprecated_function( __FUNCTION__, '1.07.02', 'wp_ajax_nopriv()' );
433
-
434
- if($controller == 'forms')
435
- FrmFormsController::preview(FrmAppHelper::get_param('form'));
436
- else
437
- do_action('frm_standalone_route', $controller, $action);
438
-
439
- do_action('frm_ajax_'. $controller .'_'. $action);
440
- die();
441
- }
442
  }
443
-
444
  //formidable shortcode
445
- public static function get_form_shortcode($atts){
446
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
447
- return FrmFormsController::get_form_shortcode($atts);
448
  }
449
 
450
- public static function widget_text_filter_callback( $matches ) {
451
- return do_shortcode( $matches[0] );
452
- }
453
-
454
- public static function update_message($features){
455
- include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
456
- }
457
-
458
- public static function get_postbox_class(){
459
- if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
460
- return 'postbox-container';
461
- else
462
- return 'inner-sidebar';
463
- }
464
-
465
- public static function pro_is_installed(){
466
- return file_exists(FrmAppHelper::plugin_path() . '/pro/formidable-pro.php');
467
- }
468
-
469
- public static function pro_is_authorized(){
470
- return get_site_option('frmpro-authorized');
471
- }
472
-
473
- public static function deauthorize(){
474
- check_ajax_referer( 'frm_ajax', 'nonce' );
475
-
476
- delete_option('frmpro-credentials');
477
- delete_option('frmpro-authorized');
478
- delete_site_option('frmpro-credentials');
479
- delete_site_option('frmpro-authorized');
480
- die();
481
  }
482
  }
1
  <?php
2
+
3
+ class FrmAppController {
4
+
5
+ public static function menu() {
6
+ add_filter( 'plugin_action_links_'. FrmAppHelper::plugin_folder() .'/formidable.php', 'FrmAppController::settings_link' );
7
+ add_filter( 'admin_body_class', 'FrmAppController::wp_admin_body_class' );
8
+
9
+ FrmAppHelper::maybe_add_permissions();
10
+
11
+ if ( ! current_user_can( 'frm_view_forms' ) ) {
12
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
14
+
15
+ $count = count( get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) );
16
+ $pos = ( (int) $count > 0 ) ? '22.7' : '29.3';
17
+ $pos = apply_filters( 'frm_menu_position', $pos );
18
+
19
+ $frm_settings = FrmAppHelper::get_settings();
20
+ add_menu_page( 'Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos );
21
  }
22
+
23
+ public static function load_wp_admin_style() {
24
+ wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version() );
25
  }
26
+
27
+ public static function get_form_nav( $form, $show_nav = '', $title = 'show' ) {
28
  global $pagenow, $frm_vars;
29
+
30
+ $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav );
31
+ if ( empty($show_nav) ) {
32
  return;
 
 
 
 
 
 
 
 
33
  }
34
+
35
+ $current_page = isset( $_GET['page'] ) ? FrmAppHelper::simple_get( 'page', 'sanitize_title' ) : ( isset( $_GET['post_type'] ) ? FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ) : 'None' );
36
+
37
+ if ( $form ) {
38
+ FrmFormsHelper::maybe_get_form( $form );
39
+
40
+ if ( is_object( $form ) ) {
41
+ $id = $form->id;
42
+ }
43
+ }
44
+
45
+ if ( ! isset($id) ) {
46
+ $form = $id = false;
47
+ }
48
+
49
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
50
  }
51
 
52
  // Adds a settings link to the plugins page
53
+ public static function settings_link($links) {
54
+ $settings = '<a href="'. admin_url( 'admin.php?page=formidable-settings' ) .'">' . __( 'Settings', 'formidable' ) . '</a>';
55
+ array_unshift( $links, $settings );
56
+
57
  return $links;
58
  }
59
+
60
  public static function update_action_links( $actions, $plugin ) {
61
+ $frm_plugin = FrmAppHelper::plugin_folder() .'/formidable.php';
62
+ if ( $frm_plugin != $plugin ) {
63
  return $actions;
64
+ }
65
+
66
+ $db_version = get_option( 'frm_db_version' );
67
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
68
+
 
69
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
70
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
71
+
72
+ return '<a href="'. add_query_arg( array( 'upgraded' => 'true' ), menu_page_url( 'formidable', 0 ) ) .'">'. __( 'Click here to complete the upgrade', 'formidable' ) .'</a>';
73
+
 
 
74
  }
75
+
76
+ return $actions;
77
  }
78
 
79
+ public static function pro_get_started_headline() {
80
+ if ( FrmAppHelper::is_admin_page( 'formidable' ) && isset( $_REQUEST['upgraded'] ) && 'true' == sanitize_title( $_REQUEST['upgraded'] ) ) {
81
  self::install();
82
  ?>
83
+ <div id="message" class="frm_message updated"><?php _e( 'Congratulations! Formidable is ready to roll.', 'formidable' ) ?></div>
84
  <?php
85
  return;
86
  }
87
+
88
  // Don't display this error as we're upgrading the thing... cmon
89
+ if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) ) {
90
  return;
91
+ }
92
+
93
+ if ( is_multisite() && ! current_user_can( 'administrator' ) ) {
94
  return;
95
  }
96
+
97
+ if ( ! isset($_GET['activate']) ) {
98
+ $db_version = (int) get_option( 'frm_db_version' );
99
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
100
+ $needs_update = ( ( $db_version < FrmAppHelper::$db_version ) || ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < FrmAppHelper::$pro_db_version ) );
101
+
102
+ if ( $needs_update ) {
103
+ FrmAppHelper::load_admin_wide_js();
104
+
105
+ $message = FrmAppHelper::kses( __( 'Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or %1$s', 'formidable' ), array( 'br' ) );
106
+ $message = sprintf( $message, '<a href="#" id="frm_install_link">' . FrmAppHelper::kses( __( 'Update Now', 'formidable' ) ) . '</a>' );
107
+ if ( FrmAppHelper::$db_version >= 21 && $db_version > 1 && $db_version < 21 ) {
108
+ // if we are moving through #21, show the 2.0 message
109
+ $message .= '<br/> There are a few things you should know about 2.0. <a href="https://formidablepro.com/things-to-know-about-2-0/">Read more</a>';
110
+ }
111
  ?>
112
+ <div class="error" id="frm_install_message"><?php echo $message; ?> </div>
 
 
 
 
 
 
 
 
 
 
113
  <?php
114
  }
115
  }
116
+
117
+ global $frm_vars;
118
+ if ( $frm_vars['pro_is_authorized'] && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) {
119
+ FrmAppHelper::load_admin_wide_js();
120
+
121
  // user is authorized, but running free version
122
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
123
  ?>
124
+ <div class="error" class="frm_previous_install">
125
+ <?php
126
+ echo wp_kses_post( apply_filters( 'frm_pro_update_msg',
127
+ sprintf(
128
+ __( 'This site has been previously authorized to run Formidable Forms.<br/>%1$sInstall the pro version%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
129
+ '<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
130
+ '<a href="#" class="frm_deauthorize_link">', '</a>'
131
+ ), esc_url( $inst_install_url )
132
+ ) ); ?>
133
+ </div>
134
+ <?php
 
 
135
  }
136
  }
137
+
138
+ public static function admin_js() {
139
  global $pagenow;
140
+
141
+ $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
142
+ if ( 'admin-ajax.php' == $pagenow && $action != 'frm_import_choices' ) {
143
  return;
144
  }
145
+ unset( $action );
146
+
147
+ $version = FrmAppHelper::plugin_version();
148
+ FrmAppHelper::load_admin_wide_js( false );
149
+
150
+ wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
151
+ 'formidable_admin_global', 'formidable', 'jquery',
152
+ 'jquery-ui-core', 'jquery-ui-draggable',
153
+ 'jquery-ui-sortable',
154
+ 'bootstrap_tooltip', 'bootstrap-multiselect',
155
+ ), $version, true );
156
+ wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version );
157
+ wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array( 'jquery' ), '3.3.2' );
158
+
159
+ // load multselect js
160
+ wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() .'/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
161
+
162
+ $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
163
+ $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
164
+ if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
165
+ add_filter( 'admin_body_class', 'FrmAppController::admin_body_class' );
166
+
167
+ wp_enqueue_script( 'admin-widgets' );
168
+ wp_enqueue_style( 'widgets' );
169
+ wp_enqueue_script( 'formidable' );
170
+ wp_enqueue_script( 'formidable_admin' );
171
+ self::localize_script( 'admin' );
172
+
173
+ wp_enqueue_style( 'formidable-admin' );
174
  add_thickbox();
175
+
176
+ wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
177
+
178
+ } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
179
+ if ( isset($_REQUEST['post_type']) ) {
180
+ $post_type = sanitize_title( $_REQUEST['post_type'] );
181
+ } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
182
+ $post = get_post( absint( $_REQUEST['post'] ) );
183
+ if ( ! $post ) {
 
 
184
  return;
185
+ }
186
  $post_type = $post->post_type;
187
+ } else {
188
  return;
189
  }
190
+
191
+ if ( $post_type == 'frm_display' ) {
192
+ wp_enqueue_script( 'jquery-ui-draggable' );
193
+ wp_enqueue_script( 'formidable_admin' );
194
+ wp_enqueue_style( 'formidable-admin' );
195
+ self::localize_script( 'admin' );
 
196
  }
197
+ } else if ( $pagenow == 'widgets.php' ) {
198
+ FrmAppHelper::load_admin_wide_js();
199
  }
200
  }
201
+
202
+ public static function admin_body_class( $classes ) {
203
  global $wp_version;
204
+
205
  //we only need this class on Formidable pages
206
+ if ( version_compare( $wp_version, '3.4.9', '>' ) ) {
207
  $classes .= ' frm_35_trigger';
208
+ }
209
+
210
  return $classes;
211
  }
212
+
213
+ public static function wp_admin_body_class( $classes ) {
214
  global $wp_version;
215
  //we need this class everywhere in the admin for the menu
216
+ if ( version_compare( $wp_version, '3.7.2', '>' ) ) {
217
  $classes .= ' frm_38_trigger';
218
+ }
219
+
220
  return $classes;
221
  }
222
+
223
+ public static function load_lang() {
224
+ load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() .'/languages/' );
225
  }
 
 
 
226
 
227
+ /**
228
+ * Filter shortcodes in text widgets
229
+ */
230
+ public static function widget_text_filter( $content ) {
231
+ $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
232
+ return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
233
+ }
234
+
235
+ public static function widget_text_filter_callback( $matches ) {
236
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::widget_text_filter_callback' );
237
+ return FrmAppHelper::widget_text_filter_callback( $matches );
238
+ }
239
+
240
+ public static function front_head() {
241
+ if ( is_multisite() ) {
242
+ $old_db_version = get_option( 'frm_db_version' );
243
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
244
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
245
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
246
+ self::install( $old_db_version );
247
  }
248
  }
249
+
250
  $version = FrmAppHelper::plugin_version();
251
+ wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array( 'jquery' ), $version, true );
252
+ wp_register_script( 'jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array( 'jquery' ), '2.0.7', true );
253
+
254
+ if ( FrmAppHelper::is_admin() ) {
 
255
  // don't load this in back-end
256
  return;
257
  }
258
+
259
+ self::localize_script( 'front' );
260
+
261
+ $frm_settings = FrmAppHelper::get_settings();
262
+
263
+ $style = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
264
+ if ( $style ) {
265
+ foreach ( (array) $style as $k => $file ) {
266
+ wp_register_style( $k, $file, array(), $version );
267
  if ( 'all' == $frm_settings->load_style ) {
268
+ wp_enqueue_style( $k );
269
  }
270
+ unset( $k, $file );
271
  }
272
  }
273
+ unset( $style );
274
+
275
+ if ( $frm_settings->load_style == 'all' ) {
276
  global $frm_vars;
277
  $frm_vars['css_loaded'] = true;
278
  }
279
  }
280
+
281
+ /**
282
+ * @param string $location
283
+ */
284
+ public static function localize_script($location) {
285
  wp_localize_script('formidable', 'frm_js', array(
286
  'ajax_url' => admin_url( 'admin-ajax.php' ),
287
  'images_url' => FrmAppHelper::plugin_url() .'/images',
288
+ 'loading' => __( 'Loading&hellip;' ),
289
+ 'remove' => __( 'Remove', 'formidable' ),
290
+ 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
291
+ 'nonce' => wp_create_nonce( 'frm_ajax' ),
292
+ 'id' => __( 'ID', 'formidable' ),
293
  ));
294
+
295
+ if ( $location == 'admin' ) {
296
+ $frm_settings = FrmAppHelper::get_settings();
297
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
298
+ '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' ),
299
+ 'desc' => __( '(Click to add description)', 'formidable' ),
300
+ 'blank' => __( '(blank)', 'formidable' ),
301
+ 'no_label' => __( '(no label)', 'formidable' ),
302
+ 'saving' => esc_attr( __( 'Saving', 'formidable' ) ),
303
+ 'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
304
+ 'ok' => __( 'OK' ),
305
+ 'cancel' => __( 'Cancel', 'formidable' ),
306
+ 'default' => __( 'Default', 'formidable' ),
307
+ 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
308
+ 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
309
+ 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
310
+ 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
311
+ 'confirm' => __( 'Are you sure?', 'formidable' ),
312
+ 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
313
+ 'conf_delete_sec' => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
314
+ 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
315
  'default_unique' => $frm_settings->unique_msg,
316
+ 'default_conf' => __( 'The entered values do not match', 'formidable' ),
317
+ 'enter_email' => __( 'Enter Email', 'formidable' ),
318
+ 'confirm_email' => __( 'Confirm Email', 'formidable' ),
319
+ 'enter_password' => __( 'Enter Password', 'formidable' ),
320
+ 'confirm_password' => __( 'Confirm Password', 'formidable' ),
321
+ 'import_complete' => __( 'Import Complete', 'formidable' ),
322
+ 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
323
+ 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
324
+ 'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
325
+ ) );
326
  }
327
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
+
330
+ public static function custom_stylesheet() {
331
+ global $frm_vars;
332
+ $css_file = array();
333
+
334
+ if ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) {
335
+ //include css in head
336
+ $uploads = FrmStylesHelper::get_upload_base();
337
+ if ( is_readable( $uploads['basedir'] .'/formidable/css/formidablepro.css' ) ) {
338
+ $css_file['formidable'] = $uploads['baseurl'] .'/formidable/css/formidablepro.css';
339
+ } else {
340
+ $css_file['formidable'] = admin_url( 'admin-ajax.php' ) . '?action=frmpro_css';
341
  }
342
  }
343
 
344
+ if ( isset($frm_vars['datepicker_loaded']) && ! empty($frm_vars['datepicker_loaded']) ) {
345
+ FrmStylesHelper::enqueue_jquery_css();
346
+ }
347
+
348
+ return $css_file;
349
  }
350
+
351
+ public static function load_css() {
352
+ $css = get_transient( 'frmpro_css' );
353
+
354
+ include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
355
+ wp_die();
356
  }
357
+
358
+ public static function footer_js( $location = 'footer' ) {
359
+ global $frm_vars;
360
+
361
+ $frm_settings = FrmAppHelper::get_settings();
362
+ if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
363
+ $css = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
364
+
365
+ if ( ! empty( $css ) ) {
366
+ foreach ( (array) $css as $css_key => $file ) {
367
+ wp_enqueue_style( $css_key );
368
+ unset( $css_key, $file );
369
+ }
370
+ }
371
+ unset( $css );
372
+ }
373
+
374
+ if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
375
+ //load formidable js
376
+ wp_enqueue_script( 'formidable' );
377
+ }
378
+ }
379
+
380
+ public static function activation_install() {
381
+ FrmAppHelper::delete_cache_and_transient( 'frm_plugin_version' );
382
+ FrmFormActionsController::actions_init();
383
+ self::install();
384
+ }
385
+
386
+ public static function install( $old_db_version = false ) {
387
+ $frmdb = new FrmDb();
388
+ $frmdb->upgrade( $old_db_version );
389
+ }
390
+
391
+ public static function uninstall() {
392
  check_ajax_referer( 'frm_ajax', 'nonce' );
393
+
394
+ if ( current_user_can( 'administrator' ) ) {
395
+ $frmdb = new FrmDb();
396
  $frmdb->uninstall();
397
  echo true;
398
  } else {
399
+ $frm_settings = FrmAppHelper::get_settings();
400
+ wp_die( $frm_settings->admin_permission );
401
  }
402
+ wp_die();
403
  }
404
+
405
+ public static function drop_tables($tables) {
406
+ global $wpdb;
407
+ $tables[] = $wpdb->prefix .'frm_fields';
408
+ $tables[] = $wpdb->prefix .'frm_forms';
409
+ $tables[] = $wpdb->prefix .'frm_items';
410
+ $tables[] = $wpdb->prefix .'frm_item_metas';
411
+ return $tables;
412
+ }
413
+
414
  // Routes for wordpress pages -- we're just replacing content here folks.
415
+ public static function page_route($content) {
416
+ global $post;
417
 
418
+ $frm_settings = FrmAppHelper::get_settings();
419
+ if ( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form']) ) {
420
  $content = FrmFormsController::page_preview();
421
  }
422
 
423
  return $content;
424
  }
425
+
426
+ public static function update_message($features) {
427
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
428
+ return FrmAppHelper::update_message( $features );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  }
430
 
431
+ public static function deauthorize() {
432
+ check_ajax_referer( 'frm_ajax', 'nonce' );
433
+
434
+ delete_option( 'frmpro-credentials' );
435
+ delete_option( 'frmpro-authorized' );
436
+ delete_site_option( 'frmpro-credentials' );
437
+ delete_site_option( 'frmpro-authorized' );
438
+ wp_die();
 
 
 
 
 
 
 
 
 
439
  }
440
+
441
  //formidable shortcode
442
+ public static function get_form_shortcode( $atts ) {
443
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
444
+ return FrmFormsController::get_form_shortcode( $atts );
445
  }
446
 
447
+ public static function get_postbox_class() {
448
+ _deprecated_function( __FUNCTION__, '2.0' );
449
+ return 'postbox-container';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  }
451
  }
classes/controllers/FrmEntriesController.php CHANGED
@@ -1,440 +1,665 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
-
6
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
-
8
- if(class_exists('FrmEntriesController'))
9
- return;
10
-
11
- class FrmEntriesController{
12
-
13
- public static function load_hooks(){
14
- add_action('admin_menu', 'FrmEntriesController::menu', 11);
15
- add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
16
- add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
17
- add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
18
- add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
19
- add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
-
22
- public static function menu(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  global $frm_vars;
24
- if(!$frm_vars['pro_is_installed']){
25
- add_submenu_page('formidable', 'Formidable |'. __('Entries', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Entries', 'formidable') .'</span>', 'administrator', 'formidable-entries', 'FrmEntriesController::list_entries');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
-
29
- public static function list_entries(){
30
- global $frm_entry;
31
- $frm_form = new FrmForm();
32
- $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
33
- $form_id = FrmAppHelper::get_param('form', false);
34
- if($form_id)
35
- $form = $frm_form->getOne($form_id);
36
- else
37
- $form = (isset($form_select[0])) ? $form_select[0] : 0;
38
-
39
- if($form)
40
- $entry_count = $frm_entry->getRecordCount($form->id);
41
-
42
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
-
45
- public static function show_form($id='', $key='', $title=false, $description=false){
46
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
47
- return FrmFormsController::show_form($id, $key, $title, $description);
48
  }
49
-
50
- public static function get_form($filename, $form, $title, $description) {
51
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
52
- return FrmFormsController::get_form($form, $title, $description);
53
  }
54
-
55
- public static function process_entry($errors='', $ajax=false){
56
- if((is_admin() and !defined('DOING_AJAX')) or !isset($_POST) or !isset($_POST['form_id']) or !is_numeric($_POST['form_id']) or !isset($_POST['item_key']))
 
57
  return;
 
 
 
58
 
59
- global $frm_entry, $frm_vars;
60
-
61
- $frm_form = new FrmForm();
62
- $form = $frm_form->getOne($_POST['form_id']);
63
- if(!$form)
64
  return;
65
-
66
- $params = FrmEntriesController::get_params($form);
67
-
68
- if(!isset($frm_vars['form_params']))
 
69
  $frm_vars['form_params'] = array();
70
- $frm_vars['form_params'][$form->id] = $params;
71
-
72
- if(isset($frm_vars['created_entries'][$_POST['form_id']]))
 
73
  return;
74
-
75
- if($errors == '')
76
- $errors = $frm_entry->validate($_POST);
77
- $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
78
-
79
- if( empty($errors) ){
 
 
80
  $_POST['frm_skip_cookie'] = 1;
81
- if($params['action'] == 'create'){
82
- if (apply_filters('frm_continue_to_create', true, $_POST['form_id']) and !isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']))
83
- $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = $frm_entry->create( $_POST );
 
84
  }
85
-
86
- do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
87
- unset($_POST['frm_skip_cookie']);
88
  }
89
  }
90
-
91
- public static function delete_entry_before_redirect($url, $form, $atts){
92
- self::_delete_entry($atts['id'], $form);
93
  return $url;
94
  }
95
-
96
  //Delete entry if not redirected
97
- public static function delete_entry_after_save($atts){
98
- self::_delete_entry($atts['entry_id'], $atts['form']);
99
  }
100
-
101
- private static function _delete_entry($entry_id, $form){
102
- if(!$form)
103
  return;
104
-
105
- $form->options = maybe_unserialize($form->options);
106
- if(isset($form->options['no_save']) and $form->options['no_save']){
107
- global $frm_entry;
108
- $frm_entry->destroy( $entry_id );
109
  }
110
  }
111
-
112
- public static function show_entry_shortcode($atts){
113
- $atts = shortcode_atts(array(
114
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
115
  'user_info' => false, 'include_blank' => false, 'default_email' => false,
116
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
117
  'font_size' => '', 'text_color' => '',
118
  'border_width' => '', 'border_color' => '',
119
- 'bg_color' => '', 'alt_bg_color' => '',
120
- ), $atts);
121
- extract($atts);
122
-
123
- if ( $format != 'text' ) {
124
  //format options are text, array, or json
125
- $plain_text = true;
126
- }
127
-
128
- global $frm_entry;
129
-
130
- if ( !$entry || !is_object($entry) ) {
131
- if ( !$id && !$default_email ) {
132
- return '';
133
- }
134
-
135
- if($id)
136
- $entry = $frm_entry->getOne($id, true);
137
- }
138
-
139
- if ( $entry ) {
140
- $form_id = $entry->form_id;
141
- $id = $entry->id;
142
- }
143
-
144
- if ( !$fields || !is_array($fields) ) {
145
- global $frm_field;
146
- $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
147
- }
148
-
149
- $content = ( $format != 'text' ) ? array() : '';
150
- $odd = true;
151
-
152
- if ( !$plain_text ) {
153
- global $frmpro_settings;
154
-
155
- $default_settings = array(
156
- 'border_color' => 'dddddd',
157
- 'bg_color' => 'f7f7f7',
158
- 'text_color' => '444444',
159
- 'font_size' => '12px',
160
- 'border_width' => '1px',
161
- 'alt_bg_color' => 'ffffff',
162
- );
163
-
164
- // merge defaults, global settings, and shortcode options
165
- foreach ( $default_settings as $key => $setting ) {
166
- if ( $atts[$key] != '' ) {
167
- continue;
168
- }
169
-
170
- if ( $frmpro_settings ) {
171
- if ( 'alt_bg_color' == $key ) {
172
- $atts[$key] = $frmpro_settings->bg_color_active;
173
- } else if ( 'border_width' == $key ) {
174
- $atts[$key] = $frmpro_settings->field_border_width;
175
- } else {
176
- $atts[$key] = $frmpro_settings->{$key};
177
- }
178
- } else {
179
- $atts[$key] = $setting;
180
- }
181
- unset($key, $setting);
182
- }
183
-
184
- unset($default_settings);
185
-
186
- $content .= "<table cellspacing='0' style='font-size:{$atts['font_size']};line-height:135%; border-bottom:{$atts['border_width']} solid #{$atts['border_color']};'><tbody>\r\n";
187
- $bg_color = " style='background-color:#{$atts['bg_color']};'";
188
- $bg_color_alt = " style='background-color:#{$atts['alt_bg_color']};'";
189
- $row_style = "style='text-align:". ( $direction == 'rtl' ? 'right' : 'left' ) .";color:#{$atts['text_color']};padding:7px 9px;border-top:{$atts['border_width']} solid #{$atts['border_color']}'";
190
- }
191
-
192
- foreach ( $fields as $f ) {
193
- if ( in_array($f->type, array('divider', 'captcha', 'break', 'html')) )
194
- continue;
195
-
196
- if ( $entry && !isset($entry->metas[$f->id]) ) {
197
- if ( $entry->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
198
- $p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
199
- 'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
200
- 'form_id' => $entry->form_id, 'field' => $f, 'type' => $f->type,
201
- 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
202
- ));
203
- if ( $p_val != '' ) {
204
- $entry->metas[$f->id] = $p_val;
205
- }
206
- }
207
-
208
- if ( !isset($entry->metas[$f->id]) && !$include_blank && !$default_email ) {
209
- continue;
210
- }
211
-
212
- $entry->metas[$f->id] = $default_email ? '['. $f->id .']' : '';
213
- }
214
-
215
- $val = '';
216
- if ( $entry ) {
217
- $prev_val = maybe_unserialize($entry->metas[$f->id]);
218
- $meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
219
-
220
- $val = $default_email ? $prev_val : apply_filters('frm_email_value', $prev_val, (object) $meta, $entry);
221
- } else if ( $default_email ) {
222
- $val = '['. $f->id .']';
223
- }
224
 
225
- if ( $f->type == 'textarea' and !$plain_text ) {
226
- $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val);
227
- }
228
-
229
- //Remove signature from default-message shortcode
230
- if ( $f->type == 'signature' && !$default_email ) {
231
- continue;
232
- }
233
-
234
- if ( is_array($val) && $format == 'text' ) {
235
- $val = implode(', ', $val);
236
- }
237
-
238
- $fname = $default_email ? '['. $f->id .' show=field_label]' : $f->name;
239
-
240
- if ( $format != 'text' ){
241
- $content[$f->field_key] = $val;
242
- } else if ( $plain_text ) {
243
- if ( 'rtl' == $direction ) {
244
- $content .= $val . ' :' . $fname . "\r\n\r\n";
245
- } else {
246
- $content .= $fname . ': ' . $val . "\r\n\r\n";
247
- }
248
- } else {
249
- if (!$default_email){
250
- $content .= '<tr'. ( $odd ? $bg_color : $bg_color_alt ) .'>';
251
- if ( 'rtl' == $direction ) {
252
- $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
253
- } else {
254
- $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
255
- }
256
- $content .= '</tr>'. "\r\n";
257
- $odd = ($odd) ? false : true;
258
- }else{
259
- $content .= '[if '. $f->id .']<tr style="[frm-alt-color]">';
260
- if ( 'rtl' == $direction ) {
261
- $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
262
- } else {
263
- $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
264
- }
265
- $content .= "</tr>\r\n[/if $f->id]";
266
- }
267
-
268
- }
269
-
270
- unset($fname, $f);
271
- }
272
-
273
- if ( $user_info ) {
274
- if ( isset($entry->description) ) {
275
- $data = maybe_unserialize($entry->description);
276
- } else if ( $default_email ) {
277
- $entry->ip = '[ip]';
278
- $data = array(
279
- 'browser' => '[browser]',
280
- 'referrer' => '[referrer]',
281
- );
282
  }
283
- if ( $format != 'text' ) {
284
- $content['ip'] = $entry->ip;
285
- $content['browser'] = $data['browser'];
286
- $content['referrer'] = $data['referrer'];
287
- } else if ( $plain_text ) {
288
- $content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
289
- if ( 'rtl' == $direction ) {
290
- $content .= $entry->ip . ' :'. __('IP Address', 'formidable') ."\r\n";
291
- $content .= $data['browser'] .' :'. __('User-Agent (Browser/OS)', 'formidable') ."\r\n";
292
- $content .= $data['referrer'] .' :'. __('Referrer', 'formidable') ."\r\n";
293
- } else {
294
- $content .= __('IP Address', 'formidable') . ': '. $entry->ip ."\r\n";
295
- $content .= __('User-Agent (Browser/OS)', 'formidable') . ': '. $data['browser']."\r\n";
296
- $content .= __('Referrer', 'formidable') . ': '. $data['referrer']."\r\n";
297
- }
298
- } else {
299
- $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
300
- if ( 'rtl' == $direction ) {
301
- $content .= "<td $row_style>". $entry->ip ."</td><th $row_style>". __('IP Address', 'formidable') . "</th>";
302
- } else {
303
- $content .= "<th $row_style>". __('IP Address', 'formidable') . "</th><td $row_style>". $entry->ip ."</td>";
304
- }
305
- $content .= '</tr>'. "\r\n";
306
- $odd = ($odd) ? false : true;
307
-
308
- if ( isset($data['browser']) ) {
309
- $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
310
- if ( 'rtl' == $direction ) {
311
- $content .= "<td $row_style>". $data['browser']."</td><th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th>";
312
- } else {
313
- $content .= "<th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th><td $row_style>". $data['browser']."</td>";
314
- }
315
- $content .= '</tr>'. "\r\n";
316
- }
317
- $odd = ($odd) ? false : true;
318
-
319
- if ( isset($data['referrer']) ) {
320
- $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
321
- if ( 'rtl' == $direction ) {
322
- $content .= "<td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td><th $row_style>".__('Referrer', 'formidable') . "</th>";
323
- } else {
324
- $content .= "<th $row_style>".__('Referrer', 'formidable') . "</th><td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td>";
325
- }
326
- $content .= '</tr>'. "\r\n";
327
- }
328
  }
329
  }
330
 
331
- if ( ! $plain_text ) {
332
- $content .= '</tbody></table>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  }
334
-
335
- if ( $format == 'json' ) {
336
- $content = json_encode($content);
 
 
 
337
  }
338
-
339
  return $content;
340
  }
341
-
342
- public static function &filter_email_value($value, $meta, $entry, $atts=array()){
343
- $frm_field = new FrmField();
344
- $field = $frm_field->getOne($meta->field_id);
345
- if(!$field)
346
- return $value;
347
-
348
  $value = self::filter_display_value($value, $field, $atts);
349
  return $value;
350
  }
351
-
352
- public static function &filter_display_value($value, $field, $atts=array()){
353
- $field->field_options = maybe_unserialize($field->field_options);
354
-
355
- $saved_value = (isset($atts['saved_value']) and $atts['saved_value']) ? true : false;
356
- if(!in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) or !isset($field->field_options['separate_value']) or !$field->field_options['separate_value'] or $saved_value)
 
 
 
 
 
 
 
 
 
357
  return $value;
358
-
359
- $field->options = maybe_unserialize($field->options);
360
- $f_values = array();
361
- $f_labels = array();
362
- foreach($field->options as $opt_key => $opt){
363
- if(!is_array($opt))
364
  continue;
365
-
366
- $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
367
- $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
368
- if($f_labels[$opt_key] == $f_values[$opt_key]){
369
- unset($f_values[$opt_key]);
370
- unset($f_labels[$opt_key]);
371
  }
372
- unset($opt_key);
373
- unset($opt);
 
 
 
 
 
374
  }
375
 
376
- if(!empty($f_values)){
377
- foreach((array)$value as $v_key => $val){
378
- if(in_array($val, $f_values)){
379
  $opt = array_search($val, $f_values);
380
- if(is_array($value))
381
- $value[$v_key] = $f_labels[$opt];
382
- else
383
- $value = $f_labels[$opt];
 
384
  }
385
- unset($v_key);
386
- unset($val);
387
  }
388
  }
389
-
390
  return $value;
391
  }
392
-
393
- public static function get_params($form=null){
394
  global $frm_vars;
395
-
396
- $frm_form = new FrmForm();
397
- if(!$form)
398
- $form = $frm_form->getAll(array(), 'name', 1);
399
- else if(!is_object($form))
400
- $form = $frm_form->getOne($form);
401
-
402
- if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
403
- return $frm_vars['form_params'][$form->id];
404
-
 
405
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
406
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
407
-
408
  $default_values = array(
409
- 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
410
- 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
411
  );
412
-
 
413
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
414
- if (!is_numeric($values['posted_form_id']))
415
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
 
416
 
417
- if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
418
- foreach ($default_values as $var => $default){
419
- if($var == 'action')
420
- $values[$var] = FrmAppHelper::get_param($action_var, $default);
421
- else
422
- $values[$var] = FrmAppHelper::get_param($var, $default);
423
- unset($var);
424
- unset($default);
 
425
  }
426
- }else{
427
- foreach ($default_values as $var => $default){
428
- $values[$var] = $default;
429
- unset($var);
430
- unset($default);
431
  }
432
  }
433
 
434
- if(in_array($values['action'], array('create', 'update')) and (!isset($_POST) or (!isset($_POST['action']) and !isset($_POST['frm_action']))))
435
  $values['action'] = 'new';
 
436
 
437
  return $values;
438
  }
439
-
 
 
 
 
 
 
 
 
440
  }
1
  <?php
2
+
3
+ class FrmEntriesController {
4
+
5
+ public static function menu() {
6
+ if ( current_user_can( 'administrator' ) && ! current_user_can( 'frm_view_entries' ) ) {
7
+ global $wp_roles;
8
+ $wp_roles->add_cap( 'administrator', 'frm_view_entries' );
9
+ $wp_roles->add_cap( 'administrator', 'frm_delete_entries' );
10
+ }
11
+
12
+ add_submenu_page('formidable', 'Formidable | '. __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
13
+
14
+ if ( ! isset( $_GET['frm_action'] ) || ! in_array( $_GET['frm_action'], array( 'edit', 'show' ) ) ) {
15
+ $frm_settings = FrmAppHelper::get_settings();
16
+ add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' );
17
+ add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' );
18
+ add_filter( 'get_user_option_manage' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' );
19
+ }
20
+ }
21
+
22
+ /* Display in Back End */
23
+ public static function route() {
24
+ $action = FrmAppHelper::get_param('frm_action');
25
+
26
+ switch ( $action ) {
27
+ case 'show':
28
+ case 'destroy':
29
+ case 'destroy_all':
30
+ return self::$action();
31
+
32
+ default:
33
+ do_action( 'frm_entry_action_route', $action );
34
+ if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
35
+ return;
36
+ }
37
+
38
+ return self::display_list();
39
+ }
40
+ }
41
+
42
+ public static function contextual_help($help, $screen_id, $screen) {
43
+ // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
44
+ if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ) {
45
+ return $help;
46
+ }
47
+
48
+ $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
49
+ $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
50
+ if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) {
51
+ return $help;
52
+ }
53
+ unset( $action, $page );
54
+
55
+ $screen->add_help_tab( array(
56
+ 'id' => 'formidable-entries-tab',
57
+ 'title' => __( 'Overview', 'formidable' ),
58
+ 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .'</p> <p>'. esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>',
59
+ ));
60
+
61
+ $screen->set_help_sidebar(
62
+ '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' .
63
+ '<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' .
64
+ '<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>'
65
+ );
66
+
67
+ return $help;
68
+ }
69
+
70
+ public static function manage_columns($columns) {
71
+ global $frm_vars, $wpdb;
72
+ $form_id = FrmEntriesHelper::get_current_form_id();
73
+
74
+ $columns[ $form_id .'_id' ] = 'ID';
75
+ $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
76
+
77
+ if ( ! $form_id ) {
78
+ return $columns;
79
+ }
80
+
81
+ $form_cols = FrmField::get_all_for_form($form_id, '', 'include');
82
+
83
+ foreach ( $form_cols as $form_col ) {
84
+ if ( FrmFieldsHelper::is_no_save_field($form_col->type) ) {
85
+ continue;
86
+ }
87
+
88
+ if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) {
89
+ $sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] );
90
+
91
+ if ( $sub_form_cols ) {
92
+ foreach ( $sub_form_cols as $k => $sub_form_col ) {
93
+ if ( in_array( $sub_form_col->type, FrmFieldsHelper::no_save_fields() ) ) {
94
+ unset( $sub_form_cols[ $k ] );
95
+ continue;
96
+ }
97
+ $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
98
+ unset($sub_form_col);
99
+ }
100
+ }
101
+ unset($sub_form_cols);
102
+ } else {
103
+ $col_id = $form_col->field_key;
104
+ if ( $form_col->form_id != $form_id ) {
105
+ $col_id .= '-_-form'. $form_col->form_id;
106
+ }
107
+
108
+ if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) {
109
+ $columns[ $form_id .'_frmsep_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
110
+ }
111
+ $columns[ $form_id .'_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
112
+ }
113
+ }
114
+
115
+ $columns[ $form_id .'_created_at' ] = __( 'Entry creation date', 'formidable' );
116
+ $columns[ $form_id .'_updated_at' ] = __( 'Entry update date', 'formidable' );
117
+ $columns[ $form_id .'_ip' ] = 'IP';
118
+
119
+ $frm_vars['cols'] = $columns;
120
+
121
+ $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
122
+ if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && ( $action == 'list' || $action == 'destroy' ) ) {
123
+ add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) );
124
+ }
125
+
126
+ return $columns;
127
+ }
128
+
129
+ public static function check_hidden_cols($check, $object_id, $meta_key, $meta_value, $prev_value) {
130
+ $frm_settings = FrmAppHelper::get_settings();
131
+ if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) {
132
+ return $check;
133
+ }
134
+
135
+ if ( empty($prev_value) ) {
136
+ $prev_value = get_metadata('user', $object_id, $meta_key, true);
137
+ }
138
+
139
+ global $frm_vars;
140
+ //add a check so we don't create a loop
141
+ $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
142
+
143
+ return $check;
144
+ }
145
+
146
+ //add hidden columns back from other forms
147
+ public static function update_hidden_cols($meta_id, $object_id, $meta_key, $meta_value ) {
148
+ $frm_settings = FrmAppHelper::get_settings();
149
+
150
+ $sanitized = sanitize_title($frm_settings->menu);
151
+ if ( $meta_key != 'manage'. $sanitized .'_page_formidable-entriescolumnshidden' ) {
152
+ return;
153
+ }
154
+
155
+ global $frm_vars;
156
+ if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
157
+ return; //don't continue if there's no previous value
158
+ }
159
+
160
+ foreach ( $meta_value as $mk => $mv ) {
161
+ //remove blank values
162
+ if ( empty( $mv ) ) {
163
+ unset( $meta_value[ $mk ] );
164
+ }
165
+ }
166
+
167
+ $cur_form_prefix = reset($meta_value);
168
+ $cur_form_prefix = explode('_', $cur_form_prefix);
169
+ $cur_form_prefix = $cur_form_prefix[0];
170
+ $save = false;
171
+
172
+ foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
173
+ if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
174
+ //don't add blank cols or process included cols
175
+ continue;
176
+ }
177
+
178
+ $form_prefix = explode( '_', $prev_hidden );
179
+ $form_prefix = $form_prefix[0];
180
+ if ( $form_prefix == $cur_form_prefix ) {
181
+ //don't add back columns that are meant to be hidden
182
+ continue;
183
+ }
184
+
185
+ $meta_value[] = $prev_hidden;
186
+ $save = true;
187
+ unset($form_prefix);
188
+ }
189
+
190
+ if ( $save ) {
191
+ $user = wp_get_current_user();
192
+ update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true );
193
+ }
194
+ }
195
+
196
+ public static function save_per_page($save, $option, $value) {
197
+ if ( $option == 'formidable_page_formidable_entries_per_page' ) {
198
+ $save = (int) $value;
199
+ }
200
+ return $save;
201
+ }
202
+
203
+ public static function sortable_columns() {
204
+ $form_id = FrmEntriesHelper::get_current_form_id();
205
+
206
+ $fields = FrmField::get_all_for_form( $form_id );
207
+
208
+ $columns = array(
209
+ $form_id .'_id' => 'id',
210
+ $form_id .'_created_at' => 'created_at',
211
+ $form_id .'_updated_at' => 'updated_at',
212
+ $form_id .'_ip' => 'ip',
213
+ $form_id .'_item_key' => 'item_key',
214
+ $form_id .'_is_draft' => 'is_draft',
215
+ );
216
+
217
+ foreach ( $fields as $field ) {
218
+ if ( $field->type != 'checkbox' && ( ! isset($field->field_options['post_field']) || $field->field_options['post_field'] == '' ) ) {
219
+ // Can't sort on checkboxes because they are stored serialized, or post fields
220
+ $columns[ $form_id .'_'. $field->field_key ] = 'meta_'. $field->id;
221
+ }
222
+ }
223
+
224
+ return $columns;
225
  }
226
+
227
+ public static function hidden_columns($result) {
228
+ global $frm_vars;
229
+
230
+ $form_id = FrmEntriesHelper::get_current_form_id();
231
+
232
+ $return = false;
233
+ foreach ( (array) $result as $r ) {
234
+ if ( ! empty( $r ) ) {
235
+ $form_prefix = explode( '_', $r );
236
+ $form_prefix = $form_prefix[0];
237
+
238
+ if ( (int) $form_prefix == (int) $form_id ) {
239
+ $return = true;
240
+ break;
241
+ }
242
+
243
+ unset($form_prefix);
244
+ }
245
+ }
246
+
247
+ if ( $return ) {
248
+ return $result;
249
+ }
250
+
251
+ $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
252
+ $max_columns = 8;
253
+ if ( $i <= $max_columns ) {
254
+ return $result;
255
+ }
256
+
257
  global $frm_vars;
258
+ if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
259
+ $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
260
+ }
261
+
262
+ if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && isset($frm_vars['current_form']->options['hidden_cols']) && ! empty($frm_vars['current_form']->options['hidden_cols']) ) {
263
+ $result = $frm_vars['current_form']->options['hidden_cols'];
264
+ } else {
265
+ $cols = $frm_vars['cols'];
266
+ $cols = array_reverse($cols, true);
267
+
268
+ $result[] = $form_id .'_id';
269
+ $i--;
270
+
271
+ $result[] = $form_id .'_item_key';
272
+ $i--;
273
+
274
+ foreach ( $cols as $col_key => $col ) {
275
+ if ( $i > $max_columns ) {
276
+ $result[] = $col_key;
277
+ }
278
+ //remove some columns by default
279
+ $i--;
280
+ unset($col_key, $col);
281
+ }
282
+ }
283
+
284
+ return $result;
285
+ }
286
+
287
+ public static function display_list( $message = '', $errors = array() ) {
288
+ global $wpdb, $frm_vars;
289
+
290
+ $form = FrmEntriesHelper::get_current_form();
291
+ $params = FrmEntriesHelper::get_admin_params( $form );
292
+
293
+ if ( $form ) {
294
+ $params['form'] = $form->id;
295
+ $frm_vars['current_form'] = $form;
296
+
297
+ if ( 'trash' == $form->status ) {
298
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
299
+ $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
300
+ $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 );
301
+ unset( $time_to_delete, $delete_timestamp );
302
+ }
303
+ }
304
+
305
+ $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
306
+
307
+ $wp_list_table = new $table_class( array( 'params' => $params ) );
308
+
309
+ $pagenum = $wp_list_table->get_pagenum();
310
+
311
+ $wp_list_table->prepare_items();
312
+
313
+ $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
314
+ if ( $pagenum > $total_pages && $total_pages > 0 ) {
315
+ $url = add_query_arg( 'paged', $total_pages );
316
+ if ( headers_sent() ) {
317
+ echo FrmAppHelper::js_redirect($url);
318
+ } else {
319
+ wp_redirect($url);
320
+ }
321
+ die();
322
+ }
323
+
324
+ if ( empty($message) && isset($_GET['import-message']) ) {
325
+ $message = __( 'Your import is complete', 'formidable' );
326
+ }
327
+
328
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
329
+ }
330
+
331
+ /* Back End CRUD */
332
+ public static function show($id = false) {
333
+ FrmAppHelper::permission_check('frm_view_entries');
334
+
335
+ if ( ! $id ) {
336
+ $id = FrmAppHelper::get_param('id');
337
+
338
+ if ( ! $id ) {
339
+ $id = FrmAppHelper::get_param('item_id');
340
+ }
341
  }
342
+
343
+ $entry = FrmEntry::getOne($id, true);
344
+
345
+ $data = maybe_unserialize($entry->description);
346
+ if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
347
+ $data = array( 'referrer' => $data );
348
+ }
349
+
350
+ $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
351
+ $to_emails = array();
352
+
353
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php');
354
+ }
355
+
356
+ public static function destroy() {
357
+ FrmAppHelper::permission_check('frm_delete_entries');
358
+
359
+ $params = FrmEntriesHelper::get_admin_params();
360
+
361
+ if ( isset($params['keep_post']) && $params['keep_post'] ) {
362
+ //unlink entry from post
363
+ global $wpdb;
364
+ $wpdb->update( $wpdb->prefix .'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) );
365
+ }
366
+
367
+ $message = '';
368
+ if ( FrmEntry::destroy( $params['id'] ) ) {
369
+ $message = __( 'Entry was Successfully Destroyed', 'formidable' );
370
+ }
371
+
372
+ self::display_list( $message );
373
  }
374
+
375
+ public static function destroy_all() {
376
+ if ( ! current_user_can( 'frm_delete_entries' ) ) {
377
+ $frm_settings = FrmAppHelper::get_settings();
378
+ wp_die( $frm_settings->admin_permission );
379
+ }
380
+
381
+ global $wpdb;
382
+ $params = FrmEntriesHelper::get_admin_params();
383
+ $message = '';
384
+ $errors = array();
385
+ $form_id = (int) $params['form'];
386
+
387
+ if ( $form_id ) {
388
+ $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
389
+ $action = FrmFormActionsHelper::get_action_for_form( $form_id, 'wppost', 1 );
390
+
391
+ if ( $action ) {
392
+ // this action takes a while, so only trigger it if there are posts to delete
393
+ foreach ( $entry_ids as $entry_id ) {
394
+ do_action( 'frm_before_destroy_entry', $entry_id );
395
+ unset( $entry_id );
396
+ }
397
+ }
398
+
399
+ $wpdb->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) and form_id=%d", $form_id ) );
400
+ $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) );
401
+ if ( $results ) {
402
+ $message = __( 'Entries were Successfully Destroyed', 'formidable' );
403
+ }
404
+ } else {
405
+ $errors = __( 'No entries were specified', 'formidable' );
406
+ }
407
+
408
+ self::display_list( $message, $errors );
409
  }
410
+
411
+ public static function show_form( $id = '', $key = '', $title = false, $description = false ) {
412
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
413
+ return FrmFormsController::show_form( $id, $key, $title, $description );
414
  }
415
+
416
+ public static function get_form( $filename, $form, $title, $description ) {
417
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
418
+ return FrmFormsController::get_form( $form, $title, $description );
419
  }
420
+
421
+ public static function process_entry( $errors = '', $ajax = false ) {
422
+ $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
423
+ if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
424
  return;
425
+ }
426
+
427
+ global $frm_vars;
428
 
429
+ $form = FrmForm::getOne( $form_id );
430
+ if ( ! $form ) {
 
 
 
431
  return;
432
+ }
433
+
434
+ $params = self::get_params( $form );
435
+
436
+ if ( ! isset( $frm_vars['form_params'] ) ) {
437
  $frm_vars['form_params'] = array();
438
+ }
439
+ $frm_vars['form_params'][ $form->id ] = $params;
440
+
441
+ if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
442
  return;
443
+ }
444
+
445
+ if ( $errors == '' ) {
446
+ $errors = FrmEntry::validate( $_POST );
447
+ }
448
+ $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
449
+
450
+ if ( empty( $errors ) ) {
451
  $_POST['frm_skip_cookie'] = 1;
452
+ if ( $params['action'] == 'create' ) {
453
+ if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
454
+ $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
455
+ }
456
  }
457
+
458
+ do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
459
+ unset( $_POST['frm_skip_cookie'] );
460
  }
461
  }
462
+
463
+ public static function delete_entry_before_redirect( $url, $form, $atts ) {
464
+ self::_delete_entry( $atts['id'], $form );
465
  return $url;
466
  }
467
+
468
  //Delete entry if not redirected
469
+ public static function delete_entry_after_save( $atts ) {
470
+ self::_delete_entry( $atts['entry_id'], $atts['form'] );
471
  }
472
+
473
+ private static function _delete_entry( $entry_id, $form ) {
474
+ if ( ! $form ) {
475
  return;
476
+ }
477
+
478
+ $form->options = maybe_unserialize( $form->options );
479
+ if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
480
+ FrmEntry::destroy( $entry_id );
481
  }
482
  }
483
+
484
+ public static function show_entry_shortcode( $atts ) {
485
+ $atts = shortcode_atts( array(
486
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
487
  'user_info' => false, 'include_blank' => false, 'default_email' => false,
488
  'form_id' => false, 'fo