Formidable Forms – Form Builder for WordPress - Version 2.0rc8

Version Description

Download this release

Release Info

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

Code changes from version 2.0rc3 to 2.0rc8

Files changed (98) hide show
  1. .travis.yml +0 -63
  2. classes/controllers/FrmAppController.php +90 -141
  3. classes/controllers/FrmEntriesController.php +148 -137
  4. classes/controllers/FrmFieldsController.php +181 -164
  5. classes/controllers/FrmFormActionsController.php +66 -62
  6. classes/controllers/FrmFormsController.php +228 -201
  7. classes/controllers/FrmHooksController.php +21 -26
  8. classes/controllers/FrmSettingsController.php +20 -20
  9. classes/controllers/FrmStatisticsController.php +13 -13
  10. classes/controllers/FrmStylesController.php +84 -71
  11. classes/controllers/FrmXMLController.php +66 -64
  12. classes/helpers/FrmAppHelper.php +581 -671
  13. classes/helpers/FrmEntriesHelper.php +138 -136
  14. classes/helpers/FrmEntriesListHelper.php +51 -46
  15. classes/helpers/FrmFieldsHelper.php +381 -218
  16. classes/helpers/FrmFormActionsHelper.php +15 -10
  17. classes/helpers/FrmFormsHelper.php +160 -148
  18. classes/helpers/FrmFormsListHelper.php +87 -70
  19. classes/helpers/FrmListHelper.php +6 -4
  20. classes/helpers/FrmStylesHelper.php +28 -27
  21. classes/helpers/FrmXMLHelper.php +410 -53
  22. classes/models/FrmDb.php +285 -288
  23. classes/models/FrmEntry.php +126 -86
  24. classes/models/FrmEntryMeta.php +67 -43
  25. classes/models/FrmField.php +138 -98
  26. classes/models/FrmForm.php +115 -105
  27. classes/models/FrmFormAction.php +26 -20
  28. classes/models/FrmNotification.php +39 -26
  29. classes/models/FrmSettings.php +14 -17
  30. classes/models/FrmStyle.php +55 -43
  31. classes/views/frm-entries/_sidebar-shared-pub.php +2 -2
  32. classes/views/frm-entries/direct.php +7 -10
  33. classes/views/frm-entries/errors.php +8 -8
  34. classes/views/frm-entries/form.php +10 -9
  35. classes/views/frm-entries/list.php +2 -2
  36. classes/views/frm-entries/no_entries.php +6 -6
  37. classes/views/frm-entries/show.php +6 -15
  38. classes/views/frm-entries/sidebar-shared.php +11 -11
  39. classes/views/frm-entries/sidebar-show.php +4 -4
  40. classes/views/frm-fields/import_choices.php +11 -46
  41. classes/views/frm-fields/input.php +26 -29
  42. classes/views/frm-fields/show-build.php +9 -10
  43. classes/views/frm-fields/single-option.php +1 -1
  44. classes/views/frm-form-actions/_action_inside.php +29 -26
  45. classes/views/frm-form-actions/_email_settings.php +12 -12
  46. classes/views/frm-form-actions/default_actions.php +7 -7
  47. classes/views/frm-form-actions/email_action.php +3 -3
  48. classes/views/frm-forms/_publish_box.php +14 -14
  49. classes/views/frm-forms/add_field.php +90 -66
  50. classes/views/frm-forms/add_field_links.php +81 -80
  51. classes/views/frm-forms/edit.php +15 -9
  52. classes/views/frm-forms/form.php +19 -10
  53. classes/views/frm-forms/insert_form_popup.php +4 -110
  54. classes/views/frm-forms/list.php +11 -7
  55. classes/views/frm-forms/mb_html_tab.php +18 -18
  56. classes/views/frm-forms/mb_insert_fields.php +2 -1
  57. classes/views/frm-forms/new-selection.php +0 -56
  58. classes/views/frm-forms/new.php +3 -3
  59. classes/views/frm-forms/settings.php +77 -57
  60. classes/views/frm-forms/shortcode_opts.php +10 -8
  61. classes/views/frm-settings/form.php +82 -63
  62. classes/views/frm-settings/license_box.php +4 -4
  63. classes/views/frm-statistics/list.php +10 -10
  64. classes/views/frm-statistics/list_displays.php +10 -10
  65. classes/views/shared/errors.php +2 -2
  66. classes/views/shared/form-nav.php +29 -20
  67. classes/views/shared/mb_adv_info.php +75 -87
  68. classes/views/styles/_buttons.php +26 -26
  69. classes/views/styles/_check-box-radio-fields.php +7 -7
  70. classes/views/styles/_date-fields.php +4 -4
  71. classes/views/styles/_field-colors.php +27 -27
  72. classes/views/styles/_field-description.php +11 -11
  73. classes/views/styles/_field-labels.php +15 -15
  74. classes/views/styles/_field-sizes.php +8 -8
  75. classes/views/styles/_form-messages.php +10 -10
  76. classes/views/styles/_general.php +20 -20
  77. classes/views/styles/_sample_form.php +25 -25
  78. classes/views/styles/_section-fields.php +30 -30
  79. classes/views/styles/custom_css.php +3 -3
  80. classes/views/styles/manage.php +7 -7
  81. classes/views/styles/show.php +16 -16
  82. classes/views/xml/forms_xml.php +6 -8
  83. classes/views/xml/import_form.php +29 -27
  84. classes/views/xml/posts_xml.php +33 -22
  85. classes/views/xml/xml.php +2 -2
  86. classes/widgets/FrmShowForm.php +9 -9
  87. css/_single_theme.css.php +22 -13
  88. css/custom_theme.css.php +52 -20
  89. css/font_icons.css +1 -1
  90. css/frm_admin.css +298 -12
  91. css/frm_display.css +0 -72
  92. css/frm_fonts.css +7 -13
  93. fonts/s11-fp.eot +0 -0
  94. fonts/s11-fp.svg +65 -60
  95. fonts/s11-fp.ttf +0 -0
  96. fonts/s11-fp.woff +0 -0
  97. formidable.php +2 -2
  98. js/formidable.min.js +0 -33
.travis.yml DELETED
@@ -1,63 +0,0 @@
1
- language: php
2
-
3
- sudo: false
4
-
5
- matrix:
6
- include:
7
- - php: '5.6'
8
- env: WP_VERSION=master WP_MULTISITE=0 PHPLINT=1
9
- - php: '5.2'
10
- env: WP_VERSION=master WP_MULTISITE=1 PHPLINT=1
11
- - php: '5.6'
12
- env: WP_VERSION=4.1 WP_MULTISITE=1
13
- - php: '5.5'
14
- env: WP_VERSION=master WP_MULTISITE=0
15
- - php: '5.5'
16
- env: WP_VERSION=4.1 WP_MULTISITE=1
17
- - php: '5.4'
18
- env: WP_VERSION=4.1 WP_MULTISITE=0
19
- - php: '5.4'
20
- env: WP_VERSION=4.1 WP_MULTISITE=1
21
- - php: '5.5'
22
- env: WP_VERSION=4.1 WP_MULTISITE=0
23
- - php: '5.5'
24
- env: WP_VERSION=4.0 WP_MULTISITE=1
25
- - php: '5.3'
26
- env: WP_VERSION=4.0 WP_MULTISITE=0
27
- - php: '5.4'
28
- env: WP_VERSION=3.9 WP_MULTISITE=0
29
- - php: '5.3'
30
- env: WP_VERSION=3.4 WP_MULTISITE=0
31
- - php: '5.3'
32
- env: WP_VERSION=3.4 WP_MULTISITE=1
33
- - php: 'hhvm'
34
- env: WP_VERSION=4.1 WP_MULTISITE=0
35
- - php: 'hhvm'
36
- env: WP_VERSION=4.1 WP_MULTISITE=1
37
-
38
- before_script:
39
- - phpenv local 5.6
40
- - composer selfupdate --no-interaction
41
- - composer install --no-interaction
42
- - phpenv local --unset
43
- - PLUGIN_SLUG=$(basename $(pwd))
44
- - export WP_DEVELOP_DIR=/tmp/wordpress/
45
- - git clone --depth=50 --branch="$WP_VERSION" git://develop.git.wordpress.org/ /tmp/wordpress
46
- - cd ..
47
- - cp -r "$PLUGIN_SLUG" "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
48
- - cd /tmp/wordpress/
49
- - cp wp-tests-config-sample.php wp-tests-config.php
50
- - sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
51
- - sed -i "s/yourusernamehere/travis/" wp-tests-config.php
52
- - sed -i "s/yourpasswordhere//" wp-tests-config.php
53
- - mysql -e "CREATE DATABASE wordpress_tests;" -uroot
54
- - git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs
55
- - git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
56
- - cd phpcs
57
- - scripts/phpcs --config-set installed_paths ../wpcs
58
- - cd "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
59
- - phpenv rehash
60
-
61
- script:
62
- - if [[ "$PHPLINT" == "1" ]]; then /tmp/wordpress/phpcs/scripts/phpcs -p -s -v -n . --standard=./codesniffer.xml --extensions=php; fi
63
- - phpunit -c phpunit.xml
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/controllers/FrmAppController.php CHANGED
@@ -24,7 +24,7 @@ class FrmAppController {
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 );
@@ -32,7 +32,8 @@ class FrmAppController {
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
 
@@ -49,7 +50,7 @@ class FrmAppController {
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
 
@@ -68,15 +69,15 @@ class FrmAppController {
68
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
69
  ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
70
 
71
- return '<a href="'. add_query_arg( array('upgraded' => 'true'), menu_page_url( 'formidable', 0 ) ) .'">'. __( 'Click here to complete the upgrade', 'formidable' ) .'</a>';
72
 
73
  }
74
 
75
  return $actions;
76
  }
77
 
78
- public static function pro_get_started_headline(){
79
- if ( FrmAppHelper::is_admin_page( 'formidable' ) && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) {
80
  self::install();
81
  ?>
82
  <div id="message" class="frm_message updated"><?php _e( 'Congratulations! Formidable is ready to roll.', 'formidable' ) ?></div>
@@ -85,7 +86,7 @@ class FrmAppController {
85
  }
86
 
87
  // Don't display this error as we're upgrading the thing... cmon
88
- if ( isset($_GET['action']) && 'upgrade-plugin' == $_GET['action'] ) {
89
  return;
90
  }
91
 
@@ -98,81 +99,79 @@ class FrmAppController {
98
  $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
99
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
100
  ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
 
101
  ?>
102
- <div class="error" id="frm_install_message"><?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>
103
- <script type="text/javascript">
104
- jQuery(document).ready(function($){ $(document.getElementById('frm_install_link')).click(frm_install_now); });
105
- function frm_install_now(){
106
- var $msg = jQuery(document.getElementById('frm_install_message'));
107
- $msg.html('<div class="frm_plugin_updating"><?php _e( 'Please wait while your site updates.', 'formidable' ) ?><div class="spinner frm_spinner"></div></div>');
108
- jQuery.ajax({
109
- type:"POST",url:ajaxurl,data:"action=frm_install",
110
- success:function(){$msg.fadeOut('slow');}
111
- });
112
- }
113
- </script>
114
  <?php
115
  }
116
  }
117
 
118
  global $frm_vars;
119
  if ( $frm_vars['pro_is_authorized'] && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) {
 
 
120
  // user is authorized, but running free version
121
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
122
  ?>
123
- <div class="error" class="frm_previous_install"><?php echo apply_filters( 'frm_pro_update_msg', sprintf( __( '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' ), '<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>
124
- <script type="text/javascript">
125
- function frm_deauthorize_now(){
126
- if(!confirm("<?php esc_attr_e( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ) ?>"))
127
- return false;
128
- jQuery('.frm_deauthorize_link').html('<span class="spinner"></span>');
129
- jQuery.ajax({type:'POST',url:ajaxurl,data:'action=frm_deauthorize&nonce='+wp_create_nonce('frm_ajax'),
130
- success:function(msg){jQuery('.error').fadeOut('slow');}
131
- });
132
- return false;
133
- }
134
- </script>
135
- <?php
136
  }
137
  }
138
 
139
- public static function admin_js(){
140
  global $pagenow;
141
 
142
- if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) {
 
143
  return;
144
  }
145
-
146
- wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.3.2' );
147
-
148
- if ( isset($_GET) && ( ( isset($_GET['page']) && strpos( $_GET['page'], 'formidable' ) === 0 ) ||
149
- ( $pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display' ) )
150
- ) {
151
- $version = FrmAppHelper::plugin_version();
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  add_filter( 'admin_body_class', 'FrmAppController::admin_body_class' );
153
 
154
- wp_enqueue_script( 'jquery-ui-sortable' );
155
- wp_enqueue_script( 'jquery-ui-draggable' );
156
  wp_enqueue_script( 'admin-widgets' );
157
  wp_enqueue_style( 'widgets' );
158
  wp_enqueue_script( 'formidable' );
159
- 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 );
160
  self::localize_script( 'admin' );
161
 
162
- wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version );
163
  add_thickbox();
164
 
165
- wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0' );
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
- } else if ( $pagenow == 'post.php' || ($pagenow == 'post-new.php' && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'frm_display') ) {
172
  if ( isset($_REQUEST['post_type']) ) {
173
- $post_type = $_REQUEST['post_type'];
174
- } else if ( isset($_REQUEST['post']) && ! empty($_REQUEST['post']) ) {
175
- $post = get_post( $_REQUEST['post'] );
176
  if ( ! $post ) {
177
  return;
178
  }
@@ -182,16 +181,17 @@ return false;
182
  }
183
 
184
  if ( $post_type == 'frm_display' ) {
185
- $version = FrmAppHelper::plugin_version();
186
  wp_enqueue_script( 'jquery-ui-draggable' );
187
- wp_enqueue_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version );
188
- wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url(). '/css/frm_admin.css', array(), $version );
189
  self::localize_script( 'admin' );
190
  }
 
 
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
@@ -202,7 +202,7 @@ return false;
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', '>' ) ) {
@@ -212,13 +212,13 @@ return false;
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 );
@@ -229,7 +229,7 @@ return false;
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;
@@ -240,8 +240,8 @@ return false;
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
@@ -259,10 +259,10 @@ return false;
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;
@@ -273,21 +273,21 @@ return false;
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_form' ),
 
284
  ));
285
 
286
  if ( $location == 'admin' ) {
287
  $frm_settings = FrmAppHelper::get_settings();
288
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
289
  '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' ),
290
- 'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '',
291
  'desc' => __( '(Click to add description)', 'formidable' ),
292
  'blank' => __( '(blank)', 'formidable' ),
293
  'no_label' => __( '(no label)', 'formidable' ),
@@ -295,14 +295,14 @@ return false;
295
  'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
296
  'ok' => __( 'OK' ),
297
  'cancel' => __( 'Cancel', 'formidable' ),
 
298
  'clear_default' => __( 'Clear default value when typing', 'formidable' ),
299
  'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
300
  'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
301
  'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
302
- 'deauthorize' => __( 'Are you sure you want to deactivate Formidable Forms on this site?', '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
  'default_unique' => $frm_settings->unique_msg,
307
  'default_conf' => __( 'The entered values do not match', 'formidable' ),
308
  'enter_email' => __( 'Enter Email', 'formidable' ),
@@ -311,15 +311,14 @@ return false;
311
  'confirm_password' => __( 'Confirm Password', 'formidable' ),
312
  'import_complete' => __( 'Import Complete', 'formidable' ),
313
  'updating' => __( 'Please wait while your site updates.', 'formidable' ),
314
- 'nonce' => wp_create_nonce( 'frm_ajax' ),
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
 
@@ -340,11 +339,11 @@ return false;
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
- die();
348
  }
349
 
350
  public static function footer_js( $location = 'footer' ) {
@@ -354,16 +353,16 @@ return false;
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
  }
@@ -380,7 +379,7 @@ return false;
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' ) ) {
@@ -391,7 +390,7 @@ return false;
391
  $frm_settings = FrmAppHelper::get_settings();
392
  wp_die( $frm_settings->admin_permission );
393
  }
394
- die();
395
  }
396
 
397
  public static function drop_tables($tables) {
@@ -404,7 +403,7 @@ return false;
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();
@@ -415,78 +414,28 @@ return false;
415
  return $content;
416
  }
417
 
418
- public static function referer_session() {
419
- $frm_settings = FrmAppHelper::get_settings();
420
-
421
- if ( ! isset($frm_settings->track) || ! $frm_settings->track || defined( 'WP_IMPORTING' ) ) {
422
- return;
423
- }
424
-
425
- // keep the page history below 100
426
- $max = 100;
427
-
428
- if ( ! isset($_SESSION) ) {
429
- session_start();
430
- }
431
-
432
- if ( ! isset($_SESSION['frm_http_pages']) || ! is_array( $_SESSION['frm_http_pages'] ) ) {
433
- $_SESSION['frm_http_pages'] = array('http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
434
- }
435
-
436
- if ( ! isset($_SESSION['frm_http_referer']) || ! is_array( $_SESSION['frm_http_referer'] ) ) {
437
- $_SESSION['frm_http_referer'] = array();
438
- }
439
-
440
- if ( ! isset($_SERVER['HTTP_REFERER']) ) {
441
- $direct = __( 'Type-in or bookmark', 'formidable' );
442
- if ( ! in_array( $direct, $_SESSION['frm_http_referer'] ) ) {
443
- $_SESSION['frm_http_referer'][] = $direct;
444
- }
445
- } else if ( strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false && ! in_array( $_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'] ) ) {
446
- $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
447
- }
448
-
449
- if ( $_SESSION['frm_http_pages'] && ! empty($_SESSION['frm_http_pages']) && ( end( $_SESSION['frm_http_pages'] ) != 'http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']) ) {
450
- $ext = substr( strrchr( substr( $_SERVER['REQUEST_URI'], 0, strrpos( $_SERVER['REQUEST_URI'], '?' ) ), '.' ), 1 );
451
- if ( ! in_array( $ext, array('css', 'js') ) ) {
452
- $_SESSION['frm_http_pages'][] = 'http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
453
- }
454
- }
455
-
456
- //keep the page history below the max
457
- if ( count( $_SESSION['frm_http_pages'] ) > $max ) {
458
- foreach ( $_SESSION['frm_http_pages'] as $pkey => $ppage ) {
459
- if ( count( $_SESSION['frm_http_pages'] ) <= $max ) {
460
- break;
461
- }
462
-
463
- unset($_SESSION['frm_http_pages'][ $pkey ]);
464
- }
465
- }
466
- }
467
-
468
- public static function update_message($features){
469
- _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
470
  return FrmAppHelper::update_message( $features );
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
 
483
  //formidable shortcode
484
- public static function get_form_shortcode($atts){
485
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
486
  return FrmFormsController::get_form_shortcode( $atts );
487
  }
488
 
489
- public static function get_postbox_class(){
490
  _deprecated_function( __FUNCTION__, '2.0' );
491
  return 'postbox-container';
492
  }
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 );
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
 
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
 
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>
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
 
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
  }
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
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', '>' ) ) {
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 );
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;
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
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;
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' ),
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
  'default_unique' => $frm_settings->unique_msg,
307
  'default_conf' => __( 'The entered values do not match', 'formidable' ),
308
  'enter_email' => __( 'Enter Email', 'formidable' ),
311
  'confirm_password' => __( 'Confirm Password', 'formidable' ),
312
  'import_complete' => __( 'Import Complete', 'formidable' ),
313
  'updating' => __( 'Please wait while your site updates.', 'formidable' ),
 
314
  'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
315
  'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
316
+ ) );
317
  }
318
  }
319
 
320
 
321
+ public static function custom_stylesheet() {
322
  global $frm_vars;
323
  $css_file = array();
324
 
339
  return $css_file;
340
  }
341
 
342
+ public static function load_css() {
343
  $css = get_transient( 'frmpro_css' );
344
 
345
  include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
346
+ wp_die();
347
  }
348
 
349
  public static function footer_js( $location = 'footer' ) {
353
  if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
354
  $css = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
355
 
356
+ if ( ! empty( $css ) ) {
357
  foreach ( (array) $css as $css_key => $file ) {
358
  wp_enqueue_style( $css_key );
359
+ unset( $css_key, $file );
360
  }
361
  }
362
+ unset( $css );
363
  }
364
 
365
+ if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
366
  //load formidable js
367
  wp_enqueue_script( 'formidable' );
368
  }
379
  $frmdb->upgrade( $old_db_version );
380
  }
381
 
382
+ public static function uninstall() {
383
  check_ajax_referer( 'frm_ajax', 'nonce' );
384
 
385
  if ( current_user_can( 'administrator' ) ) {
390
  $frm_settings = FrmAppHelper::get_settings();
391
  wp_die( $frm_settings->admin_permission );
392
  }
393
+ wp_die();
394
  }
395
 
396
  public static function drop_tables($tables) {
403
  }
404
 
405
  // Routes for wordpress pages -- we're just replacing content here folks.
406
+ public static function page_route($content) {
407
  global $post;
408
 
409
  $frm_settings = FrmAppHelper::get_settings();
414
  return $content;
415
  }
416
 
417
+ public static function update_message($features) {
418
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  return FrmAppHelper::update_message( $features );
420
  }
421
 
422
+ public static function deauthorize() {
423
  check_ajax_referer( 'frm_ajax', 'nonce' );
424
 
425
  delete_option( 'frmpro-credentials' );
426
  delete_option( 'frmpro-authorized' );
427
  delete_site_option( 'frmpro-credentials' );
428
  delete_site_option( 'frmpro-authorized' );
429
+ wp_die();
430
  }
431
 
432
  //formidable shortcode
433
+ public static function get_form_shortcode( $atts ) {
434
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
435
  return FrmFormsController::get_form_shortcode( $atts );
436
  }
437
 
438
+ public static function get_postbox_class() {
439
  _deprecated_function( __FUNCTION__, '2.0' );
440
  return 'postbox-container';
441
  }
classes/controllers/FrmEntriesController.php CHANGED
@@ -3,24 +3,24 @@
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 ) {
@@ -30,8 +30,8 @@ class FrmEntriesController {
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
 
@@ -41,36 +41,38 @@ class FrmEntriesController {
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
- if ( ! isset($_GET) || ! isset($_GET['page']) || $_GET['page'] != 'formidable-entries' || ( isset($_GET['frm_action']) && $_GET['frm_action'] != 'list' ) ) {
 
 
49
  return $help;
50
  }
 
51
 
52
  $screen->add_help_tab( array(
53
  'id' => 'formidable-entries-tab',
54
  'title' => __( 'Overview', 'formidable' ),
55
- '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>
56
- <p>'. __('Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable') . '</p>',
57
  ));
58
 
59
  $screen->set_help_sidebar(
60
- '<p><strong>' . __('For more information:', 'formidable') . '</strong></p>' .
61
- '<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . __('Documentation on Entries', 'formidable') . '</a></p>' .
62
- '<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . __('Support', 'formidable') . '</a></p>'
63
  );
64
 
65
  return $help;
66
  }
67
 
68
- public static function manage_columns($columns){
69
  global $frm_vars, $wpdb;
70
  $form_id = FrmEntriesHelper::get_current_form_id();
71
 
72
  $columns[ $form_id .'_id' ] = 'ID';
73
- $columns[ $form_id .'_item_key' ] = __('Entry Key', 'formidable');
74
 
75
  if ( ! $form_id ) {
76
  return $columns;
@@ -88,11 +90,11 @@ class FrmEntriesController {
88
 
89
  if ( $sub_form_cols ) {
90
  foreach ( $sub_form_cols as $k => $sub_form_col ) {
91
- if ( in_array($sub_form_col->type, FrmFieldsHelper::no_save_fields()) ) {
92
  unset( $sub_form_cols[ $k ] );
93
  continue;
94
  }
95
- $columns[ $form_id .'_'. $sub_form_col->field_key .'-_-'. $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
96
  unset($sub_form_col);
97
  }
98
  }
@@ -116,21 +118,23 @@ class FrmEntriesController {
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
@@ -140,7 +144,7 @@ class FrmEntriesController {
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
  $sanitized = sanitize_title($frm_settings->menu);
@@ -166,12 +170,12 @@ class FrmEntriesController {
166
  $save = false;
167
 
168
  foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
169
- if ( empty($prev_hidden) || in_array($prev_hidden, $meta_value) ) {
170
  //don't add blank cols or process included cols
171
  continue;
172
  }
173
 
174
- $form_prefix = explode('_', $prev_hidden);
175
  $form_prefix = $form_prefix[0];
176
  if ( $form_prefix == $cur_form_prefix ) {
177
  //don't add back columns that are meant to be hidden
@@ -183,20 +187,20 @@ class FrmEntriesController {
183
  unset($form_prefix);
184
  }
185
 
186
- if($save){
187
  $user = wp_get_current_user();
188
  update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true );
189
  }
190
  }
191
 
192
- public static function save_per_page($save, $option, $value){
193
  if ( $option == 'formidable_page_formidable_entries_per_page' ) {
194
  $save = (int) $value;
195
  }
196
  return $save;
197
  }
198
 
199
- public static function sortable_columns(){
200
  $form_id = FrmEntriesHelper::get_current_form_id();
201
 
202
  $fields = FrmField::get_all_for_form($form_id);
@@ -207,7 +211,7 @@ class FrmEntriesController {
207
  $form_id .'_updated_at' => 'updated_at',
208
  $form_id .'_ip' => 'ip',
209
  $form_id .'_item_key' => 'item_key',
210
- $form_id .'_is_draft' => 'is_draft'
211
  );
212
 
213
  foreach ( $fields as $field ) {
@@ -220,15 +224,15 @@ class FrmEntriesController {
220
  return $columns;
221
  }
222
 
223
- public static function hidden_columns($result){
224
  global $frm_vars;
225
 
226
  $form_id = FrmEntriesHelper::get_current_form_id();
227
 
228
  $return = false;
229
  foreach ( (array) $result as $r ) {
230
- if(!empty($r)){
231
- $form_prefix = explode('_', $r);
232
  $form_prefix = $form_prefix[0];
233
 
234
  if ( (int) $form_prefix == (int) $form_id ) {
@@ -240,13 +244,15 @@ class FrmEntriesController {
240
  }
241
  }
242
 
243
- if($return)
244
- return $result;
 
245
 
246
  $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
247
  $max_columns = 8;
248
- if($i <= $max_columns)
249
- return $result;
 
250
 
251
  global $frm_vars;
252
  if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
@@ -255,7 +261,7 @@ class FrmEntriesController {
255
 
256
  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']) ) {
257
  $result = $frm_vars['current_form']->options['hidden_cols'];
258
- }else{
259
  $cols = $frm_vars['cols'];
260
  $cols = array_reverse($cols, true);
261
 
@@ -265,9 +271,11 @@ class FrmEntriesController {
265
  $result[] = $form_id .'_item_key';
266
  $i--;
267
 
268
- foreach($cols as $col_key => $col){
269
- if($i > $max_columns)
270
- $result[] = $col_key; //remove some columns by default
 
 
271
  $i--;
272
  unset($col_key, $col);
273
  }
@@ -276,30 +284,27 @@ class FrmEntriesController {
276
  return $result;
277
  }
278
 
279
- public static function display_list($params=array(), $message='', $errors = array()){
280
  global $wpdb, $frm_vars;
281
 
282
  $form = FrmEntriesHelper::get_current_form();
283
  $params = FrmEntriesHelper::get_admin_params( $form );
284
 
285
- if($form){
286
  $params['form'] = $form->id;
287
  $frm_vars['current_form'] = $form;
288
- $where_clause = " it.form_id=$form->id";
289
 
290
  if ( 'trash' == $form->status ) {
291
  $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
292
- $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, (isset($form->options['trash_time']) ? ($form->options['trash_time']) : time()));
293
- $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);
294
- unset($time_to_delete, $delete_timestamp);
295
  }
296
- }else{
297
- $where_clause = '';
298
  }
299
 
300
- $table_class = apply_filters('frm_entries_list_class', 'FrmEntriesListHelper');
301
 
302
- $wp_list_table = new $table_class( array('params' => $params) );
303
 
304
  $pagenum = $wp_list_table->get_pagenum();
305
 
@@ -317,14 +322,14 @@ class FrmEntriesController {
317
  }
318
 
319
  if ( empty($message) && isset($_GET['import-message']) ) {
320
- $message = __('Your import is complete', 'formidable');
321
  }
322
 
323
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
324
  }
325
 
326
  /* Back End CRUD */
327
- public static function show($id = false){
328
  FrmAppHelper::permission_check('frm_view_entries');
329
 
330
  if ( ! $id ) {
@@ -338,19 +343,17 @@ class FrmEntriesController {
338
  $entry = FrmEntry::getOne($id, true);
339
 
340
  $data = maybe_unserialize($entry->description);
341
- if ( ! is_array($data) || ! isset($data['referrer']) ) {
342
- $data = array('referrer' => $data);
343
- }
344
 
345
- $fields = FrmField::get_all_for_form($entry->form_id);
346
- $date_format = get_option('date_format');
347
- $time_format = get_option('time_format');
348
  $to_emails = array();
349
 
350
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php');
351
  }
352
 
353
- public static function destroy(){
354
  FrmAppHelper::permission_check('frm_delete_entries');
355
 
356
  $params = FrmEntriesHelper::get_admin_params();
@@ -358,21 +361,21 @@ class FrmEntriesController {
358
  if ( isset($params['keep_post']) && $params['keep_post'] ) {
359
  //unlink entry from post
360
  global $wpdb;
361
- $wpdb->update( $wpdb->prefix .'frm_items', array('post_id' => ''), array('id' => $params['id']) );
362
  }
363
 
364
  $message = '';
365
  if ( FrmEntry::destroy( $params['id'] ) ) {
366
- $message = __('Entry was Successfully Destroyed', 'formidable');
367
  }
368
 
369
- self::display_list($params, $message);
370
  }
371
 
372
- public static function destroy_all(){
373
- if ( ! current_user_can('frm_delete_entries') ) {
374
  $frm_settings = FrmAppHelper::get_settings();
375
- wp_die($frm_settings->admin_permission);
376
  }
377
 
378
  global $wpdb;
@@ -382,122 +385,129 @@ class FrmEntriesController {
382
  $form_id = (int) $params['form'];
383
 
384
  if ( $form_id ) {
385
- $entry_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
386
- $action = FrmFormActionsHelper::get_action_for_form($form_id, 'wppost', 1);
387
 
388
  if ( $action ) {
389
  // this action takes a while, so only trigger it if there are posts to delete
390
  foreach ( $entry_ids as $entry_id ) {
391
- do_action('frm_before_destroy_entry', $entry_id);
392
- unset($entry_id);
393
  }
394
  }
395
 
396
- $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));
397
- $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
398
  if ( $results ) {
399
- $message = __('Entries were Successfully Destroyed', 'formidable');
400
  }
401
  } else {
402
- $errors = __('No entries were specified', 'formidable');
403
  }
404
 
405
- self::display_list($params, $message, $errors);
406
  }
407
 
408
- public static function show_form($id='', $key='', $title=false, $description=false){
409
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
410
- return FrmFormsController::show_form($id, $key, $title, $description);
411
  }
412
 
413
- public static function get_form($filename, $form, $title, $description) {
414
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
415
- return FrmFormsController::get_form($form, $title, $description);
416
  }
417
 
418
- public static function process_entry($errors='', $ajax=false){
419
- if ( FrmAppHelper::is_admin() || ! isset($_POST) || ! isset($_POST['form_id']) || ! is_numeric($_POST['form_id']) || ! isset($_POST['item_key']) ) {
 
420
  return;
421
  }
422
 
423
  global $frm_vars;
424
 
425
- $form = FrmForm::getOne($_POST['form_id']);
426
  if ( ! $form ) {
427
  return;
428
  }
429
 
430
- $params = self::get_params($form);
431
 
432
- if ( ! isset($frm_vars['form_params']) ) {
433
  $frm_vars['form_params'] = array();
434
  }
435
- $frm_vars['form_params'][$form->id] = $params;
436
 
437
- if(isset($frm_vars['created_entries'][$_POST['form_id']]))
438
  return;
 
439
 
440
  if ( $errors == '' ) {
441
- $errors = FrmEntry::validate($_POST);
442
  }
443
- $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
444
 
445
- if( empty($errors) ){
446
  $_POST['frm_skip_cookie'] = 1;
447
- if($params['action'] == 'create'){
448
- if ( apply_filters('frm_continue_to_create', true, $_POST['form_id']) && ! isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']) ) {
449
- $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = FrmEntry::create( $_POST );
450
  }
451
  }
452
 
453
- do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
454
- unset($_POST['frm_skip_cookie']);
455
  }
456
  }
457
 
458
- public static function delete_entry_before_redirect($url, $form, $atts){
459
- self::_delete_entry($atts['id'], $form);
460
  return $url;
461
  }
462
 
463
  //Delete entry if not redirected
464
- public static function delete_entry_after_save($atts){
465
- self::_delete_entry($atts['entry_id'], $atts['form']);
466
  }
467
 
468
- private static function _delete_entry($entry_id, $form){
469
  if ( ! $form ) {
470
  return;
471
  }
472
 
473
- $form->options = maybe_unserialize($form->options);
474
- if ( isset($form->options['no_save']) && $form->options['no_save'] ) {
475
  FrmEntry::destroy( $entry_id );
476
  }
477
  }
478
 
479
- public static function show_entry_shortcode($atts){
480
- $atts = shortcode_atts(array(
481
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
482
  'user_info' => false, 'include_blank' => false, 'default_email' => false,
483
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
484
  'font_size' => '', 'text_color' => '',
485
  'border_width' => '', 'border_color' => '',
486
  'bg_color' => '', 'alt_bg_color' => '',
487
- ), $atts);
488
 
489
  if ( $atts['format'] != 'text' ) {
490
  //format options are text, array, or json
491
  $atts['plain_text'] = true;
492
  }
493
 
494
- if ( ! $atts['entry'] || ! is_object($atts['entry']) ) {
 
 
 
 
 
495
  if ( ! $atts['id'] && ! $atts['default_email'] ) {
496
  return;
497
  }
498
 
499
  if ( $atts['id'] ) {
500
- $atts['entry'] = FrmEntry::getOne($atts['id'], true);
501
  }
502
  }
503
 
@@ -507,7 +517,7 @@ class FrmEntriesController {
507
  }
508
 
509
  if ( ! $atts['fields'] || ! is_array($atts['fields']) ) {
510
- $atts['fields'] = FrmField::get_all_for_form($atts['form_id']);
511
  }
512
 
513
  $values = array();
@@ -534,7 +544,7 @@ class FrmEntriesController {
534
  return $content;
535
  }
536
 
537
- public static function &filter_email_value($value, $meta, $entry, $atts=array()){
538
  $field = FrmField::getOne($meta->field_id);
539
  if ( ! $field ) {
540
  return $value;
@@ -555,9 +565,9 @@ class FrmEntriesController {
555
  return self::filter_display_value($value, $field, $atts);
556
  }
557
 
558
- public static function &filter_display_value($value, $field, $atts=array()){
559
  $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false;
560
- if ( ! in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) || ! isset($field->field_options['separate_value']) || ! $field->field_options['separate_value'] || $saved_value ) {
561
  return $value;
562
  }
563
 
@@ -568,10 +578,10 @@ class FrmEntriesController {
568
  continue;
569
  }
570
 
571
- $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
572
- $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
573
- if ( $f_labels[$opt_key] == $f_values[$opt_key] ) {
574
- unset($f_values[$opt_key], $f_labels[$opt_key]);
575
  }
576
  unset($opt_key, $opt);
577
  }
@@ -581,9 +591,9 @@ class FrmEntriesController {
581
  if ( in_array($val, $f_values) ) {
582
  $opt = array_search($val, $f_values);
583
  if ( is_array($value) ) {
584
- $value[$v_key] = $f_labels[$opt];
585
  } else {
586
- $value = $f_labels[$opt];
587
  }
588
  }
589
  unset($v_key, $val);
@@ -593,24 +603,25 @@ class FrmEntriesController {
593
  return $value;
594
  }
595
 
596
- public static function get_params($form=null){
597
  global $frm_vars;
598
 
599
  if ( ! $form ) {
600
- $form = FrmForm::getAll(array(), 'name', 1);
601
  } else {
602
  FrmFormsHelper::maybe_get_form( $form );
603
  }
604
 
605
- if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
606
- return $frm_vars['form_params'][$form->id];
 
607
 
608
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
609
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
610
 
611
  $default_values = array(
612
  'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
613
- 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
614
  );
615
 
616
  $values = array();
@@ -619,24 +630,24 @@ class FrmEntriesController {
619
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
620
  }
621
 
622
- if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
623
- foreach ($default_values as $var => $default){
624
- if($var == 'action')
625
- $values[$var] = FrmAppHelper::get_param($action_var, $default);
626
- else
627
- $values[$var] = FrmAppHelper::get_param($var, $default);
628
- unset($var);
629
- unset($default);
 
630
  }
631
- }else{
632
- foreach ($default_values as $var => $default){
633
- $values[$var] = $default;
634
- unset($var);
635
- unset($default);
636
  }
637
  }
638
 
639
- if ( in_array($values['action'], array('create', 'update')) && ( ! isset($_POST) || ( ! isset($_POST['action']) && ! isset($_POST['frm_action']) ) ) ) {
640
  $values['action'] = 'new';
641
  }
642
 
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 ) {
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
 
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;
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
  }
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
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);
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
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);
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 ) {
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 ) {
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'] ) {
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
 
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
  }
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
 
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 ) {
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();
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;
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
 
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();
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;
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
 
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
  }
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);
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();
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
 
classes/controllers/FrmFieldsController.php CHANGED
@@ -1,15 +1,17 @@
1
  <?php
2
 
3
- class FrmFieldsController{
 
 
 
4
 
5
- public static function load_field(){
6
  $fields = $_POST['field'];
7
- if ( empty($fields) ) {
8
- die();
9
  }
10
 
11
  $_GET['page'] = 'formidable';
12
- $fields = stripslashes_deep($fields);
13
 
14
  $ajax = true;
15
  $values = array();
@@ -17,14 +19,14 @@ class FrmFieldsController{
17
  $field_html = array();
18
 
19
  foreach ( $fields as $field ) {
20
- $field = htmlspecialchars_decode(nl2br($field));
21
- $field = json_decode($field, true);
22
- if ( ! isset($field['id']) ) {
23
  // this field may have already been loaded
24
  continue;
25
  }
26
 
27
- $field_id = $field['id'];
28
 
29
  if ( ! isset( $field['value'] ) ) {
30
  $field['value'] = '';
@@ -35,7 +37,7 @@ class FrmFieldsController{
35
 
36
  ob_start();
37
  include($path .'/classes/views/frm-forms/add_field.php');
38
- $field_html[$field_id] = ob_get_contents();
39
  ob_end_clean();
40
  }
41
 
@@ -43,12 +45,14 @@ class FrmFieldsController{
43
 
44
  echo json_encode($field_html);
45
 
46
- die();
47
  }
48
 
49
- public static function create(){
50
- $field_type = $_POST['field'];
51
- $form_id = $_POST['form_id'];
 
 
52
 
53
  $field = self::include_new_field($field_type, $form_id);
54
 
@@ -58,6 +62,9 @@ class FrmFieldsController{
58
  wp_die();
59
  }
60
 
 
 
 
61
  public static function include_new_field($field_type, $form_id) {
62
  $values = array();
63
  if ( FrmAppHelper::pro_is_installed() ) {
@@ -79,68 +86,86 @@ class FrmFieldsController{
79
  public static function update_form_id() {
80
  check_ajax_referer( 'frm_ajax', 'nonce' );
81
 
82
- $field_id = (int) $_POST['field'];
83
- $form_id = (int) $_POST['form_id'];
 
84
  if ( ! $field_id || ! $form_id ) {
85
  return;
86
  }
87
 
88
  FrmField::update( $field_id, compact('form_id') );
89
 
90
- die();
91
  }
92
 
93
  public static function edit_name($field = 'name', $id = '') {
 
 
94
  if ( empty($field) ) {
95
  $field = 'name';
96
  }
97
 
98
  if ( empty($id) ) {
99
- $id = str_replace('field_label_', '', $_POST['element_id']);
 
100
  }
101
 
102
- $value = trim($_POST['update_value']);
 
103
  if ( trim(strip_tags($value)) == '' ) {
104
  // set blank value if there is no content
105
  $value = '';
106
  }
107
 
108
- FrmField::update($id, array($field => $value));
109
  echo stripslashes($value);
110
  wp_die();
111
  }
112
 
113
- public static function update_ajax_option(){
114
- $field = FrmField::getOne($_POST['field']);
115
- foreach ( array('clear_on_focus', 'separate_value', 'default_blank') as $val ) {
116
- if ( isset($_POST[$val]) ) {
117
- $new_val = $_POST[$val];
 
 
 
 
 
 
 
 
 
 
118
  if ( $val == 'separate_value' ) {
119
- $new_val = (isset($field->field_options[$val]) && $field->field_options[$val]) ? 0 : 1;
120
  }
121
 
122
- $field->field_options[$val] = $new_val;
123
  unset($new_val);
124
  }
125
  unset($val);
126
  }
127
 
128
- FrmField::update( $_POST['field'], array(
129
  'field_options' => $field->field_options,
130
- 'form_id' => $field->form_id
131
  ) );
132
- die();
133
  }
134
 
135
- public static function duplicate(){
 
 
136
  global $wpdb;
137
 
138
- $copy_field = FrmField::getOne($_POST['field_id']);
 
139
  if ( ! $copy_field ) {
140
- die();
141
  }
142
 
143
- $form_id = (int) $_POST['form_id'];
144
 
145
  do_action('frm_duplicate_field', $copy_field, $form_id);
146
  do_action('frm_duplicate_field_'. $copy_field->type, $copy_field, $form_id);
@@ -148,22 +173,22 @@ class FrmFieldsController{
148
  $values = array();
149
  FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
150
 
151
- $field_count = $wpdb->get_var( $wpdb->prepare('SELECT COUNT(*) FROM '. $wpdb->prefix .'frm_fields fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id) WHERE fr.id = %d OR fr.parent_form_id = %d', $form_id, $form_id) );
152
 
153
  $values['field_order'] = $field_count + 1;
154
 
155
  if ( ! $field_id = FrmField::create($values) ) {
156
- die();
157
  }
158
 
159
  self::include_single_field($field_id, $values);
160
 
161
- die();
162
  }
163
 
164
- /*
165
- * Load a single field in the form builder along with all needed variables
166
- */
167
  public static function include_single_field( $field_id, $values, $form_id = 0 ) {
168
  $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
169
  $field_name = 'item_meta['. $field_id .']';
@@ -178,23 +203,28 @@ class FrmFieldsController{
178
  return $field;
179
  }
180
 
181
- public static function destroy(){
182
- FrmField::destroy($_POST['field_id']);
183
- die();
 
 
 
184
  }
185
 
186
  /* Field Options */
187
 
188
  //Add Single Option or Other Option
189
- public static function add_option(){
190
- $id = $_POST['field_id'];
191
- $opt_type = $_POST['opt_type'];
 
 
192
 
193
  //Get the field
194
  $field = FrmField::getOne($id);
195
- $options = maybe_unserialize($field->options);
196
- if ( !empty($options) ) {
197
- $keys = array_keys( $options );
198
  $last = str_replace( 'other_', '', end( $keys ) );
199
  } else {
200
  $last = 0;
@@ -202,7 +232,7 @@ class FrmFieldsController{
202
  $opt_key = $last + 1;
203
 
204
  if ( 'other' == $opt_type ) {
205
- $opt = __('Other', 'formidable');
206
  $other_val = '';
207
  $opt_key = 'other_' . $opt_key;
208
 
@@ -211,19 +241,19 @@ class FrmFieldsController{
211
  $field_options['other'] = 1;
212
  FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) );
213
  } else {
214
- $first_opt = reset($options);
215
- $next_opt = count($options);
216
  if ( $first_opt != '' ) {
217
  $next_opt++;
218
  }
219
- $opt = __('Option', 'formidable') .' '. $next_opt;
220
  unset($next_opt);
221
  }
222
  $field_val = $opt;
223
- $options[$opt_key] = $opt;
224
 
225
  //Update options in DB
226
- FrmField::update($id, array('options' => maybe_serialize($options)));
227
 
228
  $field_data = $field;
229
  $field = array(
@@ -234,7 +264,7 @@ class FrmFieldsController{
234
  'field_key' => $field_data->field_key,
235
  );
236
 
237
- $field_name = "item_meta[$id]";
238
  $html_id = FrmFieldsHelper::get_html_id($field);
239
  $checked = '';
240
 
@@ -243,14 +273,18 @@ class FrmFieldsController{
243
  } else {
244
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
245
  }
246
- die();
247
  }
248
 
249
  public static function edit_option() {
250
- $ids = explode('-', $_POST['element_id']);
251
- $id = $_POST['field_id'];
252
- $update_value = trim($_POST['update_value']);
253
- if ( strpos($_POST['element_id'], 'key_') ) {
 
 
 
 
254
  $new_value = $update_value;
255
  } else {
256
  $new_label = $update_value;
@@ -258,14 +292,13 @@ class FrmFieldsController{
258
 
259
  $field = FrmField::getOne($id);
260
  $separate_values = ( isset($field->field_options['separate_value']) && $field->field_options['separate_value'] );
261
- $options = maybe_unserialize($field->options);
262
 
263
  $this_opt_id = end($ids);
264
- $this_opt = (array) $options[$this_opt_id];
265
  $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ? true : false );
266
 
267
  $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
268
- $value = isset($this_opt['value']) ? $this_opt['value'] : '';
269
 
270
  if ( ! isset( $new_label ) ) {
271
  $new_label = $label;
@@ -275,22 +308,27 @@ class FrmFieldsController{
275
  $update_value = isset($new_value) ? $new_value : $value;
276
  }
277
 
278
- if ( $update_value != $new_label && $other_opt == false && $separate_values ) {
279
- $options[$this_opt_id] = array('value' => $update_value, 'label' => $new_label);
280
  } else {
281
- $options[$this_opt_id] = trim($_POST['update_value']);
282
  }
283
 
284
- FrmField::update($field->id, array('options' => $options));
285
- echo (trim($_POST['update_value']) == '') ? __('(Blank)', 'formidable') : stripslashes($_POST['update_value']);
286
- die();
287
  }
288
 
289
- public static function delete_option(){
290
- $field = FrmField::getOne($_POST['field_id']);
291
- $opt_key = $_POST['opt_key'];
292
- $options = maybe_unserialize($field->options);
293
- unset($options[$opt_key]);
 
 
 
 
 
294
  $response = array( 'other' => true );
295
 
296
  //If the deleted option is an "other" option
@@ -313,42 +351,42 @@ class FrmFieldsController{
313
  $field_options = maybe_unserialize( $field->field_options );
314
  $field_options['other'] = 0;
315
  FrmField::update( $_POST['field_id'], array( 'field_options' => maybe_serialize( $field_options ) ) );
316
- $response = array('other' => false );
317
  }
318
  }
319
  echo json_encode( $response );
320
 
321
- FrmField::update($_POST['field_id'], array('options' => maybe_serialize($options)));
322
 
323
- die();
324
  }
325
 
326
- public static function import_choices(){
327
- if ( !current_user_can('frm_edit_forms') ) {
328
- return;
329
  }
330
 
331
- $field_id = $_REQUEST['field_id'];
332
 
333
  global $current_screen, $hook_suffix;
334
 
335
  // Catch plugins that include admin-header.php before admin.php completes.
336
- if ( empty( $current_screen ) && function_exists('set_current_screen') ) {
337
  $hook_suffix = '';
338
  set_current_screen();
339
  }
340
 
341
- if ( function_exists('register_admin_color_schemes') ) {
342
  register_admin_color_schemes();
343
  }
344
 
345
  $hook_suffix = $admin_body_class = '';
346
 
347
- if ( get_user_setting('mfold') == 'f' ) {
348
  $admin_body_class .= ' folded';
349
  }
350
 
351
- if ( function_exists('is_admin_bar_showing') && is_admin_bar_showing() ) {
352
  $admin_body_class .= ' admin-bar';
353
  }
354
 
@@ -358,60 +396,29 @@ class FrmFieldsController{
358
 
359
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
360
  $prepop = array();
361
- self::get_bulk_prefilled_opts($prepop);
362
 
363
  $field = FrmField::getOne($field_id);
364
 
 
 
 
 
365
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
366
- die();
367
  }
368
 
369
- private static function get_bulk_prefilled_opts(array &$prepop) {
370
- $prepop[__('Countries', 'formidable')] = FrmAppHelper::get_countries();
371
-
372
- $states = FrmAppHelper::get_us_states();
373
- $state_abv = array_keys($states);
374
- sort($state_abv);
375
- $prepop[__('U.S. State Abbreviations', 'formidable')] = $state_abv;
376
-
377
- $states = array_values($states);
378
- sort($states);
379
- $prepop[__('U.S. States', 'formidable')] = $states;
380
- unset($state_abv, $states);
381
-
382
- $prepop[__('Age', 'formidable')] = array(
383
- __('Under 18', 'formidable'), __('18-24', 'formidable'), __('25-34', 'formidable'),
384
- __('35-44', 'formidable'), __('45-54', 'formidable'), __('55-64', 'formidable'),
385
- __('65 or Above', 'formidable'), __('Prefer Not to Answer', 'formidable')
386
- );
387
-
388
- $prepop[__('Satisfaction', 'formidable')] = array(
389
- __('Very Satisfied', 'formidable'), __('Satisfied', 'formidable'), __('Neutral', 'formidable'),
390
- __('Unsatisfied', 'formidable'), __('Very Unsatisfied', 'formidable'), __('N/A', 'formidable')
391
- );
392
-
393
- $prepop[__('Importance', 'formidable')] = array(
394
- __('Very Important', 'formidable'), __('Important', 'formidable'), __('Neutral', 'formidable'),
395
- __('Somewhat Important', 'formidable'), __('Not at all Important', 'formidable'), __('N/A', 'formidable')
396
- );
397
-
398
- $prepop[__('Agreement', 'formidable')] = array(
399
- __('Strongly Agree', 'formidable'), __('Agree', 'formidable'), __('Neutral', 'formidable'),
400
- __('Disagree', 'formidable'), __('Strongly Disagree', 'formidable'), __('N/A', 'formidable')
401
- );
402
-
403
- $prepop = apply_filters('frm_bulk_field_choices', $prepop);
404
- }
405
 
406
- public static function import_options(){
407
  if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
408
  return;
409
  }
410
 
411
- $field_id = $_POST['field_id'];
412
  $field = FrmField::getOne($field_id);
413
 
414
- if ( ! in_array($field->type, array('radio', 'checkbox', 'select')) ) {
415
  return;
416
  }
417
 
@@ -423,7 +430,7 @@ class FrmFieldsController{
423
  if ( strpos($opt, '|') !== false ) {
424
  $vals = explode('|', $opt);
425
  if ( $vals[0] != $vals[1] ) {
426
- $opts[$opt_key] = array('label' => trim($vals[0]), 'value' => trim($vals[1]));
427
  }
428
  unset($vals);
429
  }
@@ -436,7 +443,7 @@ class FrmFieldsController{
436
  $other_array = array();
437
  foreach ( $field['options'] as $opt_key => $opt ) {
438
  if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
439
- $other_array[$opt_key] = $opt;
440
  }
441
  unset($opt_key, $opt);
442
  }
@@ -450,32 +457,37 @@ class FrmFieldsController{
450
  $field['options'] = $opts;
451
  $field_name = $field['name'];
452
 
 
 
 
453
  if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
454
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
455
  } else {
456
  FrmFieldsHelper::show_single_option($field);
457
  }
458
 
459
- die();
460
  }
461
 
462
- public static function update_order(){
 
463
  if ( isset($_POST) && isset($_POST['frm_field_id']) ) {
464
- foreach ($_POST['frm_field_id'] as $position => $item)
465
- FrmField::update($item, array('field_order' => $position));
 
466
  }
467
- die();
468
  }
469
 
470
- public static function change_type($type){
471
  $type_switch = array(
472
  'scale' => 'radio',
473
  '10radio' => 'radio',
474
  'rte' => 'textarea',
475
  'website' => 'url',
476
  );
477
- if ( isset($type_switch[$type]) ) {
478
- $type = $type_switch[$type];
479
  }
480
 
481
  $frm_field_selection = FrmFieldsHelper::field_selection();
@@ -487,8 +499,8 @@ class FrmFieldsController{
487
  return $type;
488
  }
489
 
490
- public static function display_field_options($display){
491
- switch($display['type']){
492
  case 'captcha':
493
  $display['required'] = false;
494
  $display['invalid'] = true;
@@ -516,7 +528,7 @@ class FrmFieldsController{
516
  return $display;
517
  }
518
 
519
- public static function input_html($field, $echo=true){
520
  $class = array(); //$field['type'];
521
  self::add_input_classes($field, $class);
522
 
@@ -543,8 +555,12 @@ class FrmFieldsController{
543
  }
544
 
545
  private static function add_input_classes($field, array &$class) {
 
 
 
 
546
  global $frm_vars;
547
- if ( is_admin() && ! FrmAppHelper::is_preview_page() && ! in_array($field['type'], array('scale', 'radio', 'checkbox', 'data')) ) {
548
  $class[] = 'dyn_default_value';
549
  }
550
 
@@ -558,11 +574,11 @@ class FrmFieldsController{
558
  }
559
 
560
  private static function add_html_size($field, array &$add_html) {
561
- if ( ! isset($field['size']) || $field['size'] <= 0 || in_array($field['type'], array('select', 'data', 'time', 'hidden')) ) {
562
  return;
563
  }
564
 
565
- if ( FrmAppHelper::is_admin_page('formidable') ) {
566
  return;
567
  }
568
 
@@ -571,13 +587,14 @@ class FrmFieldsController{
571
  }
572
 
573
  $important = apply_filters('frm_use_important_width', 1, $field);
574
- $add_html['style'] = 'style="width:'. $field['size'] . ( $important ? ' !important' : '' ) .'"';
 
575
 
576
  self::add_html_cols($field, $add_html);
577
  }
578
 
579
  private static function add_html_cols($field, array &$add_html) {
580
- if ( ! in_array($field['type'], array('textarea', 'rte')) ) {
581
  return;
582
  }
583
 
@@ -592,22 +609,22 @@ class FrmFieldsController{
592
  // include "col" for valid html
593
  $unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
594
 
595
- if ( ! isset($calc[$unit]) ) {
596
  return;
597
  }
598
 
599
- $size = (float) str_replace($unit, '', $field['size']) / $calc[$unit];
600
 
601
  $add_html['cols'] = 'cols="'. (int) $size .'"';
602
  }
603
 
604
  private static function add_html_length($field, array &$add_html) {
605
  // check for max setting and if this field accepts maxlength
606
- if ( ! isset($field['max']) || empty($field['max']) || in_array( $field['type'], array('textarea', 'rte', 'hidden') ) ) {
607
  return;
608
  }
609
 
610
- if ( FrmAppHelper::is_admin_page('formidable') ) {
611
  // don't load on form builder page
612
  return;
613
  }
@@ -622,18 +639,18 @@ class FrmFieldsController{
622
  }
623
 
624
  // don't apply this to the form builder page
625
- if ( FrmAppHelper::is_admin_page('formidable') ) {
626
  return;
627
  }
628
 
629
  $frm_settings = FrmAppHelper::get_settings();
630
 
631
- if ( $frm_settings->use_html && ! in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden')) ) {
632
  // use HMTL5 placeholder with js fallback
633
  $add_html['placeholder'] = 'placeholder="'. esc_attr($field['default_value']) .'"';
634
  wp_enqueue_script('jquery-placeholder');
635
  } else if ( ! $frm_settings->use_html ) {
636
- $val = str_replace(array("\r\n", "\n"), '\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
637
  $add_html['data-frmval'] = 'data-frmval="'. esc_attr($val) .'"';
638
  $class[] = 'frm_toggle_default';
639
 
@@ -643,8 +660,8 @@ class FrmFieldsController{
643
  }
644
  }
645
 
646
- private static function add_shortcodes_to_html($field, array &$add_html) {
647
- if ( ! isset($field['shortcodes']) || empty($field['shortcodes']) ) {
648
  return;
649
  }
650
 
@@ -655,28 +672,28 @@ class FrmFieldsController{
655
 
656
  if ( is_numeric($k) && strpos($v, '=') ) {
657
  $add_html[] = $v;
658
- } else if ( ! empty($k) && isset($add_html[$k]) ) {
659
- $add_html[$k] = str_replace($k .'="', $k .'="'. $v, $add_html[$k]);
660
  } else {
661
- $add_html[$k] = $k .'="'. $v .'"';
662
  }
663
 
664
  unset($k, $v);
665
  }
666
  }
667
 
668
- public static function check_value($opt, $opt_key, $field){
669
- if(is_array($opt)){
670
- if ( isset($field['separate_value']) && $field['separate_value'] ) {
671
- $opt = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
672
  } else {
673
- $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
674
  }
675
  }
676
  return $opt;
677
  }
678
 
679
- public static function check_label($opt){
680
  if ( is_array($opt) ) {
681
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
682
  }
@@ -686,7 +703,7 @@ class FrmFieldsController{
686
 
687
  public static function add_conditional_update_msg() {
688
  echo '<tr><td colspan="2">';
689
- FrmAppHelper::update_message('calculate and conditionally hide and show fields');
690
  echo '</td></tr>';
691
  }
692
  }
1
  <?php
2
 
3
+ class FrmFieldsController {
4
+
5
+ public static function load_field() {
6
+ check_ajax_referer( 'frm_ajax', 'nonce' );
7
 
 
8
  $fields = $_POST['field'];
9
+ if ( empty( $fields ) ) {
10
+ wp_die();
11
  }
12
 
13
  $_GET['page'] = 'formidable';
14
+ $fields = stripslashes_deep( $fields );
15
 
16
  $ajax = true;
17
  $values = array();
19
  $field_html = array();
20
 
21
  foreach ( $fields as $field ) {
22
+ $field = htmlspecialchars_decode( nl2br( $field ) );
23
+ $field = json_decode( $field, true );
24
+ if ( ! isset( $field['id'] ) ) {
25
  // this field may have already been loaded
26
  continue;
27
  }
28
 
29
+ $field_id = absint( $field['id'] );
30
 
31
  if ( ! isset( $field['value'] ) ) {
32
  $field['value'] = '';
37
 
38
  ob_start();
39
  include($path .'/classes/views/frm-forms/add_field.php');
40
+ $field_html[ $field_id ] = ob_get_contents();
41
  ob_end_clean();
42
  }
43
 
45
 
46
  echo json_encode($field_html);
47
 
48
+ wp_die();
49
  }
50
 
51
+ public static function create() {
52
+ check_ajax_referer( 'frm_ajax', 'nonce' );
53
+
54
+ $field_type = FrmAppHelper::get_post_param( 'field', '', 'sanitize_text_field' );
55
+ $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
56
 
57
  $field = self::include_new_field($field_type, $form_id);
58
 
62
  wp_die();
63
  }
64
 
65
+ /**
66
+ * @param integer $form_id
67
+ */
68
  public static function include_new_field($field_type, $form_id) {
69
  $values = array();
70
  if ( FrmAppHelper::pro_is_installed() ) {
86
  public static function update_form_id() {
87
  check_ajax_referer( 'frm_ajax', 'nonce' );
88
 
89
+ $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
90
+ $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
91
+
92
  if ( ! $field_id || ! $form_id ) {
93
  return;
94
  }
95
 
96
  FrmField::update( $field_id, compact('form_id') );
97
 
98
+ wp_die();
99
  }
100
 
101
  public static function edit_name($field = 'name', $id = '') {
102
+ check_ajax_referer( 'frm_ajax', 'nonce' );
103
+
104
  if ( empty($field) ) {
105
  $field = 'name';
106
  }
107
 
108
  if ( empty($id) ) {
109
+ $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
110
+ $id = str_replace( 'field_label_', '', $id );
111
  }
112
 
113
+ $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' );
114
+ $value = trim( $value );
115
  if ( trim(strip_tags($value)) == '' ) {
116
  // set blank value if there is no content
117
  $value = '';
118
  }
119
 
120
+ FrmField::update( $id, array( $field => $value ) );
121
  echo stripslashes($value);
122
  wp_die();
123
  }
124
 
125
+ public static function update_ajax_option() {
126
+ check_ajax_referer( 'frm_ajax', 'nonce' );
127
+
128
+ $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
129
+ if ( ! $field_id ) {
130
+ wp_die();
131
+ }
132
+
133
+ $field = FrmField::getOne( $field_id );
134
+
135
+ foreach ( array( 'clear_on_focus', 'separate_value', 'default_blank' ) as $val ) {
136
+ if ( isset($_POST[ $val ]) ) {
137
+ // all three of these options are boolean
138
+ $new_val = FrmAppHelper::get_post_param( $val, 0, 'absint' );
139
+
140
  if ( $val == 'separate_value' ) {
141
+ $new_val = ( isset( $field->field_options[ $val ] ) && $field->field_options[ $val ] ) ? 0 : 1;
142
  }