Formidable Forms – Form Builder for WordPress - Version 1.07.11

Version Description

  • Added hook: frm_check_blacklist for disabling the comment blacklist spam check
  • Make nonce id unique per form
  • Make sure there is at least one word before truncation
  • Pro: Check conditional logic when importing dependent data from entries data
  • Pro: Added number field min and max settings to php validation
  • Pro: Added dynamic height to the chosen search field
  • Pro: Allow HTML in the message for the frm-entry-update-field shortcode
  • Pro: Added title parameter to frm-entry-update-field, frm-entry-edit-link, and frm-entry-delete-link
  • Pro: Added end_date parameter to frm-stats shortcode
  • Pro: Added hook: frm_display_value_atts
  • Pro: Added hook: frm_after_duplicate_entry
  • Pro: Added hook: frm_show_it
  • Pro: Add nonce check for importing entries
  • Pro: Fixed display of files with an icon when editing an entry
Download this release

Release Info

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

Code changes from version 2.0rc9 to 1.07.11

Files changed (76) hide show
  1. classes/controllers/FrmAppController.php +370 -331
  2. classes/controllers/FrmEntriesController.php +368 -593
  3. classes/controllers/FrmFieldsController.php +382 -560
  4. classes/controllers/FrmFormActionsController.php +0 -353
  5. classes/controllers/FrmFormsController.php +580 -833
  6. classes/controllers/FrmHooksController.php +0 -200
  7. classes/controllers/FrmSettingsController.php +60 -41
  8. classes/controllers/FrmStatisticsController.php +27 -15
  9. classes/controllers/FrmStylesController.php +0 -434
  10. classes/controllers/FrmXMLController.php +220 -188
  11. classes/helpers/FrmAppHelper.php +602 -1473
  12. classes/helpers/FrmEntriesHelper.php +134 -664
  13. classes/helpers/FrmEntriesListHelper.php +0 -264
  14. classes/helpers/FrmFieldsHelper.php +333 -1001
  15. classes/helpers/FrmFormActionsHelper.php +0 -107
  16. classes/helpers/FrmFormsHelper.php +189 -475
  17. classes/helpers/FrmFormsListHelper.php +0 -370
  18. classes/helpers/FrmListHelper.php +206 -9
  19. classes/helpers/FrmStylesHelper.php +0 -193
  20. classes/helpers/FrmXMLHelper.php +118 -775
  21. classes/models/FrmDb.php +207 -537
  22. classes/models/FrmEntry.php +337 -565
  23. classes/models/FrmEntryMeta.php +180 -253
  24. classes/models/FrmField.php +175 -359
  25. classes/models/FrmForm.php +176 -392
  26. classes/models/FrmFormAction.php +0 -529
  27. classes/models/FrmNotification.php +92 -345
  28. classes/models/FrmSettings.php +94 -186
  29. classes/models/FrmStyle.php +0 -437
  30. classes/recaptchalib.php +274 -0
  31. classes/views/frm-entries/_sidebar-shared-pub.php +0 -21
  32. classes/views/frm-entries/direct.php +11 -7
  33. classes/views/frm-entries/errors.php +31 -42
  34. classes/views/frm-entries/form.php +33 -30
  35. classes/views/frm-entries/frm-entry.php +52 -0
  36. classes/views/frm-entries/list.php +26 -29
  37. classes/views/frm-entries/new.php +8 -8
  38. classes/views/frm-entries/no_entries.php +47 -17
  39. classes/views/frm-entries/show.php +0 -74
  40. classes/views/frm-entries/sidebar-shared.php +0 -84
  41. classes/views/frm-entries/sidebar-show.php +0 -38
  42. classes/views/frm-fields/import_choices.php +58 -30
  43. classes/views/frm-fields/input.php +65 -114
  44. classes/views/frm-fields/radio.php +9 -19
  45. classes/views/frm-fields/show-build.php +0 -64
  46. classes/views/frm-fields/show.php +1 -4
  47. classes/views/frm-fields/single-option.php +15 -11
  48. classes/views/frm-form-actions/_action_inside.php +0 -57
  49. classes/views/frm-form-actions/_email_settings.php +0 -64
  50. classes/views/frm-form-actions/default_actions.php +0 -65
  51. classes/views/frm-form-actions/email_action.php +0 -40
  52. classes/views/frm-form-actions/form_action.php +0 -40
  53. classes/views/frm-forms/_publish_box.php +0 -110
  54. classes/views/frm-forms/add_field.php +233 -252
  55. classes/views/frm-forms/add_field_links.php +104 -150
  56. classes/views/frm-forms/default-templates.php +47 -0
  57. classes/views/frm-forms/edit.php +31 -26
  58. classes/views/frm-forms/form.php +14 -42
  59. classes/views/frm-forms/insert_form_popup.php +66 -46
  60. classes/views/frm-forms/list.php +11 -18
  61. classes/views/frm-forms/mb_html_tab.php +31 -30
  62. classes/views/frm-forms/mb_insert_fields.php +20 -4
  63. classes/views/frm-forms/new-field-js.php +1 -1
  64. classes/views/frm-forms/new-selection.php +56 -0
  65. classes/views/frm-forms/new.php +35 -20
  66. classes/views/frm-forms/notification.php +94 -0
  67. classes/views/frm-forms/settings.php +129 -189
  68. classes/views/frm-forms/shortcode_opts.php +0 -41
  69. classes/views/frm-forms/sidebar-settings.php +31 -9
  70. classes/views/frm-settings/form.php +112 -121
  71. classes/views/frm-settings/license_box.php +6 -6
  72. classes/views/frm-settings/styling_tab.php +4 -0
  73. classes/views/frm-statistics/list.php +9 -11
  74. classes/views/frm-statistics/list_displays.php +8 -10
  75. classes/views/shared/errors.php +4 -16
  76. classes/views/shared/form-nav.php +1 -15
classes/controllers/FrmAppController.php CHANGED
@@ -1,443 +1,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 = get_option( 'frm_db_version' );
99
- $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
 
100
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
101
- ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
102
- FrmAppHelper::load_admin_wide_js();
103
  ?>
104
- <div class="error" id="frm_install_message"><?php echo wp_kses_post( sprintf( __( 'Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or %1$s', 'formidable' ), '<a href="#" id="frm_install_link">'. esc_html( __( 'Update Now', 'formidable' ) ) .'</a>') ); ?> </div>
 
 
 
 
 
 
 
 
 
 
105
  <?php
106
  }
107
  }
108
-
109
- global $frm_vars;
110
- if ( $frm_vars['pro_is_authorized'] && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) {
111
- FrmAppHelper::load_admin_wide_js();
112
-
113
  // user is authorized, but running free version
114
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
115
  ?>
116
- <div class="error" class="frm_previous_install">
117
- <?php
118
- echo wp_kses_post( apply_filters( 'frm_pro_update_msg',
119
- sprintf(
120
- __( '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' ),
121
- '<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
122
- '<a href="#" class="frm_deauthorize_link">', '</a>'
123
- ), esc_url( $inst_install_url )
124
- ) ); ?>
125
- </div>
126
- <?php
 
 
127
  }
128
  }
129
-
130
- public static function admin_js() {
131
  global $pagenow;
132
-
133
- $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
134
- if ( 'admin-ajax.php' == $pagenow && $action != 'frm_import_choices' ) {
135
  return;
136
  }
137
- unset( $action );
138
-
139
- $version = FrmAppHelper::plugin_version();
140
- FrmAppHelper::load_admin_wide_js( false );
141
-
142
- wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
143
- 'formidable_admin_global', 'formidable', 'jquery',
144
- 'jquery-ui-core', 'jquery-ui-draggable',
145
- 'jquery-ui-sortable',
146
- 'bootstrap_tooltip', 'bootstrap-multiselect',
147
- ), $version, true );
148
- wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version );
149
- wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array( 'jquery' ), '3.3.2' );
150
-
151
- // load multselect js
152
- wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() .'/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
153
-
154
- $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
155
- $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
156
- if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
157
- add_filter( 'admin_body_class', 'FrmAppController::admin_body_class' );
158
-
159
- wp_enqueue_script( 'admin-widgets' );
160
- wp_enqueue_style( 'widgets' );
161
- wp_enqueue_script( 'formidable' );
162
- wp_enqueue_script( 'formidable_admin' );
163
- self::localize_script( 'admin' );
164
-
165
- wp_enqueue_style( 'formidable-admin' );
166
  add_thickbox();
167
-
168
- wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
169
-
170
- } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
171
- if ( isset($_REQUEST['post_type']) ) {
172
- $post_type = sanitize_title( $_REQUEST['post_type'] );
173
- } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
174
- $post = get_post( absint( $_REQUEST['post'] ) );
175
- if ( ! $post ) {
 
 
176
  return;
177
- }
178
  $post_type = $post->post_type;
179
- } else {
180
  return;
181
  }
182
-
183
- if ( $post_type == 'frm_display' ) {
184
- wp_enqueue_script( 'jquery-ui-draggable' );
185
- wp_enqueue_script( 'formidable_admin' );
186
- wp_enqueue_style( 'formidable-admin' );
187
- self::localize_script( 'admin' );
 
188
  }
189
- } else if ( $pagenow == 'widgets.php' ) {
190
- FrmAppHelper::load_admin_wide_js();
191
  }
192
  }
193
-
194
- public static function admin_body_class( $classes ) {
195
  global $wp_version;
196
-
197
  //we only need this class on Formidable pages
198
- if ( version_compare( $wp_version, '3.4.9', '>' ) ) {
199
  $classes .= ' frm_35_trigger';
200
- }
201
-
202
  return $classes;
203
  }
204
-
205
- public static function wp_admin_body_class( $classes ) {
206
  global $wp_version;
207
  //we need this class everywhere in the admin for the menu
208
- if ( version_compare( $wp_version, '3.7.2', '>' ) ) {
209
  $classes .= ' frm_38_trigger';
210
- }
211
-
212
  return $classes;
213
  }
214
-
215
- public static function load_lang() {
216
- load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() .'/languages/' );
217
- }
218
-
219
- /**
220
- * Filter shortcodes in text widgets
221
- */
222
- public static function widget_text_filter( $content ) {
223
- $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
224
- return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
225
- }
226
-
227
- public static function widget_text_filter_callback( $matches ) {
228
- _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::widget_text_filter_callback' );
229
- return FrmAppHelper::widget_text_filter_callback( $matches );
230
  }
 
 
 
231
 
232
- public static function front_head() {
233
- if ( is_multisite() ) {
234
- $old_db_version = get_option( 'frm_db_version' );
235
- $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
236
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
237
- ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
238
- self::install( $old_db_version );
239
  }
240
  }
241
-
242
  $version = FrmAppHelper::plugin_version();
243
- wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array( 'jquery' ), $version, true );
244
- wp_register_script( 'jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array( 'jquery' ), '2.0.7', true );
245
-
246
- if ( FrmAppHelper::is_admin() ) {
 
247
  // don't load this in back-end
248
  return;
249
  }
250
-
251
- self::localize_script( 'front' );
252
-
253
- $frm_settings = FrmAppHelper::get_settings();
254
-
255
- $style = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
256
- if ( $style ) {
257
- foreach ( (array) $style as $k => $file ) {
258
- wp_register_style( $k, $file, array(), $version );
259
  if ( 'all' == $frm_settings->load_style ) {
260
- wp_enqueue_style( $k );
261
  }
262
- unset( $k, $file );
263
  }
264
  }
265
- unset( $style );
266
-
267
- if ( $frm_settings->load_style == 'all' ) {
268
  global $frm_vars;
269
  $frm_vars['css_loaded'] = true;
270
  }
271
  }
272
-
273
- /**
274
- * @param string $location
275
- */
276
- public static function localize_script($location) {
277
  wp_localize_script('formidable', 'frm_js', array(
278
  'ajax_url' => admin_url( 'admin-ajax.php' ),
279
  'images_url' => FrmAppHelper::plugin_url() .'/images',
280
- 'loading' => __( 'Loading&hellip;' ),
281
- 'remove' => __( 'Remove', 'formidable' ),
282
- 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
283
- 'nonce' => wp_create_nonce( 'frm_ajax' ),
284
- 'id' => __( 'ID', 'formidable' ),
285
  ));
286
-
287
- if ( $location == 'admin' ) {
288
- $frm_settings = FrmAppHelper::get_settings();
289
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
290
- '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' ),
291
- 'desc' => __( '(Click to add description)', 'formidable' ),
292
- 'blank' => __( '(blank)', 'formidable' ),
293
- 'no_label' => __( '(no label)', 'formidable' ),
294
- 'saving' => esc_attr( __( 'Saving', 'formidable' ) ),
295
- 'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
296
- 'ok' => __( 'OK' ),
297
- 'cancel' => __( 'Cancel', 'formidable' ),
298
- 'default' => __( 'Default', 'formidable' ),
299
- 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
300
- 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
301
- 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
302
- 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
303
- 'confirm' => __( 'Are you sure?', 'formidable' ),
304
- 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
305
- 'conf_delete_sec' => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
306
- 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
307
  'default_unique' => $frm_settings->unique_msg,
308
- 'default_conf' => __( 'The entered values do not match', 'formidable' ),
309
- 'enter_email' => __( 'Enter Email', 'formidable' ),
310
- 'confirm_email' => __( 'Confirm Email', 'formidable' ),
311
- 'enter_password' => __( 'Enter Password', 'formidable' ),
312
- 'confirm_password' => __( 'Confirm Password', 'formidable' ),
313
- 'import_complete' => __( 'Import Complete', 'formidable' ),
314
- 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
315
- 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
316
- 'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
317
- ) );
318
- }
319
- }
320
-
321
-
322
- public static function custom_stylesheet() {
323
- global $frm_vars;
324
- $css_file = array();
325
-
326
- if ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) {
327
- //include css in head
328
- $uploads = FrmStylesHelper::get_upload_base();
329
- if ( is_readable( $uploads['basedir'] .'/formidable/css/formidablepro.css' ) ) {
330
- $css_file['formidable'] = $uploads['baseurl'] .'/formidable/css/formidablepro.css';
331
- } else {
332
- $css_file['formidable'] = admin_url( 'admin-ajax.php' ) . '?action=frmpro_css';
333
- }
334
- }
335
-
336
- if ( isset($frm_vars['datepicker_loaded']) && ! empty($frm_vars['datepicker_loaded']) ) {
337
- FrmStylesHelper::enqueue_jquery_css();
338
  }
339
-
340
- return $css_file;
341
- }
342
-
343
- public static function load_css() {
344
- $css = get_transient( 'frmpro_css' );
345
-
346
- include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
347
- wp_die();
348
  }
349
-
350
- public static function footer_js( $location = 'footer' ) {
351
- global $frm_vars;
352
-
353
- $frm_settings = FrmAppHelper::get_settings();
354
- if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
355
- $css = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
356
-
357
- if ( ! empty( $css ) ) {
358
- foreach ( (array) $css as $css_key => $file ) {
359
- wp_enqueue_style( $css_key );
360
- unset( $css_key, $file );
 
 
 
 
 
361
  }
 
 
 
362
  }
363
- unset( $css );
364
  }
365
 
366
- if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
367
- //load formidable js
368
- wp_enqueue_script( 'formidable' );
369
- }
370
  }
371
-
372
- public static function activation_install() {
373
- FrmAppHelper::delete_cache_and_transient( 'frm_plugin_version' );
374
- FrmFormActionsController::actions_init();
375
- self::install();
376
  }
377
-
378
- public static function install( $old_db_version = false ) {
379
- $frmdb = new FrmDb();
380
- $frmdb->upgrade( $old_db_version );
381
- }
382
-
383
- public static function uninstall() {
384
  check_ajax_referer( 'frm_ajax', 'nonce' );
385
-
386
- if ( current_user_can( 'administrator' ) ) {
387
- $frmdb = new FrmDb();
388
  $frmdb->uninstall();
389
  echo true;
390
  } else {
391
- $frm_settings = FrmAppHelper::get_settings();
392
- wp_die( $frm_settings->admin_permission );
393
  }
394
- wp_die();
395
  }
396
-
397
- public static function drop_tables($tables) {
398
- global $wpdb;
399
- $tables[] = $wpdb->prefix .'frm_fields';
400
- $tables[] = $wpdb->prefix .'frm_forms';
401
- $tables[] = $wpdb->prefix .'frm_items';
402
- $tables[] = $wpdb->prefix .'frm_item_metas';
403
- return $tables;
404
- }
405
-
406
  // Routes for wordpress pages -- we're just replacing content here folks.
407
- public static function page_route($content) {
408
- global $post;
409
 
410
- $frm_settings = FrmAppHelper::get_settings();
411
- if ( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form']) ) {
412
  $content = FrmFormsController::page_preview();
413
  }
414
 
415
  return $content;
416
  }
417
-
418
- public static function update_message($features) {
419
- _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
420
- return FrmAppHelper::update_message( $features );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }
422
 
423
- public static function deauthorize() {
424
- check_ajax_referer( 'frm_ajax', 'nonce' );
425
-
426
- delete_option( 'frmpro-credentials' );
427
- delete_option( 'frmpro-authorized' );
428
- delete_site_option( 'frmpro-credentials' );
429
- delete_site_option( 'frmpro-authorized' );
430
- wp_die();
 
 
 
 
 
 
 
 
 
431
  }
432
-
433
  //formidable shortcode
434
- public static function get_form_shortcode( $atts ) {
435
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
436
- return FrmFormsController::get_form_shortcode( $atts );
437
  }
438
 
439
- public static function get_postbox_class() {
440
- _deprecated_function( __FUNCTION__, '2.0' );
441
- return 'postbox-container';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  }
443
  }
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
  }
classes/controllers/FrmEntriesController.php CHANGED
@@ -1,665 +1,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, 'format' => 'text', 'direction' => 'ltr',
489
  'font_size' => '', 'text_color' => '',
490
  'border_width' => '', 'border_color' => '',
491
- 'bg_color' => '', 'alt_bg_color' => '',
492
- ), $atts );
493
-
494
- if ( $atts['format'] != 'text' ) {
 
495
  //format options are text, array, or json
496
- $atts['plain_text'] = true;
497
- }
498
-
499
- if ( is_object( $atts['entry'] ) && ! isset( $atts['entry']->metas ) ) {
500
- // if the entry does not include metas, force it again
501
- $atts['entry'] = false;
502
- }
503
-
504
- if ( ! $atts['entry'] || ! is_object( $atts['entry'] ) ) {
505
- if ( ! $atts['id'] && ! $atts['default_email'] ) {
506
- return;
507
  }
508
-
509
- if ( $atts['id'] ) {
510
- $atts['entry'] = FrmEntry::getOne( $atts['id'], true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  }
512
- }
513
-
514
- if ( $atts['entry'] ) {
515
- $atts['form_id'] = $atts['entry']->form_id;
516
- $atts['id'] = $atts['entry']->id;
517
- }
518
-
519
- if ( ! $atts['fields'] || ! is_array($atts['fields']) ) {
520
- $atts['fields'] = FrmField::get_all_for_form( $atts['form_id'], '', 'include' );
521
- }
522
 
523
- $values = array();
524
- foreach ( $atts['fields'] as $f ) {
525
- FrmEntriesHelper::fill_entry_values($atts, $f, $values);
526
- unset($f);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
527
  }
528
 
529
- FrmEntriesHelper::fill_entry_user_info($atts, $values);
530
-
531
- if ( $atts['format'] == 'json' ) {
532
- return json_encode($values);
533
- } else if ( $atts['format'] == 'array' ) {
534
- return $values;
535
  }
536
-
537
- $content = array();
538
- FrmEntriesHelper::convert_entry_to_content($values, $atts, $content);
539
-
540
- if ( 'text' == $atts['format'] ) {
541
- $content = implode('', $content);
542
  }
543
-
544
  return $content;
545
  }
546
-
547
- public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) {
548
- $field = FrmField::getOne($meta->field_id);
549
- if ( ! $field ) {
550
- return $value;
551
- }
552
-
553
  $value = self::filter_display_value($value, $field, $atts);
554
  return $value;
555
  }
556
-
557
- public static function &filter_shortcode_value($value, $tag, $atts, $field) {
558
- $plain_text = add_filter('frm_plain_text_email', true);
559
- FrmEntriesHelper::textarea_display_value( $value, $field->type, $plain_text );
560
-
561
- if ( isset($atts['show']) && $atts['show'] == 'value' ) {
562
- return $value;
563
- }
564
-
565
- return self::filter_display_value($value, $field, $atts);
566
- }
567
-
568
- public static function &filter_display_value( $value, $field, $atts = array() ) {
569
- $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false;
570
- if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! isset( $field->field_options['separate_value'] ) || ! $field->field_options['separate_value'] || $saved_value ) {
571
  return $value;
572
- }
573
-
574
- $f_values = $f_labels = array();
575
-
576
- foreach ( $field->options as $opt_key => $opt ) {
577
- if ( ! is_array($opt) ) {
578
  continue;
 
 
 
 
 
 
579
  }
580
-
581
- $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt);
582
- $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ];
583
- if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) {
584
- unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] );
585
- }
586
- unset($opt_key, $opt);
587
  }
588
 
589
- if ( ! empty($f_values) ) {
590
- foreach ( (array) $value as $v_key => $val ) {
591
- if ( in_array($val, $f_values) ) {
592
  $opt = array_search($val, $f_values);
593
- if ( is_array($value) ) {
594
- $value[ $v_key ] = $f_labels[ $opt ];
595
- } else {
596
- $value = $f_labels[ $opt ];
597
- }
598
  }
599
- unset($v_key, $val);
 
600
  }
601
  }
602
-
603
  return $value;
604
  }
605
-
606
- public static function get_params( $form = null ) {
607
  global $frm_vars;
608
-
609
- if ( ! $form ) {
610
- $form = FrmForm::getAll( array(), 'name', 1 );
611
- } else {
612
- FrmFormsHelper::maybe_get_form( $form );
613
- }
614
-
615
- if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
616
- return $frm_vars['form_params'][ $form->id ];
617
- }
618
-
619
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
620
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
621
-
622
  $default_values = array(
623
- 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
624
- 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action,
625
  );
626
-
627
- $values = array();
628
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
629
- if ( ! is_numeric($values['posted_form_id']) ) {
630
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
631
- }
632
 
633
- if ( $form->id == $values['posted_form_id'] ) {
634
- //if there are two forms on the same page, make sure not to submit both
635
- foreach ( $default_values as $var => $default ) {
636
- if ( $var == 'action' ) {
637
- $values[ $var ] = FrmAppHelper::get_param( $action_var, $default );
638
- } else {
639
- $values[ $var ] = FrmAppHelper::get_param( $var, $default );
640
- }
641
- unset( $var, $default );
642
  }
643
- } else {
644
- foreach ( $default_values as $var => $default ) {
645
- $values[ $var ] = $default;
646
- unset( $var, $default );
 
647
  }
648
  }
649
 
650
- if ( in_array( $values['action'], array( 'create', 'update' ) ) && ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) ) {
651
  $values['action'] = 'new';
652
- }
653
 
654
  return $values;
655
  }
656
-
657
- public static function entry_sidebar($entry) {
658
- $data = maybe_unserialize($entry->description);
659
- $date_format = get_option('date_format');
660
- $time_format = get_option('time_format');
661
-
662
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php');
663
- }
664
-
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