Formidable Forms – Form Builder for WordPress - Version 2.0b8

Version Description

Download this release

Release Info

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

Code changes from version 1.07.10 to 2.0b8

Files changed (101) hide show
  1. .gitignore +1 -0
  2. classes/controllers/FrmAppController.php +250 -244
  3. classes/controllers/FrmEntriesController.php +515 -318
  4. classes/controllers/FrmFieldsController.php +453 -294
  5. classes/controllers/FrmFormActionsController.php +343 -0
  6. classes/controllers/FrmFormsController.php +671 -450
  7. classes/controllers/FrmHooksController.php +209 -0
  8. classes/controllers/FrmSettingsController.php +19 -40
  9. classes/controllers/FrmStatisticsController.php +4 -16
  10. classes/controllers/FrmStylesController.php +395 -0
  11. classes/controllers/FrmXMLController.php +148 -174
  12. classes/helpers/FrmAppHelper.php +1191 -399
  13. classes/helpers/FrmEntriesHelper.php +562 -115
  14. classes/helpers/FrmEntriesListHelper.php +255 -0
  15. classes/helpers/FrmFieldsHelper.php +748 -256
  16. classes/helpers/FrmFormActionsHelper.php +106 -0
  17. classes/helpers/FrmFormsHelper.php +367 -122
  18. classes/helpers/FrmFormsListHelper.php +331 -0
  19. classes/helpers/FrmListHelper.php +2 -202
  20. classes/helpers/FrmStylesHelper.php +192 -0
  21. classes/helpers/FrmXMLHelper.php +389 -92
  22. classes/models/FrmDb.php +483 -177
  23. classes/models/FrmEntry.php +511 -318
  24. classes/models/FrmEntryMeta.php +201 -159
  25. classes/models/FrmField.php +257 -133
  26. classes/models/FrmForm.php +356 -150
  27. classes/models/FrmFormAction.php +522 -0
  28. classes/models/FrmNotification.php +275 -91
  29. classes/models/FrmSettings.php +174 -80
  30. classes/models/FrmStyle.php +418 -0
  31. classes/recaptchalib.php +0 -274
  32. classes/views/frm-entries/_sidebar-shared-pub.php +21 -0
  33. classes/views/frm-entries/direct.php +6 -7
  34. classes/views/frm-entries/errors.php +37 -26
  35. classes/views/frm-entries/form.php +22 -27
  36. classes/views/frm-entries/frm-entry.php +0 -52
  37. classes/views/frm-entries/list.php +29 -26
  38. classes/views/frm-entries/new.php +7 -7
  39. classes/views/frm-entries/no_entries.php +16 -46
  40. classes/views/frm-entries/show.php +83 -0
  41. classes/views/frm-entries/sidebar-show.php +36 -0
  42. classes/views/frm-fields/import_choices.php +22 -15
  43. classes/views/frm-fields/input.php +115 -45
  44. classes/views/frm-fields/radio.php +23 -9
  45. classes/views/frm-fields/show-build.php +67 -0
  46. classes/views/frm-fields/show.php +4 -1
  47. classes/views/frm-fields/single-option.php +11 -14
  48. classes/views/frm-form-actions/_action_inside.php +53 -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 +170 -175
  55. classes/views/frm-forms/add_field_links.php +101 -63
  56. classes/views/frm-forms/default-templates.php +0 -47
  57. classes/views/frm-forms/edit.php +18 -29
  58. classes/views/frm-forms/form.php +28 -9
  59. classes/views/frm-forms/insert_form_popup.php +143 -59
  60. classes/views/frm-forms/list.php +9 -6
  61. classes/views/frm-forms/mb_html_tab.php +12 -13
  62. classes/views/frm-forms/mb_insert_fields.php +2 -19
  63. classes/views/frm-forms/new-field-js.php +1 -1
  64. classes/views/frm-forms/new-selection.php +10 -10
  65. classes/views/frm-forms/new.php +18 -33
  66. classes/views/frm-forms/notification.php +0 -94
  67. classes/views/frm-forms/settings.php +148 -109
  68. classes/views/frm-forms/sidebar-settings.php +9 -31
  69. classes/views/frm-settings/form.php +58 -68
  70. classes/views/frm-settings/license_box.php +2 -2
  71. classes/views/frm-settings/styling_tab.php +0 -4
  72. classes/views/frm-statistics/list.php +6 -4
  73. classes/views/frm-statistics/list_displays.php +5 -3
  74. classes/views/shared/errors.php +16 -4
  75. classes/views/shared/form-nav.php +26 -6
  76. classes/views/shared/head.php +5 -5
  77. classes/views/shared/mb_adv_info.php +262 -0
  78. classes/views/shared/nav.php +0 -1
  79. classes/views/shared/update_message.php +1 -1
  80. classes/views/styles/_buttons.php +134 -0
  81. classes/views/styles/_check-box-radio-fields.php +33 -0
  82. classes/views/styles/_date-fields.php +40 -0
  83. classes/views/styles/_field-colors.php +114 -0
  84. classes/views/styles/_field-description.php +31 -0
  85. classes/views/styles/_field-labels.php +57 -0
  86. classes/views/styles/_field-sizes.php +35 -0
  87. classes/views/styles/_form-messages.php +59 -0
  88. classes/views/styles/_general.php +74 -0
  89. classes/views/styles/_sample_form.php +100 -0
  90. classes/views/styles/_section-fields.php +113 -0
  91. classes/views/styles/custom_css.php +32 -0
  92. classes/views/styles/manage.php +59 -0
  93. classes/views/styles/show.php +110 -0
  94. classes/views/xml/default-templates.xml +0 -0
  95. classes/views/xml/forms_xml.php +5 -6
  96. classes/views/xml/import_form.php +15 -15
  97. classes/views/xml/posts_xml.php +81 -0
  98. classes/views/xml/xml.php +7 -8
  99. classes/widgets/FrmShowForm.php +35 -25
  100. css/_single_theme.css.php +786 -0
  101. css/codemirror.css +136 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
1
+ .DS_Store
classes/controllers/FrmAppController.php CHANGED
@@ -1,152 +1,121 @@
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
  ?>
@@ -162,55 +131,58 @@ success:function(msg){jQuery('.error').fadeOut('slow');}
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);
@@ -219,60 +191,68 @@ return false;
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);
@@ -281,13 +261,13 @@ return false;
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' ),
@@ -295,15 +275,17 @@ return false;
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'),
@@ -314,30 +296,64 @@ return false;
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
 
@@ -345,138 +361,128 @@ return false;
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'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None');
36
+ if ( $form ) {
37
+ FrmFormsHelper::maybe_get_form( $form );
38
+
39
+ if ( is_object($form) ) {
40
+ $id = $form->id;
41
+ }
42
+ }
43
+
44
+ if ( !isset($id) ) {
45
+ $form = $id = false;
46
  }
47
+
48
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
49
  }
50
 
51
  // Adds a settings link to the plugins page
52
+ public static function settings_link($links){
53
  $settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>';
54
  array_unshift($links, $settings);
55
+
56
  return $links;
57
  }
58
+
59
  public static function update_action_links( $actions, $plugin ) {
60
+
61
+ if ( FrmAppHelper::plugin_folder() .'/formidable.php' != $plugin )
62
  return $actions;
63
+
 
 
64
  $db_version = get_option('frm_db_version');
65
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option('frmpro_db_version') : false;
66
+
67
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
68
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
69
+
70
+ return '<a href="'. add_query_arg(array('upgraded' => 'true'), menu_page_url( 'formidable', 0 )) .'">'. __( 'Click here to complete the upgrade', 'formidable' ) .'</a>';
71
+
 
 
72
  }
73
+
74
+ return $actions;
75
  }
76
 
77
  public static function pro_get_started_headline(){
78
+ if ( FrmAppHelper::is_admin_page('formidable') && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) {
79
  self::install();
80
  ?>
81
  <div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div>
82
  <?php
83
  return;
84
  }
85
+
86
  // Don't display this error as we're upgrading the thing... cmon
87
+ if ( isset($_GET['action']) && 'upgrade-plugin' == $_GET['action'] ) {
88
  return;
89
+ }
90
+
91
  if ( is_multisite() && !current_user_can('administrator') ) {
92
  return;
93
  }
94
+
95
+ if ( ! isset($_GET['activate']) ) {
 
96
  $db_version = get_option('frm_db_version');
97
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option('frmpro_db_version') : false;
98
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
99
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
100
  ?>
101
+ <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 href="javascript:void(0)" id="frm_install_link"><?php _e('Update Now', 'formidable') ?></a></div>
102
  <script type="text/javascript">
103
+ jQuery(document).ready(function($){ $(document.getElementById('frm_install_link')).click(frm_install_now); });
104
  function frm_install_now(){
105
+ var $msg = jQuery(document.getElementById('frm_install_message'));
106
+ $msg.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>');
107
  jQuery.ajax({
108
  type:"POST",url:ajaxurl,data:"action=frm_install",
109
+ success:function(){$msg.fadeOut('slow');}
110
  });
111
  }
112
  </script>
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
  // user is authorized, but running free version
120
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
121
  ?>
131
  return false;
132
  }
133
  </script>
134
+ <?php
135
  }
136
  }
137
+
138
  public static function admin_js(){
139
  global $pagenow;
140
+
141
  if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) {
142
  return;
143
  }
144
+
145
+ wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.2.0');
146
+
 
 
147
  if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
148
  ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
149
  ) {
150
  $version = FrmAppHelper::plugin_version();
151
+ add_filter('admin_body_class', 'FrmAppController::admin_body_class' );
152
+
153
  wp_enqueue_script('jquery-ui-sortable');
154
  wp_enqueue_script('jquery-ui-draggable');
155
  wp_enqueue_script('admin-widgets');
156
  wp_enqueue_style('widgets');
157
  wp_enqueue_script('formidable');
158
+ wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() .'/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version, true);
159
  self::localize_script('admin');
160
+
161
  wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version);
162
  add_thickbox();
163
+
164
  wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
165
  wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
166
+
167
+ if ( FrmAppHelper::is_admin_page('formidable-settings') || FrmAppHelper::is_admin_page('formidable-styles') ) {
168
+ // load multselect js
169
+ wp_enqueue_script('bootstrap-multiselect', FrmAppHelper::plugin_url() .'/js/bootstrap-multiselect.js', array('jquery', 'bootstrap_tooltip'), '0.9.8', true);
170
+ }
171
+
172
+ } else if ( $pagenow == 'post.php' || ($pagenow == 'post-new.php' && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'frm_display') ) {
173
+ if ( isset($_REQUEST['post_type']) ) {
174
  $post_type = $_REQUEST['post_type'];
175
+ } else if ( isset($_REQUEST['post']) && !empty($_REQUEST['post']) ) {
176
  $post = get_post($_REQUEST['post']);
177
+ if ( !$post ) {
178
  return;
179
+ }
180
  $post_type = $post->post_type;
181
+ } else {
182
  return;
183
  }
184
+
185
+ if ( $post_type == 'frm_display' ) {
186
  $version = FrmAppHelper::plugin_version();
187
  wp_enqueue_script('jquery-ui-draggable');
188
  wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version);
191
  }
192
  }
193
  }
194
+
195
  public static function admin_body_class($classes){
196
  global $wp_version;
197
+
198
  //we only need this class on Formidable pages
199
+ if ( version_compare( $wp_version, '3.4.9', '>') ) {
200
  $classes .= ' frm_35_trigger';
201
+ }
202
+
203
  return $classes;
204
  }
205
+
206
  public static function wp_admin_body_class($classes){
207
  global $wp_version;
208
  //we need this class everywhere in the admin for the menu
209
+ if ( version_compare( $wp_version, '3.7.2', '>') ) {
210
  $classes .= ' frm_38_trigger';
211
+ }
212
+
213
  return $classes;
214
  }
215
+
216
  public static function load_lang(){
217
+ load_plugin_textdomain('formidable', false, FrmAppHelper::plugin_folder() .'/languages/' );
218
+ }
219
+
220
+ /*
221
+ * Filter shortcodes in text widgets
222
+ */
223
+ public static function widget_text_filter( $content ) {
224
+ $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
225
+ return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
226
  }
 
 
 
227
 
228
+ public static function front_head(){
229
  if (is_multisite()){
 
230
  $old_db_version = get_option('frm_db_version');
231
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option('frmpro_db_version') : false;
232
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
233
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
234
  self::install($old_db_version);
235
  }
236
  }
237
+
238
  $version = FrmAppHelper::plugin_version();
239
  wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true);
240
  wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true);
241
+
242
+ if ( FrmAppHelper::is_admin() ) {
 
243
  // don't load this in back-end
244
  return;
245
  }
246
+
247
  self::localize_script('front');
248
+
249
  wp_enqueue_script('jquery');
250
+
251
+ $frm_settings = FrmAppHelper::get_settings();
252
+
253
+ $style = apply_filters('get_frm_stylesheet', array());
254
  if($style){
255
+ foreach ( (array) $style as $k => $file ) {
256
  wp_register_style($k, $file, array(), $version);
257
  if ( 'all' == $frm_settings->load_style ) {
258
  wp_enqueue_style($k);
261
  }
262
  }
263
  unset($style);
264
+
265
+ if ( $frm_settings->load_style == 'all' ) {
266
  global $frm_vars;
267
  $frm_vars['css_loaded'] = true;
268
  }
269
  }
270
+
271
  public static function localize_script($location){
272
  wp_localize_script('formidable', 'frm_js', array(
273
  'ajax_url' => admin_url( 'admin-ajax.php' ),
275
  'loading' => __('Loading&hellip;'),
276
  'remove' => __('Remove', 'formidable'),
277
  'offset' => apply_filters('frm_scroll_offset', 4),
278
+ 'nonce' => wp_create_nonce('frm_form'),
279
  ));
280
+
281
  if($location == 'admin'){
282
+ $frm_settings = FrmAppHelper::get_settings();
283
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
284
  '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'),
285
  'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '',
286
+ 'desc' => __('(Click to add description)', 'formidable'),
287
+ 'blank' => __('(blank)', 'formidable'),
288
+ 'no_label' => __('(no label)', 'formidable'),
289
  'saving' => esc_attr(__('Saving', 'formidable')),
290
  'saved' => esc_attr(__('Saved', 'formidable')),
291
  'ok' => __('OK'),
296
  'no_valid_default' => __('Default value will NOT pass form validation', 'formidable'),
297
  'deauthorize' => __('Are you sure you want to deactivate Formidable Pro on this site?', 'formidable'),
298
  'confirm' => __('Are you sure?', 'formidable'),
299
+ 'conf_delete' => __('Are you sure you want to delete this field and all data associated with it?', 'formidable'),
300
+ 'conf_delete_sec' => __('WARNING: This will delete all fields inside of the section as well.', 'formidable'),
301
  'default_unique' => $frm_settings->unique_msg,
302
+ 'default_conf' => __('The entered values do not match', 'formidable'),
303
+ 'enter_email' => __('Enter Email', 'formidable'),
304
+ 'confirm_email' => __('Confirm Email', 'formidable'),
305
+ 'enter_password' => __('Enter Password', 'formidable'),
306
+ 'confirm_password' => __('Confirm Password', 'formidable'),
307
  'import_complete' => __('Import Complete', 'formidable'),
308
  'updating' => __('Please wait while your site updates.', 'formidable'),
309
  'nonce' => wp_create_nonce('frm_ajax'),
310
+ 'no_save_warning' => __('Warning: There is no way to retrieve unsaved entries.', 'formidable'),
311
+ 'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
312
  ));
313
  }
314
  }
315
+
316
+
317
+ public static function custom_stylesheet(){
318
+ global $frm_vars;
319
+ $css_file = array();
320
+
321
+ if ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) {
322
+ //include css in head
323
+ $uploads = FrmStylesHelper::get_upload_base();
324
+ if ( is_readable($uploads['basedir'] .'/formidable/css/formidablepro.css') ) {
325
+ $css_file['formidable'] = $uploads['baseurl'] .'/formidable/css/formidablepro.css';
326
+ } else {
327
+ $css_file['formidable'] = admin_url('admin-ajax.php') . '?action=frmpro_css';
328
+ }
329
+ }
330
+
331
+ if ( isset($frm_vars['datepicker_loaded']) && ! empty($frm_vars['datepicker_loaded']) ) {
332
+ FrmStylesHelper::enqueue_jquery_css();
333
+ }
334
+
335
+ return $css_file;
336
+ }
337
+
338
+ public static function load_css(){
339
+ $css = get_transient('frmpro_css');
340
+
341
+ include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
342
+ die();
343
+ }
344
+
345
  public static function footer_js($location='footer'){
346
+ global $frm_vars;
347
+
348
+ $frm_settings = FrmAppHelper::get_settings();
349
+ if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
350
+ $css = apply_filters('get_frm_stylesheet', array());
351
+
 
 
352
  if(!empty($css)){
353
  echo "\n".'<script type="text/javascript">';
354
+ foreach ( (array) $css as $css_key => $file ) {
355
+ wp_enqueue_style($css_key);
356
+ unset($css_key, $file);
 
 
357
  }
358
  unset($css);
359
 
361
  }
362
  }
363
 
364
+ if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty($frm_vars['forms_loaded']) ) {
365
+ //load formidable js
366
+ wp_enqueue_script('formidable');
367
+ }
368
+ }
369
+
370
+ public static function activation_install() {
371
+ FrmAppHelper::delete_cache_and_transient('frm_plugin_version');
372
+ FrmFormActionsController::actions_init();
373
+ self::install();
374
  }
375
+
376
  public static function install($old_db_version=false){
377
+ $frmdb = new FrmDb();
378
  $frmdb->upgrade($old_db_version);
379
  }
380
+
381
  public static function uninstall(){
382
  check_ajax_referer( 'frm_ajax', 'nonce' );
383
+
384
  if ( current_user_can('administrator') ) {
385
+ $frmdb = new FrmDb();
386
  $frmdb->uninstall();
387
  echo true;
388
  } else {
389
+ $frm_settings = FrmAppHelper::get_settings();
390
  wp_die($frm_settings->admin_permission);
391
  }
392
  die();
393
  }
394
+
395
+ public static function drop_tables($tables) {
396
+ global $wpdb;
397
+ $tables[] = $wpdb->prefix .'frm_fields';
398
+ $tables[] = $wpdb->prefix .'frm_forms';
399
+ $tables[] = $wpdb->prefix .'frm_items';
400
+ $tables[] = $wpdb->prefix .'frm_item_metas';
401
+ return $tables;
402
+ }
403
+
404
  // Routes for wordpress pages -- we're just replacing content here folks.
405
  public static function page_route($content){
406
+ global $post;
407
 
408
+ $frm_settings = FrmAppHelper::get_settings();
409
  if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
410
  $content = FrmFormsController::page_preview();
411
  }
412
 
413
  return $content;
414
  }
415
+
416
  public static function referer_session() {
417
+ $frm_settings = FrmAppHelper::get_settings();
418
+
419
  if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) {
420
  return;
421
  }
422
+
423
  // keep the page history below 100
424
  $max = 100;
425
+
426
  if ( !isset($_SESSION) )
427
  session_start();
428
+
429
+ if ( ! isset($_SESSION['frm_http_pages']) || ! is_array($_SESSION['frm_http_pages']) ) {
430
+ $_SESSION['frm_http_pages'] = array('http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
431
+ }
432
+
433
+ if ( ! isset($_SESSION['frm_http_referer']) || ! is_array($_SESSION['frm_http_referer']) ) {
434
  $_SESSION['frm_http_referer'] = array();
435
+ }
436
+
437
+ if ( ! isset($_SERVER['HTTP_REFERER']) ) {
438
+ $direct = __('Type-in or bookmark', 'formidable');
439
+ if(!in_array($direct, $_SESSION['frm_http_referer']))
440
+ $_SESSION['frm_http_referer'][] = $direct;
441
+ } else if ( strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false && ! in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer']) ) {
442
+ $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
443
+ }
444
+
445
+ if ( $_SESSION['frm_http_pages'] && ! empty($_SESSION['frm_http_pages']) && ( end($_SESSION['frm_http_pages']) != 'http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']) ) {
446
+ $ext = substr(strrchr(substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '?')), '.'), 1);
447
+ if ( ! in_array($ext, array('css', 'js')) ) {
448
+ $_SESSION['frm_http_pages'][] = 'http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
449
  }
450
  }
451
+
 
 
 
452
  //keep the page history below the max
453
  if(count($_SESSION['frm_http_pages']) > $max){
454
  foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
455
  if(count($_SESSION['frm_http_pages']) <= $max)
456
  break;
457
+
458
  unset($_SESSION['frm_http_pages'][$pkey]);
459
  }
460
  }
461
  }
462
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  public static function update_message($features){
464
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
465
+ return FrmAppHelper::update_message($features);
 
 
 
 
 
 
466
  }
467
+
 
 
 
 
 
 
 
 
468
  public static function deauthorize(){
469
  check_ajax_referer( 'frm_ajax', 'nonce' );
470
+
471
  delete_option('frmpro-credentials');
472
  delete_option('frmpro-authorized');
473
  delete_site_option('frmpro-credentials');
474
  delete_site_option('frmpro-authorized');
475
  die();
476
  }
477
+
478
+ //formidable shortcode
479
+ public static function get_form_shortcode($atts){
480
+ _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
481
+ return FrmFormsController::get_form_shortcode($atts);
482
+ }
483
+
484
+ public static function get_postbox_class(){
485
+ _deprecated_function( __FUNCTION__, '2.0');
486
+ return 'postbox-container';
487
+ }
488
  }
classes/controllers/FrmEntriesController.php CHANGED
@@ -1,114 +1,473 @@
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,
@@ -116,300 +475,137 @@ class FrmEntriesController{
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');
@@ -431,10 +627,11 @@ class FrmEntriesController{
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
+ $frm_settings = FrmAppHelper::get_settings();
13
+
14
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Entries', 'formidable'), __('Entries', 'formidable'), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
15
+
16
+ if ( ! isset($_GET['frm_action']) || ! in_array($_GET['frm_action'], array('edit', 'show')) ) {
17
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' );
18
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' );
19
+ add_filter('get_user_option_manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' );
20
+ }
21
+ }
22
+
23
+ /* Display in Back End */
24
+ public static function route(){
25
+ $action = FrmAppHelper::get_param('frm_action');
26
+
27
+ switch ( $action ) {
28
+ case 'show':
29
+ case 'destroy':
30
+ case 'destroy_all':
31
+ return self::$action();
32
+
33
+ default:
34
+ do_action('frm_entry_action_route', $action);
35
+ if ( apply_filters('frm_entry_stop_action_route', false, $action) ) {
36
+ return;
37
+ }
38
+
39
+ return self::display_list();
40
+ }
41
+ }
42
+
43
+ public static function contextual_help($help, $screen_id, $screen) {
44
+ // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
45
+ if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ){
46
+ return $help;
47
+ }
48
+
49
+ if ( ! isset($_GET) || ! isset($_GET['page']) || $_GET['page'] != 'formidable-entries' || ( isset($_GET['frm_action']) && $_GET['frm_action'] != 'list' ) ) {
50
+ return $help;
51
+ }
52
+
53
+ $screen->add_help_tab( array(
54
+ 'id' => 'formidable-entries-tab',
55
+ 'title' => __( 'Overview', 'formidable' ),
56
+ 'content' => '<p>' . __('This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable') .'</p>
57
+ <p>'. __('Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable') . '</p>',
58
+ ));
59
+
60
+ $screen->set_help_sidebar(
61
+ '<p><strong>' . __('For more information:', 'formidable') . '</strong></p>' .
62
+ '<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . __('Documentation on Entries', 'formidable') . '</a></p>' .
63
+ '<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . __('Support', 'formidable') . '</a></p>'
64
+ );
65
+
66
+ return $help;
67
+ }
68
+
69
+ public static function manage_columns($columns){
70
+ global $frm_vars, $wpdb;
71
+ $form_id = FrmEntriesHelper::get_current_form_id();
72
+
73
+ $columns[$form_id .'_id'] = 'ID';
74
+ $columns[$form_id .'_item_key'] = __('Entry Key', 'formidable');
75
+
76
+ if ( ! $form_id ) {
77
+ return $columns;
78
+ }
79
+
80
+ $form_cols = FrmField::get_all_for_form($form_id, '', 'include');
81
+
82
+ foreach ( $form_cols as $form_col ) {
83
+ if ( FrmFieldsHelper::is_no_save_field($form_col->type) ) {
84
+ continue;
85
+ }
86
+
87
+ if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) {
88
+ $columns[$form_id .'_frmsep_'. $form_col->field_key] = FrmAppHelper::truncate($form_col->name, 35);
89
+ }
90
+
91
+ if ( $form_col->type == 'form' && isset($form_col->field_options['form_select']) && !empty($form_col->field_options['form_select']) ) {
92
+ $sub_form_cols = FrmField::get_all_for_form($form_col->field_options['form_select']);
93
+
94
+ if ( $sub_form_cols ) {
95
+ foreach ( $sub_form_cols as $k => $sub_form_col ) {
96
+ if ( in_array($sub_form_col->type, FrmFieldsHelper::no_save_fields()) ) {
97
+ unset($sub_form_cols[$k]);
98
+ continue;
99
+ }
100
+ $columns[$form_id .'_'. $sub_form_col->field_key .'-_-'. $form_col->id] = FrmAppHelper::truncate($sub_form_col->name, 35);
101
+ unset($sub_form_col);
102
+ }
103
+ }
104
+ unset($sub_form_cols);
105
+ } else if ( $form_col->form_id != $form_id ) {
106
+ $columns[$form_id .'_'. $form_col->field_key .'-_-form'. $form_col->form_id] = FrmAppHelper::truncate($form_col->name, 35);
107
+ } else {
108
+ $columns[$form_id .'_'. $form_col->field_key] = FrmAppHelper::truncate($form_col->name, 35);
109
+ }
110
+
111
+ }
112
+
113
+ $columns[$form_id .'_created_at'] = __('Entry creation date', 'formidable');
114
+ $columns[$form_id .'_updated_at'] = __('Entry update date', 'formidable');
115
+ $columns[$form_id .'_ip'] = 'IP';
116
+
117
+ $frm_vars['cols'] = $columns;
118
+
119
+ if ( FrmAppHelper::is_admin_page('formidable-entries') && ( ! isset($_GET['frm_action']) || $_GET['frm_action'] == 'list' || $_GET['frm_action'] == 'destroy' ) ) {
120
+ add_screen_option( 'per_page', array('label' => __('Entries', 'formidable'), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page') );
121
+ }
122
+
123
+ return $columns;
124
  }
125
+
126
+ public static function check_hidden_cols($check, $object_id, $meta_key, $meta_value, $prev_value){
127
+ $frm_settings = FrmAppHelper::get_settings();
128
+ if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) {
129
+ return $check;
130
+ }
131
+
132
+ if ( empty($prev_value) )
133
+ $prev_value = get_metadata('user', $object_id, $meta_key, true);
134
+
135
  global $frm_vars;
136
+ //add a check so we don't create a loop
137
+ $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
138
+
139
+ return $check;
140
+ }
141
+
142
+ //add hidden columns back from other forms
143
+ public static function update_hidden_cols($meta_id, $object_id, $meta_key, $meta_value ){
144
+ $frm_settings = FrmAppHelper::get_settings();
145
+
146
+ if($meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden')
147
+ return;
148
+
149
+ global $frm_vars;
150
+ if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
151
+ return; //don't continue if there's no previous value
152
+ }
153
+
154
+ foreach($meta_value as $mk => $mv){
155
+ //remove blank values
156
+ if(empty($mv))
157
+ unset($meta_value[$mk]);
158
+ }
159
+
160
+ $cur_form_prefix = reset($meta_value);
161
+ $cur_form_prefix = explode('_', $cur_form_prefix);
162
+ $cur_form_prefix = $cur_form_prefix[0];
163
+ $save = false;
164
+
165
+ foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
166
+ if ( empty($prev_hidden) || in_array($prev_hidden, $meta_value) ) {
167
+ //don't add blank cols or process included cols
168
+ continue;
169
+ }
170
+
171
+ $form_prefix = explode('_', $prev_hidden);
172
+ $form_prefix = $form_prefix[0];
173
+ if($form_prefix == $cur_form_prefix) //don't add back columns that are meant to be hidden
174
+ continue;
175
+
176
+ $meta_value[] = $prev_hidden;
177
+ $save = true;
178
+ unset($form_prefix);
179
+ }
180
+
181
+ if($save){
182
+ $user = wp_get_current_user();
183
+ update_user_option($user->ID, 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden', $meta_value, true);
184
+ }
185
+ }
186
+
187
+ public static function save_per_page($save, $option, $value){
188
+ if ( $option == 'formidable_page_formidable_entries_per_page' ) {
189
+ $save = (int) $value;
190
+ }
191
+ return $save;
192
+ }
193
+
194
+ public static function sortable_columns(){
195
+ $form_id = FrmEntriesHelper::get_current_form_id();
196
+
197
+ $fields = FrmField::get_all_for_form($form_id);
198
+
199
+ $columns = array(
200
+ $form_id .'_id' => 'id',
201
+ $form_id .'_created_at' => 'created_at',
202
+ $form_id .'_updated_at' => 'updated_at',
203
+ $form_id .'_ip' => 'ip',
204
+ $form_id .'_item_key' => 'item_key',
205
+ $form_id .'_is_draft' => 'is_draft'
206
+ );
207
+
208
+ foreach ( $fields as $field ) {
209
+ if ( $field->type != 'checkbox' && ( ! isset($field->field_options['post_field']) || $field->field_options['post_field'] == '' ) ) {
210
+ // Can't sort on checkboxes because they are stored serialized, or post fields
211
+ $columns[ $form_id .'_'. $field->field_key ] = 'meta_'. $field->id;
212
+ }
213
+ }
214
+
215
+ return $columns;
216
+ }
217
+
218
+ public static function hidden_columns($result){
219
+ global $frm_vars;
220
+
221
+ $form_id = FrmEntriesHelper::get_current_form_id();
222
+
223
+ $return = false;
224
+ foreach ( (array) $result as $r ) {
225
+ if(!empty($r)){
226
+ $form_prefix = explode('_', $r);
227
+ $form_prefix = $form_prefix[0];
228
+
229
+ if ( (int) $form_prefix == (int) $form_id ) {
230
+ $return = true;
231
+ break;
232
+ }
233
+
234
+ unset($form_prefix);
235
+ }
236
+ }
237
+
238
+ if($return)
239
+ return $result;
240
+
241
+ $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
242
+ $max_columns = 8;
243
+ if($i <= $max_columns)
244
+ return $result;
245
+
246
+ global $frm_vars;
247
+ if(isset($frm_vars['current_form']) and $frm_vars['current_form'])
248
+ $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
249
+
250
+ if(isset($frm_vars['current_form']) and $frm_vars['current_form'] and isset($frm_vars['current_form']->options['hidden_cols']) and !empty($frm_vars['current_form']->options['hidden_cols'])){
251
+ $result = $frm_vars['current_form']->options['hidden_cols'];
252
+ }else{
253
+ $cols = $frm_vars['cols'];
254
+ $cols = array_reverse($cols, true);
255
+
256
+ $result[] = $form_id .'_id';
257
+ $i--;
258
+
259
+ $result[] = $form_id .'_item_key';
260
+ $i--;
261
+
262
+ foreach($cols as $col_key => $col){
263
+ if($i > $max_columns)
264
+ $result[] = $col_key; //remove some columns by default
265
+ $i--;
266
+ unset($col_key);
267
+ unset($col);
268
+ }
269
+ }
270
+
271
+ return $result;
272
+ }
273
+
274
+ public static function display_list($params=array(), $message='', $errors = array()){
275
+ global $wpdb, $frm_vars;
276
+
277
+ $form = FrmEntriesHelper::get_current_form();
278
+ $params = FrmEntriesHelper::get_admin_params( $form );
279
+
280
+ if($form){
281
+ $params['form'] = $form->id;
282
+ $frm_vars['current_form'] = $form;
283
+ $where_clause = " it.form_id=$form->id";
284
+
285
+ if ( 'trash' == $form->status ) {
286
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
287
+ $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, (isset($form->options['trash_time']) ? ($form->options['trash_time']) : time()));
288
+ $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);
289
+ unset($time_to_delete, $delete_timestamp);
290
+ }
291
+ }else{
292
+ $where_clause = '';
293
+ }
294
+
295
+ $table_class = apply_filters('frm_entries_list_class', 'FrmEntriesListHelper');
296
+
297
+ $wp_list_table = new $table_class( array('params' => $params) );
298
+
299
+ $pagenum = $wp_list_table->get_pagenum();
300
+
301
+ $wp_list_table->prepare_items();
302
+
303
+ $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
304
+ if ( $pagenum > $total_pages && $total_pages > 0 ) {
305
+ $url = add_query_arg( 'paged', $total_pages );
306
+ if ( headers_sent() ) {
307
+ echo FrmAppHelper::js_redirect($url);
308
+ } else {
309
+ wp_redirect($url);
310
+ }
311
+ die();
312
+ }
313
+
314
+ if ( empty($message) && isset($_GET['import-message']) ) {
315
+ $message = __('Your import is complete', 'formidable');
316
+ }
317
+
318
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
319
+ }
320
+
321
+ /* Back End CRUD */
322
+ public static function show($id = false){
323
+ FrmAppHelper::permission_check('frm_view_entries');
324
+
325
+ if ( ! $id ) {
326
+ $id = FrmAppHelper::get_param('id');
327
+
328
+ if ( ! $id ) {
329
+ $id = FrmAppHelper::get_param('item_id');
330
+ }
331
+ }
332
+
333
+ $entry = FrmEntry::getOne($id, true);
334
+
335
+ $data = maybe_unserialize($entry->description);
336
+ if ( ! is_array($data) || ! isset($data['referrer']) ) {
337
+ $data = array('referrer' => $data);
338
+ }
339
+
340
+ $fields = FrmField::get_all_for_form($entry->form_id);
341
+ $date_format = get_option('date_format');
342
+ $time_format = get_option('time_format');
343
+ $to_emails = array();
344
+
345
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php');
346
+ }
347
+
348
+ public static function destroy(){
349
+ FrmAppHelper::permission_check('frm_delete_entries');
350
+
351
+ $params = FrmEntriesHelper::get_admin_params();
352
+
353
+ if ( isset($params['keep_post']) && $params['keep_post'] ) {
354
+ //unlink entry from post
355
+ global $wpdb;
356
+ $wpdb->update( $wpdb->prefix .'frm_items', array('post_id' => ''), array('id' => $params['id']) );
357
+ }
358
+
359
+ $message = '';
360
+ if ( FrmEntry::destroy( $params['id'] ) ) {
361
+ $message = __('Entry was Successfully Destroyed', 'formidable');
362
  }
363
+
364
+ self::display_list($params, $message);
365
  }
366
+
367
+ public static function destroy_all(){
368
+ if ( ! current_user_can('frm_delete_entries') ) {
369
+ $frm_settings = FrmAppHelper::get_settings();
370
+ wp_die($frm_settings->admin_permission);
371
+ }
372
+
373
+ global $wpdb;
374
+ $params = FrmEntriesHelper::get_admin_params();
375
+ $message = '';
376
+ $errors = array();
377
+ $form_id = (int) $params['form'];
378
+
379
+ if ( $form_id ) {
380
+ $entry_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
381
+ $action = FrmFormActionsHelper::get_action_for_form($form_id, 'wppost', 1);
382
+
383
+ if ( $action ) {
384
+ // this action takes a while, so only trigger it if there are posts to delete
385
+ foreach ( $entry_ids as $entry_id ) {
386
+ do_action('frm_before_destroy_entry', $entry_id);
387
+ unset($entry_id);
388
+ }
389
+ }
390
+
391
+ $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));
392
+ $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
393
+ if ( $results ) {
394
+ $message = __('Entries were Successfully Destroyed', 'formidable');
395
+ }
396
+ } else {
397
+ $errors = __('No entries were specified', 'formidable');
398
+ }
399
+
400
+ self::display_list($params, $message, $errors);
401
  }
402
+
403
  public static function show_form($id='', $key='', $title=false, $description=false){
404
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
405
  return FrmFormsController::show_form($id, $key, $title, $description);
406
  }
407
+
408
  public static function get_form($filename, $form, $title, $description) {
409
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
410
  return FrmFormsController::get_form($form, $title, $description);
411
  }
412
+
413
  public static function process_entry($errors='', $ajax=false){
414
+ if ( FrmAppHelper::is_admin() || ! isset($_POST) || ! isset($_POST['form_id']) || ! is_numeric($_POST['form_id']) || ! isset($_POST['item_key']) ) {
415
  return;
416
+ }
417
 
418
+ global $frm_vars;
419
+
420
+ $form = FrmForm::getOne($_POST['form_id']);
 
421
  if(!$form)
422
  return;
423
+
424
+ $params = self::get_params($form);
425
+
426
  if(!isset($frm_vars['form_params']))
427
  $frm_vars['form_params'] = array();
428
  $frm_vars['form_params'][$form->id] = $params;
429
+
430
  if(isset($frm_vars['created_entries'][$_POST['form_id']]))
431
  return;
432
+
433
+ if ( $errors == '' ) {
434
+ $errors = FrmEntry::validate($_POST);
435
+ }
436
  $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
437
+
438
  if( empty($errors) ){
439
  $_POST['frm_skip_cookie'] = 1;
440
  if($params['action'] == 'create'){
441
+ if ( apply_filters('frm_continue_to_create', true, $_POST['form_id']) && ! isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']) ) {
442
+ $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = FrmEntry::create( $_POST );
443
+ }
444
  }
445
+
446
  do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
447
  unset($_POST['frm_skip_cookie']);
448
  }
449
  }
450
+
451
  public static function delete_entry_before_redirect($url, $form, $atts){
452
  self::_delete_entry($atts['id'], $form);
453
  return $url;
454
  }
455
+
456
  //Delete entry if not redirected
457
  public static function delete_entry_after_save($atts){
458
  self::_delete_entry($atts['entry_id'], $atts['form']);
459
  }
460
+
461
  private static function _delete_entry($entry_id, $form){
462
  if(!$form)
463
  return;
464
+
465
  $form->options = maybe_unserialize($form->options);
466
+ if ( isset($form->options['no_save']) && $form->options['no_save'] ) {
467
+ FrmEntry::destroy( $entry_id );
 
468
  }
469
  }
470
+
471
  public static function show_entry_shortcode($atts){
472
  $atts = shortcode_atts(array(
473
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
475
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
476
  'font_size' => '', 'text_color' => '',
477
  'border_width' => '', 'border_color' => '',
478
+ 'bg_color' => '', 'alt_bg_color' => '',
479
  ), $atts);
480
+
481
+ if ( $atts['format'] != 'text' ) {
 
482
  //format options are text, array, or json
483
+ $atts['plain_text'] = true;
484
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
 
486
+ if ( ! $atts['entry'] || ! is_object($atts['entry']) ) {
487
+ if ( ! $atts['id'] && ! $atts['default_email'] ) {
488
+ return;
 
 
 
 
 
 
 
 
489
  }
490
+
491
+ if ( $atts['id'] ) {
492
+ $atts['entry'] = FrmEntry::getOne($atts['id'], true);