Formidable Forms – Form Builder for WordPress - Version 1.07.11

Version Description

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

Release Info

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

Code changes from version 2.0rc9 to 1.07.11

Files changed (76) hide show
  1. classes/controllers/FrmAppController.php +370 -331
  2. classes/controllers/FrmEntriesController.php +368 -593
  3. classes/controllers/FrmFieldsController.php +382 -560
  4. classes/controllers/FrmFormActionsController.php +0 -353
  5. classes/controllers/FrmFormsController.php +580 -833
  6. classes/controllers/FrmHooksController.php +0 -200
  7. classes/controllers/FrmSettingsController.php +60 -41
  8. classes/controllers/FrmStatisticsController.php +27 -15
  9. classes/controllers/FrmStylesController.php +0 -434
  10. classes/controllers/FrmXMLController.php +220 -188
  11. classes/helpers/FrmAppHelper.php +602 -1473
  12. classes/helpers/FrmEntriesHelper.php +134 -664
  13. classes/helpers/FrmEntriesListHelper.php +0 -264
  14. classes/helpers/FrmFieldsHelper.php +333 -1001
  15. classes/helpers/FrmFormActionsHelper.php +0 -107
  16. classes/helpers/FrmFormsHelper.php +189 -475
  17. classes/helpers/FrmFormsListHelper.php +0 -370
  18. classes/helpers/FrmListHelper.php +206 -9
  19. classes/helpers/FrmStylesHelper.php +0 -193
  20. classes/helpers/FrmXMLHelper.php +118 -775
  21. classes/models/FrmDb.php +207 -537
  22. classes/models/FrmEntry.php +337 -565
  23. classes/models/FrmEntryMeta.php +180 -253
  24. classes/models/FrmField.php +175 -359
  25. classes/models/FrmForm.php +176 -392
  26. classes/models/FrmFormAction.php +0 -529
  27. classes/models/FrmNotification.php +92 -345
  28. classes/models/FrmSettings.php +94 -186
  29. classes/models/FrmStyle.php +0 -437
  30. classes/recaptchalib.php +274 -0
  31. classes/views/frm-entries/_sidebar-shared-pub.php +0 -21
  32. classes/views/frm-entries/direct.php +11 -7
  33. classes/views/frm-entries/errors.php +31 -42
  34. classes/views/frm-entries/form.php +33 -30
  35. classes/views/frm-entries/frm-entry.php +52 -0
  36. classes/views/frm-entries/list.php +26 -29
  37. classes/views/frm-entries/new.php +8 -8
  38. classes/views/frm-entries/no_entries.php +47 -17
  39. classes/views/frm-entries/show.php +0 -74
  40. classes/views/frm-entries/sidebar-shared.php +0 -84
  41. classes/views/frm-entries/sidebar-show.php +0 -38
  42. classes/views/frm-fields/import_choices.php +58 -30
  43. classes/views/frm-fields/input.php +65 -114
  44. classes/views/frm-fields/radio.php +9 -19
  45. classes/views/frm-fields/show-build.php +0 -64
  46. classes/views/frm-fields/show.php +1 -4
  47. classes/views/frm-fields/single-option.php +15 -11
  48. classes/views/frm-form-actions/_action_inside.php +0 -57
  49. classes/views/frm-form-actions/_email_settings.php +0 -64
  50. classes/views/frm-form-actions/default_actions.php +0 -65
  51. classes/views/frm-form-actions/email_action.php +0 -40
  52. classes/views/frm-form-actions/form_action.php +0 -40
  53. classes/views/frm-forms/_publish_box.php +0 -110
  54. classes/views/frm-forms/add_field.php +233 -252
  55. classes/views/frm-forms/add_field_links.php +104 -150
  56. classes/views/frm-forms/default-templates.php +47 -0
  57. classes/views/frm-forms/edit.php +31 -26
  58. classes/views/frm-forms/form.php +14 -42
  59. classes/views/frm-forms/insert_form_popup.php +66 -46
  60. classes/views/frm-forms/list.php +11 -18
  61. classes/views/frm-forms/mb_html_tab.php +31 -30
  62. classes/views/frm-forms/mb_insert_fields.php +20 -4
  63. classes/views/frm-forms/new-field-js.php +1 -1
  64. classes/views/frm-forms/new-selection.php +56 -0
  65. classes/views/frm-forms/new.php +35 -20
  66. classes/views/frm-forms/notification.php +94 -0
  67. classes/views/frm-forms/settings.php +129 -189
  68. classes/views/frm-forms/shortcode_opts.php +0 -41
  69. classes/views/frm-forms/sidebar-settings.php +31 -9
  70. classes/views/frm-settings/form.php +112 -121
  71. classes/views/frm-settings/license_box.php +6 -6
  72. classes/views/frm-settings/styling_tab.php +4 -0
  73. classes/views/frm-statistics/list.php +9 -11
  74. classes/views/frm-statistics/list_displays.php +8 -10
  75. classes/views/shared/errors.php +4 -16
  76. classes/views/shared/form-nav.php +1 -15
classes/controllers/FrmAppController.php CHANGED
@@ -1,443 +1,482 @@
1
  <?php
2
-
3
- class FrmAppController {
4
-
5
- public static function menu() {
6
- add_filter( 'plugin_action_links_'. FrmAppHelper::plugin_folder() .'/formidable.php', 'FrmAppController::settings_link' );
7
- add_filter( 'admin_body_class', 'FrmAppController::wp_admin_body_class' );
8
-
9
- FrmAppHelper::maybe_add_permissions();
10
-
11
- if ( ! current_user_can( 'frm_view_forms' ) ) {
12
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
14
-
15
- $count = count( get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) );
16
- $pos = ( (int) $count > 0 ) ? '22.7' : '29.3';
17
- $pos = apply_filters( 'frm_menu_position', $pos );
18
-
19
- $frm_settings = FrmAppHelper::get_settings();
20
- add_menu_page( 'Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos );
 
 
 
 
 
21
  }
22
-
23
- public static function load_wp_admin_style() {
24
- wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version() );
25
  }
26
-
27
- public static function get_form_nav( $form, $show_nav = '', $title = 'show' ) {
28
  global $pagenow, $frm_vars;
29
-
30
- $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav );
31
- if ( empty($show_nav) ) {
32
  return;
 
 
 
 
 
 
 
 
33
  }
34
-
35
- $current_page = isset( $_GET['page'] ) ? FrmAppHelper::simple_get( 'page', 'sanitize_title' ) : ( isset( $_GET['post_type'] ) ? FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ) : 'None' );
36
-
37
- if ( $form ) {
38
- FrmFormsHelper::maybe_get_form( $form );
39
-
40
- if ( is_object( $form ) ) {
41
- $id = $form->id;
42
- }
43
- }
44
-
45
- if ( ! isset($id) ) {
46
- $form = $id = false;
47
- }
48
-
49
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
50
  }
51
 
52
  // Adds a settings link to the plugins page
53
- public static function settings_link($links) {
54
- $settings = '<a href="'. admin_url( 'admin.php?page=formidable-settings' ) .'">' . __( 'Settings', 'formidable' ) . '</a>';
55
- array_unshift( $links, $settings );
56
-
57
  return $links;
58
  }
59
-
60
  public static function update_action_links( $actions, $plugin ) {
61
- $frm_plugin = FrmAppHelper::plugin_folder() .'/formidable.php';
62
- if ( $frm_plugin != $plugin ) {
63
  return $actions;
64
- }
65
-
66
- $db_version = get_option( 'frm_db_version' );
67
- $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
68
-
 
69
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
70
- ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
71
-
72
- return '<a href="'. add_query_arg( array( 'upgraded' => 'true' ), menu_page_url( 'formidable', 0 ) ) .'">'. __( 'Click here to complete the upgrade', 'formidable' ) .'</a>';
73
-
 
 
74
  }
75
-
76
- return $actions;
77
  }
78
 
79
- public static function pro_get_started_headline() {
80
- if ( FrmAppHelper::is_admin_page( 'formidable' ) && isset( $_REQUEST['upgraded'] ) && 'true' == sanitize_title( $_REQUEST['upgraded'] ) ) {
81
  self::install();
82
  ?>
83
- <div id="message" class="frm_message updated"><?php _e( 'Congratulations! Formidable is ready to roll.', 'formidable' ) ?></div>
84
  <?php
85
  return;
86
  }
87
-
88
  // Don't display this error as we're upgrading the thing... cmon
89
- if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) ) {
90
  return;
91
- }
92
-
93
- if ( is_multisite() && ! current_user_can( 'administrator' ) ) {
94
  return;
95
  }
96
-
97
- if ( ! isset($_GET['activate']) ) {
98
- $db_version = get_option( 'frm_db_version' );
99
- $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
 
100
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
101
- ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
102
- FrmAppHelper::load_admin_wide_js();
103
  ?>
104
- <div class="error" id="frm_install_message"><?php echo wp_kses_post( sprintf( __( 'Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or %1$s', 'formidable' ), '<a href="#" id="frm_install_link">'. esc_html( __( 'Update Now', 'formidable' ) ) .'</a>') ); ?> </div>
 
 
 
 
 
 
 
 
 
 
105
  <?php
106
  }
107
  }
108
-
109
- global $frm_vars;
110
- if ( $frm_vars['pro_is_authorized'] && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) {
111
- FrmAppHelper::load_admin_wide_js();
112
-
113
  // user is authorized, but running free version
114
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
115
  ?>
116
- <div class="error" class="frm_previous_install">
117
- <?php
118
- echo wp_kses_post( apply_filters( 'frm_pro_update_msg',
119
- sprintf(
120
- __( 'This site has been previously authorized to run Formidable Forms.<br/>%1$sInstall the pro version%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
121
- '<a href="' . esc_url( $inst_install_url ) . '" target="_blank">', '</a>',
122
- '<a href="#" class="frm_deauthorize_link">', '</a>'
123
- ), esc_url( $inst_install_url )
124
- ) ); ?>
125
- </div>
126
- <?php
 
 
127
  }
128
  }
129
-
130
- public static function admin_js() {
131
  global $pagenow;
132
-
133
- $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
134
- if ( 'admin-ajax.php' == $pagenow && $action != 'frm_import_choices' ) {
135
  return;
136
  }
137
- unset( $action );
138
-
139
- $version = FrmAppHelper::plugin_version();
140
- FrmAppHelper::load_admin_wide_js( false );
141
-
142
- wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array(
143
- 'formidable_admin_global', 'formidable', 'jquery',
144
- 'jquery-ui-core', 'jquery-ui-draggable',
145
- 'jquery-ui-sortable',
146
- 'bootstrap_tooltip', 'bootstrap-multiselect',
147
- ), $version, true );
148
- wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version );
149
- wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array( 'jquery' ), '3.3.2' );
150
-
151
- // load multselect js
152
- wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() .'/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
153
-
154
- $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
155
- $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
156
- if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
157
- add_filter( 'admin_body_class', 'FrmAppController::admin_body_class' );
158
-
159
- wp_enqueue_script( 'admin-widgets' );
160
- wp_enqueue_style( 'widgets' );
161
- wp_enqueue_script( 'formidable' );
162
- wp_enqueue_script( 'formidable_admin' );
163
- self::localize_script( 'admin' );
164
-
165
- wp_enqueue_style( 'formidable-admin' );
166
  add_thickbox();
167
-
168
- wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
169
-
170
- } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
171
- if ( isset($_REQUEST['post_type']) ) {
172
- $post_type = sanitize_title( $_REQUEST['post_type'] );
173
- } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
174
- $post = get_post( absint( $_REQUEST['post'] ) );
175
- if ( ! $post ) {
 
 
176
  return;
177
- }
178
  $post_type = $post->post_type;
179
- } else {
180
  return;
181
  }
182
-
183
- if ( $post_type == 'frm_display' ) {
184
- wp_enqueue_script( 'jquery-ui-draggable' );
185
- wp_enqueue_script( 'formidable_admin' );
186
- wp_enqueue_style( 'formidable-admin' );
187
- self::localize_script( 'admin' );
 
188
  }
189
- } else if ( $pagenow == 'widgets.php' ) {
190
- FrmAppHelper::load_admin_wide_js();
191
  }
192
  }
193
-
194
- public static function admin_body_class( $classes ) {
195
  global $wp_version;
196
-
197
  //we only need this class on Formidable pages
198
- if ( version_compare( $wp_version, '3.4.9', '>' ) ) {
199
  $classes .= ' frm_35_trigger';
200
- }
201
-
202
  return $classes;
203
  }
204
-
205
- public static function wp_admin_body_class( $classes ) {
206
  global $wp_version;
207
  //we need this class everywhere in the admin for the menu
208
- if ( version_compare( $wp_version, '3.7.2', '>' ) ) {
209
  $classes .= ' frm_38_trigger';
210
- }
211
-
212
  return $classes;
213
  }
214
-
215
- public static function load_lang() {
216
- load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() .'/languages/' );
217
- }
218
-
219
- /**
220
- * Filter shortcodes in text widgets
221
- */
222
- public static function widget_text_filter( $content ) {
223
- $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
224
- return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
225
- }
226
-
227
- public static function widget_text_filter_callback( $matches ) {
228
- _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::widget_text_filter_callback' );
229
- return FrmAppHelper::widget_text_filter_callback( $matches );
230
  }
 
 
 
231
 
232
- public static function front_head() {
233
- if ( is_multisite() ) {
234
- $old_db_version = get_option( 'frm_db_version' );
235
- $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false;
236
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
237
- ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
238
- self::install( $old_db_version );
239
  }
240
  }
241
-
242
  $version = FrmAppHelper::plugin_version();
243
- wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array( 'jquery' ), $version, true );
244
- wp_register_script( 'jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array( 'jquery' ), '2.0.7', true );
245
-
246
- if ( FrmAppHelper::is_admin() ) {
 
247
  // don't load this in back-end
248
  return;
249
  }
250
-
251
- self::localize_script( 'front' );
252
-
253
- $frm_settings = FrmAppHelper::get_settings();
254
-
255
- $style = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
256
- if ( $style ) {
257
- foreach ( (array) $style as $k => $file ) {
258
- wp_register_style( $k, $file, array(), $version );
259
  if ( 'all' == $frm_settings->load_style ) {
260
- wp_enqueue_style( $k );
261
  }
262
- unset( $k, $file );
263
  }
264
  }
265
- unset( $style );
266
-
267
- if ( $frm_settings->load_style == 'all' ) {
268
  global $frm_vars;
269
  $frm_vars['css_loaded'] = true;
270
  }
271
  }
272
-
273
- /**
274
- * @param string $location
275
- */
276
- public static function localize_script($location) {
277
  wp_localize_script('formidable', 'frm_js', array(
278
  'ajax_url' => admin_url( 'admin-ajax.php' ),
279
  'images_url' => FrmAppHelper::plugin_url() .'/images',
280
- 'loading' => __( 'Loading&hellip;' ),
281
- 'remove' => __( 'Remove', 'formidable' ),
282
- 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
283
- 'nonce' => wp_create_nonce( 'frm_ajax' ),
284
- 'id' => __( 'ID', 'formidable' ),
285
  ));
286
-
287
- if ( $location == 'admin' ) {
288
- $frm_settings = FrmAppHelper::get_settings();
289
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
290
- 'confirm_uninstall' => __( 'Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable' ),
291
- 'desc' => __( '(Click to add description)', 'formidable' ),
292
- 'blank' => __( '(blank)', 'formidable' ),
293
- 'no_label' => __( '(no label)', 'formidable' ),
294
- 'saving' => esc_attr( __( 'Saving', 'formidable' ) ),
295
- 'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
296
- 'ok' => __( 'OK' ),
297
- 'cancel' => __( 'Cancel', 'formidable' ),
298
- 'default' => __( 'Default', 'formidable' ),
299
- 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
300
- 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
301
- 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
302
- 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
303
- 'confirm' => __( 'Are you sure?', 'formidable' ),
304
- 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
305
- 'conf_delete_sec' => __( 'WARNING: This will delete all fields inside of the section as well.', 'formidable' ),
306
- 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
307
  'default_unique' => $frm_settings->unique_msg,
308
- 'default_conf' => __( 'The entered values do not match', 'formidable' ),
309
- 'enter_email' => __( 'Enter Email', 'formidable' ),
310
- 'confirm_email' => __( 'Confirm Email', 'formidable' ),
311
- 'enter_password' => __( 'Enter Password', 'formidable' ),
312
- 'confirm_password' => __( 'Confirm Password', 'formidable' ),
313
- 'import_complete' => __( 'Import Complete', 'formidable' ),
314
- 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
315
- 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
316
- 'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
317
- ) );
318
- }
319
- }
320
-
321
-
322
- public static function custom_stylesheet() {
323
- global $frm_vars;
324
- $css_file = array();
325
-
326
- if ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) {
327
- //include css in head
328
- $uploads = FrmStylesHelper::get_upload_base();
329
- if ( is_readable( $uploads['basedir'] .'/formidable/css/formidablepro.css' ) ) {
330
- $css_file['formidable'] = $uploads['baseurl'] .'/formidable/css/formidablepro.css';
331
- } else {
332
- $css_file['formidable'] = admin_url( 'admin-ajax.php' ) . '?action=frmpro_css';
333
- }
334
- }
335
-
336
- if ( isset($frm_vars['datepicker_loaded']) && ! empty($frm_vars['datepicker_loaded']) ) {
337
- FrmStylesHelper::enqueue_jquery_css();
338
  }
339
-
340
- return $css_file;
341
- }
342
-
343
- public static function load_css() {
344
- $css = get_transient( 'frmpro_css' );
345
-
346
- include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
347
- wp_die();
348
  }
349
-
350
- public static function footer_js( $location = 'footer' ) {
351
- global $frm_vars;
352
-
353
- $frm_settings = FrmAppHelper::get_settings();
354
- if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
355
- $css = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
356
-
357
- if ( ! empty( $css ) ) {
358
- foreach ( (array) $css as $css_key => $file ) {
359
- wp_enqueue_style( $css_key );
360
- unset( $css_key, $file );
 
 
 
 
 
361
  }
 
 
 
362
  }
363
- unset( $css );
364
  }
365
 
366
- if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
367
- //load formidable js
368
- wp_enqueue_script( 'formidable' );
369
- }
370
  }
371
-
372
- public static function activation_install() {
373
- FrmAppHelper::delete_cache_and_transient( 'frm_plugin_version' );
374
- FrmFormActionsController::actions_init();
375
- self::install();
376
  }
377
-
378
- public static function install( $old_db_version = false ) {
379
- $frmdb = new FrmDb();
380
- $frmdb->upgrade( $old_db_version );
381
- }
382
-
383
- public static function uninstall() {
384
  check_ajax_referer( 'frm_ajax', 'nonce' );
385
-
386
- if ( current_user_can( 'administrator' ) ) {
387
- $frmdb = new FrmDb();
388
  $frmdb->uninstall();
389
  echo true;
390
  } else {
391
- $frm_settings = FrmAppHelper::get_settings();
392
- wp_die( $frm_settings->admin_permission );
393
  }
394
- wp_die();
395
  }
396
-
397
- public static function drop_tables($tables) {
398
- global $wpdb;
399
- $tables[] = $wpdb->prefix .'frm_fields';
400
- $tables[] = $wpdb->prefix .'frm_forms';
401
- $tables[] = $wpdb->prefix .'frm_items';
402
- $tables[] = $wpdb->prefix .'frm_item_metas';
403
- return $tables;
404
- }
405
-
406
  // Routes for wordpress pages -- we're just replacing content here folks.
407
- public static function page_route($content) {
408
- global $post;
409
 
410
- $frm_settings = FrmAppHelper::get_settings();
411
- if ( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form']) ) {
412
  $content = FrmFormsController::page_preview();
413
  }
414
 
415
  return $content;
416
  }
417
-
418
- public static function update_message($features) {
419
- _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
420
- return FrmAppHelper::update_message( $features );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  }
422
 
423
- public static function deauthorize() {
424
- check_ajax_referer( 'frm_ajax', 'nonce' );
425
-
426
- delete_option( 'frmpro-credentials' );
427
- delete_option( 'frmpro-authorized' );
428
- delete_site_option( 'frmpro-credentials' );
429
- delete_site_option( 'frmpro-authorized' );
430
- wp_die();
 
 
 
 
 
 
 
 
 
431
  }
432
-
433
  //formidable shortcode
434
- public static function get_form_shortcode( $atts ) {
435
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
436
- return FrmFormsController::get_form_shortcode( $atts );
437
  }
438
 
439
- public static function get_postbox_class() {
440
- _deprecated_function( __FUNCTION__, '2.0' );
441
- return 'postbox-container';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  }
443
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
6
+
7
+ if(class_exists('FrmAppController'))
8
+ return;
9
+
10
+ class FrmAppController{
11
+ public static function load_hooks(){
12
+ add_action('admin_menu', 'FrmAppController::menu', 1);
13
+ add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
14
+ add_filter('plugin_action_links_formidable/formidable.php', 'FrmAppController::settings_link', 10, 2 );
15
+ add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
16
+ add_action('admin_notices', 'FrmAppController::pro_get_started_headline');
17
+ add_filter('the_content', 'FrmAppController::page_route', 10);
18
+ add_action('plugins_loaded', 'FrmAppController::load_lang');
19
+ add_action('init', 'FrmAppController::front_head');
20
+ add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
21
+ add_action('admin_init', 'FrmAppController::admin_js', 11);
22
+ register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::install');
23
+ add_action('wp_ajax_frm_install', 'FrmAppController::install');
24
+ add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall');
25
+ add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize');
26
+
27
+ // Used to process standalone requests
28
+ add_action('init', 'FrmAppController::parse_standalone_request', 40);
29
+ // Update the session data
30
+ add_action('init', 'FrmAppController::referer_session', 1);
31
+ }
32
+
33
+ public static function menu(){
34
+ global $frm_vars, $frm_settings;
35
+
36
+ if ( current_user_can('administrator') && !current_user_can('frm_view_forms') ) {
37
+ global $current_user;
38
+ $frm_roles = FrmAppHelper::frm_capabilities();
39
+ foreach($frm_roles as $frm_role => $frm_role_description)
40
+ $current_user->add_cap( $frm_role );
41
+ unset($frm_roles);
42
+ unset($frm_role);
43
+ unset($frm_role_description);
44
  }
45
+
46
+ $count = count(get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ));
47
+ $pos = ((int)$count > 0) ? '22.7' : '29.3';
48
+ $pos = apply_filters('frm_menu_position', $pos);
49
+
50
+ if(current_user_can('frm_view_forms')){
51
+ add_menu_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
52
+ }else if(current_user_can('frm_view_entries') and $frm_vars['pro_is_installed']){
53
+ add_menu_page('Formidable', $frm_settings->menu, 'frm_view_entries', 'formidable', 'FrmProEntriesController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
54
+ }
55
+
56
+ add_filter('admin_body_class', 'FrmAppController::wp_admin_body_class');
57
  }
58
+
59
+ public static function load_wp_admin_style(){
60
+ wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version());
61
  }
62
+
63
+ public static function get_form_nav($id, $show_nav=false){
64
  global $pagenow, $frm_vars;
65
+
66
+ $show_nav = FrmAppHelper::get_param('show_nav', $show_nav);
67
+ if(!$show_nav)
68
  return;
69
+
70
+ $current_page = (isset($_GET['page'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None');
71
+ if($id and is_numeric($id)){
72
+ $frm_form = new FrmForm();
73
+ $form = $frm_form->getOne($id);
74
+ unset($frm_form);
75
+ }else{
76
+ $form = false;
77
  }
78
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
80
  }
81
 
82
  // Adds a settings link to the plugins page
83
+ public static function settings_link($links, $file){
84
+ $settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>';
85
+ array_unshift($links, $settings);
86
+
87
  return $links;
88
  }
89
+
90
  public static function update_action_links( $actions, $plugin ) {
91
+
92
+ if ( 'formidable/formidable.php' != $plugin )
93
  return $actions;
94
+
95
+ global $frm_vars;
96
+
97
+ $db_version = get_option('frm_db_version');
98
+ $pro_db_version = $frm_vars['pro_is_installed'] ? get_option('frmpro_db_version') : false;
99
+
100
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
101
+ ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
102
+
103
+ return sprintf( '<a href="%s">%s</a>', add_query_arg(array('upgraded' => 'true'), menu_page_url( 'formidable', 0 )), __( 'Click here to complete the upgrade', 'formidable' ) );
104
+
105
+ } else {
106
+ return $actions;
107
  }
 
 
108
  }
109
 
110
+ public static function pro_get_started_headline(){
111
+ if ( isset($_GET['page']) && 'formidable' == $_GET['page'] && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) {
112
  self::install();
113
  ?>
114
+ <div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div>
115
  <?php
116
  return;
117
  }
118
+
119
  // Don't display this error as we're upgrading the thing... cmon
120
+ if(isset($_GET['action']) and $_GET['action'] == 'upgrade-plugin')
121
  return;
122
+
123
+ if ( is_multisite() && !current_user_can('administrator') ) {
 
124
  return;
125
  }
126
+
127
+ if(!isset($_GET['activate'])){
128
+ global $frm_vars;
129
+ $db_version = get_option('frm_db_version');
130
+ $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false;
131
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
132
+ ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
 
133
  ?>
134
+ <div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or', 'formidable'); ?> <a id="frm_install_link" href="javascript:void(0)"><?php _e('Update Now', 'formidable') ?></a></div>
135
+ <script type="text/javascript">
136
+ jQuery(document).ready(function($){ $('#frm_install_link').click(frm_install_now); });
137
+ function frm_install_now(){
138
+ jQuery('#frm_install_message').html('<div style="line-height:24px;"><?php _e("Please wait while your site updates.", "formidable") ?><div class="spinner frm_spinner" style="float:left;display:block;"></div></div>');
139
+ jQuery.ajax({
140
+ type:"POST",url:ajaxurl,data:"action=frm_install",
141
+ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
142
+ });
143
+ }
144
+ </script>
145
  <?php
146
  }
147
  }
148
+
149
+ if ( self::pro_is_authorized() && !self::pro_is_installed()) {
 
 
 
150
  // user is authorized, but running free version
151
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
152
  ?>
153
+ <div class="error" style="padding:7px;"><?php echo apply_filters('frm_pro_update_msg', sprintf(__('This site has been previously authorized to run Formidable Pro.<br/>%1$sInstall the pro version%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable'), '<a href="'. $inst_install_url .'" target="_blank">', '</a>', '<a href="javascript:void(0)" onclick="frm_deauthorize_now()" class="frm_deauthorize_link">', '</a>'), $inst_install_url); ?></div>
154
+ <script type="text/javascript">
155
+ function frm_deauthorize_now(){
156
+ if(!confirm("<?php esc_attr_e('Are you sure you want to deauthorize Formidable Pro on this site?', 'formidable') ?>"))
157
+ return false;
158
+ jQuery('.frm_deauthorize_link').html('<span class="spinner" style="display:inline-block;margin-top:0;float:none;"></span>');
159
+ jQuery.ajax({type:'POST',url:ajaxurl,data:'action=frm_deauthorize&nonce='+wp_create_nonce('frm_ajax'),
160
+ success:function(msg){jQuery('.error').fadeOut('slow');}
161
+ });
162
+ return false;
163
+ }
164
+ </script>
165
+ <?php
166
  }
167
  }
168
+
169
+ public static function admin_js(){
170
  global $pagenow;
171
+
172
+ if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) {
 
173
  return;
174
  }
175
+
176
+ wp_enqueue_script('jquery');
177
+ wp_enqueue_script('jquery-ui-core');
178
+ wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.0.3');
179
+
180
+ if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
181
+ ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
182
+ ) {
183
+ $version = FrmAppHelper::plugin_version();
184
+ add_filter('admin_body_class', 'FrmAppController::admin_body_class');
185
+
186
+ wp_enqueue_script('jquery-ui-sortable');
187
+ wp_enqueue_script('jquery-ui-draggable');
188
+ wp_enqueue_script('admin-widgets');
189
+ wp_enqueue_style('widgets');
190
+ wp_enqueue_script('formidable');
191
+ wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() .'/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version, true);
192
+ self::localize_script('admin');
193
+
194
+ wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version);
 
 
 
 
 
 
 
 
 
195
  add_thickbox();
196
+
197
+ wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
198
+ wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
199
+
200
+
201
+ }else if($pagenow == 'post.php' or ($pagenow == 'post-new.php' and isset($_REQUEST['post_type']) and $_REQUEST['post_type'] == 'frm_display')){
202
+ if(isset($_REQUEST['post_type'])){
203
+ $post_type = $_REQUEST['post_type'];
204
+ }else if(isset($_REQUEST['post']) and !empty($_REQUEST['post'])){
205
+ $post = get_post($_REQUEST['post']);
206
+ if(!$post)
207
  return;
 
208
  $post_type = $post->post_type;
209
+ }else{
210
  return;
211
  }
212
+
213
+ if($post_type == 'frm_display'){
214
+ $version = FrmAppHelper::plugin_version();
215
+ wp_enqueue_script('jquery-ui-draggable');
216
+ wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version);
217
+ wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url(). '/css/frm_admin.css', array(), $version);
218
+ self::localize_script('admin');
219
  }
 
 
220
  }
221
  }
222
+
223
+ public static function admin_body_class($classes){
224
  global $wp_version;
225
+
226
  //we only need this class on Formidable pages
227
+ if(version_compare( $wp_version, '3.4.9', '>'))
228
  $classes .= ' frm_35_trigger';
229
+
 
230
  return $classes;
231
  }
232
+
233
+ public static function wp_admin_body_class($classes){
234
  global $wp_version;
235
  //we need this class everywhere in the admin for the menu
236
+ if(version_compare( $wp_version, '3.7.2', '>'))
237
  $classes .= ' frm_38_trigger';
238
+
 
239
  return $classes;
240
  }
241
+
242
+ public static function load_lang(){
243
+ load_plugin_textdomain('formidable', false, 'formidable/languages/' );
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  }
245
+
246
+ public static function front_head(){
247
+ global $frm_settings;
248
 
249
+ if (is_multisite()){
250
+ global $frm_vars;
251
+ $old_db_version = get_option('frm_db_version');
252
+ $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false;
253
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
254
+ ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
255
+ self::install($old_db_version);
256
  }
257
  }
258
+
259
  $version = FrmAppHelper::plugin_version();
260
+ wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true);
261
+ wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true);
262
+ wp_register_script('recaptcha-ajax', 'http'. (is_ssl() ? 's' : '').'://www.google.com/recaptcha/api/js/recaptcha_ajax.js', '', true);
263
+
264
+ if ( is_admin() && !defined('DOING_AJAX') ) {
265
  // don't load this in back-end
266
  return;
267
  }
268
+
269
+ self::localize_script('front');
270
+
271
+ wp_enqueue_script('jquery');
272
+
273
+ $style = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
274
+ if($style){
275
+ foreach((array)$style as $k => $file){
276
+ wp_register_style($k, $file, array(), $version);
277
  if ( 'all' == $frm_settings->load_style ) {
278
+ wp_enqueue_style($k);
279
  }
280
+ unset($k, $file);
281
  }
282
  }
283
+ unset($style);
284
+
285
+ if ( $frm_settings->load_style == 'all' ) {
286
  global $frm_vars;
287
  $frm_vars['css_loaded'] = true;
288
  }
289
  }
290
+
291
+ public static function localize_script($location){
 
 
 
292
  wp_localize_script('formidable', 'frm_js', array(
293
  'ajax_url' => admin_url( 'admin-ajax.php' ),
294
  'images_url' => FrmAppHelper::plugin_url() .'/images',
295
+ 'loading' => __('Loading&hellip;'),
296
+ 'remove' => __('Remove', 'formidable'),
297
+ 'offset' => apply_filters('frm_scroll_offset', 4),
 
 
298
  ));
299
+
300
+ if($location == 'admin'){
301
+ global $frm_settings;
302
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
303
+ 'confirm_uninstall' => __('Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable'),
304
+ 'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '',
305
+ 'desc' => __('(Click here to add a description or instructions)', 'formidable'),
306
+ 'blank' => __('(Blank)', 'formidable'),
307
+ 'saving' => esc_attr(__('Saving', 'formidable')),
308
+ 'saved' => esc_attr(__('Saved', 'formidable')),
309
+ 'ok' => __('OK'),
310
+ 'cancel' => __('Cancel', 'formidable'),
311
+ 'clear_default' => __('Clear default value when typing', 'formidable'),
312
+ 'no_clear_default' => __('Do not clear default value when typing', 'formidable'),
313
+ 'valid_default' => __('Default value will pass form validation', 'formidable'),
314
+ 'no_valid_default' => __('Default value will NOT pass form validation', 'formidable'),
315
+ 'deauthorize' => __('Are you sure you want to deactivate Formidable Pro on this site?', 'formidable'),
316
+ 'confirm' => __('Are you sure?', 'formidable'),
 
 
 
317
  'default_unique' => $frm_settings->unique_msg,
318
+ 'import_complete' => __('Import Complete', 'formidable'),
319
+ 'updating' => __('Please wait while your site updates.', 'formidable'),
320
+ 'nonce' => wp_create_nonce('frm_ajax'),
321
+ ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  }
 
 
 
 
 
 
 
 
 
323
  }
324
+
325
+ public static function footer_js($location='footer'){
326
+ global $frm_settings, $frm_vars;
327
+
328
+ if($frm_vars['load_css'] and (!is_admin() or defined('DOING_AJAX')) and ($frm_settings->load_style != 'none')){
329
+ if(isset($frm_vars['css_loaded']) && $frm_vars['css_loaded'])
330
+ $css = apply_filters('get_frm_stylesheet', array());
331
+ else
332
+ $css = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
333
+
334
+ if(!empty($css)){
335
+ echo "\n".'<script type="text/javascript">';
336
+ foreach((array)$css as $css_key => $file){
337
+ echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\''. ($css_key + (isset($frm_vars['css_loaded']) ? $frm_vars['css_loaded'] : false)) .'-css\' href=\''. $file. '\' type=\'text/css\' media=\'all\' /%3E"));';
338
+ //wp_enqueue_style($css_key);
339
+ unset($css_key);
340
+ unset($file);
341
  }
342
+ unset($css);
343
+
344
+ echo '</script>'."\n";
345
  }
 
346
  }
347
 
348
+ if((!is_admin() or defined('DOING_AJAX')) and $location != 'header' and !empty($frm_vars['forms_loaded'])) //load formidable js
349
+ FrmAppHelper::load_scripts(array('formidable'));
 
 
350
  }
351
+
352
+ public static function install($old_db_version=false){
353
+ global $frmdb;
354
+ $frmdb->upgrade($old_db_version);
 
355
  }
356
+
357
+ public static function uninstall(){
 
 
 
 
 
358
  check_ajax_referer( 'frm_ajax', 'nonce' );
359
+
360
+ if ( current_user_can('administrator') ) {
361
+ global $frmdb;
362
  $frmdb->uninstall();
363
  echo true;
364
  } else {
365
+ global $frm_settings;
366
+ wp_die($frm_settings->admin_permission);
367
  }
368
+ die();
369
  }
370
+
 
 
 
 
 
 
 
 
 
371
  // Routes for wordpress pages -- we're just replacing content here folks.
372
+ public static function page_route($content){
373
+ global $post, $frm_settings;
374
 
375
+ if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
 
376
  $content = FrmFormsController::page_preview();
377
  }
378
 
379
  return $content;
380
  }
381
+
382
+ public static function referer_session() {
383
+ global $frm_settings;
384
+
385
+ if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) {
386
+ return;
387
+ }
388
+
389
+ // keep the page history below 100
390
+ $max = 100;
391
+
392
+ if ( !isset($_SESSION) )
393
+ session_start();
394
+
395
+ if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) )
396
+ $_SESSION['frm_http_pages'] = array("http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
397
+
398
+ if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) )
399
+ $_SESSION['frm_http_referer'] = array();
400
+
401
+ if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) {
402
+ if (! isset($_SERVER['HTTP_REFERER'])){
403
+ $direct = __('Type-in or bookmark', 'formidable');
404
+ if(!in_array($direct, $_SESSION['frm_http_referer']))
405
+ $_SESSION['frm_http_referer'][] = $direct;
406
+ }else{
407
+ $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
408
+ }
409
+ }
410
+
411
+ if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']))
412
+ $_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
413
+
414
+ //keep the page history below the max
415
+ if(count($_SESSION['frm_http_pages']) > $max){
416
+ foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
417
+ if(count($_SESSION['frm_http_pages']) <= $max)
418
+ break;
419
+
420
+ unset($_SESSION['frm_http_pages'][$pkey]);
421
+ }
422
+ }
423
  }
424
 
425
+ public static function parse_standalone_request(){
426
+ $plugin = FrmAppHelper::get_param('plugin');
427
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
428
+ $action = FrmAppHelper::get_param($action);
429
+ $controller = FrmAppHelper::get_param('controller');
430
+
431
+ if( !empty($plugin) and $plugin == 'formidable' and !empty($controller) ){
432
+ _deprecated_function( __FUNCTION__, '1.07.02', 'wp_ajax_nopriv()' );
433
+
434
+ if($controller == 'forms')
435
+ FrmFormsController::preview(FrmAppHelper::get_param('form'));
436
+ else
437
+ do_action('frm_standalone_route', $controller, $action);
438
+
439
+ do_action('frm_ajax_'. $controller .'_'. $action);
440
+ die();
441
+ }
442
  }
443
+
444
  //formidable shortcode
445
+ public static function get_form_shortcode($atts){
446
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
447
+ return FrmFormsController::get_form_shortcode($atts);
448
  }
449
 
450
+ public static function widget_text_filter_callback( $matches ) {
451
+ return do_shortcode( $matches[0] );
452
+ }
453
+
454
+ public static function update_message($features){
455
+ include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
456
+ }
457
+
458
+ public static function get_postbox_class(){
459
+ if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
460
+ return 'postbox-container';
461
+ else
462
+ return 'inner-sidebar';
463
+ }
464
+
465
+ public static function pro_is_installed(){
466
+ return file_exists(FrmAppHelper::plugin_path() . '/pro/formidable-pro.php');
467
+ }
468
+
469
+ public static function pro_is_authorized(){
470
+ return get_site_option('frmpro-authorized');
471
+ }
472
+
473
+ public static function deauthorize(){
474
+ check_ajax_referer( 'frm_ajax', 'nonce' );
475
+
476
+ delete_option('frmpro-credentials');
477
+ delete_option('frmpro-authorized');
478
+ delete_site_option('frmpro-credentials');
479
+ delete_site_option('frmpro-authorized');
480
+ die();
481
  }
482
  }
classes/controllers/FrmEntriesController.php CHANGED
@@ -1,665 +1,440 @@
1
  <?php
2
-
3
- class FrmEntriesController {
4
-
5
- public static function menu() {
6
- if ( current_user_can( 'administrator' ) && ! current_user_can( 'frm_view_entries' ) ) {
7
- global $wp_roles;
8
- $wp_roles->add_cap( 'administrator', 'frm_view_entries' );
9
- $wp_roles->add_cap( 'administrator', 'frm_delete_entries' );
10
- }
11
-
12
- add_submenu_page('formidable', 'Formidable | '. __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
13
-
14
- if ( ! isset( $_GET['frm_action'] ) || ! in_array( $_GET['frm_action'], array( 'edit', 'show' ) ) ) {
15
- $frm_settings = FrmAppHelper::get_settings();
16
- add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' );
17
- add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' );
18
- add_filter( 'get_user_option_manage' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' );
19
- }
20
- }
21
-
22
- /* Display in Back End */
23
- public static function route() {
24
- $action = FrmAppHelper::get_param('frm_action');
25
-
26
- switch ( $action ) {
27
- case 'show':
28
- case 'destroy':
29
- case 'destroy_all':
30
- return self::$action();
31
-
32
- default:
33
- do_action( 'frm_entry_action_route', $action );
34
- if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
35
- return;
36
- }
37
-
38
- return self::display_list();
39
- }
40
- }
41
-
42
- public static function contextual_help($help, $screen_id, $screen) {
43
- // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
44
- if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ) {
45
- return $help;
46
- }
47
-
48
- $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
49
- $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
50
- if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) {
51
- return $help;
52
- }
53
- unset( $action, $page );
54
-
55
- $screen->add_help_tab( array(
56
- 'id' => 'formidable-entries-tab',
57
- 'title' => __( 'Overview', 'formidable' ),
58
- 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .'</p> <p>'. esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>',
59
- ));
60
-
61
- $screen->set_help_sidebar(
62
- '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' .
63
- '<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' .
64
- '<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>'
65
- );
66
-
67
- return $help;
68
- }
69
-
70
- public static function manage_columns($columns) {
71
- global $frm_vars, $wpdb;
72
- $form_id = FrmEntriesHelper::get_current_form_id();
73
-
74
- $columns[ $form_id .'_id' ] = 'ID';
75
- $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
76
-
77
- if ( ! $form_id ) {
78
- return $columns;
79
- }
80
-
81
- $form_cols = FrmField::get_all_for_form($form_id, '', 'include');
82
-
83
- foreach ( $form_cols as $form_col ) {
84
- if ( FrmFieldsHelper::is_no_save_field($form_col->type) ) {
85
- continue;
86
- }
87
-
88
- if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) {
89
- $sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] );
90
-
91
- if ( $sub_form_cols ) {
92
- foreach ( $sub_form_cols as $k => $sub_form_col ) {
93
- if ( in_array( $sub_form_col->type, FrmFieldsHelper::no_save_fields() ) ) {
94
- unset( $sub_form_cols[ $k ] );
95
- continue;
96
- }
97
- $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
98
- unset($sub_form_col);
99
- }
100
- }
101
- unset($sub_form_cols);
102
- } else {
103
- $col_id = $form_col->field_key;
104
- if ( $form_col->form_id != $form_id ) {
105
- $col_id .= '-_-form'. $form_col->form_id;
106
- }
107
-
108
- if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) {
109
- $columns[ $form_id .'_frmsep_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
110
- }
111
- $columns[ $form_id .'_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
112
- }
113
- }
114
-
115
- $columns[ $form_id .'_created_at' ] = __( 'Entry creation date', 'formidable' );
116
- $columns[ $form_id .'_updated_at' ] = __( 'Entry update date', 'formidable' );
117
- $columns[ $form_id .'_ip' ] = 'IP';
118
-
119
- $frm_vars['cols'] = $columns;
120
-
121
- $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
122
- if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && ( $action == 'list' || $action == 'destroy' ) ) {
123
- add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) );
124
- }
125
-
126
- return $columns;
127
- }
128
-
129
- public static function check_hidden_cols($check, $object_id, $meta_key, $meta_value, $prev_value) {
130
- $frm_settings = FrmAppHelper::get_settings();
131
- if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) {
132
- return $check;
133
- }
134
-
135
- if ( empty($prev_value) ) {
136
- $prev_value = get_metadata('user', $object_id, $meta_key, true);
137
- }
138
-
139
- global $frm_vars;
140
- //add a check so we don't create a loop
141
- $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
142
-
143
- return $check;
144
- }
145
-
146
- //add hidden columns back from other forms
147
- public static function update_hidden_cols($meta_id, $object_id, $meta_key, $meta_value ) {
148
- $frm_settings = FrmAppHelper::get_settings();
149
-
150
- $sanitized = sanitize_title($frm_settings->menu);
151
- if ( $meta_key != 'manage'. $sanitized .'_page_formidable-entriescolumnshidden' ) {
152
- return;
153
- }
154
-
155
- global $frm_vars;
156
- if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
157
- return; //don't continue if there's no previous value
158
- }
159
-
160
- foreach ( $meta_value as $mk => $mv ) {
161
- //remove blank values
162
- if ( empty( $mv ) ) {
163
- unset( $meta_value[ $mk ] );
164
- }
165
- }
166
-
167
- $cur_form_prefix = reset($meta_value);
168
- $cur_form_prefix = explode('_', $cur_form_prefix);
169
- $cur_form_prefix = $cur_form_prefix[0];
170
- $save = false;
171
-
172
- foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
173
- if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
174
- //don't add blank cols or process included cols
175
- continue;
176
- }
177
-
178
- $form_prefix = explode( '_', $prev_hidden );
179
- $form_prefix = $form_prefix[0];
180
- if ( $form_prefix == $cur_form_prefix ) {
181
- //don't add back columns that are meant to be hidden
182
- continue;
183
- }
184
-
185
- $meta_value[] = $prev_hidden;
186
- $save = true;
187
- unset($form_prefix);
188
- }
189
-
190
- if ( $save ) {
191
- $user = wp_get_current_user();
192
- update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true );
193
- }
194
- }
195
-
196
- public static function save_per_page($save, $option, $value) {
197
- if ( $option == 'formidable_page_formidable_entries_per_page' ) {
198
- $save = (int) $value;
199
- }
200
- return $save;
201
- }
202
-
203
- public static function sortable_columns() {
204
- $form_id = FrmEntriesHelper::get_current_form_id();
205
-
206
- $fields = FrmField::get_all_for_form( $form_id );
207
-
208
- $columns = array(
209
- $form_id .'_id' => 'id',
210
- $form_id .'_created_at' => 'created_at',
211
- $form_id .'_updated_at' => 'updated_at',
212
- $form_id .'_ip' => 'ip',
213
- $form_id .'_item_key' => 'item_key',
214
- $form_id .'_is_draft' => 'is_draft',
215
- );
216
-
217
- foreach ( $fields as $field ) {
218
- if ( $field->type != 'checkbox' && ( ! isset($field->field_options['post_field']) || $field->field_options['post_field'] == '' ) ) {
219
- // Can't sort on checkboxes because they are stored serialized, or post fields
220
- $columns[ $form_id .'_'. $field->field_key ] = 'meta_'. $field->id;
221
- }
222
- }
223
-
224
- return $columns;
225
  }
226
-
227
- public static function hidden_columns($result) {
228
- global $frm_vars;
229
-
230
- $form_id = FrmEntriesHelper::get_current_form_id();
231
-
232
- $return = false;
233
- foreach ( (array) $result as $r ) {
234
- if ( ! empty( $r ) ) {
235
- $form_prefix = explode( '_', $r );
236
- $form_prefix = $form_prefix[0];
237
-
238
- if ( (int) $form_prefix == (int) $form_id ) {
239
- $return = true;
240
- break;
241
- }
242
-
243
- unset($form_prefix);
244
- }
245
- }
246
-
247
- if ( $return ) {
248
- return $result;
249
- }
250
-
251
- $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
252
- $max_columns = 8;
253
- if ( $i <= $max_columns ) {
254
- return $result;
255
- }
256
-
257
  global $frm_vars;
258
- if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
259
- $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
260
- }
261
-
262
- if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && isset($frm_vars['current_form']->options['hidden_cols']) && ! empty($frm_vars['current_form']->options['hidden_cols']) ) {
263
- $result = $frm_vars['current_form']->options['hidden_cols'];
264
- } else {
265
- $cols = $frm_vars['cols'];
266
- $cols = array_reverse($cols, true);
267
-
268
- $result[] = $form_id .'_id';
269
- $i--;
270
-
271
- $result[] = $form_id .'_item_key';
272
- $i--;
273
-
274
- foreach ( $cols as $col_key => $col ) {
275
- if ( $i > $max_columns ) {
276
- $result[] = $col_key;
277
- }
278
- //remove some columns by default
279
- $i--;
280
- unset($col_key, $col);
281
- }
282
- }
283
-
284
- return $result;
285
- }
286
-
287
- public static function display_list( $message = '', $errors = array() ) {
288
- global $wpdb, $frm_vars;
289
-
290
- $form = FrmEntriesHelper::get_current_form();
291
- $params = FrmEntriesHelper::get_admin_params( $form );
292
-
293
- if ( $form ) {
294
- $params['form'] = $form->id;
295
- $frm_vars['current_form'] = $form;
296
-
297
- if ( 'trash' == $form->status ) {
298
- $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
299
- $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
300
- $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
301
- unset( $time_to_delete, $delete_timestamp );
302
- }
303
- }
304
-
305
- $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
306
-
307
- $wp_list_table = new $table_class( array( 'params' => $params ) );
308
-
309
- $pagenum = $wp_list_table->get_pagenum();
310
-
311
- $wp_list_table->prepare_items();
312
-
313
- $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
314
- if ( $pagenum > $total_pages && $total_pages > 0 ) {
315
- $url = add_query_arg( 'paged', $total_pages );
316
- if ( headers_sent() ) {
317
- echo FrmAppHelper::js_redirect($url);
318
- } else {
319
- wp_redirect($url);
320
- }
321
- die();
322
- }
323
-
324
- if ( empty($message) && isset($_GET['import-message']) ) {
325
- $message = __( 'Your import is complete', 'formidable' );
326
- }
327
-
328
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
329
- }
330
-
331
- /* Back End CRUD */
332
- public static function show($id = false) {
333
- FrmAppHelper::permission_check('frm_view_entries');
334
-
335
- if ( ! $id ) {
336
- $id = FrmAppHelper::get_param('id');
337
-
338
- if ( ! $id ) {
339
- $id = FrmAppHelper::get_param('item_id');
340
- }
341
  }
342
-
343
- $entry = FrmEntry::getOne($id, true);
344
-
345
- $data = maybe_unserialize($entry->description);
346
- if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
347
- $data = array( 'referrer' => $data );
348
- }
349
-
350
- $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
351
- $to_emails = array();
352
-
353
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php');
354
- }
355
-
356
- public static function destroy() {
357
- FrmAppHelper::permission_check('frm_delete_entries');
358
-
359
- $params = FrmEntriesHelper::get_admin_params();
360
-
361
- if ( isset($params['keep_post']) && $params['keep_post'] ) {
362
- //unlink entry from post
363
- global $wpdb;
364
- $wpdb->update( $wpdb->prefix .'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) );
365
- }
366
-
367
- $message = '';
368
- if ( FrmEntry::destroy( $params['id'] ) ) {
369
- $message = __( 'Entry was Successfully Destroyed', 'formidable' );
370
- }
371
-
372
- self::display_list( $message );
373
  }
374
-
375
- public static function destroy_all() {
376
- if ( ! current_user_can( 'frm_delete_entries' ) ) {
377
- $frm_settings = FrmAppHelper::get_settings();
378
- wp_die( $frm_settings->admin_permission );
379
- }
380
-
381
- global $wpdb;
382
- $params = FrmEntriesHelper::get_admin_params();
383
- $message = '';
384
- $errors = array();
385
- $form_id = (int) $params['form'];
386
-
387
- if ( $form_id ) {
388
- $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
389
- $action = FrmFormActionsHelper::get_action_for_form( $form_id, 'wppost', 1 );
390
-
391
- if ( $action ) {
392
- // this action takes a while, so only trigger it if there are posts to delete
393
- foreach ( $entry_ids as $entry_id ) {
394
- do_action( 'frm_before_destroy_entry', $entry_id );
395
- unset( $entry_id );
396
- }
397
- }
398
-
399
- $wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) );
400
- $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) );
401
- if ( $results ) {
402
- $message = __( 'Entries were Successfully Destroyed', 'formidable' );
403
- }
404
- } else {
405
- $errors = __( 'No entries were specified', 'formidable' );
406
- }
407
-
408
- self::display_list( $message, $errors );
409
  }
410
-
411
- public static function show_form( $id = '', $key = '', $title = false, $description = false ) {
412
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
413
- return FrmFormsController::show_form( $id, $key, $title, $description );
414
  }
415
-
416
- public static function get_form( $filename, $form, $title, $description ) {
417
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
418
- return FrmFormsController::get_form( $form, $title, $description );
419
  }
420
-
421
- public static function process_entry( $errors = '', $ajax = false ) {
422
- $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
423
- if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
424
  return;
425
- }
426
-
427
- global $frm_vars;
428
 
429
- $form = FrmForm::getOne( $form_id );
430
- if ( ! $form ) {
 
 
 
431
  return;
432
- }
433
-
434
- $params = self::get_params( $form );
435
-
436
- if ( ! isset( $frm_vars['form_params'] ) ) {
437
  $frm_vars['form_params'] = array();
438
- }
439
- $frm_vars['form_params'][ $form->id ] = $params;
440
-
441
- if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
442
  return;
443
- }
444
-
445
- if ( $errors == '' ) {
446
- $errors = FrmEntry::validate( $_POST );
447
- }
448
- $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
449
-
450
- if ( empty( $errors ) ) {
451
  $_POST['frm_skip_cookie'] = 1;
452
- if ( $params['action'] == 'create' ) {
453
- if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
454
- $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
455
- }
456
  }
457
-
458
- do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
459
- unset( $_POST['frm_skip_cookie'] );
460
  }
461
  }
462
-
463
- public static function delete_entry_before_redirect( $url, $form, $atts ) {
464
- self::_delete_entry( $atts['id'], $form );
465
  return $url;
466
  }
467
-
468
  //Delete entry if not redirected
469
- public static function delete_entry_after_save( $atts ) {
470
- self::_delete_entry( $atts['entry_id'], $atts['form'] );
471
  }
472
-
473
- private static function _delete_entry( $entry_id, $form ) {
474
- if ( ! $form ) {
475
  return;
476
- }
477
-
478
- $form->options = maybe_unserialize( $form->options );
479
- if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
480
- FrmEntry::destroy( $entry_id );
481
  }
482
  }
483
-
484
- public static function show_entry_shortcode( $atts ) {
485
- $atts = shortcode_atts( array(
486
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
487
  'user_info' => false, 'include_blank' => false, 'default_email' => false,
488
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
489
  'font_size' => '', 'text_color' => '',
490
  'border_width' => '', 'border_color' => '',
491
- 'bg_color' => '', 'alt_bg_color' => '',
492
- ), $atts );
493
-
494
- if ( $atts['format'] != 'text' ) {
 
495
  //format options are text, array, or json
496
- $atts['plain_text'] = true;
497
- }
498
-
499
- if ( is_object( $atts['entry'] ) && ! isset( $atts['entry']->metas ) ) {
500
- // if the entry does not include metas, force it again
501
- $atts['entry'] = false;
502
- }
503
-
504
- if ( ! $atts['entry'] || ! is_object( $atts['entry'] ) ) {
505
- if ( ! $atts['id'] && ! $atts['default_email'] ) {
506
- return;
507
  }
508
-
509
- if ( $atts['id'] ) {
510
- $atts['entry'] = FrmEntry::getOne( $atts['id'], true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  }
512
- }
513
-
514
- if ( $atts['entry'] ) {
515
- $atts['form_id'] = $atts['entry']->form_id;
516
- $atts['id'] = $atts['entry']->id;
517
- }
518
-
519
- if ( ! $atts['fields'] || ! is_array($atts['fields']) ) {
520
- $atts['fields'] = FrmField::get_all_for_form( $atts['form_id'], '', 'include' );
521
- }
522
 
523
- $values = array();
524
- foreach ( $atts['fields'] as $f ) {
525
- FrmEntriesHelper::fill_entry_values($atts, $f, $values);
526
- unset($f);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
527
  }
528
 
529
- FrmEntriesHelper::fill_entry_user_info($atts, $values);
530
-
531
- if ( $atts['format'] == 'json' ) {
532
- return json_encode($values);
533
- } else if ( $atts['format'] == 'array' ) {
534
- return $values;
535
  }
536
-
537
- $content = array();
538
- FrmEntriesHelper::convert_entry_to_content($values, $atts, $content);
539
-
540
- if ( 'text' == $atts['format'] ) {
541
- $content = implode('', $content);
542
  }
543
-
544
  return $content;
545
  }
546
-
547
- public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) {
548
- $field = FrmField::getOne($meta->field_id);
549
- if ( ! $field ) {
550
- return $value;
551
- }
552
-
553
  $value = self::filter_display_value($value, $field, $atts);
554
  return $value;
555
  }
556
-
557
- public static function &filter_shortcode_value($value, $tag, $atts, $field) {
558
- $plain_text = add_filter('frm_plain_text_email', true);
559
- FrmEntriesHelper::textarea_display_value( $value, $field->type, $plain_text );
560
-
561
- if ( isset($atts['show']) && $atts['show'] == 'value' ) {
562
- return $value;
563
- }
564
-
565
- return self::filter_display_value($value, $field, $atts);
566
- }
567
-
568
- public static function &filter_display_value( $value, $field, $atts = array() ) {
569
- $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false;
570
- if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! isset( $field->field_options['separate_value'] ) || ! $field->field_options['separate_value'] || $saved_value ) {
571
  return $value;
572
- }
573
-
574
- $f_values = $f_labels = array();
575
-
576
- foreach ( $field->options as $opt_key => $opt ) {
577
- if ( ! is_array($opt) ) {
578
  continue;
 
 
 
 
 
 
579
  }
580
-
581
- $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt);
582
- $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ];
583
- if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) {
584
- unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] );
585
- }
586
- unset($opt_key, $opt);
587
  }
588
 
589
- if ( ! empty($f_values) ) {
590
- foreach ( (array) $value as $v_key => $val ) {
591
- if ( in_array($val, $f_values) ) {
592
  $opt = array_search($val, $f_values);
593
- if ( is_array($value) ) {
594
- $value[ $v_key ] = $f_labels[ $opt ];
595
- } else {
596
- $value = $f_labels[ $opt ];
597
- }
598
  }
599
- unset($v_key, $val);
 
600
  }
601
  }
602
-
603
  return $value;
604
  }
605
-
606
- public static function get_params( $form = null ) {
607
  global $frm_vars;
608
-
609
- if ( ! $form ) {
610
- $form = FrmForm::getAll( array(), 'name', 1 );
611
- } else {
612
- FrmFormsHelper::maybe_get_form( $form );
613
- }
614
-
615
- if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
616
- return $frm_vars['form_params'][ $form->id ];
617
- }
618
-
619
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
620
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
621
-
622
  $default_values = array(
623
- 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
624
- 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action,
625
  );
626
-
627
- $values = array();
628
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
629
- if ( ! is_numeric($values['posted_form_id']) ) {
630
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
631
- }
632
 
633
- if ( $form->id == $values['posted_form_id'] ) {
634
- //if there are two forms on the same page, make sure not to submit both
635
- foreach ( $default_values as $var => $default ) {
636
- if ( $var == 'action' ) {
637
- $values[ $var ] = FrmAppHelper::get_param( $action_var, $default );
638
- } else {
639
- $values[ $var ] = FrmAppHelper::get_param( $var, $default );
640
- }
641
- unset( $var, $default );
642
  }
643
- } else {
644
- foreach ( $default_values as $var => $default ) {
645
- $values[ $var ] = $default;
646
- unset( $var, $default );
 
647
  }
648
  }
649
 
650
- if ( in_array( $values['action'], array( 'create', 'update' ) ) && ( ! $_POST || ( ! isset( $_POST['action'] ) && ! isset( $_POST['frm_action'] ) ) ) ) {
651
  $values['action'] = 'new';
652
- }
653
 
654
  return $values;
655
  }
656
-
657
- public static function entry_sidebar($entry) {
658
- $data = maybe_unserialize($entry->description);
659
- $date_format = get_option('date_format');
660
- $time_format = get_option('time_format');
661
-
662
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php');
663
- }
664
-
665
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
+
8
+ if(class_exists('FrmEntriesController'))
9
+ return;
10
+
11
+ class FrmEntriesController{
12
+
13
+ public static function load_hooks(){
14
+ add_action('admin_menu', 'FrmEntriesController::menu', 11);
15
+ add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
16
+ add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
17
+ add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
18
+ add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
19
+ add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
+
22
+ public static function menu(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  global $frm_vars;
24
+ if(!$frm_vars['pro_is_installed']){
25
+ add_submenu_page('formidable', 'Formidable |'. __('Entries', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Entries', 'formidable') .'</span>', 'administrator', 'formidable-entries', 'FrmEntriesController::list_entries');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
+
29
+ public static function list_entries(){
30
+ global $frm_entry;
31
+ $frm_form = new FrmForm();
32
+ $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
33
+ $form_id = FrmAppHelper::get_param('form', false);
34
+ if($form_id)
35
+ $form = $frm_form->getOne($form_id);
36
+ else
37
+ $form = (isset($form_select[0])) ? $form_select[0] : 0;
38
+
39
+ if($form)
40
+ $entry_count = $frm_entry->getRecordCount($form->id);
41
+
42
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
+
45
+ public static function show_form($id='', $key='', $title=false, $description=false){
46
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
47
+ return FrmFormsController::show_form($id, $key, $title, $description);
48
  }
49
+
50
+ public static function get_form($filename, $form, $title, $description) {
51
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
52
+ return FrmFormsController::get_form($form, $title, $description);
53
  }
54
+
55
+ public static function process_entry($errors='', $ajax=false){
56
+ if((is_admin() and !defined('DOING_AJAX')) or !isset($_POST) or !isset($_POST['form_id']) or !is_numeric($_POST['form_id']) or !isset($_POST['item_key']))
 
57
  return;
 
 
 
58
 
59
+ global $frm_entry, $frm_vars;
60
+
61
+ $frm_form = new FrmForm();
62
+ $form = $frm_form->getOne($_POST['form_id']);
63
+ if(!$form)
64
  return;
65
+
66
+ $params = FrmEntriesController::get_params($form);
67
+
68
+ if(!isset($frm_vars['form_params']))
 
69
  $frm_vars['form_params'] = array();
70
+ $frm_vars['form_params'][$form->id] = $params;
71
+
72
+ if(isset($frm_vars['created_entries'][$_POST['form_id']]))
 
73
  return;
74
+
75
+ if($errors == '')
76
+ $errors = $frm_entry->validate($_POST);
77
+ $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
78
+
79
+ if( empty($errors) ){
 
 
80
  $_POST['frm_skip_cookie'] = 1;
81
+ if($params['action'] == 'create'){
82
+ if (apply_filters('frm_continue_to_create', true, $_POST['form_id']) and !isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']))
83
+ $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = $frm_entry->create( $_POST );
 
84
  }
85
+
86
+ do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
87
+ unset($_POST['frm_skip_cookie']);
88
  }
89
  }
90
+
91
+ public static function delete_entry_before_redirect($url, $form, $atts){
92
+ self::_delete_entry($atts['id'], $form);
93
  return $url;
94
  }
95
+
96
  //Delete entry if not redirected
97
+ public static function delete_entry_after_save($atts){
98
+ self::_delete_entry($atts['entry_id'], $atts['form']);
99
  }
100
+
101
+ private static function _delete_entry($entry_id, $form){
102
+ if(!$form)
103
  return;
104
+
105
+ $form->options = maybe_unserialize($form->options);
106
+ if(isset($form->options['no_save']) and $form->options['no_save']){
107
+ global $frm_entry;
108
+ $frm_entry->destroy( $entry_id );
109
  }
110
  }
111
+
112
+ public static function show_entry_shortcode($atts){
113
+ $atts = shortcode_atts(array(
114
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
115
  'user_info' => false, 'include_blank' => false, 'default_email' => false,
116
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
117
  'font_size' => '', 'text_color' => '',
118
  'border_width' => '', 'border_color' => '',
119
+ 'bg_color' => '', 'alt_bg_color' => '',
120
+ ), $atts);
121
+ extract($atts);
122
+
123
+ if ( $format != 'text' ) {
124
  //format options are text, array, or json
125
+ $plain_text = true;
126
+ }
127
+
128
+ global $frm_entry;
129
+
130
+ if ( !$entry || !is_object($entry) ) {
131
+ if ( !$id && !$default_email ) {
132
+ return '';
 
 
 
133
  }
134
+
135
+ if($id)
136
+ $entry = $frm_entry->getOne($id, true);
137
+ }
138
+
139
+ if ( $entry ) {
140
+ $form_id = $entry->form_id;
141
+ $id = $entry->id;
142
+ }
143
+
144
+ if ( !$fields || !is_array($fields) ) {
145
+ global $frm_field;
146
+ $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
147
+ }
148
+
149
+ $content = ( $format != 'text' ) ? array() : '';
150
+ $odd = true;
151
+
152
+ if ( !$plain_text ) {
153
+ global $frmpro_settings;
154
+
155
+ $default_settings = array(
156
+ 'border_color' => 'dddddd',
157
+ 'bg_color' => 'f7f7f7',
158
+ 'text_color' => '444444',
159
+ 'font_size' => '12px',
160
+ 'border_width' => '1px',
161
+ 'alt_bg_color' => 'ffffff',
162
+ );
163
+
164
+ // merge defaults, global settings, and shortcode options
165
+ foreach ( $default_settings as $key => $setting ) {
166
+ if ( $atts[$key] != '' ) {
167
+ continue;
168
+ }
169
+
170
+ if ( $frmpro_settings ) {
171
+ if ( 'alt_bg_color' == $key ) {
172
+ $atts[$key] = $frmpro_settings->bg_color_active;
173
+ } else if ( 'border_width' == $key ) {
174
+ $atts[$key] = $frmpro_settings->field_border_width;
175
+ } else {
176
+ $atts[$key] = $frmpro_settings->{$key};
177
+ }
178
+ } else {
179
+ $atts[$key] = $setting;
180
+ }
181
+ unset($key, $setting);
182
+ }
183
+
184
+ unset($default_settings);
185
+
186
+ $content .= "<table cellspacing='0' style='font-size:{$atts['font_size']};line-height:135%; border-bottom:{$atts['border_width']} solid #{$atts['border_color']};'><tbody>\r\n";
187
+ $bg_color = " style='background-color:#{$atts['bg_color']};'";
188
+ $bg_color_alt = " style='background-color:#{$atts['alt_bg_color']};'";
189
+ $row_style = "style='text-align:". ( $direction == 'rtl' ? 'right' : 'left' ) .";color:#{$atts['text_color']};padding:7px 9px;border-top:{$atts['border_width']} solid #{$atts['border_color']}'";
190
+ }
191
+
192
+ foreach ( $fields as $f ) {
193
+ if ( in_array($f->type, array('divider', 'captcha', 'break', 'html')) )
194
+ continue;
195
+
196
+ if ( $entry && !isset($entry->metas[$f->id]) ) {
197
+ if ( $entry->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
198
+ $p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
199
+ 'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
200
+ 'form_id' => $entry->form_id, 'field' => $f, 'type' => $f->type,
201
+ 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
202
+ ));
203
+ if ( $p_val != '' ) {
204
+ $entry->metas[$f->id] = $p_val;
205
+ }
206
+ }
207
+
208
+ if ( !isset($entry->metas[$f->id]) && !$include_blank && !$default_email ) {
209
+ continue;
210
+ }
211
+
212
+ $entry->metas[$f->id] = $default_email ? '['. $f->id .']' : '';
213
+ }
214
+
215
+ $val = '';
216
+ if ( $entry ) {
217
+ $prev_val = maybe_unserialize($entry->metas[$f->id]);
218
+ $meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
219
+
220
+ $val = $default_email ? $prev_val : apply_filters('frm_email_value', $prev_val, (object) $meta, $entry);
221
+ } else if ( $default_email ) {
222
+ $val = '['. $f->id .']';
223
  }
 
 
 
 
 
 
 
 
 
 
224
 
225
+ if ( $f->type == 'textarea' and !$plain_text ) {
226
+ $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val);
227
+ }
228
+
229
+ //Remove signature from default-message shortcode
230
+ if ( $f->type == 'signature' && !$default_email ) {
231
+ continue;
232
+ }
233
+
234
+ if ( is_array($val) && $format == 'text' ) {
235
+ $val = implode(', ', $val);
236
+ }
237
+
238
+ $fname = $default_email ? '['. $f->id .' show=field_label]' : $f->name;
239
+
240
+ if ( $format != 'text' ){
241
+ $content[$f->field_key] = $val;
242
+ } else if ( $plain_text ) {
243
+ if ( 'rtl' == $direction ) {
244
+ $content .= $val . ' :' . $fname . "\r\n\r\n";
245
+ } else {
246
+ $content .= $fname . ': ' . $val . "\r\n\r\n";
247
+ }
248
+ } else {
249
+ if (!$default_email){
250
+ $content .= '<tr'. ( $odd ? $bg_color : $bg_color_alt ) .'>';
251
+ if ( 'rtl' == $direction ) {
252
+ $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
253
+ } else {
254
+ $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
255
+ }
256
+ $content .= '</tr>'. "\r\n";
257
+ $odd = ($odd) ? false : true;
258
+ }else{
259
+ $content .= '[if '. $f->id .']<tr style="[frm-alt-color]">';
260
+ if ( 'rtl' == $direction ) {
261
+ $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
262
+ } else {
263
+ $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
264
+ }
265
+ $content .= "</tr>\r\n[/if $f->id]";
266
+ }
267
+
268
+ }
269
+
270
+ unset($fname, $f);
271
+ }
272
+
273
+ if ( $user_info ) {
274
+ if ( isset($entry->description) ) {
275
+ $data = maybe_unserialize($entry->description);
276
+ } else if ( $default_email ) {
277
+ $entry->ip = '[ip]';
278
+ $data = array(
279
+ 'browser' => '[browser]',
280
+ 'referrer' => '[referrer]',
281
+ );
282
+ }
283
+ if ( $format != 'text' ) {
284
+ $content['ip'] = $entry->ip;
285
+ $content['browser'] = $data['browser'];
286
+ $content['referrer'] = $data['referrer'];
287
+ } else if ( $plain_text ) {
288
+ $content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
289
+ if ( 'rtl' == $direction ) {
290
+ $content .= $entry->ip . ' :'. __('IP Address', 'formidable') ."\r\n";
291
+ $content .= $data['browser'] .' :'. __('User-Agent (Browser/OS)', 'formidable') ."\r\n";
292
+ $content .= $data['referrer'] .' :'. __('Referrer', 'formidable') ."\r\n";
293
+ } else {
294
+ $content .= __('IP Address', 'formidable') . ': '. $entry->ip ."\r\n";
295
+ $content .= __('User-Agent (Browser/OS)', 'formidable') . ': '. $data['browser']."\r\n";
296
+ $content .= __('Referrer', 'formidable') . ': '. $data['referrer']."\r\n";
297
+ }
298
+ } else {
299
+ $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
300
+ if ( 'rtl' == $direction ) {
301
+ $content .= "<td $row_style>". $entry->ip ."</td><th $row_style>". __('IP Address', 'formidable') . "</th>";
302
+ } else {
303
+ $content .= "<th $row_style>". __('IP Address', 'formidable') . "</th><td $row_style>". $entry->ip ."</td>";
304
+ }
305
+ $content .= '</tr>'. "\r\n";
306
+ $odd = ($odd) ? false : true;
307
+
308
+ if ( isset($data['browser']) ) {
309
+ $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
310
+ if ( 'rtl' == $direction ) {
311
+ $content .= "<td $row_style>". $data['browser']."</td><th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th>";
312
+ } else {
313
+ $content .= "<th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th><td $row_style>". $data['browser']."</td>";
314
+ }
315
+ $content .= '</tr>'. "\r\n";
316
+ }
317
+ $odd = ($odd) ? false : true;
318
+
319
+ if ( isset($data['referrer']) ) {
320
+ $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
321
+ if ( 'rtl' == $direction ) {
322
+ $content .= "<td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td><th $row_style>".__('Referrer', 'formidable') . "</th>";
323
+ } else {
324
+ $content .= "<th $row_style>".__('Referrer', 'formidable') . "</th><td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td>";
325
+ }
326
+ $content .= '</tr>'. "\r\n";
327
+ }
328
+ }
329
  }
330
 
331
+ if ( ! $plain_text ) {
332
+ $content .= '</tbody></table>';
 
 
 
 
333
  }
334
+
335
+ if ( $format == 'json' ) {
336
+ $content = json_encode($content);
 
 
 
337
  }
338
+
339
  return $content;
340
  }
341
+
342
+ public static function &filter_email_value($value, $meta, $entry, $atts=array()){
343
+ $frm_field = new FrmField();
344
+ $field = $frm_field->getOne($meta->field_id);
345
+ if(!$field)
346
+ return $value;
347
+
348
  $value = self::filter_display_value($value, $field, $atts);
349
  return $value;
350
  }
351
+
352
+ public static function &filter_display_value($value, $field, $atts=array()){
353
+ $field->field_options = maybe_unserialize($field->field_options);
354
+
355
+ $saved_value = (isset($atts['saved_value']) and $atts['saved_value']) ? true : false;
356
+ if(!in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) or !isset($field->field_options['separate_value']) or !$field->field_options['separate_value'] or $saved_value)
 
 
 
 
 
 
 
 
 
357
  return $value;
358
+
359
+ $field->options = maybe_unserialize($field->options);
360
+ $f_values = array();
361
+ $f_labels = array();
362
+ foreach($field->options as $opt_key => $opt){
363
+ if(!is_array($opt))
364
  continue;
365
+
366
+ $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
367
+ $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
368
+ if($f_labels[$opt_key] == $f_values[$opt_key]){
369
+ unset($f_values[$opt_key]);
370
+ unset($f_labels[$opt_key]);
371
  }
372
+ unset($opt_key);
373
+ unset($opt);
 
 
 
 
 
374
  }
375
 
376
+ if(!empty($f_values)){
377
+ foreach((array)$value as $v_key => $val){
378
+ if(in_array($val, $f_values)){
379
  $opt = array_search($val, $f_values);
380
+ if(is_array($value))
381
+ $value[$v_key] = $f_labels[$opt];
382
+ else
383
+ $value = $f_labels[$opt];
 
384
  }
385
+ unset($v_key);
386
+ unset($val);
387
  }
388
  }
389
+
390
  return $value;
391
  }
392
+
393
+ public static function get_params($form=null){
394
  global $frm_vars;
395
+
396
+ $frm_form = new FrmForm();
397
+ if(!$form)
398
+ $form = $frm_form->getAll(array(), 'name', 1);
399
+ else if(!is_object($form))
400
+ $form = $frm_form->getOne($form);
401
+
402
+ if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
403
+ return $frm_vars['form_params'][$form->id];
404
+
 
405
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
406
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
407
+
408
  $default_values = array(
409
+ 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
410
+ 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
411
  );
412
+
 
413
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
414
+ if (!is_numeric($values['posted_form_id']))
415
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
 
416
 
417
+ if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
418
+ foreach ($default_values as $var => $default){
419
+ if($var == 'action')
420
+ $values[$var] = FrmAppHelper::get_param($action_var, $default);
421
+ else
422
+ $values[$var] = FrmAppHelper::get_param($var, $default);
423
+ unset($var);
424
+ unset($default);
 
425
  }
426
+ }else{
427
+ foreach ($default_values as $var => $default){
428
+ $values[$var] = $default;
429
+ unset($var);
430
+ unset($default);
431
  }
432
  }
433
 
434
+ if(in_array($values['action'], array('create', 'update')) and (!isset($_POST) or (!isset($_POST['action']) and !isset($_POST['frm_action']))))
435
  $values['action'] = 'new';
 
436
 
437
  return $values;
438
  }
439
+
 
 
 
 
 
 
 
 
440
  }
classes/controllers/FrmFieldsController.php CHANGED
@@ -1,506 +1,414 @@
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();
18
  $path = FrmAppHelper::plugin_path();
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'] = '';
33
  }
34
-
35
- $field_name = 'item_meta['. $field_id .']';
36
- $html_id = FrmFieldsHelper::get_html_id($field);
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
-
44
  unset($path);
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
-
59
- // this hook will allow for multiple fields to be added at once
60
- do_action('frm_after_field_created', $field, $form_id);
61
-
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() ) {
71
  $values['post_type'] = FrmProFormsHelper::post_type($form_id);
72
- }
73
-
74
- $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_type, $form_id));
75
- $field_id = FrmField::create( $field_values );
76
-
77
- if ( ! $field_id ) {
78
- return false;
79
- }
80
-
81
- $field = self::include_single_field($field_id, $values, $form_id);
82
-
83
- return $field;
 
84
  }
85
-
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
  }
143
-
144
- $field->field_options[ $val ] = $new_val;
145
- unset($new_val);
146
- }
147
  unset($val);
148
  }
149
 
150
- FrmField::update( $field_id, array(
151
- 'field_options' => $field->field_options,
152
- 'form_id' => $field->form_id,
153
- ) );
154
- wp_die();
155
  }
156
-
157
- public static function duplicate() {
158
- check_ajax_referer( 'frm_ajax', 'nonce' );
159
-
160
  global $wpdb;
161
-
162
- $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
163
- $copy_field = FrmField::getOne( $field_id );
164
- if ( ! $copy_field ) {
165
- wp_die();
166
- }
167
-
168
- $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
169
-
170
- do_action('frm_duplicate_field', $copy_field, $form_id);
171
- do_action('frm_duplicate_field_'. $copy_field->type, $copy_field, $form_id);
172
-
173
  $values = array();
174
- FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
175
-
176
- $field_count = FrmDb::get_count( $wpdb->prefix .'frm_fields fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) );
177
-
 
 
 
178
  $values['field_order'] = $field_count + 1;
179
-
180
- if ( ! $field_id = FrmField::create($values) ) {
181
- wp_die();
182
- }
183
-
184
- self::include_single_field($field_id, $values);
185
-
186
- wp_die();
187
- }
188
-
189
- /**
190
- * Load a single field in the form builder along with all needed variables
191
- */
192
- public static function include_single_field( $field_id, $values, $form_id = 0 ) {
193
- $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
194
- $field_name = 'item_meta['. $field_id .']';
195
- $html_id = FrmFieldsHelper::get_html_id($field);
196
- $id = $form_id ? $form_id : $field['form_id'];
197
- if ( $field['type'] == 'html' ) {
198
- $field['stop_filter'] = true;
199
- }
200
-
201
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
202
-
203
- return $field;
204
- }
205
-
206
- public static function destroy() {
207
- check_ajax_referer( 'frm_ajax', 'nonce' );
208
-
209
- $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
210
- FrmField::destroy( $field_id );
211
- wp_die();
212
  }
 
 
 
 
 
 
213
 
214
  /* Field Options */
215
-
216
- //Add Single Option or Other Option
217
- public static function add_option() {
218
- check_ajax_referer( 'frm_ajax', 'nonce' );
219
-
220
- $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
221
- $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' );
222
-
223
- //Get the field
224
- $field = FrmField::getOne($id);
225
-
226
- if ( ! empty( $field->options ) ) {
227
- $keys = array_keys( $field->options );
228
- $last = str_replace( 'other_', '', end( $keys ) );
229
- } else {
230
  $last = 0;
231
- }
232
  $opt_key = $last + 1;
233
-
234
- if ( 'other' == $opt_type ) {
235
- $opt = esc_html__( 'Other', 'formidable' );
236
- $other_val = '';
237
- $opt_key = 'other_' . $opt_key;
238
-
239
- //Update value of "other" in DB
240
- $field_options = maybe_unserialize( $field->field_options );
241
- $field_options['other'] = 1;
242
- FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) );
243
- } else {
244
- $first_opt = reset( $field->options );
245
- $next_opt = count( $field->options );
246
- if ( $first_opt != '' ) {
247
- $next_opt++;
248
- }
249
- $opt = esc_html__( 'Option', 'formidable' ) .' '. $next_opt;
250
- unset($next_opt);
251
- }
252
  $field_val = $opt;
253
- $field->options[ $opt_key ] = $opt;
254
-
255
- //Update options in DB
256
- FrmField::update( $id, array( 'options' => $field->options ) );
257
-
258
- $field_data = $field;
259
- $field = array(
260
- 'type' => $field_data->type,
261
- 'id' => $id,
262
- 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0,
263
- 'form_id' => $field_data->form_id,
264
- 'field_key' => $field_data->field_key,
265
- );
266
-
267
- $field_name = 'item_meta['. $id .']';
268
- $html_id = FrmFieldsHelper::get_html_id($field);
269
  $checked = '';
270
 
271
- if ( 'other' == $opt_type ) {
272
- require(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
273
- } else {
274
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
275
- }
276
- wp_die();
 
 
 
 
277
  }
278
 
279
- public static function edit_option() {
280
- check_ajax_referer( 'frm_ajax', 'nonce' );
281
-
282
- $element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' );
283
- $ids = explode( '-', $element_id );
284
- $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
285
-
286
- $orig_update_value = $update_value = trim( FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ) );
287
- if ( strpos( $element_id, 'key_' ) ) {
288
- $new_value = $update_value;
289
  } else {
290
- $new_label = $update_value;
291
- }
292
-
293
- $field = FrmField::getOne($id);
294
- $separate_values = ( isset($field->field_options['separate_value']) && $field->field_options['separate_value'] );
295
-
296
- $this_opt_id = end($ids);
297
- $this_opt = (array) $field->options[ $this_opt_id ];
298
- $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ? true : false );
299
-
300
  $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
301
- $value = isset($this_opt['value']) ? $this_opt['value'] : '';
302
-
303
- if ( ! isset( $new_label ) ) {
 
 
304
  $new_label = $label;
305
  }
306
-
307
  if ( isset($new_value) || isset($value) ) {
308
  $update_value = isset($new_value) ? $new_value : $value;
309
  }
310
-
311
- if ( $update_value != $new_label && $other_opt === false && $separate_values ) {
312
- $field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label );
313
  } else {
314
- $field->options[ $this_opt_id ] = $orig_update_value;
315
  }
316
-
317
- FrmField::update( $field->id, array( 'options' => $field->options ) );
318
- echo ( $orig_update_value == '' ) ? esc_html__( '(Blank)', 'formidable' ) : stripslashes( $orig_update_value );
319
- wp_die();
320
  }
321
 
322
- public static function delete_option() {
323
- check_ajax_referer( 'frm_ajax', 'nonce' );
324
-
325
- $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
326
- $field = FrmField::getOne( $field_id );
327
- // Opt key will NOT be numeric for "Other" options
328
- $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' );
329
-
330
- $options = $field->options;
331
- unset( $options[ $opt_key ] );
332
- $response = array( 'other' => true );
333
-
334
- //If the deleted option is an "other" option
335
- if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
336
- //Assume all other options are gone, unless proven otherwise
337
- $other = false;
338
-
339
- //Check if all other options are really gone
340
- foreach ( $options as $o_key => $o_val ) {
341
- //If there is still an other option in the field, set other to true
342
- if ( FrmAppHelper::is_other_opt( $o_key ) ) {
343
- $other = true;
344
- break;
345
- }
346
- unset( $o_key, $o_val );
347
- }
348
-
349
- //If all other options are gone
350
- if ( false === $other ) {
351
- $field_options = maybe_unserialize( $field->field_options );
352
- $field_options['other'] = 0;
353
- FrmField::update( $_POST['field_id'], array( 'field_options' => maybe_serialize( $field_options ) ) );
354
- $response = array( 'other' => false );
355
- }
356
- }
357
- echo json_encode( $response );
358
-
359
- FrmField::update( $_POST['field_id'], array( 'options' => maybe_serialize( $options ) ) );
360
-
361
- wp_die();
362
  }
363
-
364
- public static function import_choices() {
365
- if ( ! current_user_can( 'frm_edit_forms' ) ) {
366
- wp_die();
367
  }
368
-
369
- $field_id = absint( $_REQUEST['field_id'] );
370
-
371
  global $current_screen, $hook_suffix;
372
 
373
  // Catch plugins that include admin-header.php before admin.php completes.
374
- if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) {
375
  $hook_suffix = '';
376
  set_current_screen();
377
  }
378
-
379
- if ( function_exists( 'register_admin_color_schemes' ) ) {
380
  register_admin_color_schemes();
381
  }
382
-
383
  $hook_suffix = $admin_body_class = '';
384
-
385
- if ( get_user_setting( 'mfold' ) == 'f' ) {
386
  $admin_body_class .= ' folded';
387
- }
388
 
389
- if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
390
  $admin_body_class .= ' admin-bar';
391
  }
392
 
393
- if ( is_rtl() ) {
394
  $admin_body_class .= ' rtl';
395
- }
396
 
397
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
398
  $prepop = array();
399
- FrmFieldsHelper::get_bulk_prefilled_opts($prepop);
400
-
401
- $field = FrmField::getOne($field_id);
402
-
403
- wp_enqueue_script( 'utils' );
404
- wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url(). '/css/frm_admin.css' );
405
- FrmAppHelper::load_admin_wide_js();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
407
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
408
- wp_die();
409
  }
410
-
411
- public static function import_options() {
412
- check_ajax_referer( 'frm_ajax', 'nonce' );
413
-
414
- if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
415
  return;
416
- }
417
-
418
- $field_id = absint( $_POST['field_id'] );
419
- $field = FrmField::getOne($field_id);
420
-
421
- if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
 
422
  return;
423
- }
424
-
425
  $field = FrmFieldsHelper::setup_edit_vars($field);
426
- $opts = stripslashes_deep($_POST['opts']);
427
  $opts = explode("\n", rtrim($opts, "\n"));
428
  if ( $field['separate_value'] ) {
429
  foreach ( $opts as $opt_key => $opt ) {
430
  if ( strpos($opt, '|') !== false ) {
431
  $vals = explode('|', $opt);
432
  if ( $vals[0] != $vals[1] ) {
433
- $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) );
434
  }
435
  unset($vals);
436
  }
437
- unset($opt_key, $opt);
438
- }
439
- }
440
-
441
- //Keep other options after bulk update
442
- if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
443
- $other_array = array();
444
- foreach ( $field['options'] as $opt_key => $opt ) {
445
- if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
446
- $other_array[ $opt_key ] = $opt;
447
- }
448
- unset($opt_key, $opt);
449
- }
450
- if ( ! empty($other_array) ) {
451
- $opts = array_merge( $opts, $other_array);
452
  }
453
  }
454
-
455
- FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) );
456
-
457
  $field['options'] = $opts;
458
  $field_name = $field['name'];
459
-
460
- // Get html_id which will be used in single-option.php
461
- $html_id = FrmFieldsHelper::get_html_id( $field );
462
-
463
  if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
464
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
465
  } else {
466
- FrmFieldsHelper::show_single_option($field);
 
 
 
 
467
  }
468
-
469
- wp_die();
470
  }
471
 
472
- public static function update_order() {
473
- check_ajax_referer( 'frm_ajax', 'nonce' );
474
- if ( isset($_POST) && isset($_POST['frm_field_id']) ) {
475
- foreach ( $_POST['frm_field_id'] as $position => $item ) {
476
- FrmField::update( $item, array( 'field_order' => $position ) );
477
- }
478
  }
479
- wp_die();
480
  }
 
 
 
481
 
482
- public static function change_type($type) {
483
- $type_switch = array(
484
- 'scale' => 'radio',
485
- '10radio' => 'radio',
486
- 'rte' => 'textarea',
487
- 'website' => 'url',
488
- );
489
- if ( isset( $type_switch[ $type ] ) ) {
490
- $type = $type_switch[ $type ];
491
- }
492
-
493
  $frm_field_selection = FrmFieldsHelper::field_selection();
494
  $types = array_keys($frm_field_selection);
495
- if ( ! in_array($type, $types) && $type != 'captcha' ) {
496
  $type = 'text';
497
- }
498
 
499
  return $type;
500
  }
501
-
502
- public static function display_field_options($display) {
503
- switch($display['type']) {
504
  case 'captcha':
505
  $display['required'] = false;
506
  $display['invalid'] = true;
@@ -517,193 +425,107 @@ class FrmFieldsController {
517
  case 'select':
518
  $display['size'] = true;
519
  break;
520
- case 'url':
521
- case 'website':
522
- case 'email':
523
- $display['size'] = true;
524
- $display['clear_on_focus'] = true;
525
- $display['invalid'] = true;
526
  }
527
-
528
  return $display;
529
  }
530
-
531
- public static function input_html( $field, $echo = true ) {
532
- $class = array(); //$field['type'];
533
- self::add_input_classes($field, $class);
534
-
535
- $add_html = array();
536
- self::add_html_size($field, $add_html);
537
- self::add_html_length($field, $add_html);
538
- self::add_html_placeholder($field, $add_html, $class);
539
-
540
- $class = apply_filters('frm_field_classes', implode(' ', $class), $field);
541
-
542
- if ( ! empty($class) ) {
543
- $add_html['class'] = 'class="'. trim($class) .'"';
544
- }
545
-
546
- self::add_shortcodes_to_html($field, $add_html);
547
-
548
- $add_html = implode(' ', $add_html);
549
-
550
- if ( $echo ) {
551
- echo $add_html;
552
- }
553
-
554
- return $add_html;
555
- }
556
-
557
- private static function add_input_classes($field, array &$class) {
558
- if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
559
- return;
560
- }
561
-
562
- global $frm_vars;
563
- if ( is_admin() && ! FrmAppHelper::is_preview_page() && ! in_array( $field['type'], array( 'scale', 'radio', 'checkbox', 'data' ) ) ) {
564
- $class[] = 'dyn_default_value';
565
- }
566
-
567
- if ( isset($field['size']) && $field['size'] > 0 ) {
568
- $class[] = 'auto_width';
569
- }
570
-
571
- if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
572
- $class[] = $field['input_class'];
573
- }
574
- }
575
-
576
- private static function add_html_size($field, array &$add_html) {
577
- if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden' ) ) ) {
578
- return;
579
- }
580
-
581
- if ( FrmAppHelper::is_admin_page('formidable' ) ) {
582
- return;
583
- }
584
-
585
- if ( is_numeric($field['size']) ) {
586
- $field['size'] .= 'px';
587
- }
588
-
589
- $important = apply_filters('frm_use_important_width', 1, $field);
590
- // Note: This inline styling must stay since we cannot realistically set a class for every possible field size
591
- $add_html['style'] = 'style="width:'. esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) .'"';
592
-
593
- self::add_html_cols($field, $add_html);
594
- }
595
-
596
- private static function add_html_cols($field, array &$add_html) {
597
- if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
598
- return;
599
- }
600
-
601
- // convert to cols for textareas
602
- $calc = array(
603
- '' => 7.08,
604
- 'px' => 7.08,
605
- 'rem' => 0.444,
606
- 'em' => 0.544,
607
- );
608
-
609
- // include "col" for valid html
610
- $unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
611
-
612
- if ( ! isset( $calc[ $unit ] ) ) {
613
- return;
614
- }
615
-
616
- $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
617
-
618
- $add_html['cols'] = 'cols="'. (int) $size .'"';
619
- }
620
-
621
- private static function add_html_length($field, array &$add_html) {
622
- // check for max setting and if this field accepts maxlength
623
- if ( ! isset( $field['max'] ) || empty( $field['max'] ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden' ) ) ) {
624
- return;
625
- }
626
-
627
- if ( FrmAppHelper::is_admin_page('formidable' ) ) {
628
- // don't load on form builder page
629
- return;
630
- }
631
-
632
- $add_html['maxlength'] = 'maxlength="'. $field['max'] .'"';
633
- }
634
-
635
- private static function add_html_placeholder($field, array &$add_html, array &$class) {
636
- // check for a default value and placeholder setting
637
- if ( ! isset($field['clear_on_focus']) || ! $field['clear_on_focus'] || empty($field['default_value']) ) {
638
- return;
639
- }
640
-
641
- // don't apply this to the form builder page
642
- if ( FrmAppHelper::is_admin_page('formidable' ) ) {
643
- return;
644
- }
645
-
646
- $frm_settings = FrmAppHelper::get_settings();
647
-
648
- if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) {
649
- // use HMTL5 placeholder with js fallback
650
- $add_html['placeholder'] = 'placeholder="'. esc_attr($field['default_value']) .'"';
651
- wp_enqueue_script('jquery-placeholder');
652
- } else if ( ! $frm_settings->use_html ) {
653
- $val = str_replace( array("\r\n", "\n"), '\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
654
- $add_html['data-frmval'] = 'data-frmval="'. esc_attr($val) .'"';
655
- $class[] = 'frm_toggle_default';
656
-
657
- if ( $field['value'] == $field['default_value'] ) {
658
- $class[] = 'frm_default';
659
  }
660
  }
661
- }
662
-
663
- private static function add_shortcodes_to_html( $field, array &$add_html ) {
664
- if ( ! isset( $field['shortcodes'] ) || empty( $field['shortcodes'] ) ) {
665
- return;
666
- }
667
-
668
- foreach ( $field['shortcodes'] as $k => $v ) {
669
- if ( 'opt' === $k ) {
670
- continue;
671
- }
672
-
673
- if ( is_numeric($k) && strpos($v, '=') ) {
674
- $add_html[] = $v;
675
- } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
676
- $add_html[ $k ] = str_replace( $k .'="', $k .'="'. $v, $add_html[ $k ] );
677
- } else {
678
- $add_html[ $k ] = $k .'="'. $v .'"';
 
 
 
 
679
  }
680
-
681
- unset($k, $v);
682
  }
 
 
 
 
 
683
  }
684
-
685
- public static function check_value( $opt, $opt_key, $field ) {
686
- if ( is_array( $opt ) ) {
687
- if ( isset( $field['separate_value'] ) && $field['separate_value'] ) {
688
- $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
689
- } else {
690
- $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
691
  }
692
  }
693
  return $opt;
694
  }
695
-
696
- public static function check_label($opt) {
697
- if ( is_array($opt) ) {
698
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
699
- }
700
-
701
  return $opt;
702
  }
703
-
704
- public static function add_conditional_update_msg() {
705
- echo '<tr><td colspan="2">';
706
- FrmAppHelper::update_message( 'calculate and conditionally hide and show fields' );
707
- echo '</td></tr>';
708
- }
709
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
+
8
+ if(class_exists('FrmFieldsController'))
9
+ return;
10
+
11
+ class FrmFieldsController{
12
+ public static function load_hooks(){
13
+ add_action('wp_ajax_frm_load_field', 'FrmFieldsController::load_field');
14
+ add_action('wp_ajax_frm_insert_field', 'FrmFieldsController::create');
15
+ add_action('wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name');
16
+ add_action('wp_ajax_frm_field_desc_in_place_edit', 'FrmFieldsController::edit_description');
17
+ add_action('wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option');
18
+ add_action('wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate');
19
+ add_action('wp_ajax_frm_delete_field', 'FrmFieldsController::destroy');
20
+ add_action('wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option');
21
+ add_action('wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option');
22
+ add_action('wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option');
23
+ add_action('wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices');
24
+ add_action('wp_ajax_frm_import_options', 'FrmFieldsController::import_options');
25
+ add_action('wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order');
26
+ add_filter('frm_field_type', 'FrmFieldsController::change_type');
27
+ add_filter('frm_display_field_options', 'FrmFieldsController::display_field_options');
28
+ add_action('frm_field_input_html', 'FrmFieldsController::input_html');
29
+ add_filter('frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3);
30
+ add_filter('frm_field_label_seen', 'FrmFieldsController::check_label', 10, 3);
31
+ }
32
+
33
+ public static function load_field(){
34
  $fields = $_POST['field'];
35
+ if ( empty($fields) ) {
36
+ die();
37
  }
38
+
39
  $_GET['page'] = 'formidable';
40
+ $fields = stripslashes_deep($fields);
41
+
42
  $ajax = true;
43
  $values = array();
44
  $path = FrmAppHelper::plugin_path();
45
  $field_html = array();
46
+
47
  foreach ( $fields as $field ) {
48
+ $field = htmlspecialchars_decode(nl2br($field));
49
+ $field = json_decode($field, true);
50
+
51
+ $field_id = $field['id'];
52
+
53
+ if ( !isset($field['value']) ) {
 
 
 
 
54
  $field['value'] = '';
55
  }
56
+
57
+ $field_name = "item_meta[$field_id]";
58
+
 
59
  ob_start();
60
  include($path .'/classes/views/frm-forms/add_field.php');
61
+ $field_html[$field_id] = ob_get_contents();
62
  ob_end_clean();
63
  }
64
+
65
  unset($path);
66
+
67
  echo json_encode($field_html);
68
+
69
+ die();
70
  }
71
+
72
+ public static function create(){
73
+ $field_data = $_POST['field'];
74
+ $form_id = $_POST['form_id'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  $values = array();
76
+ if(class_exists('FrmProForm'))
77
  $values['post_type'] = FrmProFormsHelper::post_type($form_id);
78
+
79
+ $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_data, $form_id));
80
+
81
+ $frm_field = new FrmField();
82
+ $field_id = $frm_field->create( $field_values );
83
+
84
+ if ($field_id){
85
+ $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id));
86
+ $field_name = "item_meta[$field_id]";
87
+ $id = $form_id;
88
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
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
+ $frm_field = new FrmField();
109
+ $form = $frm_field->update($id, array($field => $value));
110
+ echo stripslashes($value);
111
+ die();
112
  }
113
+
114
 
115
+ public static function edit_description(){
116
+ $id = str_replace('field_description_', '', $_POST['element_id']);
117
+ self::edit_name('description', $id);
118
+ }
119
+
120
+ public static function update_ajax_option(){
121
+ $frm_field = new FrmField();
122
+ $field = $frm_field->getOne($_POST['field']);
123
+ foreach ( array('clear_on_focus', 'separate_value', 'default_blank') as $val ) {
124
+ if ( isset($_POST[$val]) ) {
125
+ $new_val = $_POST[$val];
 
 
 
 
126
  if ( $val == 'separate_value' ) {
127
+ $new_val = (isset($field->field_options[$val]) && $field->field_options[$val]) ? 0 : 1;
128
  }
129
+
130
+ $field->field_options[$val] = $new_val;
131
+ unset($new_val);
132
+ }
133
  unset($val);
134
  }
135
 
136
+ $frm_field->update($_POST['field'], array('field_options' => $field->field_options));
137
+ die();
 
 
 
138
  }
139
+
140
+ public static function duplicate(){
 
 
141
  global $wpdb;
142
+
143
+ $frm_field = new FrmField();
144
+ $copy_field = $frm_field->getOne($_POST['field_id']);
145
+ if (!$copy_field) return;
146
+
 
 
 
 
 
 
 
147
  $values = array();
148
+ $values['field_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_fields', 'field_key');
149
+ $values['options'] = maybe_serialize($copy_field->options);
150
+ $values['default_value'] = maybe_serialize($copy_field->default_value);
151
+ $values['form_id'] = $copy_field->form_id;
152
+ foreach (array('name', 'description', 'type', 'field_options', 'required') as $col)
153
+ $values[$col] = $copy_field->{$col};
154
+ $field_count = FrmAppHelper::getRecordCount(array('form_id' => $copy_field->form_id), $wpdb->prefix . 'frm_fields');
155
  $values['field_order'] = $field_count + 1;
156
+
157
+ $field_id = $frm_field->create($values);
158
+
159
+ if ($field_id){
160
+ $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id));
161
+ $field_name = "item_meta[$field_id]";
162
+ $id = $field['form_id'];
163
+ if($field['type'] == 'html')
164
+ $field['stop_filter'] = true;
165
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
166
+ }
167
+ die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
+
170
+ public static function destroy(){
171
+ $frm_field = new FrmField();
172
+ $field_id = $frm_field->destroy($_POST['field_id']);
173
+ die();
174
+ }
175
 
176
  /* Field Options */
177
+ public static function add_option(){
178
+ $frm_field = new FrmField();
179
+
180
+ $id = $_POST['field_id'];
181
+ $field = $frm_field->getOne($id);
182
+ $options = maybe_unserialize($field->options);
183
+ if(!empty($options))
184
+ $last = max(array_keys($options));
185
+ else
 
 
 
 
 
 
186
  $last = 0;
187
+
188
  $opt_key = $last + 1;
189
+ $first_opt = reset($options);
190
+ $next_opt = count($options);
191
+ if($first_opt != '')
192
+ $next_opt++;
193
+ $opt = __('Option', 'formidable') .' '. $next_opt;
194
+ unset($next_opt);
195
+
 
 
 
 
 
 
 
 
 
 
 
 
196
  $field_val = $opt;
197
+ $options[$opt_key] = $opt;
198
+ $frm_field->update($id, array('options' => maybe_serialize($options)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  $checked = '';
200
 
201
+ $field_data = $frm_field->getOne($id);
202
+ $field_data->field_options = maybe_unserialize($field_data->field_options);
203
+ $field = array();
204
+ $field['type'] = $field_data->type;
205
+ $field['id'] = $id;
206
+ $field['separate_value'] = isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0;
207
+ $field_name = "item_meta[$id]";
208
+
209
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
210
+ die();
211
  }
212
 
213
+ public static function edit_option(){
214
+ $ids = explode('-', $_POST['element_id']);
215
+ $id = str_replace('field_', '', $ids[0]);
216
+ if ( strpos($_POST['element_id'], 'key_') ) {
217
+ $id = str_replace('key_', '', $id);
218
+ $new_value = trim($_POST['update_value']);
 
 
 
 
219
  } else {
220
+ $new_label = trim($_POST['update_value']);
221
+ }
222
+
223
+ $frm_field = new FrmField();
224
+ $field = $frm_field->getOne($id);
225
+ $options = maybe_unserialize($field->options);
226
+ $this_opt = (array) $options[$ids[1]];
227
+
 
 
228
  $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
229
+ if ( isset($this_opt['value']) ) {
230
+ $value = $this_opt['value'];
231
+ }
232
+
233
+ if ( !isset($new_label) ) {
234
  $new_label = $label;
235
  }
236
+
237
  if ( isset($new_value) || isset($value) ) {
238
  $update_value = isset($new_value) ? $new_value : $value;
239
  }
240
+
241
+ if ( isset($update_value) && $update_value != $new_label ) {
242
+ $options[$ids[1]] = array('value' => $update_value, 'label' => $new_label);
243
  } else {
244
+ $options[$ids[1]] = trim($_POST['update_value']);
245
  }
246
+
247
+ $frm_field->update($id, array('options' => maybe_serialize($options)));
248
+ echo (trim($_POST['update_value']) == '') ? __('(Blank)', 'formidable') : stripslashes($_POST['update_value']);
249
+ die();
250
  }
251
 
252
+ public static function delete_option(){
253
+ $frm_field = new FrmField();
254
+ $field = $frm_field->getOne($_POST['field_id']);
255
+ $options = maybe_unserialize($field->options);
256
+ unset($options[$_POST['opt_key']]);
257
+ $frm_field->update($_POST['field_id'], array('options' => maybe_serialize($options)));
258
+ die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  }
260
+
261
+ public static function import_choices(){
262
+ if ( !current_user_can('frm_edit_forms') ) {
263
+ return;
264
  }
265
+
266
+ $field_id = $_REQUEST['field_id'];
267
+
268
  global $current_screen, $hook_suffix;
269
 
270
  // Catch plugins that include admin-header.php before admin.php completes.
271
+ if ( empty( $current_screen ) && function_exists('set_current_screen') ) {
272
  $hook_suffix = '';
273
  set_current_screen();
274
  }
275
+
276
+ if ( function_exists('register_admin_color_schemes') ) {
277
  register_admin_color_schemes();
278
  }
279
+
280
  $hook_suffix = $admin_body_class = '';
281
+
282
+ if ( get_user_setting('mfold') == 'f' )
283
  $admin_body_class .= ' folded';
 
284
 
285
+ if ( function_exists('is_admin_bar_showing') && is_admin_bar_showing() ) {
286
  $admin_body_class .= ' admin-bar';
287
  }
288
 
289
+ if ( is_rtl() )
290
  $admin_body_class .= ' rtl';
 
291
 
292
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
293
  $prepop = array();
294
+ $prepop[__('Countries', 'formidable')] = FrmAppHelper::get_countries();
295
+
296
+ $states = FrmAppHelper::get_us_states();
297
+ $state_abv = array_keys($states);
298
+ sort($state_abv);
299
+ $prepop[__('U.S. State Abbreviations', 'formidable')] = $state_abv;
300
+ $states = array_values($states);
301
+ sort($states);
302
+ $prepop[__('U.S. States', 'formidable')] = $states;
303
+ unset($state_abv);
304
+ unset($states);
305
+
306
+ $prepop[__('Age', 'formidable')] = array(
307
+ __('Under 18', 'formidable'), __('18-24', 'formidable'), __('25-34', 'formidable'),
308
+ __('35-44', 'formidable'), __('45-54', 'formidable'), __('55-64', 'formidable'),
309
+ __('65 or Above', 'formidable'), __('Prefer Not to Answer', 'formidable')
310
+ );
311
+
312
+ $prepop[__('Satisfaction', 'formidable')] = array(
313
+ __('Very Satisfied', 'formidable'), __('Satisfied', 'formidable'), __('Neutral', 'formidable'),
314
+ __('Unsatisfied', 'formidable'), __('Very Unsatisfied', 'formidable'), __('N/A', 'formidable')
315
+ );
316
 
317
+ $prepop[__('Importance', 'formidable')] = array(
318
+ __('Very Important', 'formidable'), __('Important', 'formidable'), __('Neutral', 'formidable'),
319
+ __('Somewhat Important', 'formidable'), __('Not at all Important', 'formidable'), __('N/A', 'formidable')
320
+ );
321
+
322
+ $prepop[__('Agreement', 'formidable')] = array(
323
+ __('Strongly Agree', 'formidable'), __('Agree', 'formidable'), __('Neutral', 'formidable'),
324
+ __('Disagree', 'formidable'), __('Strongly Disagree', 'formidable'), __('N/A', 'formidable')
325
+ );
326
+
327
+ $prepop = apply_filters('frm_bulk_field_choices', $prepop);
328
+
329
+ $frm_field = new FrmField();
330
+ $field = $frm_field->getOne($field_id);
331
+
332
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
333
+ die();
334
  }
335
+
336
+ public static function import_options(){
337
+ if(!is_admin() or !current_user_can('frm_edit_forms'))
 
 
338
  return;
339
+
340
+ extract(stripslashes_deep($_POST));
341
+
342
+ $frm_field = new FrmField();
343
+ $field = $frm_field->getOne($field_id);
344
+
345
+ if(!in_array($field->type, array('radio', 'checkbox', 'select')))
346
  return;
347
+
 
348
  $field = FrmFieldsHelper::setup_edit_vars($field);
 
349
  $opts = explode("\n", rtrim($opts, "\n"));
350
  if ( $field['separate_value'] ) {
351
  foreach ( $opts as $opt_key => $opt ) {
352
  if ( strpos($opt, '|') !== false ) {
353
  $vals = explode('|', $opt);
354
  if ( $vals[0] != $vals[1] ) {
355
+ $opts[$opt_key] = array('label' => trim($vals[0]), 'value' => trim($vals[1]));
356
  }
357
  unset($vals);
358
  }
359
+ unset($opt_key);
360
+ unset($opt);
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
  }
363
+
364
+ $frm_field->update($field_id, array('options' => maybe_serialize($opts)));
365
+
366
  $field['options'] = $opts;
367
  $field_name = $field['name'];
368
+
 
 
 
369
  if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
370
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
371
  } else {
372
+ foreach ( $field['options'] as $opt_key => $opt ) {
373
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
374
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
375
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
376
+ }
377
  }
378
+
379
+ die();
380
  }
381
 
382
+ public static function update_order(){
383
+ if(isset($_POST) and isset($_POST['frm_field_id'])){
384
+ $frm_field = new FrmField();
385
+
386
+ foreach ($_POST['frm_field_id'] as $position => $item)
387
+ $frm_field->update($item, array('field_order' => $position));
388
  }
389
+ die();
390
  }
391
+
392
+ public static function change_type($type){
393
+ global $frm_vars;
394
 
395
+ if ($frm_vars['pro_is_installed']) return $type;
396
+
397
+ if($type == 'scale' || $type == '10radio')
398
+ $type = 'radio';
399
+ else if($type == 'rte')
400
+ $type = 'textarea';
401
+
 
 
 
 
402
  $frm_field_selection = FrmFieldsHelper::field_selection();
403
  $types = array_keys($frm_field_selection);
404
+ if (!in_array($type, $types) && $type != 'captcha')
405
  $type = 'text';
 
406
 
407
  return $type;
408
  }
409
+
410
+ public static function display_field_options($display){
411
+ switch($display['type']){
412
  case 'captcha':
413
  $display['required'] = false;
414
  $display['invalid'] = true;
425
  case 'select':
426
  $display['size'] = true;
427
  break;
 
 
 
 
 
 
428
  }
429
+
430
  return $display;
431
  }
432
+
433
+ public static function input_html($field, $echo=true){
434
+ global $frm_settings, $frm_vars;
435
+
436
+ $class = ''; //$field['type'];
437
+
438
+ if ( is_admin() && (!isset($frm_vars['preview']) || !$frm_vars['preview']) && !in_array($field['type'], array('scale', 'radio', 'checkbox', 'data')) ) {
439
+ $class .= 'dyn_default_value';
440
+ }
441
+
442
+ $add_html = '';
443
+
444
+ if(isset($field['size']) and $field['size'] > 0){
445
+ if(!in_array($field['type'], array('textarea', 'select', 'data', 'time', 'hidden')))
446
+ $add_html .= ' size="'. $field['size'] .'"';
447
+ $class .= " auto_width";
448
+ }
449
+
450
+ if ( isset($field['max']) && !in_array($field['type'], array('textarea', 'rte', 'hidden')) && !empty($field['max']) && (!is_admin() || !isset($_GET) || !isset($_GET['page']) || $_GET['page'] != 'formidable') ) {
451
+ $add_html .= ' maxlength="'. $field['max'] .'"';
452
+ }
453
+
454
+ if(!is_admin() or defined('DOING_AJAX') or !isset($_GET) or !isset($_GET['page']) or $_GET['page'] == 'formidable-entries'){
455
+ /*if(isset($field['required']) and $field['required']){
456
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
457
+ $action = FrmAppHelper::get_param($action);
458
+
459
+ //if($field['type'] != 'checkbox')
460
+ // $add_html .= ' required="required"';
461
+
462
+ if($field['type'] == 'file' and $action == 'edit'){
463
+ //don't add the required class if this is a file upload when editing
464
+ }else{
465
+ $class .= " required";
466
+ }
467
+ unset($action);
468
+ }*/
469
+
470
+ if(isset($field['clear_on_focus']) and $field['clear_on_focus'] and !empty($field['default_value'])){
471
+
472
+ if($frm_settings->use_html and !in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden'))){
473
+ $add_html .= ' placeholder="'. esc_attr($field['default_value']) .'"';
474
+ FrmAppHelper::load_scripts('jquery-placeholder');
475
+ }else if(!$frm_settings->use_html){
476
+ $val = str_replace(array("\r\n", "\n"), '\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
477
+ $add_html .= ' onfocus="frmClearDefault('."'". $val ."'". ',this)" onblur="frmReplaceDefault('."'". $val ."'". ',this)"';
478
+ if($field['value'] == $field['default_value'])
479
+ $class .= ' frm_default';
480
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  }
482
  }
483
+
484
+ if(isset($field['input_class']) and !empty($field['input_class']))
485
+ $class .= ' '. $field['input_class'];
486
+
487
+ $class = apply_filters('frm_field_classes', $class, $field);
488
+
489
+ if(!empty($class))
490
+ $add_html .= ' class="'. trim($class) .'"';
491
+
492
+ if ( isset($field['shortcodes']) && !empty($field['shortcodes']) ) {
493
+ foreach ( $field['shortcodes'] as $k => $v ) {
494
+ if ( 'opt' === $k || (!is_numeric($k) && strpos($add_html, " $k=")) ) {
495
+ continue;
496
+ }
497
+
498
+ if ( is_numeric($k) && strpos($v, '=') ) {
499
+ $add_html .= ' '. $v;
500
+ } else {
501
+ $add_html .= ' '. $k .'="'. $v .'"';
502
+ }
503
+
504
+ unset($k, $v);
505
  }
 
 
506
  }
507
+
508
+ if($echo)
509
+ echo $add_html;
510
+
511
+ return $add_html;
512
  }
513
+
514
+ public static function check_value($opt, $opt_key, $field){
515
+ if(is_array($opt)){
516
+ if(isset($field['separate_value']) and $field['separate_value']){
517
+ $opt = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
518
+ }else{
519
+ $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
520
  }
521
  }
522
  return $opt;
523
  }
524
+
525
+ public static function check_label($opt, $opt_key, $field){
526
+ if(is_array($opt))
527
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
528
+
 
529
  return $opt;
530
  }
 
 
 
 
 
 
531
  }
classes/controllers/FrmFormActionsController.php DELETED
@@ -1,353 +0,0 @@
1
- <?php
2
-
3
- class FrmFormActionsController {
4
- public static $action_post_type = 'frm_form_actions';
5
- public static $registered_actions;
6
-
7
- public static function register_post_types() {
8
- register_post_type( self::$action_post_type, array(
9
- 'label' => __( 'Form Actions', 'formidable' ),
10
- 'description' => '',
11
- 'public' => false,
12
- 'show_ui' => false,
13
- 'exclude_from_search' => true,
14
- 'show_in_nav_menus' => false,
15
- 'show_in_menu' => true,
16
- 'capability_type' => 'page',
17
- 'supports' => array(
18
- 'title', 'editor', 'excerpt', 'custom-fields',
19
- 'page-attributes',
20
- ),
21
- 'has_archive' => false,
22
- ) );
23
-
24
- /**
25
- * post_content: json settings
26
- * menu_order: form id
27
- * post_excerpt: action type
28
- */
29
-
30
- self::actions_init();
31
- }
32
-
33
- public static function actions_init() {
34
- self::$registered_actions = new Frm_Form_Action_Factory();
35
- self::register_actions();
36
- do_action( 'frm_form_actions_init' );
37
- }
38
-
39
- public static function register_actions() {
40
- $action_classes = apply_filters( 'frm_registered_form_actions', array(
41
- 'email' => 'FrmEmailAction',
42
- 'wppost' => 'FrmDefPostAction',
43
- 'register' => 'FrmDefRegAction',
44
- 'paypal' => 'FrmDefPayPalAction',
45
- 'aweber' => 'FrmDefAweberAction',
46
- 'mailchimp' => 'FrmDefMlcmpAction',
47
- 'twilio' => 'FrmDefTwilioAction',
48
- 'highrise' => 'FrmDefHrsAction',
49
- ) );
50
-
51
- include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php');
52
- include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php');
53
-
54
- foreach ( $action_classes as $action_class ) {
55
- self::$registered_actions->register($action_class);
56
- }
57
- }
58
-
59
- public static function get_form_actions($action = 'all' ) {
60
- $temp_actions = self::$registered_actions;
61
- if ( empty($temp_actions) ) {
62
- self::actions_init();
63
- $temp_actions = self::$registered_actions->actions;
64
- } else {
65
- $temp_actions = $temp_actions->actions;
66
- }
67
-
68
- $actions = array();
69
-
70
- foreach ( $temp_actions as $a ) {
71
- if ( 'all' != $action && $a->id_base == $action ) {
72
- return $a;
73
- }
74
-
75
- $actions[$a->id_base] = $a;
76
- }
77
- unset( $temp_actions, $a );
78
-
79
- $action_limit = 10;
80
- if ( count( $actions ) <= $action_limit ) {
81
- return $actions;
82
- }
83
-
84
- // remove the last few inactive icons if there are too many
85
- $temp_actions = $actions;
86
- arsort( $temp_actions );
87
- foreach ( $temp_actions as $type => $a ) {
88
- if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) {
89
- unset( $actions[$type] );
90
- if ( count( $actions ) <= $action_limit ) {
91
- break;
92
- }
93
- }
94
- unset( $type, $a );
95
- }
96
-
97
- return $actions;
98
- }
99
-
100
- public static function list_actions( $form, $values ) {
101
- if ( empty( $form ) ) {
102
- return;
103
- }
104
-
105
- do_action( 'frm_before_list_actions', $form ); // use this hook to migrate old settings into a new action
106
-
107
- $form_actions = FrmFormActionsHelper::get_action_for_form( $form->id );
108
-
109
- $action_controls = self::get_form_actions();
110
-
111
- $action_map = array();
112
-
113
- foreach ( $action_controls as $key => $control ) {
114
- $action_map[ $control->id_base ] = $key;
115
- }
116
-
117
- foreach ( $form_actions as $action ) {
118
- if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
119
- // don't try and show settings if action no longer exists
120
- continue;
121
- }
122
-
123
- self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
124
- }
125
- }
126
-
127
- public static function action_control($form_action, $form, $action_key, $action_control, $values) {
128
- $action_control->_set($action_key);
129
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php');
130
- }
131
-
132
- public static function add_form_action() {
133
- check_ajax_referer( 'frm_ajax', 'nonce' );
134
-
135
- global $frm_vars;
136
-
137
- $action_key = absint( $_POST['list_id'] );
138
- $action_type = sanitize_text_field( $_POST['type'] );
139
-
140
- $action_control = self::get_form_actions( $action_type );
141
- $action_control->_set($action_key);
142
-
143
- $form_id = absint( $_POST['form_id'] );
144
-
145
- $form_action = $action_control->prepare_new($form_id);
146
-
147
- $values = array();
148
- $form = self::fields_to_values($form_id, $values);
149
-
150
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php');
151
- wp_die();
152
- }
153
-
154
- public static function fill_action() {
155
- check_ajax_referer( 'frm_ajax', 'nonce' );
156
-
157
- $action_key = absint( $_POST['action_id'] );
158
- $action_type = sanitize_text_field( $_POST['action_type'] );
159
-
160
- $action_control = self::get_form_actions( $action_type );
161
- if ( empty($action_control) ) {
162
- wp_die();
163
- }
164
-
165
- $form_action = $action_control->get_single_action( $action_key );
166
-
167
- $values = array();
168
- $form = self::fields_to_values($form_action->menu_order, $values);
169
-
170
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_action_inside.php');
171
- wp_die();
172
- }
173
-
174
- private static function fields_to_values($form_id, array &$values) {
175
- $form = FrmForm::getOne($form_id);
176
-
177
- $values = array( 'fields' => array(), 'id' => $form->id);
178
-
179
- $fields = FrmField::get_all_for_form($form->id);
180
- foreach ( $fields as $k => $f ) {
181
- $f = (array) $f;
182
- $opts = (array) $f['field_options'];
183
- $f = array_merge($opts, $f);
184
- if ( ! isset( $f['post_field'] ) ) {
185
- $f['post_field'] = '';
186
- }
187
- $values['fields'][] = $f;
188
- unset($k, $f);
189
- }
190
-
191
- return $form;
192
- }
193
-
194
- public static function update_settings($form_id) {
195
- global $wpdb;
196
-
197
- $registered_actions = self::$registered_actions->actions;
198
-
199
- $old_actions = FrmDb::get_col( $wpdb->posts, array( 'post_type' => self::$action_post_type, 'menu_order' => $form_id), 'ID' );
200
- $new_actions = array();
201
-
202
- foreach ( $registered_actions as $registered_action ) {
203
- $action_ids = $registered_action->update_callback($form_id);
204
- if ( ! empty( $action_ids ) ) {
205
- $new_actions[] = $action_ids;
206
- }
207
- }
208
-
209
- //Only use array_merge if there are new actions
210
- if ( ! empty( $new_actions ) ) {
211
- $new_actions = call_user_func_array( 'array_merge', $new_actions );
212
- }
213
- $old_actions = array_diff( $old_actions, $new_actions );
214
-
215
- // delete any actions that were not included on the page
216
- if ( ! empty( $old_actions ) ) {
217
- foreach ( $old_actions as $old_id ) {
218
- wp_delete_post( $old_id );
219
- }
220
- }
221
- }
222
-
223
- public static function trigger_create_actions( $entry_id, $form_id ) {
224
- self::trigger_actions( 'create', $form_id, $entry_id );
225
- }
226
-
227
- /**
228
- * @param string $event
229
- */
230
- public static function trigger_actions( $event, $form, $entry, $type = 'all' ) {
231
- $form_actions = FrmFormActionsHelper::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type );
232
-
233
- if ( empty( $form_actions ) ) {
234
- return;
235
- }
236
-
237
- FrmFormsHelper::maybe_get_form( $form );
238
-
239
- $link_settings = self::get_form_actions( $type );
240
- if ( 'all' != $type ) {
241
- $link_settings = array( $type => $link_settings );
242
- }
243
-
244
- $stored_actions = $action_priority = array();
245
-
246
- foreach ( $form_actions as $action ) {
247
-
248
- if ( ! in_array( $event, $action->post_content['event'] ) ) {
249
- continue;
250
- }
251
-
252
- if ( ! is_object( $entry ) ) {
253
- $entry = FrmEntry::getOne( $entry, true );
254
- }
255
-
256
- if ( ! $form || ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ! $entry || $entry->form_id != $form->id ) {
257
- //don't trigger actions for sub forms
258
- continue;
259
- }
260
-
261
- if ( $entry->is_draft ) {
262
- // TODO: add trigger actions for drafts
263
- continue;
264
- }
265
-
266
- // check conditional logic
267
- $stop = FrmFormActionsHelper::action_conditions_met($action, $entry);
268
- if ( $stop ) {
269
- continue;
270
- }
271
-
272
- // store actions so they can be triggered with the correct priority
273
- $stored_actions[ $action->ID ] = $action;
274
- $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
275
-
276
- unset($action);
277
- }
278
-
279
- if ( ! empty( $stored_actions ) ) {
280
- asort($action_priority);
281
-
282
- // make sure hooks are loaded
283
- new FrmNotification();
284
-
285
- foreach ( $action_priority as $action_id => $priority ) {
286
- $action = $stored_actions[ $action_id ];
287
- do_action('frm_trigger_'. $action->post_excerpt .'_action', $action, $entry, $form, $event);
288
- do_action('frm_trigger_'. $action->post_excerpt .'_'. $event .'_action', $action, $entry, $form);
289
-
290
- // If post is created, get updated $entry object
291
- if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
292
- $entry = FrmEntry::getOne($entry->id, true);
293
- }
294
- }
295
- }
296
- }
297
-
298
- public static function duplicate_form_actions($form_id, $values, $args = array() ) {
299
- if ( ! isset($args['old_id']) || empty($args['old_id']) ) {
300
- // continue if we know which actions to copy
301
- return;
302
- }
303
-
304
- $action_controls = self::get_form_actions( );
305
-
306
- foreach ( $action_controls as $action_control ) {
307
- $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
308
- unset( $action_control );
309
- }
310
- }
311
-
312
- public static function limit_by_type( $where ) {
313
- global $frm_vars, $wpdb;
314
-
315
- if ( ! isset( $frm_vars['action_type'] ) ) {
316
- return $where;
317
- }
318
-
319
- $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
320
- return $where;
321
- }
322
-
323
- }
324
-
325
-
326
- class Frm_Form_Action_Factory {
327
- public $actions = array();
328
-
329
- public function __construct() {
330
- add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
331
- }
332
-
333
- public function register($action_class) {
334
- $this->actions[ $action_class ] = new $action_class();
335
- }
336
-
337
- public function unregister($action_class) {
338
- if ( isset( $this->actions[ $action_class ] ) ) {
339
- unset($this->actions[ $action_class ]);
340
- }
341
- }
342
-
343
- public function _register_actions() {
344
- $keys = array_keys($this->actions);
345
-
346
- foreach ( $keys as $key ) {
347
- // don't register new action if old action with the same id is already registered
348
- if ( ! isset( $this->actions[ $key ] ) ) {
349
- $this->actions[ $key ]->_register();
350
- }
351
- }
352
- }
353
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/controllers/FrmFormsController.php CHANGED
@@ -1,468 +1,364 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- class FrmFormsController {
4
-
5
- public static function trigger_load_form_hooks() {
6
- FrmHooksController::trigger_load_hook( 'load_form_hooks' );
7
- }
8
-
9
- /**
10
- * The hooks only needed when a form is loaded
11
- */
12
- public static function load_form_hooks() {
13
- add_filter('frm_form_classes', 'FrmFormsController::form_classes' );
14
- }
15
-
16
- public static function menu() {
17
- add_submenu_page('formidable', 'Formidable | '. __( 'Forms', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
18
-
19
- add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
20
-
21
- add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
22
- add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
23
- }
24
-
25
- public static function head() {
26
  wp_enqueue_script('formidable-editinplace');
27
-
28
- if ( wp_is_mobile() ) {
29
- wp_enqueue_script( 'jquery-touch-punch' );
30
- }
31
  }
32
-
33
- public static function register_widgets() {
34
  require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
35
  register_widget('FrmShowForm');
36
  }
37
-
38
- public static function list_form() {
39
- FrmAppHelper::permission_check('frm_view_forms');
40
-
41
- $params = FrmFormsHelper::get_params();
42
- $errors = self::process_bulk_form_actions( array());
43
- $errors = apply_filters('frm_admin_list_form_action', $errors);
44
-
45
- return self::display_forms_list($params, '', false, $errors);
46
  }
47
-
48
- public static function new_form( $values = array() ) {
49
- FrmAppHelper::permission_check('frm_edit_forms');
50
-
 
 
 
 
51
  global $frm_vars;
52
-
53
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
54
- $action = empty( $values ) ? sanitize_title( FrmAppHelper::get_param( $action ) ) : $values[ $action ];
55
-
56
- if ($action == 'create') {
 
57
  return self::create($values);
58
- } else if ($action == 'new') {
59
- $frm_field_selection = FrmFieldsHelper::field_selection();
60
  $values = FrmFormsHelper::setup_new_vars($values);
61
- $id = FrmForm::create( $values );
62
- $form = FrmForm::getOne($id);
63
-
64
- // add default email notification
65
- $action_control = FrmFormActionsController::get_form_actions( 'email' );
66
- $action_control->create($form->id);
67
-
68
- $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
69
-
70
  $values['id'] = $id;
71
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
 
 
 
72
  }
73
  }
74
-
75
- public static function create( $values = array() ) {
76
- FrmAppHelper::permission_check('frm_edit_forms');
77
-
78
- global $frm_vars;
79
- if ( empty( $values ) ) {
80
  $values = $_POST;
81
- }
82
-
83
- //Set radio button and checkbox meta equal to "other" value
84
- if ( FrmAppHelper::pro_is_installed() ) {
85
- $values = FrmProEntry::mod_other_vals( $values, 'back' );
86
- }
87
-
88
- $id = isset($values['id']) ? absint( $values['id'] ) : absint( FrmAppHelper::get_param( 'id' ) );
89
-
90
- if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
91
- $frm_settings = FrmAppHelper::get_settings();
92
- $errors = array( 'form' => $frm_settings->admin_permission );
93
- } else {
94
- $errors = FrmForm::validate($values);
95
- }
96
-
97
- if ( count($errors) > 0 ) {
98
  $hide_preview = true;
99
  $frm_field_selection = FrmFieldsHelper::field_selection();
100
- $form = FrmForm::getOne( $id );
101
- $fields = FrmField::get_all_for_form($id);
102
-
103
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
104
- $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
105
-
106
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
107
- } else {
108
- FrmForm::update( $id, $values, true );
109
  die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
 
 
110
  }
111
  }
112
-
113
- public static function edit( $values = false ) {
114
- FrmAppHelper::permission_check('frm_edit_forms');
115
-
116
- $id = isset( $values['id'] ) ? absint( $values['id'] ) : absint( FrmAppHelper::get_param( 'id' ) );
 
 
 
117
  return self::get_edit_vars($id);
118
  }
119
-
120
- public static function settings( $id = false, $message = '' ) {
121
- FrmAppHelper::permission_check('frm_edit_forms');
122
-
123
- if ( ! $id || ! is_numeric($id) ) {
124
- $id = absint( FrmAppHelper::get_param( 'id' ) );
125
- }
126
  return self::get_settings_vars($id, '', $message);
127
  }
128
-
129
- public static function update_settings() {
130
- FrmAppHelper::permission_check('frm_edit_forms');
131
-
132
- $id = absint( FrmAppHelper::get_param( 'id' ) );
133
-
134
- $errors = FrmForm::validate($_POST);
135
- if ( count($errors) > 0 ) {
136
  return self::get_settings_vars($id, $errors);
 
 
 
 
137
  }
138
-
139
- do_action('frm_before_update_form_settings', $id);
140
-
141
- FrmForm::update( $id, $_POST );
142
-
143
- $message = __( 'Settings Successfully Updated', 'formidable' );
144
- return self::get_settings_vars($id, '', $message);
145
  }
146
-
147
- public static function edit_key() {
148
- check_ajax_referer( 'frm_ajax', 'nonce' );
149
- FrmAppHelper::permission_check('frm_edit_forms', 'hide');
150
-
 
151
  global $wpdb;
152
- $values = array( 'form_key' => trim($_POST['update_value']));
153
-
154
- FrmForm::update($_POST['form_id'], $values);
155
- $key = FrmForm::getKeyById($_POST['form_id']);
156
- echo stripslashes($key);
157
- wp_die();
158
  }
159
 
160
- public static function edit_description() {
161
- check_ajax_referer( 'frm_ajax', 'nonce' );
162
- FrmAppHelper::permission_check('frm_edit_forms', 'hide');
163
-
164
- FrmForm::update($_POST['form_id'], array( 'description' => $_POST['update_value']));
165
- $description = FrmAppHelper::use_wpautop(stripslashes($_POST['update_value']));
 
 
 
 
166
  echo $description;
167
- wp_die();
168
  }
 
 
 
169
 
170
- public static function update( $values = array() ) {
171
- if ( empty( $values ) ) {
172
  $values = $_POST;
173
- }
174
-
175
- //Set radio button and checkbox meta equal to "other" value
176
- if ( FrmAppHelper::pro_is_installed() ) {
177
- $values = FrmProEntry::mod_other_vals( $values, 'back' );
178
- }
179
-
180
- $errors = FrmForm::validate( $values );
181
- $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
182
- if ( $permission_error !== false ) {
183
- $errors['form'] = $permission_error;
184
- }
185
-
186
- $id = isset( $values['id'] ) ? (int) $values['id'] : (int) FrmAppHelper::get_param( 'id' );
187
-
188
- if ( count( $errors ) > 0 ) {
189
- return self::get_edit_vars( $id, $errors );
190
- } else {
191
- FrmForm::update( $id, $values );
192
- $message = __( 'Form was Successfully Updated', 'formidable' );
193
- if ( defined( 'DOING_AJAX' ) ) {
194
- die( $message );
195
  }
196
- return self::get_edit_vars( $id, '', $message );
197
  }
198
  }
199
-
200
- public static function bulk_create_template( $ids ) {
201
- FrmAppHelper::permission_check( 'frm_edit_forms' );
202
-
203
- foreach ( $ids as $id ) {
204
- FrmForm::duplicate( $id, true, true );
205
  }
206
-
207
- return __( 'Form template was Successfully Created', 'formidable' );
208
- }
209
-
210
- /**
211
- * Redirect to the url for creating from a template
212
- * Also delete the current form
213
- * @since 2.0
214
- */
215
- public static function _create_from_template() {
216
- check_ajax_referer( 'frm_ajax', 'nonce' );
217
-
218
- $current_form = (int) FrmAppHelper::get_param( 'this_form' );
219
- $template_id = (int) FrmAppHelper::get_param( 'id' );
220
-
221
- if ( $current_form ) {
222
- FrmForm::destroy( $current_form );
223
- }
224
-
225
- echo admin_url( 'admin.php?page=formidable&action=duplicate&id=' . $template_id );
226
- wp_die();
227
- }
228
-
229
- public static function duplicate() {
230
- FrmAppHelper::permission_check('frm_edit_forms');
231
-
232
- $params = FrmFormsHelper::get_params();
233
- $form = FrmForm::duplicate( $params['id'], $params['template'], true );
234
- $message = ($params['template']) ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
235
  if ( $form ) {
236
  return self::get_edit_vars($form, '', $message, true);
237
  } else {
238
- return self::display_forms_list($params, __( 'There was a problem creating new template.', 'formidable' ));
239
- }
240
- }
241
-
242
- public static function page_preview() {
243
- $params = FrmFormsHelper::get_params();
244
- if ( ! $params['form'] ) {
245
- return;
246
- }
247
-
248
- $form = FrmForm::getOne( $params['form'] );
249
- if ( ! $form ) {
250
- return;
251
- }
252
- return self::show_form( $form->id, '', true, true );
253
- }
254
-
255
- public static function preview() {
256
- do_action( 'frm_wp' );
257
-
258
- global $frm_vars;
 
 
 
259
  $frm_vars['preview'] = true;
260
-
261
- if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
 
262
  global $wp;
263
- $root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
264
  include_once( $root.'/wp-config.php' );
265
  $wp->init();
266
  $wp->register_globals();
267
  }
268
-
269
- if ( FrmAppHelper::pro_is_installed() ) {
270
  FrmProEntriesController::register_scripts();
271
- }
272
-
273
- header( 'Content-Type: text/html; charset='. get_option( 'blog_charset' ) );
274
 
275
  $plugin = FrmAppHelper::get_param('plugin');
276
  $controller = FrmAppHelper::get_param('controller');
277
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
278
- $form = FrmForm::getAll( array( 'form_key' => $key), '', 1);
279
- if ( empty($form) ) {
280
- $form = FrmForm::getAll( array(), '', 1 );
281
- }
282
-
283
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
284
- wp_die();
285
- }
286
-
287
- public static function untrash() {
288
- FrmFormsHelper::change_form_status('untrash');
289
- }
290
-
291
- public static function bulk_untrash($ids) {
292
- FrmAppHelper::permission_check('frm_edit_forms');
293
-
294
- $count = FrmForm::set_status( $ids, 'published' );
295
-
296
- $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
297
- return $message;
298
- }
299
-
300
- public static function trash() {
301
- FrmFormsHelper::change_form_status('trash');
302
- }
303
-
304
- public static function bulk_trash($ids) {
305
- FrmAppHelper::permission_check('frm_delete_forms');
306
-
307
- $count = 0;
308
- foreach ( $ids as $id ) {
309
- if ( FrmForm::trash( $id ) ) {
310
- $count++;
311
- }
312
- }
313
-
314
- $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
315
- $message = sprintf(_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="'. esc_url(wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type='. $current_page .'&item-action[]='. implode('item-action[]=', $ids), 'bulk-toplevel_page_formidable' )) .'">', '</a>' );
316
-
317
- return $message;
318
- }
319
-
320
- public static function destroy() {
321
- FrmAppHelper::permission_check('frm_delete_forms');
322
-
323
- $params = FrmFormsHelper::get_params();
324
-
325
- //check nonce url
326
- check_admin_referer('destroy_form_' . $params['id']);
327
-
328
- $count = 0;
329
- if ( FrmForm::destroy( $params['id'] ) ) {
330
- $count++;
331
- }
332
-
333
- $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
334
-
335
- self::display_forms_list($params, $message, 1);
336
- }
337
-
338
- public static function bulk_destroy($ids) {
339
- FrmAppHelper::permission_check('frm_delete_forms');
340
-
341
- $count = 0;
342
- foreach ( $ids as $id ) {
343
- $d = FrmForm::destroy( $id );
344
- if ( $d ) {
345
- $count++;
346
- }
347
- }
348
-
349
- $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
350
-
351
- return $message;
352
- }
353
-
354
- private static function delete_all() {
355
- //check nonce url
356
- $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
357
- if ( $permission_error !== false ) {
358
- self::display_forms_list( array(), '', 1, array( $permission_error ) );
359
- return;
360
- }
361
-
362
- $count = self::scheduled_delete(time());
363
- $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
364
-
365
- self::display_forms_list( array(), $message, 1 );
366
- }
367
-
368
- /**
369
- * Delete trashed forms based on how long they have been trashed
370
- * @return int The number of forms deleted
371
- */
372
- public static function scheduled_delete($delete_timestamp = '') {
373
- global $wpdb;
374
-
375
- $trash_forms = FrmDb::get_results($wpdb->prefix .'frm_forms', array( 'status' => 'trash'), 'id, options' );
376
-
377
- if ( ! $trash_forms ) {
378
- return;
379
- }
380
-
381
- if ( empty($delete_timestamp) ) {
382
- $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
383
- }
384
-
385
- $count = 0;
386
- foreach ( $trash_forms as $form ) {
387
- $form->options = maybe_unserialize($form->options);
388
- if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
389
- FrmForm::destroy($form->id);
390
- $count++;
391
- }
392
-
393
- unset($form);
394
- }
395
- return $count;
396
- }
397
-
398
- public static function insert_form_button($content) {
399
- if ( current_user_can('frm_view_forms') ) {
400
- $content .= '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . __( 'Add forms and content', 'formidable' ) . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> Formidable</a>';
401
-
402
- }
403
  return $content;
404
  }
405
-
406
- public static function insert_form_popup() {
407
- $page = basename($_SERVER['PHP_SELF']);
408
- if ( ! in_array($page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php') ) ) {
409
  return;
410
- }
411
-
412
- FrmAppHelper::load_admin_wide_js();
413
-
414
- $shortcodes = array(
415
- 'formidable' => array( 'name' => __( 'Form', 'formidable' ), 'label' => __( 'Insert a Form', 'formidable' )),
416
- );
417
-
418
- $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
419
-
420
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/insert_form_popup.php');
421
- }
422
-
423
- public static function get_shortcode_opts() {
424
- check_ajax_referer( 'frm_ajax', 'nonce' );
425
-
426
- $shortcode = sanitize_text_field( $_POST['shortcode'] );
427
- if ( empty($shortcode) ) {
428
- wp_die();
429
- }
430
-
431
- echo '<div id="sc-opts-'. esc_attr( $shortcode ) .'" class="frm_shortcode_option">';
432
- echo '<input type="radio" name="frmsc" value="'. esc_attr($shortcode) .'" id="sc-'. esc_attr($shortcode) .'" class="frm_hidden" />';
433
-
434
- $form_id = '';
435
- $opts = array();
436
- switch( $shortcode ) {
437
- case 'formidable':
438
- $form_id = 'id';
439
- $opts = array(
440
- //'key' => ',
441
- 'title' => array( 'val' => 1, 'label' => __( 'Display form title', 'formidable' )),
442
- 'description' => array( 'val' => 1, 'label' => __( 'Display form description', 'formidable' )),
443
- 'minimize' => array( 'val' => 1, 'label' => __( 'Minimize form HTML', 'formidable' )),
444
- );
445
- break;
446
- }
447
- $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
448
-
449
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/shortcode_opts.php');
450
-
451
- echo '</div>';
452
-
453
- wp_die();
454
  }
455
-
456
- public static function display_forms_list( $params = array(), $message = '', $current_page_ov = false, $errors = array() ) {
457
- FrmAppHelper::permission_check( 'frm_view_forms' );
458
-
459
- global $wpdb, $frm_vars;
460
-
461
- if ( empty( $params ) ) {
462
- $params = FrmFormsHelper::get_params();
463
- }
464
-
465
- $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
 
467
  $pagenum = $wp_list_table->get_pagenum();
468
 
@@ -473,313 +369,217 @@ class FrmFormsController {
473
  wp_redirect( add_query_arg( 'paged', $total_pages ) );
474
  die();
475
  }
476
-
 
 
 
477
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
478
  }
479
-
480
- public static function get_columns($columns) {
481
  $columns['cb'] = '<input type="checkbox" />';
482
- $columns['id'] = 'ID';
483
-
484
- $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : 'published';
485
-
486
- if ( 'template' == $type ) {
487
- $columns['name'] = __( 'Template Name', 'formidable' );
488
- $columns['type'] = __( 'Type', 'formidable' );
489
- $columns['form_key'] = __( 'Key', 'formidable' );
490
- } else {
491
- $columns['name'] = __( 'Form Title', 'formidable' );
492
- $columns['entries'] = __( 'Entries', 'formidable' );
493
- $columns['form_key'] = __( 'Key', 'formidable' );
494
- $columns['shortcode'] = __( 'Shortcodes', 'formidable' );
495
- }
496
-
497
- $columns['created_at'] = __( 'Date', 'formidable' );
498
-
499
- add_screen_option( 'per_page', array( 'label' => __( 'Forms', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_per_page' ) );
500
-
501
  return $columns;
502
  }
503
-
504
  public static function get_sortable_columns() {
505
  return array(
506
- 'id' => 'id',
507
- 'name' => 'name',
508
  'description' => 'description',
509
- 'form_key' => 'form_key',
510
- 'created_at' => 'created_at',
511
  );
512
  }
513
-
514
- public static function hidden_columns( $result ) {
515
  $return = false;
516
- foreach ( (array) $result as $r ) {
517
- if ( ! empty( $r ) ) {
518
  $return = true;
519
  break;
520
  }
521
  }
522
-
523
- if ( $return ) {
524
  return $result;
525
- }
526
-
527
- $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
528
 
529
  $result[] = 'created_at';
530
- if ( $type == 'template' ) {
531
  $result[] = 'id';
532
  $result[] = 'form_key';
533
- }
534
-
535
  return $result;
536
  }
537
-
538
- public static function save_per_page( $save, $option, $value ) {
539
- if ( $option == 'formidable_page_formidable_per_page' ) {
540
- $save = (int) $value;
541
- }
542
  return $save;
543
  }
544
 
545
- private static function get_edit_vars( $id, $errors = '', $message = '', $create_link = false ) {
546
- global $frm_vars;
547
-
548
- $form = FrmForm::getOne( $id );
549
- if ( ! $form ) {
550
- wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) );
551
  }
552
-
553
- if ( $form->parent_form_id ) {
554
- wp_die( sprintf(__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable&frm_action=edit&id='. $form->parent_form_id) .'">', '</a>' ));
555
- }
556
-
557
  $frm_field_selection = FrmFieldsHelper::field_selection();
558
- $fields = FrmField::get_all_for_form($form->id);
559
-
560
- // Automatically add end section fields if they don't exist (2.0 migration)
561
- $reset_fields = false;
562
- FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
563
-
564
- if ( $reset_fields ) {
565
- $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
566
- }
567
-
568
- unset($end_section_values, $last_order, $open, $reset_fields);
569
-
570
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
571
-
572
- $edit_message = __( 'Form was Successfully Updated', 'formidable' );
573
  if ( $form->is_template && $message == $edit_message ) {
574
- $message = __( 'Template was Successfully Updated', 'formidable' );
575
  }
576
-
577
- $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
578
-
579
  if ( $form->default_template ) {
580
- wp_die(__( 'That template cannot be edited', 'formidable' ));
581
  } else if ( defined('DOING_AJAX') ) {
582
- wp_die();
583
  } else if ( $create_link ) {
584
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
585
  } else {
586
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
587
  }
588
  }
589
-
590
- public static function get_settings_vars( $id, $errors = '', $message = '' ) {
591
- FrmAppHelper::permission_check( 'frm_edit_forms' );
592
-
593
- global $frm_vars;
594
-
595
- $form = FrmForm::getOne( $id );
596
-
597
- $fields = FrmField::get_all_for_form($id);
598
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
599
-
600
- if ( isset($values['default_template']) && $values['default_template'] ) {
601
- wp_die(__( 'That template cannot be edited', 'formidable' ));
602
- }
603
-
604
- $action_controls = FrmFormActionsController::get_form_actions();
605
-
606
  $sections = apply_filters('frm_add_form_settings_section', array(), $values);
607
- $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
608
-
609
- $styles = apply_filters('frm_get_style_opts', array());
610
-
611
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/settings.php');
612
- }
613
-
614
- public static function mb_tags_box( $form_id, $class = '' ) {
615
- $fields = FrmField::get_all_for_form($form_id, '', 'include');
616
- $linked_forms = array();
617
- $col = 'one';
618
- $settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false;
619
-
620
- $cond_shortcodes = apply_filters('frm_conditional_shortcodes', array());
621
-
622
- $adv_shortcodes = array(
623
- 'sep=", "' => array( 'label' => __( 'Separator', 'formidable' ), 'title' => __( 'Use a different separator for checkbox fields', 'formidable' ) ),
624
- 'format="d-m-Y"' => __( 'Date Format', 'formidable' ),
625
- 'show="field_label"' => __( 'Field Label', 'formidable' ),
626
- 'wpautop=0' => array( 'label' => __( 'No Auto P', 'formidable' ), 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' )),
627
- );
628
- $adv_shortcodes = apply_filters('frm_advanced_shortcodes', $adv_shortcodes);
629
-
630
- // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
631
-
632
- $user_fields = apply_filters('frm_user_shortcodes', array());
633
-
634
- include(FrmAppHelper::plugin_path() .'/classes/views/shared/mb_adv_info.php');
635
- }
636
-
637
- // Insert the form class setting into the form
638
- public static function form_classes($form) {
639
- if ( isset($form->options['form_class']) ) {
640
- echo esc_attr($form->options['form_class']);
641
- }
642
- }
643
-
644
- public static function get_email_html() {
645
- check_ajax_referer( 'frm_ajax', 'nonce' );
646
- echo FrmEntriesController::show_entry_shortcode( array(
647
- 'form_id' => $_POST['form_id'],
648
- 'default_email' => true,
649
- 'plain_text' => $_POST['plain_text'],
650
- ) );
651
- wp_die();
652
- }
653
-
654
- public static function filter_content( $content, $form, $entry = false ) {
655
- if ( ! $entry || ! is_object( $entry ) ) {
656
- if ( ! $entry || ! is_numeric( $entry ) ) {
657
- $entry = ( $_POST && isset( $_POST['id'] ) ) ? $_POST['id'] : false;
658
- }
659
-
660
- FrmEntriesHelper::maybe_get_entry( $entry );
661
- }
662
-
663
- if ( ! $entry ) {
664
- return $content;
665
- }
666
-
667
- if ( is_object( $form ) ) {
668
- $form = $form->id;
669
- }
670
-
671
- $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
672
- $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
673
-
674
- return $content;
675
- }
676
-
677
- public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
678
- return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
679
- }
680
-
681
- public static function process_bulk_form_actions( $errors ) {
682
- if ( ! $_REQUEST ) {
683
- return $errors;
684
- }
685
-
686
- $bulkaction = FrmAppHelper::get_param( 'action' );
687
  if ( $bulkaction == -1 ) {
688
- $bulkaction = FrmAppHelper::get_param( 'action2' );
689
- }
690
-
691
- if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
692
- FrmAppHelper::remove_get_action();
693
-
694
- $bulkaction = str_replace( 'bulk_', '', $bulkaction );
695
  }
696
 
697
- $ids = FrmAppHelper::get_param( 'item-action', '' );
698
- if ( empty( $ids ) ) {
699
- $errors[] = __( 'No forms were specified', 'formidable' );
700
- return $errors;
701
- }
702
-
703
- $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
704
- if ( $permission_error !== false ) {
705
- $errors[] = $permission_error;
706
- return $errors;
707
- }
708
-
709
- if ( ! is_array( $ids ) ) {
710
- $ids = explode( ',', $ids );
711
- }
712
-
713
- switch ( $bulkaction ) {
714
- case 'delete':
715
- $message = self::bulk_destroy( $ids );
716
- break;
717
- case 'trash':
718
- $message = self::bulk_trash( $ids );
719
- break;
720
- case 'untrash':
721
- $message = self::bulk_untrash( $ids );
722
- break;
723
- case 'create_template':
724
- $message = self::bulk_create_template( $ids );
725
- break;
726
  }
727
 
728
- if ( isset( $message ) && ! empty( $message ) ) {
729
- echo '<div id="message" class="updated frm_msg_padding">'.$message.'</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
  }
731
-
732
  return $errors;
733
  }
734
-
735
- public static function add_default_templates( $path, $default = true, $template = true ) {
736
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
737
-
 
738
  $path = untrailingslashit(trim($path));
739
- $templates = glob( $path .'/*.php' );
740
-
741
- for($i = count($templates) - 1; $i >= 0; $i--) {
742
- $filename = str_replace( '.php', '', str_replace( $path.'/', '', $templates[ $i ] ) );
743
- $template_query = array( 'form_key' => $filename);
744
- if ( $template ) {
745
- $template_query['is_template'] = 1;
746
- }
747
- if ( $default ) {
748
- $template_query['default_template'] = 1;
749
- }
750
- $form = FrmForm::getAll( $template_query, '', 1 );
751
-
752
  $values = FrmFormsHelper::setup_new_vars();
753
  $values['form_key'] = $filename;
754
  $values['is_template'] = $template;
755
  $values['status'] = 'published';
756
- if ( $default ) {
757
- $values['default_template'] = 1;
758
- }
759
-
760
- include( $templates[ $i ] );
761
-
762
  //get updated form
763
- if ( isset($form) && ! empty($form) ) {
764
- $old_id = $form->id;
765
- $form = FrmForm::getOne($form->id);
766
  } else {
767
- $old_id = false;
768
- $form = FrmForm::getAll( $template_query, '', 1 );
769
- }
770
-
771
- if ( $form ) {
772
- do_action('frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id));
773
  }
 
 
 
774
  }
775
  }
776
 
777
- public static function route() {
778
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
779
- $vars = array();
780
- if ( isset( $_POST['frm_compact_fields'] ) ) {
781
- FrmAppHelper::permission_check( 'frm_edit_forms' );
782
-
 
 
783
  $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('&quot;', '\\\"', $_POST['frm_compact_fields'] ))));
784
  $json_vars = json_decode($json_vars, true);
785
  if ( empty($json_vars) ) {
@@ -788,103 +588,100 @@ class FrmFormsController {
788
  if ( 'edit' == $action ) {
789
  $action = 'update';
790
  }
791
-
792
- add_filter('frm_validate_form', 'FrmFormsController::json_error');
793
  } else {
794
  $vars = FrmAppHelper::json_to_array($json_vars);
795
- $action = $vars[ $action ];
796
- $_REQUEST = array_merge( $_REQUEST, $vars );
797
- unset( $_REQUEST['frm_compact_fields'] );
798
  }
799
- } else {
800
  $action = FrmAppHelper::get_param($action);
801
- if ( isset( $_REQUEST['delete_all'] ) ) {
802
- // override the action for this page
803
- $action = 'delete_all';
804
- }
805
  }
806
-
807
- add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
808
- FrmAppHelper::trigger_hook_load( 'form' );
809
-
810
- switch ( $action ) {
811
- case 'new':
812
- return self::new_form($vars);
813
- case 'create':
814
- case 'edit':
815
- case 'update':
816
- case 'duplicate':
817
- case 'trash':
818
- case 'untrash':
819
- case 'destroy':
820
- case 'delete_all':
821
- case 'settings':
822
- case 'update_settings':
823
- return self::$action( $vars );
824
- default:
825
- do_action('frm_form_action_'. $action);
826
- if ( apply_filters('frm_form_stop_action_'. $action, false) ) {
827
- return;
828
- }
829
-
830
- $action = FrmAppHelper::get_param('action');
831
- if ( $action == -1 ) {
832
- $action = FrmAppHelper::get_param('action2');
833
- }
834
-
835
- if ( strpos($action, 'bulk_') === 0 ) {
836
- FrmAppHelper::remove_get_action();
837
- return self::list_form();
838
- }
839
-
 
 
840
  return self::display_forms_list();
 
841
  }
842
  }
843
-
844
- public static function json_error( $errors ) {
845
- $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
846
  return $errors;
847
  }
848
-
849
-
850
  /* FRONT-END FORMS */
851
  public static function admin_bar_css() {
852
  FrmAppController::load_wp_admin_style();
853
  }
854
-
855
  public static function admin_bar_configure() {
856
  if ( is_admin() || !current_user_can('frm_edit_forms') ) {
857
  return;
858
  }
859
-
860
  global $frm_vars;
861
  if ( empty($frm_vars['forms_loaded']) ) {
862
  return;
863
  }
864
-
865
  $actions = array();
866
- foreach ( $frm_vars['forms_loaded'] as $form ) {
867
  if ( is_object($form) ) {
868
- $actions[ $form->id ] = $form->name;
869
  }
870
  unset($form);
871
  }
872
-
873
  if ( empty($actions) ) {
874
  return;
875
  }
876
-
877
  asort($actions);
878
-
879
  global $wp_admin_bar;
880
-
881
  if ( count($actions) == 1 ) {
882
  $wp_admin_bar->add_menu( array(
883
  'title' => 'Edit Form',
884
  'href' => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
885
- 'id' => 'frm-forms',
886
  ) );
887
- } else {
888
  $wp_admin_bar->add_menu( array(
889
  'id' => 'frm-forms',
890
  'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
@@ -893,19 +690,21 @@ class FrmFormsController {
893
  'title' => __( 'Edit Forms', 'formidable' ),
894
  ),
895
  ) );
896
-
897
  foreach ( $actions as $form_id => $name ) {
898
 
899
  $wp_admin_bar->add_menu( array(
900
  'parent' => 'frm-forms',
901
  'id' => 'edit_form_'. $form_id,
902
- 'title' => empty($name) ? __( '(no title)') : $name,
903
  'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
904
  ) );
905
  }
906
- }
907
  }
908
-
 
 
909
  //formidable shortcode
910
  public static function get_form_shortcode($atts) {
911
  global $frm_vars;
@@ -916,153 +715,101 @@ class FrmFormsController {
916
  }
917
  return $sc .']';
918
  }
919
-
920
- $shortcode_atts = shortcode_atts( array(
921
  'id' => '', 'key' => '', 'title' => false, 'description' => false,
922
  'readonly' => false, 'entry_id' => false, 'fields' => array(),
923
  'exclude_fields' => array(), 'minimize' => false,
924
  ), $atts);
925
  do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
926
-
927
- return self::show_form(
928
- $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
929
- $shortcode_atts['description'], $atts
930
- );
931
- }
932
-
933
- public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
934
- if ( empty( $id ) ) {
 
 
 
 
 
 
935
  $id = $key;
936
  }
937
-
938
  // no form id or key set
939
- if ( empty( $id ) ) {
940
- return __( 'Please select a valid form', 'formidable' );
941
  }
942
-
943
- $form = FrmForm::getOne( $id );
944
- if ( ! $form || $form->parent_form_id ) {
945
- return __( 'Please select a valid form', 'formidable' );
946
  }
947
-
948
- add_action( 'frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks' );
949
- FrmAppHelper::trigger_hook_load( 'form', $form );
950
-
951
- $form = apply_filters( 'frm_pre_display_form', $form );
952
-
953
- $frm_settings = FrmAppHelper::get_settings();
954
-
955
  // don't show a draft form on a page
956
- global $post;
957
- if ( $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ( ! $post || $post->ID != $frm_settings->preview_page_id ) && ! FrmAppHelper::is_preview_page() ) {
958
- return __( 'Please select a valid form', 'formidable' );
959
  }
960
-
961
  // don't show the form if user should be logged in
962
- if ( $form->logged_in && ! is_user_logged_in() ) {
963
- return do_shortcode( $frm_settings->login_msg );
964
  }
965
-
966
  // don't show the form if user doesn't have permission
967
- if ( $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] ) ) {
968
- return do_shortcode( $frm_settings->login_msg );
969
  }
970
-
971
- $form = self::get_form( $form, $title, $description, $atts );
972
-
973
  // check for external shortcodes
974
- $form = do_shortcode( $form );
975
-
976
  return $form;
977
  }
 
 
 
 
978
 
979
- public static function get_form( $form, $title, $description, $atts = array() ) {
980
- ob_start();
981
-
982
- self::get_form_contents( $form, $title, $description, $atts );
983
- FrmEntriesHelper::enqueue_scripts( FrmEntriesController::get_params( $form ) );
984
-
985
- $contents = ob_get_contents();
986
- ob_end_clean();
987
-
988
- // check if minimizing is turned on
989
- if ( isset( $atts['minimize'] ) && ! empty( $atts['minimize'] ) ) {
990
- $contents = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $contents );
991
- }
992
-
993
- return $contents;
994
- }
995
-
996
- public static function get_form_contents($form, $title, $description, $atts) {
997
- global $frm_vars;
998
-
999
- $frm_settings = FrmAppHelper::get_settings();
1000
-
1001
  $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
1002
-
 
1003
  $user_ID = get_current_user_id();
1004
-
1005
  $params = FrmEntriesController::get_params($form);
1006
 
1007
  $message = $errors = '';
1008
 
 
 
1009
  if ( $params['posted_form_id'] == $form->id && $_POST ) {
1010
- $errors = isset( $frm_vars['created_entries'][ $form->id ] ) ? $frm_vars['created_entries'][ $form->id ]['errors'] : array();
1011
- }
1012
-
1013
- $fields = FrmFieldsHelper::get_form_fields( $form->id, ( isset( $errors ) && ! empty( $errors ) ) );
1014
-
1015
- if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) {
1016
- do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
1017
- if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) {
1018
- $values = FrmEntriesHelper::setup_new_vars($fields, $form);
1019
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
 
 
 
 
 
1020
  }
1021
- return;
1022
- }
1023
-
1024
- if ( ! empty($errors) ) {
1025
- $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
1026
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1027
- return;
1028
  }
1029
-
1030
- do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
1031
- if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) {
1032
- return;
1033
- }
1034
-
1035
- $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
1036
- $created = ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form->id ] ) ) ? $frm_vars['created_entries'][ $form->id ]['entry_id'] : 0;
1037
- $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
1038
-
1039
- if ( $created && is_numeric($created) && $conf_method != 'message' ) {
1040
- do_action('frm_success_action', $conf_method, $form, $form->options, $created);
1041
- do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
1042
- return;
1043
- }
1044
-
1045
- if ( $created && is_numeric($created) ) {
1046
- $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
1047
- $class = 'frm_message';
1048
- } else {
1049
- $message = $frm_settings->failed_msg;
1050
- $class = 'frm_error_style';
1051
- }
1052
- $message = apply_filters('frm_content', $message, $form, $created);
1053
- $message = '<div class="'. $class .'">'. wpautop(do_shortcode($message)) .'</div>';
1054
- $message = apply_filters('frm_main_feedback', $message, $form, $created);
1055
-
1056
- if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) {
1057
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1058
- } else {
1059
- global $frm_vars;
1060
- FrmFormsHelper::form_loaded($form, $values['custom_style'], $frm_vars['load_css']);
1061
-
1062
- $include_extra_container = 'frm_forms'. FrmFormsHelper::get_form_style_class($values);
1063
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
1064
- }
1065
-
1066
- do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
1067
  }
 
1068
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
+
8
+ if(class_exists('FrmFormsController'))
9
+ return;
10
+
11
+ class FrmFormsController{
12
+ public static function load_hooks(){
13
+ add_action('admin_menu', 'FrmFormsController::menu', 10);
14
+ add_action('admin_menu', 'FrmFormsController::mid_menu', 40);
15
+ add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head');
16
+ add_action('widgets_init', 'FrmFormsController::register_widgets');
17
+ add_action('wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key');
18
+ add_action('wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description');
19
+ add_action('wp_ajax_frm_delete_form_wo_fields', 'FrmFormsController::destroy_wo_fields');
20
+ add_action('frm_after_duplicate_form', 'FrmFormsController::after_duplicate', 10, 2);
21
+ add_action('wp_ajax_frm_save_form', 'FrmFormsController::route');
22
+ add_filter('frm_submit_button', 'FrmFormsController::submit_button_label');
23
+ add_filter('media_buttons_context', 'FrmFormsController::insert_form_button');
24
+ //add_action('media_buttons', 'FrmFormsController::show_form_button', 20);
25
+ add_action('admin_footer', 'FrmFormsController::insert_form_popup');
26
+
27
+ add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
28
+
29
+ add_action('wp_ajax_frm_forms_preview', 'FrmFormsController::preview');
30
+ add_action('wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview');
31
+
32
+ add_filter('frm_admin_list_form_action', 'FrmFormsController::process_bulk_form_actions');
33
+
34
+ add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' );
35
+ add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
36
+
37
+ //Shortcodes
38
+ add_shortcode('formidable', 'FrmFormsController::get_form_shortcode');
39
+ add_filter( 'widget_text', 'FrmFormsController::widget_text_filter', 9 );
40
+ }
41
+
42
+ public static function menu(){
43
+ global $frm_settings;
44
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Forms', 'formidable'), __('Forms', 'formidable'), 'frm_view_forms', 'formidable', 'FrmFormsController::route');
45
+
46
+ add_action('admin_head-'. sanitize_title($frm_settings->menu) .'_page_formidable-templates', 'FrmFormsController::head');
47
+
48
+ add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
49
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_columns', 'FrmFormsController::get_columns', 0 );
50
+ add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns');
51
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_sortable_columns', 'FrmFormsController::get_sortable_columns');
52
+ add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns');
53
+ add_filter('get_user_option_manage'. sanitize_title($frm_settings->menu) .'_page_formidable-templatescolumnshidden', 'FrmFormsController::hidden_columns');
54
+ }
55
+
56
+ public static function mid_menu(){
57
+ global $frm_settings;
58
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Templates', 'formidable'), __('Templates', 'formidable'), 'frm_view_forms', 'formidable-templates', 'FrmFormsController::template_list');
59
+ }
60
+
61
+ public static function head(){
62
+ global $frm_settings;
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  wp_enqueue_script('formidable-editinplace');
65
+ wp_enqueue_script('jquery-frm-themepicker');
 
 
 
66
  }
67
+
68
+ public static function register_widgets(){
69
  require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
70
  register_widget('FrmShowForm');
71
  }
72
+
73
+ public static function list_form(){
74
+ $params = self::get_params();
75
+ $errors = apply_filters('frm_admin_list_form_action', array());
76
+ return self::display_forms_list($params, '', false, false, $errors);
 
 
 
 
77
  }
78
+
79
+ public static function template_list(){
80
+ $_POST['template'] = 1;
81
+ $errors = apply_filters('frm_admin_list_form_action', array());
82
+ return self::display_forms_list();
83
+ }
84
+
85
+ public static function new_form($values=false){
86
  global $frm_vars;
87
+
88
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
89
+ $action = ($values) ? $values[$action] : FrmAppHelper::get_param($action);
90
+ $frm_form = new FrmForm();
91
+
92
+ if ($action == 'create'){
93
  return self::create($values);
94
+ }else if ($action == 'new'){
95
+ $frm_field_selection = FrmFieldsHelper::field_selection();
96
  $values = FrmFormsHelper::setup_new_vars($values);
97
+ $id = $frm_form->create( $values );
98
+ $form = $frm_form->getOne($id);
 
 
 
 
 
 
 
99
  $values['id'] = $id;
100
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
101
+ }else{
102
+ $all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
103
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new-selection.php');
104
  }
105
  }
106
+
107
+ public static function create($values=false){
108
+ global $frm_entry, $frm_field, $frm_vars;
109
+ if(!$values)
 
 
110
  $values = $_POST;
111
+
112
+ if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce'))) ) {
113
+ global $frm_settings;
114
+ $errors['form'] = $frm_settings->admin_permission;
115
+ }
116
+
117
+ $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
118
+
119
+ $frm_form = new FrmForm();
120
+ $errors = $frm_form->validate($values);
121
+
122
+ if( count($errors) > 0 ){
 
 
 
 
 
123
  $hide_preview = true;
124
  $frm_field_selection = FrmFieldsHelper::field_selection();
125
+ $form = $frm_form->getOne( $id );
126
+ $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
 
127
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
 
 
128
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
129
+ }else{
130
+ $form = $frm_form->update( $id, $values, true );
131
  die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
132
+ //$message = __('Form was Successfully Created', 'formidable');
133
+ //return self::settings($record, $message);
134
  }
135
  }
136
+
137
+ public static function edit($values=false){
138
+ if ( ! current_user_can('frm_edit_forms') ) {
139
+ global $frm_settings;
140
+ wp_die($frm_settings->admin_permission);
141
+ }
142
+
143
+ $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
144
  return self::get_edit_vars($id);
145
  }
146
+
147
+ public static function settings($id=false, $message=''){
148
+ if(!$id or !is_numeric($id))
149
+ $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
 
 
 
150
  return self::get_settings_vars($id, '', $message);
151
  }
152
+
153
+ public static function update_settings(){
154
+ $id = FrmAppHelper::get_param('id');
155
+
156
+ $frm_form = new FrmForm();
157
+ $errors = $frm_form->validate($_POST);
158
+
159
+ if( count($errors) > 0 ){
160
  return self::get_settings_vars($id, $errors);
161
+ }else{
162
+ $record = $frm_form->update( $_POST['id'], $_POST );
163
+ $message = __('Settings Successfully Updated', 'formidable');
164
+ return self::get_settings_vars($id, '', $message);
165
  }
 
 
 
 
 
 
 
166
  }
167
+
168
+ public static function edit_key(){
169
+ if ( ! current_user_can('frm_edit_forms') ) {
170
+ die();
171
+ }
172
+
173
  global $wpdb;
174
+ $values = array('form_key' => trim($_POST['update_value']));
175
+ $frm_form = new FrmForm();
176
+ $form = $frm_form->update($_POST['form_id'], $values);
177
+ $key = $wpdb->get_var($wpdb->prepare("SELECT form_key FROM {$wpdb->prefix}frm_forms WHERE id=%d", $_POST['form_id']));
178
+ echo stripslashes($key);
179
+ die();
180
  }
181
 
182
+ public static function edit_description(){
183
+ if ( ! current_user_can('frm_edit_forms') ) {
184
+ die();
185
+ }
186
+
187
+ $frm_form = new FrmForm();
188
+ $form = $frm_form->update($_POST['form_id'], array('description' => $_POST['update_value']));
189
+ $description = stripslashes($_POST['update_value']);
190
+ if(apply_filters('frm_use_wpautop', true))
191
+ $description = wpautop(str_replace( '<br>', '<br />', $description));
192
  echo $description;
193
+ die();
194
  }
195
+
196
+ public static function update($values=false){
197
+ $frm_form = new FrmForm();
198
 
199
+ if(!$values)
 
200
  $values = $_POST;
201
+
202
+ $errors = $frm_form->validate($values);
203
+
204
+ if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce')) ) ) {
205
+ global $frm_settings;
206
+ $errors['form'] = $frm_settings->admin_permission;
207
+ }
208
+
209
+ $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
210
+
211
+ if( count($errors) > 0 ){
212
+ return self::get_edit_vars($id, $errors);
213
+ }else{
214
+ $record = $frm_form->update( $id, $values );
215
+ $message = __('Form was Successfully Updated', 'formidable');
216
+ if ( defined('DOING_AJAX') ) {
217
+ die($message);
 
 
 
 
 
218
  }
219
+ return self::get_edit_vars($id, '', $message);
220
  }
221
  }
222
+
223
+ public static function duplicate(){
224
+ if ( ! current_user_can('frm_edit_forms') ) {
225
+ global $frm_settings;
226
+ wp_die($frm_settings->admin_permission);
 
227
  }
228
+
229
+ $frm_form = new FrmForm();
230
+
231
+ $params = self::get_params();
232
+ $form = $frm_form->duplicate( $params['id'], $params['template'], true );
233
+ $message = ($params['template']) ? __('Form template was Successfully Created', 'formidable') : __('Form was Successfully Copied', 'formidable');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  if ( $form ) {
235
  return self::get_edit_vars($form, '', $message, true);
236
  } else {
237
+ return self::display_forms_list($params, __('There was a problem creating new template.', 'formidable'));
238
+ }
239
+ }
240
+
241
+
242
+ public static function after_duplicate($form_id, $values) {
243
+ $frm_form = new FrmForm();
244
+ $frm_form->after_duplicate($form_id, $values);
245
+ }
246
+
247
+ public static function page_preview(){
248
+ $params = self::get_params();
249
+ if (!$params['form']) return;
250
+
251
+ $frm_form = new FrmForm();
252
+ $form = $frm_form->getOne($params['form']);
253
+ if(!$form) return;
254
+ return self::show_form($form->id, '', true, true);
255
+ }
256
+
257
+ public static function preview(){
258
+ do_action('frm_wp');
259
+
260
+ global $frm_settings, $frm_vars;
261
  $frm_vars['preview'] = true;
262
+
263
+ $frm_form = new FrmForm();
264
+ if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
265
  global $wp;
266
+ $root = dirname(dirname(dirname(dirname(__FILE__))));
267
  include_once( $root.'/wp-config.php' );
268
  $wp->init();
269
  $wp->register_globals();
270
  }
271
+
272
+ if($frm_vars['pro_is_installed'])
273
  FrmProEntriesController::register_scripts();
274
+
275
+ header("Content-Type: text/html; charset=". get_option( 'blog_charset' ));
 
276
 
277
  $plugin = FrmAppHelper::get_param('plugin');
278
  $controller = FrmAppHelper::get_param('controller');
279
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
280
+ $form = $frm_form->getAll(array('form_key' => $key), '', 1);
281
+ if (!$form) $form = $frm_form->getAll('', '', 1);
282
+
 
 
283
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
284
+ die();
285
+ }
286
+
287
+ public static function destroy(){
288
+ if(!current_user_can('frm_delete_forms')){
289
+ global $frm_settings;
290
+ wp_die($frm_settings->admin_permission);
291
+ }
292
+
293
+ $frm_form = new FrmForm();
294
+ $params = self::get_params();
295
+ $message = '';
296
+ if ($frm_form->destroy( $params['id'] ))
297
+ $message = __('Form was Successfully Deleted', 'formidable');
298
+ self::display_forms_list($params, $message, '', 1);
299
+ }
300
+
301
+ public static function destroy_wo_fields(){
302
+ global $frm_field, $frmdb, $wpdb;
303
+ $id = $_POST['form_id'];
304
+ if ($frmdb->get_count($wpdb->prefix . 'frm_fields', array('form_id' => $id)) <= 0){
305
+ $frm_form = new FrmForm();
306
+ $frm_form->destroy($id);
307
+ }
308
+ die();
309
+ }
310
+
311
+ public static function submit_button_label($submit){
312
+ if (!$submit or empty($submit)){
313
+ global $frm_settings;
314
+ $submit = $frm_settings->submit_value;
315
+ }
316
+ return $submit;
317
+ }
318
+
319
+ public static function insert_form_button($content){
320
+ if(current_user_can('frm_view_forms'))
321
+ $content .= '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . __("Add Formidable Form", 'formidable') . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> '. __('Add Form', 'formidable') . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  return $content;
323
  }
324
+
325
+ public static function show_form_button($id){
326
+ if($id != 'content')
 
327
  return;
328
+ echo '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox" title="' . __("Add Formidable Form", 'formidable') . '"><img src="'. esc_url(FrmAppHelper::plugin_url() .'/images/form_16.png') .'" alt="' . __("Add Formidable Form", 'formidable') . '" /></a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  }
330
+
331
+ public static function insert_form_popup(){
332
+ $page = basename($_SERVER['PHP_SELF']);
333
+ if(in_array($page, array('post.php', 'page.php', 'page-new.php', 'post-new.php')) or (isset($_GET) and isset($_GET['page']) and $_GET['page'] == 'formidable-entry-templates')){
334
+ if(class_exists('FrmProDisplay')){
335
+ global $frmpro_display;
336
+ $displays = $frmpro_display->getAll('', 'post_title');
337
+ }
338
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/insert_form_popup.php');
339
+ }
340
+ }
341
+
342
+ public static function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
343
+ global $wpdb, $frmdb, $frm_entry, $frm_vars;
344
+
345
+ if(!$params)
346
+ $params = self::get_params();
347
+
348
+ $page_params = '&action=0&&frm_action=0&page=formidable';
349
+
350
+ $frm_form = new FrmForm();
351
+ if ($params['template']){
352
+ $default_templates = $frm_form->getAll(array('default_template' => 1));
353
+ $all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
354
+ }
355
+
356
+ require( FrmAppHelper::plugin_path() .'/classes/helpers/FrmListHelper.php' );
357
+
358
+ $args = array('table_name' => $wpdb->prefix .'frm_forms', 'params' => $params);
359
+ $args['page_name'] = $params['template'] ? '-template' : '';
360
+ $wp_list_table = new FrmListHelper($args);
361
+ unset($args);
362
 
363
  $pagenum = $wp_list_table->get_pagenum();
364
 
369
  wp_redirect( add_query_arg( 'paged', $total_pages ) );
370
  die();
371
  }
372
+
373
+ if ( ! empty( $_REQUEST['s'] ) )
374
+ $page_params .= '&s='. urlencode($_REQUEST['s']);
375
+
376
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
377
  }
378
+
379
+ public static function get_columns($columns){
380
  $columns['cb'] = '<input type="checkbox" />';
381
+ $columns['id'] = 'ID';
382
+ $columns['name'] = __('Name');
383
+ $columns['description'] = __('Description');
384
+ $columns['form_key'] = __('Key', 'formidable');
385
+
386
+ if($_GET['page'] == 'formidable-templates'){
387
+ add_screen_option( 'per_page', array('label' => __('Templates', 'formidable'), 'default' => 10, 'option' => 'formidable_page_formidable_templates_per_page') );
388
+ }else{
389
+ $columns['entries'] = __('Entries', 'formidable');
390
+ $columns['link'] = __('Actions', 'formidable');
391
+ $columns['shortcode'] = __('Shortcodes', 'formidable');
392
+ add_screen_option( 'per_page', array('label' => __('Forms', 'formidable'), 'default' => 20, 'option' => 'formidable_page_formidable_per_page') );
393
+ }
394
+
395
+ $columns['created_at'] = __('Date', 'formidable');
396
+
 
 
 
397
  return $columns;
398
  }
399
+
400
  public static function get_sortable_columns() {
401
  return array(
402
+ 'id' => 'id',
403
+ 'name' => 'name',
404
  'description' => 'description',
405
+ 'form_key' => 'form_key',
406
+ 'created_at' => 'created_at'
407
  );
408
  }
409
+
410
+ public static function hidden_columns($result){
411
  $return = false;
412
+ foreach((array)$result as $r){
413
+ if(!empty($r)){
414
  $return = true;
415
  break;
416
  }
417
  }
418
+
419
+ if($return)
420
  return $result;
 
 
 
421
 
422
  $result[] = 'created_at';
423
+ if($_GET['page'] == 'formidable-templates'){
424
  $result[] = 'id';
425
  $result[] = 'form_key';
426
+ }
427
+
428
  return $result;
429
  }
430
+
431
+ public static function save_per_page($save, $option, $value){
432
+ if($option == 'formidable_page_formidable_per_page' or $option == 'formidable_page_formidable_templates_per_page')
433
+ $save = (int)$value;
 
434
  return $save;
435
  }
436
 
437
+ private static function get_edit_vars($id, $errors = '', $message='', $create_link=false){
438
+ global $frm_entry, $frm_field, $frm_vars;
439
+ $frm_form = new FrmForm();
440
+ $form = $frm_form->getOne( $id );
441
+ if ( !$form ) {
442
+ wp_die( __('You are trying to edit a form that does not exist.', 'formidable') );
443
  }
444
+
 
 
 
 
445
  $frm_field_selection = FrmFieldsHelper::field_selection();
446
+ $fields = $frm_field->getAll(array('fi.form_id' => $form->id), 'field_order');
 
 
 
 
 
 
 
 
 
 
 
447
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
448
+
449
+ $edit_message = __('Form was Successfully Updated', 'formidable');
450
  if ( $form->is_template && $message == $edit_message ) {
451
+ $message = __('Template was Successfully Updated', 'formidable');
452
  }
453
+
 
 
454
  if ( $form->default_template ) {
455
+ wp_die(__('That template cannot be edited', 'formidable'));
456
  } else if ( defined('DOING_AJAX') ) {
457
+ die();
458
  } else if ( $create_link ) {
459
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
460
  } else {
461
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
462
  }
463
  }
464
+
465
+ public static function get_settings_vars($id, $errors = '', $message=''){
466
+ global $frm_entry, $frm_field, $frm_vars;
467
+ $frm_form = new FrmForm();
468
+ $form = $frm_form->getOne( $id );
469
+ $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
 
 
 
470
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
 
 
 
 
 
 
 
471
  $sections = apply_filters('frm_add_form_settings_section', array(), $values);
472
+ $pro_feature = $frm_vars['pro_is_installed'] ? '' : ' class="pro_feature"';
473
+ if (isset($values['default_template']) && $values['default_template'])
474
+ wp_die(__('That template cannot be edited', 'formidable'));
475
+ else
476
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/settings.php');
477
+ }
478
+
479
+ public static function get_params(){
480
+ $values = array();
481
+ foreach (array('template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default)
482
+ $values[$var] = FrmAppHelper::get_param($var, $default);
483
+
484
+ return $values;
485
+ }
486
+
487
+ public static function process_bulk_form_actions($errors) {
488
+ if ( !isset($_POST) ) return;
489
+
490
+ $bulkaction = FrmAppHelper::get_param('action');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  if ( $bulkaction == -1 ) {
492
+ $bulkaction = FrmAppHelper::get_param('action2');
 
 
 
 
 
 
493
  }
494
 
495
+ if ( !empty($bulkaction) && strpos($bulkaction, 'bulk_') === 0 ) {
496
+ if ( isset($_GET) && isset($_GET['action']) ) {
497
+ $_SERVER['REQUEST_URI'] = str_replace('&action=' .$_GET['action'], '', $_SERVER['REQUEST_URI']);
498
+ }
499
+ if ( isset($_GET) && isset($_GET['action2']) ) {
500
+ $_SERVER['REQUEST_URI'] = str_replace('&action=' .$_GET['action2'], '', $_SERVER['REQUEST_URI']);
501
+ }
502
+
503
+ $bulkaction = str_replace('bulk_', '', $bulkaction);
504
+ } else {
505
+ $bulkaction = '-1';
506
+ if(isset($_POST['bulkaction']) && $_POST['bulkaction'] != '-1') {
507
+ $bulkaction = $_POST['bulkaction'];
508
+ } else if(isset($_POST['bulkaction2']) && $_POST['bulkaction2'] != '-1') {
509
+ $bulkaction = $_POST['bulkaction2'];
510
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  }
512
 
513
+ $ids = FrmAppHelper::get_param('item-action', '');
514
+ if ( empty($ids) ) {
515
+ $errors[] = __('No forms were specified', 'formidable');
516
+ } else {
517
+ if ( $bulkaction == 'delete' ) {
518
+ if ( !current_user_can('frm_delete_forms') ) {
519
+ global $frm_settings;
520
+ $errors[] = $frm_settings->admin_permission;
521
+ } else {
522
+ if ( !is_array($ids) ) {
523
+ $ids = explode(',', $ids);
524
+ }
525
+
526
+ if ( is_array($ids) ) {
527
+ if ( $bulkaction == 'delete' ) {
528
+ $frm_form = new FrmForm();
529
+ foreach ( $ids as $form_id ) {
530
+ $frm_form->destroy($form_id);
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }
536
  }
 
537
  return $errors;
538
  }
539
+
540
+ public static function add_default_templates($path, $default=true, $template=true){
541
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
542
+
543
+ global $frm_field;
544
  $path = untrailingslashit(trim($path));
545
+ $templates = glob($path."/*.php");
546
+
547
+ $frm_form = new FrmForm();
548
+ for($i = count($templates) - 1; $i >= 0; $i--){
549
+ $filename = str_replace('.php', '', str_replace($path.'/', '', $templates[$i]));
550
+ $template_query = array('form_key' => $filename);
551
+ if($template) $template_query['is_template'] = 1;
552
+ if($default) $template_query['default_template'] = 1;
553
+ $form = $frm_form->getAll($template_query, '', 1);
554
+
 
 
 
555
  $values = FrmFormsHelper::setup_new_vars();
556
  $values['form_key'] = $filename;
557
  $values['is_template'] = $template;
558
  $values['status'] = 'published';
559
+ if($default) $values['default_template'] = 1;
560
+
561
+ include($templates[$i]);
562
+
 
 
563
  //get updated form
564
+ if ( isset($form) && $form ) {
565
+ $form = $frm_form->getOne($form->id);
 
566
  } else {
567
+ $form = $frm_form->getAll($template_query, '', 1);
 
 
 
 
 
568
  }
569
+
570
+ if($form)
571
+ do_action('frm_after_duplicate_form', $form->id, (array)$form);
572
  }
573
  }
574
 
575
+ public static function route(){
576
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
577
+ $vars = false;
578
+ if(isset($_POST['frm_compact_fields'])){
579
+ if ( !current_user_can('frm_edit_forms') && !current_user_can('administrator') ) {
580
+ global $frm_settings;
581
+ wp_die($frm_settings->admin_permission);
582
+ }
583
  $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('&quot;', '\\\"', $_POST['frm_compact_fields'] ))));
584
  $json_vars = json_decode($json_vars, true);
585
  if ( empty($json_vars) ) {
588
  if ( 'edit' == $action ) {
589
  $action = 'update';
590
  }
591
+
592
+ add_filter('frm_validate_form', array(__CLASS__, 'json_error'));
593
  } else {
594
  $vars = FrmAppHelper::json_to_array($json_vars);
595
+ $action = $vars[$action];
 
 
596
  }
597
+ }else{
598
  $action = FrmAppHelper::get_param($action);
 
 
 
 
599
  }
600
+
601
+ if($action == 'new' or $action == 'new-selection')
602
+ return self::new_form($vars);
603
+ else if($action == 'create')
604
+ return self::create($vars);
605
+ else if($action == 'edit')
606
+ return self::edit($vars);
607
+ else if($action == 'update')
608
+ return self::update($vars);
609
+ else if($action == 'duplicate')
610
+ return self::duplicate();
611
+ else if($action == 'destroy')
612
+ return self::destroy();
613
+ else if($action == 'list-form')
614
+ return self::list_form();
615
+ else if($action == 'settings')
616
+ return self::settings();
617
+ else if($action == 'update_settings')
618
+ return self::update_settings();
619
+ else{
620
+ do_action('frm_form_action_'. $action);
621
+ if(apply_filters('frm_form_stop_action_'. $action, false))
622
+ return;
623
+
624
+ $action = FrmAppHelper::get_param('action');
625
+ if($action == -1)
626
+ $action = FrmAppHelper::get_param('action2');
627
+
628
+ if(strpos($action, 'bulk_') === 0){
629
+ if(isset($_GET) and isset($_GET['action']))
630
+ $_SERVER['REQUEST_URI'] = str_replace('&action='.$_GET['action'], '', $_SERVER['REQUEST_URI']);
631
+ if(isset($_GET) and isset($_GET['action2']))
632
+ $_SERVER['REQUEST_URI'] = str_replace('&action='.$_GET['action2'], '', $_SERVER['REQUEST_URI']);
633
+
634
+ return self::list_form();
635
+ }else{
636
  return self::display_forms_list();
637
+ }
638
  }
639
  }
640
+
641
+ public static function json_error($errors) {
642
+ $errors['json'] = __('Abnormal HTML characters prevented your form from saving correctly', 'formidable');
643
  return $errors;
644
  }
645
+
646
+
647
  /* FRONT-END FORMS */
648
  public static function admin_bar_css() {
649
  FrmAppController::load_wp_admin_style();
650
  }
651
+
652
  public static function admin_bar_configure() {
653
  if ( is_admin() || !current_user_can('frm_edit_forms') ) {
654
  return;
655
  }
656
+
657
  global $frm_vars;
658
  if ( empty($frm_vars['forms_loaded']) ) {
659
  return;
660
  }
661
+
662
  $actions = array();
663
+ foreach ($frm_vars['forms_loaded'] as $form ) {
664
  if ( is_object($form) ) {
665
+ $actions[$form->id] = $form->name;
666
  }
667
  unset($form);
668
  }
669
+
670
  if ( empty($actions) ) {
671
  return;
672
  }
673
+
674
  asort($actions);
675
+
676
  global $wp_admin_bar;
677
+
678
  if ( count($actions) == 1 ) {
679
  $wp_admin_bar->add_menu( array(
680
  'title' => 'Edit Form',
681
  'href' => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
682
+ 'id' => 'frm-forms'
683
  ) );
684
+ } else {
685
  $wp_admin_bar->add_menu( array(
686
  'id' => 'frm-forms',
687
  'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
690
  'title' => __( 'Edit Forms', 'formidable' ),
691
  ),
692
  ) );
693
+
694
  foreach ( $actions as $form_id => $name ) {
695
 
696
  $wp_admin_bar->add_menu( array(
697
  'parent' => 'frm-forms',
698
  'id' => 'edit_form_'. $form_id,
699
+ 'title' => empty($name) ? __('(no title)') : $name,
700
  'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
701
  ) );
702
  }
703
+ }
704
  }
705
+
706
+
707
+
708
  //formidable shortcode
709
  public static function get_form_shortcode($atts) {
710
  global $frm_vars;
715
  }
716
  return $sc .']';
717
  }
718
+
719
+ $shortcode_atts = shortcode_atts(array(
720
  'id' => '', 'key' => '', 'title' => false, 'description' => false,
721
  'readonly' => false, 'entry_id' => false, 'fields' => array(),
722
  'exclude_fields' => array(), 'minimize' => false,
723
  ), $atts);
724
  do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
725
+ extract($shortcode_atts);
726
+ return self::show_form($id, $key, $title, $description, $atts);
727
+ }
728
+
729
+ //filter form shortcode in text widgets
730
+ public static function widget_text_filter( $content ) {
731
+ $regex = '/\[\s*formidable\s+.*\]/';
732
+ return preg_replace_callback( $regex, 'FrmAppController::widget_text_filter_callback', $content );
733
+ }
734
+
735
+ public static function show_form($id = '', $key = '', $title = false, $description = false, $atts = array()) {
736
+ global $frm_settings, $post;
737
+
738
+ $frm_form = new FrmForm();
739
+ if ( empty($id) ) {
740
  $id = $key;
741
  }
742
+
743
  // no form id or key set
744
+ if ( empty($id) ) {
745
+ return __('Please select a valid form', 'formidable');
746
  }
747
+
748
+ $form = $frm_form->getOne($id);
749
+ if ( !$form ) {
750
+ return __('Please select a valid form', 'formidable');
751
  }
752
+ $form = apply_filters('frm_pre_display_form', $form);
753
+
 
 
 
 
 
 
754
  // don't show a draft form on a page
755
+ if ( $form->status == 'draft' && (!$post || $post->ID != $frm_settings->preview_page_id) ) {
756
+ return __('Please select a valid form', 'formidable');
 
757
  }
758
+
759
  // don't show the form if user should be logged in
760
+ if ( $form->logged_in && !is_user_logged_in() ) {
761
+ return do_shortcode($frm_settings->login_msg);
762
  }
763
+
764
  // don't show the form if user doesn't have permission
765
+ if ( $form->logged_in && get_current_user_id() && isset($form->options['logged_in_role']) && $form->options['logged_in_role'] != '' && !FrmAppHelper::user_has_permission($form->options['logged_in_role']) ) {
766
+ return do_shortcode($frm_settings->login_msg);
767
  }
768
+
769
+ $form = self::get_form($form, $title, $description, $atts);
770
+
771
  // check for external shortcodes
772
+ $form = do_shortcode($form);
773
+
774
  return $form;
775
  }
776
+
777
+ public static function get_form($form, $title, $description, $atts = array()) {
778
+ global $frm_field, $frm_entry, $frm_entry_meta, $frm_settings, $frm_vars;
779
+ $form_name = $form->name;
780
 
781
+ $frm_form = new FrmForm();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782
  $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
783
+ $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
784
+
785
  $user_ID = get_current_user_id();
786
+
787
  $params = FrmEntriesController::get_params($form);
788
 
789
  $message = $errors = '';
790
 
791
+ FrmEntriesHelper::enqueue_scripts($params);
792
+
793
  if ( $params['posted_form_id'] == $form->id && $_POST ) {
794
+ $errors = isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['errors'] : array();
795
+ }
796
+
797
+ $fields = FrmFieldsHelper::get_form_fields($form->id, (isset($errors) && !empty($errors)));
798
+
799
+ $filename = FrmAppHelper::plugin_path() .'/classes/views/frm-entries/frm-entry.php';
800
+
801
+ if ( is_file($filename) ) {
802
+ ob_start();
803
+ include $filename;
804
+ $contents = ob_get_contents();
805
+ ob_end_clean();
806
+ // check if minimizing is turned on
807
+ if ( isset($atts['minimize']) && !empty($atts['minimize']) ) {
808
+ $contents = str_replace(array("\r\n", "\r", "\n", "\t", " "), '', $contents);
809
  }
810
+ return $contents;
 
 
 
 
 
 
811
  }
812
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
813
  }
814
+
815
  }
classes/controllers/FrmHooksController.php DELETED
@@ -1,200 +0,0 @@
1
- <?php
2
-
3
- class FrmHooksController {
4
- /**
5
- * Trigger plugin-wide hook loading
6
- */
7
- public static function trigger_load_hook( $hooks = 'load_hooks' ) {
8
- $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) );
9
-
10
- $trigger_hooks = $hooks;
11
- $hooks = (array) $hooks;
12
-
13
- if ( 'load_hooks' == $trigger_hooks ) {
14
- if ( is_admin() ) {
15
- $hooks[] = 'load_admin_hooks';
16
- if ( defined( 'DOING_AJAX' ) ) {
17
- $hooks[] = 'load_ajax_hooks';
18
- $hooks[] = 'load_form_hooks';
19
- }
20
- }
21
-
22
- if ( is_multisite() ) {
23
- $hooks[] = 'load_multisite_hooks';
24
- }
25
- } else {
26
- // Make sure the hooks are only triggered once
27
- add_filter('frm'. str_replace('load', '', $trigger_hooks) .'_loaded', '__return_true');
28
- }
29
- unset($trigger_hooks);
30
-
31
- // Instansiate Controllers
32
- foreach ( $controllers as $c ) {
33
- foreach ( $hooks as $hook ) {
34
- call_user_func( array( $c, $hook ) );
35
- unset( $hook );
36
- }
37
- unset( $c );
38
- }
39
-
40
- }
41
-
42
- public static function load_hooks() {
43
- if ( ! is_admin() ) {
44
- add_filter('the_content', 'FrmAppController::page_route', 10);
45
- }
46
-
47
- add_action('plugins_loaded', 'FrmAppController::load_lang' );
48
- add_action('init', 'FrmAppController::front_head' );
49
- add_filter('widget_text', 'FrmAppController::widget_text_filter', 8 );
50
- add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
51
-
52
- // Entries controller
53
- add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
54
- add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
55
- add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
56
- add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
57
- add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
58
- add_filter('frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4);
59
-
60
- // Form Actions Controller
61
- add_action('init', 'FrmFormActionsController::register_post_types', 1);
62
- add_action('frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 2);
63
-
64
- // Forms Controller
65
- add_action('widgets_init', 'FrmFormsController::register_widgets' );
66
- add_filter('frm_content', 'FrmFormsController::filter_content', 10, 3);
67
- add_filter('frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3);
68
- add_action('admin_bar_init', 'FrmFormsController::admin_bar_css' );
69
- add_action('wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
70
- add_action('wp_scheduled_delete', 'FrmFormsController::scheduled_delete' );
71
-
72
- // Form Shortcodes
73
- add_shortcode('formidable', 'FrmFormsController::get_form_shortcode' );
74
-
75
- // Styles Controller
76
- add_action('init', 'FrmStylesController::register_post_types', 0);
77
- add_filter('frm_get_style_opts', 'FrmStylesController::get_style_opts');
78
- add_filter('frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2);
79
- add_filter('frm_show_entry_styles', 'FrmStylesController::show_entry_styles');
80
- }
81
-
82
- public static function load_admin_hooks() {
83
- add_action('admin_menu', 'FrmAppController::menu', 1);
84
- add_action('admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
85
- add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
86
- add_action('admin_notices', 'FrmAppController::pro_get_started_headline' );
87
- add_action('admin_init', 'FrmAppController::admin_js', 11);
88
- register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::activation_install' );
89
-
90
- // Entries Controller
91
- add_action('admin_menu', 'FrmEntriesController::menu', 12);
92
- add_filter('contextual_help', 'FrmEntriesController::contextual_help', 10, 3 );
93
- add_filter('set-screen-option', 'FrmEntriesController::save_per_page', 10, 3);
94
- add_filter('update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5);
95
- add_action('updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4);
96
-
97
- // Fields Controller
98
- add_filter('frm_display_field_options', 'FrmFieldsController::display_field_options');
99
- add_action('frm_field_options_form', 'FrmFieldsController::add_conditional_update_msg', 50);
100
-
101
- // Form Actions Controller
102
- if ( FrmAppHelper::is_admin_page('formidable' ) ) {
103
- add_action('frm_before_update_form_settings', 'FrmFormActionsController::update_settings');
104
- }
105
- add_action('frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3);
106
-
107
- // Forms Controller
108
- add_action('admin_menu', 'FrmFormsController::menu', 10);
109
- add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
110
-
111
- add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
112
- add_action('admin_footer', 'FrmFormsController::insert_form_popup' );
113
- add_filter('media_buttons_context', 'FrmFormsController::insert_form_button' );
114
-
115
- // Forms Model
116
- add_action('frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2);
117
-
118
- // Settings Controller
119
- add_action('admin_menu', 'FrmSettingsController::menu', 45);
120
- add_action('frm_before_settings', 'FrmSettingsController::license_box');
121
-
122
- // Stats Controller
123
- add_action('admin_menu', 'FrmStatisticsController::menu', 24);
124
- add_action('frm_form_action_reports', 'FrmStatisticsController::list_reports');
125
-
126
- // Styles Controller
127
- add_action('admin_menu', 'FrmStylesController::menu', 14);
128
- add_action('admin_init', 'FrmStylesController::admin_init');
129
-
130
- // XML Controller
131
- add_action('admin_menu', 'FrmXMLController::menu', 41);
132
- }
133
-
134
- public static function load_ajax_hooks() {
135
- add_action('wp_ajax_frm_install', 'FrmAppController::install' );
136
- add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
137
- add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
138
-
139
- add_action('wp_ajax_frmpro_css', 'FrmAppController::load_css' );
140
- add_action('wp_ajax_nopriv_frmpro_css', 'FrmAppController::load_css' );
141
-
142
- // Fields Controller
143
- add_action('wp_ajax_frm_load_field', 'FrmFieldsController::load_field');
144
- add_action('wp_ajax_frm_insert_field', 'FrmFieldsController::create');
145
- add_action('wp_ajax_frm_update_field_form_id', 'FrmFieldsController::update_form_id');
146
- add_action('wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name');
147
- add_action('wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option');
148
- add_action('wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate');
149
- add_action('wp_ajax_frm_delete_field', 'FrmFieldsController::destroy');
150
- add_action('wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option');
151
- add_action('wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option');
152
- add_action('wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option');
153
- add_action('wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices');
154
- add_action('wp_ajax_frm_import_options', 'FrmFieldsController::import_options');
155
- add_action('wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order');
156
-
157
- // Form Actions Controller
158
- add_action('wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action');
159
- add_action('wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action');
160
-
161
- // Forms Controller
162
- add_action( 'wp_ajax_frm_create_from_template', 'FrmFormsController::_create_from_template' );
163
- add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' );
164
- add_action( 'wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key' );
165
- add_action( 'wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description' );
166
- add_action('wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' );
167
- add_action('wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' );
168
- add_action('wp_ajax_frm_forms_preview', 'FrmFormsController::preview' );
169
- add_action('wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' );
170
-
171
- // Styles Controller
172
- add_action('wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling');
173
- add_action('wp_ajax_frm_change_styling', 'FrmStylesController::change_styling');
174
- add_action('wp_ajax_frmpro_load_css', 'FrmStylesController::load_css');
175
- add_action('wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css');
176
-
177
- // XML Controller
178
- add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
179
- }
180
-
181
- public static function load_form_hooks() {
182
- // Fields Controller
183
- add_filter('frm_field_type', 'FrmFieldsController::change_type');
184
- add_action('frm_field_input_html', 'FrmFieldsController::input_html');
185
- add_filter('frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3);
186
- add_filter('frm_field_label_seen', 'FrmFieldsController::check_label');
187
-
188
- // Styles Controller
189
- add_filter('frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
190
- }
191
-
192
- public static function load_view_hooks() {
193
- // Hooks go here when a view is loaded
194
- }
195
-
196
- public static function load_multisite_hooks() {
197
- // drop tables when mu site is deleted
198
- add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
199
- }
200
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/controllers/FrmSettingsController.php CHANGED
@@ -1,70 +1,89 @@
1
  <?php
 
 
 
2
 
3
- class FrmSettingsController {
4
 
5
- public static function menu() {
6
- add_submenu_page('formidable', 'Formidable | '. __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route');
 
 
 
 
 
7
  }
8
 
9
- public static function license_box() {
 
 
 
 
10
  $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
11
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/license_box.php');
12
  }
13
 
14
- public static function display_form( $errors = array(), $message = '' ) {
15
- global $frm_vars;
16
-
17
- $frm_settings = FrmAppHelper::get_settings();
18
  $frm_roles = FrmAppHelper::frm_capabilities();
19
-
20
  $uploads = wp_upload_dir();
21
  $target_path = $uploads['basedir'] . '/formidable/css';
22
- $sections = apply_filters('frm_add_settings_section', array());
23
-
24
- $captcha_lang = FrmAppHelper::locales('captcha');
25
-
 
 
 
 
 
 
 
 
26
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/form.php');
27
  }
28
 
29
- public static function process_form( $stop_load = false ) {
30
- global $frm_vars;
31
-
32
- $frm_settings = FrmAppHelper::get_settings();
33
-
34
- if ( ! isset( $_POST['process_form'] ) || ! wp_verify_nonce( $_POST['process_form'], 'process_form_nonce' ) ) {
35
- wp_die( $frm_settings->admin_permission );
36
- }
37
-
38
  $errors = array();
39
  $message = '';
40
-
41
- if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) {
42
  //$errors = $frm_settings->validate($_POST,array());
43
- $frm_settings->update( stripslashes_deep( $_POST ) );
44
 
45
- if ( empty( $errors ) ) {
46
  $frm_settings->store();
47
- $message = __( 'Settings Saved', 'formidable' );
48
  }
49
- } else {
50
- $message = __( 'Settings Saved', 'formidable' );
51
  }
52
-
53
- if ( $stop_load == 'stop_load' ) {
54
  $frm_vars['settings_routed'] = true;
55
  return;
56
  }
57
-
58
- self::display_form( $errors, $message );
59
  }
60
-
61
- public static function route( $stop_load = false ) {
62
- $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
63
- $action = FrmAppHelper::get_param( $action );
64
- if ( $action == 'process-form' ) {
65
- return self::process_form( $stop_load );
66
- } else if ( $stop_load != 'stop_load' ) {
 
 
 
 
67
  return self::display_form();
68
- }
69
  }
70
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
 
6
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
 
8
+ if(class_exists('FrmSettingsController'))
9
+ return;
10
+
11
+ class FrmSettingsController{
12
+ public static function load_hooks(){
13
+ add_action('admin_menu', 'FrmSettingsController::menu', 45);
14
+ add_action('frm_before_settings', 'FrmSettingsController::license_box');
15
  }
16
 
17
+ public static function menu(){
18
+ add_submenu_page('formidable', 'Formidable | '. __('Global Settings', 'formidable'), __('Global Settings', 'formidable'), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route');
19
+ }
20
+
21
+ public static function license_box(){
22
  $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
23
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/license_box.php');
24
  }
25
 
26
+ public static function display_form($errors=array(), $message=''){
27
+ global $frm_settings, $frm_vars;
28
+
 
29
  $frm_roles = FrmAppHelper::frm_capabilities();
30
+
31
  $uploads = wp_upload_dir();
32
  $target_path = $uploads['basedir'] . '/formidable/css';
33
+ $sections = apply_filters('frm_add_settings_section', array(
34
+ 'styling' => array('name' => __('Form Styling', 'formidable'), 'class' => 'FrmSettingsController', 'function' => 'styling_tab')
35
+ ));
36
+
37
+ $recaptcha_themes = array(
38
+ 'red' => __('Red', 'formidable'),
39
+ 'white' => __('White', 'formidable'),
40
+ 'blackglass' => __('Black Glass', 'formidable'),
41
+ 'clean' => __('Clean', 'formidable'),
42
+ //'custom' => __('Custom', 'formidable'),
43
+ );
44
+
45
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/form.php');
46
  }
47
 
48
+ public static function process_form($stop_load=false){
49
+ global $frm_settings, $frm_vars;
50
+
51
+ if(!isset($_POST['process_form']) or !wp_verify_nonce($_POST['process_form'], 'process_form_nonce'))
52
+ wp_die($frm_settings->admin_permission);
53
+
 
 
 
54
  $errors = array();
55
  $message = '';
56
+
57
+ if(!isset($frm_vars['settings_routed']) or !$frm_vars['settings_routed']){
58
  //$errors = $frm_settings->validate($_POST,array());
59
+ $frm_settings->update(stripslashes_deep($_POST));
60
 
61
+ if( empty($errors) ){
62
  $frm_settings->store();
63
+ $message = __('Settings Saved', 'formidable');
64
  }
65
+ }else{
66
+ $message = __('Settings Saved', 'formidable');
67
  }
68
+
69
+ if($stop_load == 'stop_load'){
70
  $frm_vars['settings_routed'] = true;
71
  return;
72
  }
73
+
74
+ self::display_form($errors, $message);
75
  }
76
+
77
+ public static function styling_tab(){
78
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/styling_tab.php');
79
+ }
80
+
81
+ public static function route($stop_load=false){
82
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
83
+ $action = FrmAppHelper::get_param($action);
84
+ if($action == 'process-form')
85
+ return self::process_form($stop_load);
86
+ else if($stop_load != 'stop_load')
87
  return self::display_form();
 
88
  }
89
  }
classes/controllers/FrmStatisticsController.php CHANGED
@@ -1,20 +1,32 @@
1
  <?php
 
2
 
3
- class FrmStatisticsController {
 
4
 
5
- public static function menu() {
6
- add_submenu_page( 'formidable', 'Formidable | '. __( 'Views', 'formidable' ), '<span class="frm_inactive_menu">'. __( 'Views', 'formidable' ) .'</span>', 'administrator', 'formidable-entry-templates', 'FrmStatisticsController::list_displays' );
7
- }
8
-
9
- public static function list_reports() {
10
- add_filter('frm_form_stop_action_reports', '__return_true');
11
- $form = FrmAppHelper::get_param('form', false);
12
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list.php');
13
- }
14
-
15
- public static function list_displays() {
16
- $form = FrmAppHelper::get_param('form', false);
17
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list_displays.php');
18
- }
 
 
 
 
 
 
 
 
 
 
19
 
20
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
+ if(class_exists('FrmStatisticsController'))
5
+ return;
6
 
7
+ class FrmStatisticsController{
8
+ public static function load_hooks(){
9
+ add_action('admin_menu', 'FrmStatisticsController::menu', 24);
10
+ }
11
+
12
+ public static function menu(){
13
+ global $frm_vars;
14
+ if($frm_vars['pro_is_installed'])
15
+ return;
16
+
17
+ add_submenu_page('formidable', 'Formidable | '. __('Views', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Views', 'formidable') .'</span>', 'administrator', 'formidable-entry-templates', 'FrmStatisticsController::list_displays');
18
+
19
+ add_submenu_page('formidable', 'Formidable | '. __('Reports', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Reports', 'formidable') .'</span>', 'administrator', 'formidable-reports', 'FrmStatisticsController::list_reports');
20
+ }
21
+
22
+ public static function list_reports(){
23
+ $form = FrmAppHelper::get_param('form', false);
24
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list.php');
25
+ }
26
+
27
+ public static function list_displays(){
28
+ $form = FrmAppHelper::get_param('form', false);
29
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list_displays.php');
30
+ }
31
 
32
  }
classes/controllers/FrmStylesController.php DELETED
@@ -1,434 +0,0 @@
1
- <?php
2
-
3
- class FrmStylesController {
4
- public static $post_type = 'frm_styles';
5
- public static $screen = 'formidable_page_formidable-styles';
6
-
7
- public static function load_pro_hooks() {
8
- if ( FrmAppHelper::pro_is_installed() ) {
9
- FrmProStylesController::load_pro_hooks();
10
- }
11
- }
12
-
13
- public static function register_post_types() {
14
- register_post_type( self::$post_type, array(
15
- 'label' => __( 'Styles', 'formidable' ),
16
- 'public' => false,
17
- 'show_ui' => false,
18
- 'capability_type' => 'page',
19
- 'capabilities' => array(
20
- 'edit_post' => 'frm_change_settings',
21
- 'edit_posts' => 'frm_change_settings',
22
- 'edit_others_posts' => 'frm_change_settings',
23
- 'publish_posts' => 'frm_change_settings',
24
- 'delete_post' => 'frm_change_settings',
25
- 'delete_posts' => 'frm_change_settings',
26
- 'read_private_posts' => 'read_private_posts',
27
- ),
28
- 'supports' => array(
29
- 'title',
30
- ),
31
- 'has_archive' => false,
32
- 'labels' => array(
33
- 'name' => __( 'Styles', 'formidable' ),
34
- 'singular_name' => __( 'Style', 'formidable' ),
35
- 'menu_name' => __( 'Style', 'formidable' ),
36
- 'edit' => __( 'Edit' ),
37
- 'add_new_item' => __( 'Create a New Style', 'formidable' ),
38
- 'edit_item' => __( 'Edit Style', 'formidable' )
39
- )
40
- ) );
41
- }
42
-
43
- public static function menu() {
44
- add_submenu_page('formidable', 'Formidable | '. __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route');
45
- }
46
-
47
- public static function admin_init() {
48
- if ( ! FrmAppHelper::is_admin_page('formidable-styles') ) {
49
- return;
50
- }
51
-
52
- self::load_pro_hooks();
53
- wp_enqueue_script('jquery-ui-datepicker');
54
-
55
- $version = FrmAppHelper::plugin_version();
56
- wp_enqueue_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array( 'jquery'), $version);
57
-
58
- wp_enqueue_style('jquery-ui-base', FrmAppHelper::jquery_ui_base_url() .'/themes/base/ui.all.css');
59
- wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css');
60
-
61
- $style = apply_filters('frm_style_head', false);
62
- if ( $style ) {
63
- wp_enqueue_style('frm-single-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_load_css&flat=1&'. http_build_query($style->post_content));
64
- }
65
- }
66
-
67
- public static function new_style($return = '') {
68
- FrmAppHelper::update_message( __( 'create multiple styling templates', 'formidable' ), 'wrap' );
69
- self::load_styler('default');
70
- }
71
-
72
- public static function edit($style_id = false, $message = '') {
73
- if ( ! $style_id ) {
74
- $style_id = FrmAppHelper::get_param('id');
75
- if ( empty($style_id) ) {
76
- $style_id = 'default';
77
- }
78
- }
79
-
80
- if ( 'default' == $style_id ) {
81
- $style = 'default';
82
- } else {
83
- $frm_style = new FrmStyle($style_id);
84
- $style = $frm_style->get_one();
85
- $style = $style->ID;
86
- }
87
-
88
- self::load_styler($style, $message);
89
- }
90
-
91
- public static function save() {
92
- $frm_style = new FrmStyle();
93
- $message = '';
94
- $post_id = ( $_POST && isset($_POST['ID']) ) ? $_POST['ID'] : false;
95
- if ( $post_id !== false && isset($_POST['frm_style']) && wp_verify_nonce($_POST['frm_style'], 'frm_style_nonce') ) {
96
- $id = $frm_style->update($post_id);
97
- if ( empty($post_id) && ! empty($id) ) {
98
- // set the post id to the new style so it will be loaded for editing
99
- $post_id = reset($id);
100
- }
101
- // include the CSS that includes this style
102
- echo '<link href="'. admin_url('admin-ajax.php') .'?action=frmpro_css" type="text/css" rel="Stylesheet" class="frm-custom-theme" />';
103
- $message = __( 'Your styling settings have been saved.', 'formidable' );
104
- }
105
-
106
- return self::edit($post_id, $message);
107
- }
108
-
109
- public static function load_styler($style, $message = '') {
110
- global $frm_settings;
111
-
112
- $frm_style = new FrmStyle();
113
- $styles = $frm_style->get_all();
114
-
115
- if ( is_numeric($style) ) {
116
- $style = $styles[ $style ];
117
- } else if ( 'default' == $style ) {
118
- $style = $frm_style->get_default_style($styles);
119
- }
120
-
121
- self::add_meta_boxes();
122
-
123
- include(FrmAppHelper::plugin_path() .'/classes/views/styles/show.php');
124
- }
125
-
126
- private static function manage($message = '', $forms = array()) {
127
- $frm_style = new FrmStyle();
128
- $styles = $frm_style->get_all();
129
- $default_style = $frm_style->get_default_style($styles);
130
-
131
- if ( empty($forms) ) {
132
- $forms = FrmForm::get_published_forms();
133
- }
134
-
135
- include(FrmAppHelper::plugin_path() .'/classes/views/styles/manage.php');
136
- }
137
-
138
- private static function manage_styles() {
139
- if ( ! $_POST || ! isset($_POST['style']) || ! isset($_POST['frm_manage_style']) || ! wp_verify_nonce($_POST['frm_manage_style'], 'frm_manage_style_nonce') ) {
140
- return self::manage();
141
- }
142
-
143
- global $wpdb;
144
-
145
- $forms = FrmForm::get_published_forms();
146
- foreach ( $forms as $form ) {
147
- if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) {
148
- continue;
149
- }
150
-
151
- $form->options['custom_style'] = $_POST['style'][ $form->id ];
152
-
153
- $wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => maybe_serialize($form->options)), array( 'id' => $form->id));
154
- unset($form);
155
- }
156
-
157
- $message = __( 'Your form styles have been saved.', 'formidable' );
158
- return self::manage($message, $forms);
159
- }
160
-
161
- public static function custom_css( $message = '', $style = null ) {
162
- wp_enqueue_style('codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css');
163
- wp_enqueue_script('codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7');
164
- wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), '4.7' );
165
-
166
- if ( ! isset($style) ) {
167
- $frm_style = new FrmStyle();
168
- $style = $frm_style->get_default_style();
169
- }
170
-
171
- include(FrmAppHelper::plugin_path() .'/classes/views/styles/custom_css.php');
172
- }
173
-
174
- public static function save_css() {
175
- $frm_style = new FrmStyle();
176
-
177
- $message = '';
178
- $post_id = ( $_POST && isset($_POST['ID']) ) ? $_POST['ID'] : false;
179
- if ( isset($_POST['frm_custom_css']) && wp_verify_nonce($_POST['frm_custom_css'], 'frm_custom_css_nonce') ) {
180
- $frm_style->update($post_id);
181
- $message = __( 'Your styling settings have been saved.', 'formidable' );
182
- }
183
-
184
- return self::custom_css($message);
185
- }
186
-
187
- public static function route() {
188
- $action = FrmAppHelper::get_param('frm_action');
189
-
190
- switch ( $action ) {
191
- case 'edit':
192
- case 'save':
193
- case 'manage':
194
- case 'manage_styles':
195
- case 'custom_css':
196
- case 'save_css':
197
- return self::$action();
198
- default:
199
- do_action( 'frm_style_action_route', $action );
200
- if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
201
- return;
202
- }
203
-
204
- if ( 'new_style' == $action ) {
205
- return self::$action();
206
- }
207
-
208
- return self::edit();
209
- }
210
- }
211
-
212
- public static function reset_styling() {
213
- check_ajax_referer( 'frm_ajax', 'nonce' );
214
-
215
- $frm_style = new FrmStyle();
216
- $defaults = $frm_style->get_defaults();
217
-
218
- echo json_encode( $defaults );
219
- wp_die();
220
- }
221
-
222
- public static function change_styling() {
223
- check_ajax_referer( 'frm_ajax', 'nonce' );
224
-
225
- $frm_style = new FrmStyle();
226
- $defaults = $frm_style->get_defaults();
227
-
228
- // remove the # from the colors
229
- foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) {
230
- if ( ! is_array($v) && strpos($v, '#') === 0 ) {
231
- $_GET['frm_style_setting']['post_content'][ $k ] = str_replace( '#', '', $v );
232
- }
233
- }
234
-
235
- echo '<style type="text/css">';
236
- include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php');
237
- echo '</style>';
238
- wp_die();
239
- }
240
-
241
- private static function add_meta_boxes() {
242
-
243
- // setup meta boxes
244
- $meta_boxes = array(
245
- 'general' => __( 'General', 'formidable' ),
246
- 'field-labels' => __( 'Field Labels', 'formidable' ),
247
- 'field-description' => __( 'Field Description', 'formidable' ),
248
- 'field-colors' => __( 'Field Colors', 'formidable' ),
249
- 'field-sizes' => __( 'Field Settings', 'formidable' ),
250
- 'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ),
251
- 'section-fields' => __( 'Section Fields', 'formidable' ),
252
- 'date-fields' => __( 'Date Fields', 'formidable' ),
253
- 'buttons' => __( 'Buttons', 'formidable' ),
254
- 'form-messages' => __( 'Form Messages', 'formidable' ),
255
- );
256
-
257
- foreach ( $meta_boxes as $nicename => $name ) {
258
- add_meta_box( $nicename .'-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename );
259
- unset($nicename, $name);
260
- }
261
- }
262
-
263
- public static function include_style_section($atts, $sec) {
264
- extract($atts);
265
- $current_tab = isset($_GET['page-tab']) ? $_GET['page-tab'] : 'default';
266
- include(FrmAppHelper::plugin_path() .'/classes/views/styles/_'. $sec['args'] .'.php');
267
- }
268
-
269
- public static function load_css() {
270
- header('Content-type: text/css');
271
-
272
- $frm_style = new FrmStyle();
273
- $defaults = $frm_style->get_defaults();
274
-
275
- include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php');
276
- wp_die();
277
- }
278
-
279
- /**
280
- * Check if the Formidable styling should be loaded,
281
- * then enqueue it for the footer
282
- * @since 2.0
283
- */
284
- public static function enqueue_style() {
285
- global $frm_vars;
286
-
287
- if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
288
- // the CSS has already been loaded
289
- return;
290
- }
291
-
292
- $frm_settings = FrmAppHelper::get_settings();
293
- if ( $frm_settings->load_style != 'none' ) {
294
- wp_enqueue_style( 'formidable' );
295
- $frm_vars['css_loaded'] = true;
296
- }
297
- }
298
-
299
- // Get the stylesheets for the form settings page
300
- public static function get_style_opts() {
301
- $frm_style = new FrmStyle();
302
- $styles = $frm_style->get_all();
303
-
304
- return $styles;
305
- }
306
-
307
- public static function get_form_style( $form = 'default' ) {
308
- $style = FrmFormsHelper::get_form_style( $form );
309
-
310
- if ( empty( $style ) || 1 == $style ) {
311
- $style = 'default';
312
- }
313
-
314
- $frm_style = new FrmStyle( $style );
315
- return $frm_style->get_one();
316
- }
317
-
318
- /**
319
- * @param string $class
320
- * @param string $style
321
- */
322
- public static function get_form_style_class($class, $style) {
323
- if ( 1 == $style ) {
324
- $style = 'default';
325
- }
326
-
327
- $frm_style = new FrmStyle($style);
328
- $style = $frm_style->get_one();
329
-
330
- if ( $style ) {
331
- $class .= ' frm_style_'. $style->post_name;
332
- }
333
-
334
- return $class;
335
- }
336
-
337
- /**
338
- * @param string $val
339
- */
340
- public static function get_style_val($val, $form = 'default') {
341
- $style = self::get_form_style($form);
342
- if ( $style && isset( $style->post_content[ $val ] ) ) {
343
- return $style->post_content[ $val ];
344
- }
345
- }
346
-
347
- public static function show_entry_styles($default_styles) {
348
- $frm_style = new FrmStyle('default');
349
- $style = $frm_style->get_one();
350
-
351
- if ( ! $style ) {
352
- return $default_styles;
353
- }
354
-
355
- foreach ( $default_styles as $name => $val ) {
356
- $setting = $name;
357
- if ( 'border_width' == $name ) {
358
- $setting = 'field_border_width';
359
- } else if ( 'alt_bg_color' == $name ) {
360
- $setting = 'bg_color_active';
361
- }
362
- $default_styles[ $name ] = $style->post_content[ $setting ];
363
- unset($name, $val);
364
- }
365
-
366
- return $default_styles;
367
- }
368
-
369
- public static function &important_style($important, $field) {
370
- $important = self::get_style_val('important_style', $field['form_id']);
371
- return $important;
372
- }
373
-
374
- /**
375
- * Fallback for WP < 3.6
376
- */
377
- public static function do_accordion_sections( $screen, $context, $object ) {
378
- if ( function_exists( 'do_accordion_sections' ) ) {
379
- return do_accordion_sections( $screen, $context, $object );
380
- }
381
-
382
- global $wp_meta_boxes;
383
-
384
- $screen = 'formidable_page_formidable-styles';
385
- $screen = convert_to_screen( $screen );
386
-
387
- $page = $screen->id;
388
-
389
- $hidden = get_hidden_meta_boxes( $screen );
390
- ?>
391
- <div id="side-sortables" class="accordion-container">
392
- <?php
393
- $i = 0;
394
- $first_open = false;
395
- do {
396
- if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[ $page ] ) || ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
397
- break;
398
- }
399
-
400
- foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
401
- if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
402
- foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
403
- if ( false == $box || ! $box['title'] ) {
404
- continue;
405
- }
406
-
407
- $i++;
408
- $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
409
-
410
- if ( ! $first_open && empty( $hidden_class ) ) {
411
- $first_open = true;
412
- }
413
-
414
- ?>
415
- <div class="postbox <?php echo esc_attr( $box['id'] ); ?>">
416
- <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ) ?>"><br/></div>
417
- <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
418
- <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
419
- <div class="inside">
420
- <?php call_user_func( $box['callback'], $object, $box ); ?>
421
- </div><!-- .inside -->
422
- </div><!-- .accordion-section-content -->
423
- </div><!-- .postbox -->
424
- <?php
425
- }
426
- }
427
- }
428
- } while ( 0 );
429
- ?>
430
- </div><!-- .accordion-container -->
431
- <?php
432
- return $i;
433
- }
434
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/controllers/FrmXMLController.php CHANGED
@@ -1,294 +1,326 @@
1
  <?php
 
2
 
3
- class FrmXMLController {
4
-
 
 
 
 
5
  public static function menu() {
6
- add_submenu_page('formidable', 'Formidable | '. __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route');
7
  }
8
-
9
  public static function add_default_templates() {
10
- if ( !function_exists( 'libxml_disable_entity_loader' ) ) {
11
  // XML import is not enabled on your server
12
  return;
13
  }
14
-
 
 
15
  $set_err = libxml_use_internal_errors(true);
16
  $loader = libxml_disable_entity_loader( true );
17
-
18
  $files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
19
-
20
- foreach ( (array) $files as $file ) {
21
- FrmXMLHelper::import_xml($file);
22
  unset($file);
23
  }
24
- /*
25
  if(is_wp_error($result))
26
  $errors[] = $result->get_error_message();
27
  else if($result)
28
  $message = $result;
29
- */
30
-
31
- unset( $files );
32
-
33
  libxml_use_internal_errors( $set_err );
34
  libxml_disable_entity_loader( $loader );
35
  }
36
-
37
  public static function route() {
38
- $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
39
- $action = FrmAppHelper::get_param( $action );
40
- if ( $action == 'import_xml' ) {
41
  return self::import_xml();
42
- } else if ( $action == 'export_xml' ) {
43
  return self::export_xml();
44
  } else {
45
- if ( apply_filters( 'frm_xml_route', true, $action ) ) {
46
  return self::form();
47
  }
48
  }
49
  }
50
-
51
- public static function form( $errors = array(), $message = '' ) {
52
- $forms = FrmForm::getAll( array( 'status' => array( null, '', 'published' ) ), 'name' );
53
-
54
- $export_types = apply_filters( 'frm_xml_export_types',
55
- array( 'forms' => __( 'Forms', 'formidable' ) )
 
 
 
 
 
56
  );
57
-
58
- $export_format = apply_filters( 'frm_export_formats', array(
59
- 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
60
- ) );
61
-
62
- if ( FrmAppHelper::pro_is_installed() ) {
63
- $frmpro_settings = new FrmProSettings();
64
- $csv_format = $frmpro_settings->csv_format;
65
- } else {
66
- $csv_format = 'UTF-8';
67
- }
68
-
69
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php');
70
  }
71
-
72
  public static function import_xml() {
73
  $errors = array();
74
  $message = '';
75
-
76
- $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce');
77
- if ( $permission_error !== false ) {
78
- $errors[] = $permission_error;
79
  self::form($errors);
80
  return;
81
  }
82
-
83
- if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) {
84
  $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
85
  self::form($errors);
86
  return;
87
  }
88
-
89
  $file = $_FILES['frm_import_file']['tmp_name'];
90
-
91
- if ( ! is_uploaded_file( $file ) ) {
92
  unset($file);
93
  $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
94
  self::form($errors);
95
  return;
96
  }
97
-
98
  //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
99
-
100
- $export_format = apply_filters('frm_export_formats', array(
101
  'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
102
  ));
103
-
104
  $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
105
- if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
106
  // allow other file types to be imported
107
  do_action('frm_before_import_'. $file_type );
108
  return;
109
  }
110
  unset($file_type);
111
-
112
  //$media_id = FrmProAppHelper::upload_file('frm_import_file');
113
-
114
- if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
115
- $errors[] = __( 'XML import is not enabled on your server.', 'formidable' );
116
- self::form( $errors );
117
- return;
118
- }
119
-
120
- $set_err = libxml_use_internal_errors( true );
121
- $loader = libxml_disable_entity_loader( true );
122
-
123
- $result = FrmXMLHelper::import_xml( $file );
124
- FrmXMLHelper::parse_message( $result, $message, $errors );
125
-
126
- unset( $file );
127
-
128
- libxml_use_internal_errors( $set_err );
129
- libxml_disable_entity_loader( $loader );
130
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  self::form($errors, $message);
132
  }
133
-
134
  public static function export_xml() {
135
- $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
136
- if ( ! empty($error) ) {
137
- wp_die( $error );
 
138
  }
139
-
140
- $ids = array();
141
- if ( isset($_POST['frm_export_forms']) ) {
142
  $ids = $_POST['frm_export_forms'];
 
 
143
  }
144
-
145
- $type = false;
146
- if ( isset($_POST['type']) ) {
147
  $type = $_POST['type'];
148
  }
149
-
150
  $format = isset($_POST['format']) ? $_POST['format'] : 'xml';
151
-
152
- if ( ! headers_sent() && ! $type ) {
153
  wp_redirect(admin_url('admin.php?page=formidable-import'));
154
  die();
155
  }
156
-
157
  if ( $format == 'xml' ) {
158
  self::generate_xml($type, compact('ids'));
159
  } else {
160
  do_action('frm_export_format_'. $format, compact('ids'));
161
  }
162
-
163
- wp_die();
164
  }
165
-
 
 
 
 
 
 
 
 
 
 
166
  public static function generate_xml($type, $args = array() ) {
167
  global $wpdb;
168
-
169
- $type = (array) $type;
170
- if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) {
171
- // make sure the form is included if there are entries
172
- $type[] = 'forms';
173
- }
174
-
175
- if ( in_array( 'forms', $type) ) {
176
- // include actions with forms
177
- $type[] = 'actions';
178
- }
179
-
180
  $tables = array(
181
- 'items' => $wpdb->prefix .'frm_items',
182
- 'forms' => $wpdb->prefix .'frm_forms',
183
- 'posts' => $wpdb->posts,
184
- 'styles' => $wpdb->posts,
185
- 'actions' => $wpdb->posts,
186
  );
187
-
188
- $defaults = array( 'ids' => false);
189
  $args = wp_parse_args( $args, $defaults );
190
-
191
  $sitename = sanitize_key( get_bloginfo( 'name' ) );
192
-
193
- if ( ! empty( $sitename ) ) {
194
- $sitename .= '.';
195
- }
196
  $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
197
 
198
  header( 'Content-Description: File Transfer' );
199
  header( 'Content-Disposition: attachment; filename=' . $filename );
200
  header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
201
-
202
  //make sure ids are numeric
203
- if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
204
- $args['ids'] = array_filter( $args['ids'], 'is_numeric' );
205
- }
206
-
207
  $records = array();
208
-
209
- foreach ( $type as $tb_type ) {
210
- $where = array();
211
- $join = '';
212
- $table = $tables[ $tb_type ];
213
-
214
- $select = $table .'.id';
215
- $query_vars = array();
216
-
217
- switch ( $tb_type ) {
218
- case 'forms':
219
- //add forms
220
- if ( $args['ids'] ) {
221
- $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table .'.parent_form_id' => $args['ids'] );
222
- } else {
223
- $where[ $table . '.status !' ] = 'draft';
224
- }
225
- break;
226
- case 'actions':
227
- $select = $table .'.ID';
228
- $where['post_type'] = FrmFormActionsController::$action_post_type;
229
- if ( ! empty($args['ids']) ) {
230
- $where['menu_order'] = $args['ids'];
231
- }
232
- break;
233
- case 'items':
234
- //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
235
- if ( $args['ids'] ) {
236
- $where[ $table . '.form_id' ] = $args['ids'];
237
- }
238
- break;
239
- case 'styles':
240
- // Loop through all exported forms and get their selected style IDs
241
- $form_ids = $args['ids'];
242
- $style_ids = array();
243
- foreach ( $form_ids as $form_id ) {
244
- $form_data = FrmForm::getOne( $form_id );
245
- // For forms that have not been updated while running 2.0, check if custom_style is set
246
- if ( isset( $form_data->options['custom_style'] ) ) {
247
- $style_ids[] = $form_data->options['custom_style'];
248
- }
249
- unset( $form_id, $form_data );
250
- }
251
- $select = $table .'.ID';
252
- $where['post_type'] = 'frm_styles';
253
-
254
- // Only export selected styles
255
- if ( ! empty( $style_ids ) ) {
256
- $where['ID'] = $style_ids;
257
- }
258
- break;
259
- default:
260
- $select = $table .'.ID';
261
- $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
262
- $where['pm.meta_key'] = 'frm_form_id';
263
-
264
- if ( empty($args['ids']) ) {
265
- $where['pm.meta_value >'] = 1;
266
- } else {
267
- $where['pm.meta_value'] = $args['ids'];
268
- }
269
- break;
270
  }
271
 
272
- $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select );
 
 
 
273
  unset($tb_type);
274
  }
 
 
275
 
 
 
276
  echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
277
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
278
  }
279
-
280
- public static function allow_mime($mimes) {
281
- if ( ! isset( $mimes['csv'] ) ) {
282
  // allow csv files
283
  $mimes['csv'] = 'text/csv';
284
  }
285
-
286
- if ( ! isset( $mimes['xml'] ) ) {
287
  // allow xml
288
  $mimes['xml'] = 'text/xml';
289
  }
290
 
291
  return $mimes;
292
  }
293
-
294
  }
1
  <?php
2
+ if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
 
4
+ class FrmXMLController{
5
+ public static function load_hooks(){
6
+ add_action('admin_menu', 'FrmXMLController::menu', 41);
7
+ add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
8
+ }
9
+
10
  public static function menu() {
11
+ add_submenu_page('formidable', 'Formidable | Import/Export', 'Import/Export', 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route');
12
  }
13
+
14
  public static function add_default_templates() {
15
+ if ( !function_exists( 'libxml_disable_entity_loader' ) ){
16
  // XML import is not enabled on your server
17
  return;
18
  }
19
+
20
+ include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
21
+
22
  $set_err = libxml_use_internal_errors(true);
23
  $loader = libxml_disable_entity_loader( true );
24
+
25
  $files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
26
+
27
+ foreach ( (array) $files as $file) {
28
+ $result = FrmXMLHelper::import_xml($file);
29
  unset($file);
30
  }
 
31
  if(is_wp_error($result))
32
  $errors[] = $result->get_error_message();
33
  else if($result)
34
  $message = $result;
35
+
36
+ unset($files);
37
+
 
38
  libxml_use_internal_errors( $set_err );
39
  libxml_disable_entity_loader( $loader );
40
  }
41
+
42
  public static function route() {
43
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
44
+ $action = FrmAppHelper::get_param($action);
45
+ if($action == 'import_xml') {
46
  return self::import_xml();
47
+ } else if($action == 'export_xml') {
48
  return self::export_xml();
49
  } else {
50
+ if ( apply_filters('frm_xml_route', true, $action) ){
51
  return self::form();
52
  }
53
  }
54
  }
55
+
56
+ public static function form($errors = array(), $message = '') {
57
+ //wp_enqueue_script('jquery-chosen');
58
+ //wp_enqueue_style('formidable');
59
+
60
+ $frm_form = new FrmForm();
61
+ $forms = $frm_form->getAll("status is NULL OR status = '' OR status = 'published'", ' ORDER BY name');
62
+ unset($frm_form);
63
+
64
+ $export_types = apply_filters('frm_xml_export_types',
65
+ array('forms' => __('Forms', 'formidable'))
66
  );
67
+
68
+ $export_format = apply_filters('frm_export_formats', array(
69
+ 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
70
+ ));
71
+
72
+ global $frmpro_settings;
73
+ $csv_format = $frmpro_settings ? $frmpro_settings->csv_format : 'UTF-8';
74
+
 
 
 
 
75
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php');
76
  }
77
+
78
  public static function import_xml() {
79
  $errors = array();
80
  $message = '';
81
+
82
+ if ( !current_user_can('frm_edit_forms') || ! isset($_POST['import-xml']) || ! wp_verify_nonce($_POST['import-xml'], 'import-xml-nonce') ) {
83
+ global $frm_settings;
84
+ $errors[] = $frm_settings->admin_permission;
85
  self::form($errors);
86
  return;
87
  }
88
+
89
+ if ( !isset($_FILES) || !isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int)$_FILES['frm_import_file']['size'] < 1) {
90
  $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
91
  self::form($errors);
92
  return;
93
  }
94
+
95
  $file = $_FILES['frm_import_file']['tmp_name'];
96
+
97
+ if ( !is_uploaded_file($file) ) {
98
  unset($file);
99
  $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
100
  self::form($errors);
101
  return;
102
  }
103
+
104
  //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
105
+
106
+ $export_format = apply_filters('frm_export_formats', array(
107
  'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
108
  ));
109
+
110
  $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
111
+ if ( $file_type != 'xml' && isset($export_format[$file_type]) ) {
112
  // allow other file types to be imported
113
  do_action('frm_before_import_'. $file_type );
114
  return;
115
  }
116
  unset($file_type);
117
+
118
  //$media_id = FrmProAppHelper::upload_file('frm_import_file');
119
+ //if(is_numeric($media_id)){
120
+
121
+ if ( !function_exists( 'libxml_disable_entity_loader' ) ) {
122
+ $errors[] = __('XML import is not enabled on your server.', 'formidable');
123
+ self::form($errors);
124
+ return;
125
+ }
126
+
127
+ include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
128
+
129
+ $set_err = libxml_use_internal_errors(true);
130
+ $loader = libxml_disable_entity_loader( true );
131
+
132
+ $result = FrmXMLHelper::import_xml($file);
133
+ if ( is_wp_error($result) ) {
134
+ $errors[] = $result->get_error_message();
135
+ } else if ( $result ) {
136
+ if ( is_array($result) ) {
137
+ $t_strings = array(
138
+ 'imported' => __('Imported', 'formidable'),
139
+ 'updated' => __('Updated', 'formidable'),
140
+ );
141
+
142
+ $message = '<ul>';
143
+ foreach ( $result as $type => $results ) {
144
+ if ( !isset($t_strings[$type]) ) {
145
+ // only print imported and updated
146
+ continue;
147
+ }
148
+
149
+ $s_message = array();
150
+ foreach ( $results as $k => $m ) {
151
+ if ( $m ) {
152
+ $strings = array(
153
+ 'forms' => sprintf(_n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
154
+ 'fields' => sprintf(_n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m),
155
+ 'items' => sprintf(_n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m),
156
+ 'views' => sprintf(_n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m),
157
+ 'posts' => sprintf(_n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m),
158
+ 'terms' => sprintf(_n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m),
159
+ );
160
+
161
+ $s_message[] = isset($strings[$k]) ? $strings[$k] : $t_strings[$type] .' '. $m .' '. ucfirst($k);
162
+ }
163
+ unset($k);
164
+ unset($m);
165
+ }
166
+
167
+ if ( !empty($s_message) ) {
168
+ $message .= '<li><strong>'. $t_strings[$type] .':</strong> ';
169
+ $message .= implode(', ', $s_message);
170
+ $message .= '</li>';
171
+ }
172
+
173
+ }
174
+
175
+ if ( $message == '<ul>' ) {
176
+ $message = '';
177
+ $errors[] = __('Nothing was imported or updated', 'formidable');
178
+ } else {
179
+ $message .= '</ul>';
180
+ }
181
+ } else {
182
+ $message = $result;
183
+ }
184
+ }
185
+
186
+ unset($file);
187
+
188
+ libxml_use_internal_errors( $set_err );
189
+ libxml_disable_entity_loader( $loader );
190
+ //}else{
191
+ // foreach ($media_id->errors as $error)
192
+ // echo $error[0];
193
+ //}
194
+
195
  self::form($errors, $message);
196
  }
197
+
198
  public static function export_xml() {
199
+ if ( !current_user_can('frm_edit_forms') ) {
200
+ global $frm_settings;
201
+ echo $frm_settings->admin_permission;
202
+ die();
203
  }
204
+
205
+ if (isset($_POST['frm_export_forms'])) {
 
206
  $ids = $_POST['frm_export_forms'];
207
+ } else {
208
+ $ids = array();
209
  }
210
+
211
+ if ( isset($_POST['type']) ){
 
212
  $type = $_POST['type'];
213
  }
214
+
215
  $format = isset($_POST['format']) ? $_POST['format'] : 'xml';
216
+
217
+ if ( !headers_sent() && (!isset($type) || !$type) ) {
218
  wp_redirect(admin_url('admin.php?page=formidable-import'));
219
  die();
220
  }
221
+
222
  if ( $format == 'xml' ) {
223
  self::generate_xml($type, compact('ids'));
224
  } else {
225
  do_action('frm_export_format_'. $format, compact('ids'));
226
  }
227
+
228
+ die();
229
  }
230
+
231
+ public static function export_xml_direct($controller = 'forms', $ids = false) {
232
+ if ( !current_user_can('frm_edit_forms') ) {
233
+ global $frm_settings;
234
+ wp_die($frm_settings->admin_permission);
235
+ }
236
+ $is_template = FrmAppHelper::get_param('is_template', false);
237
+ self::generate_xml($controller, compact('ids', 'is_template'));
238
+ die();
239
+ }
240
+
241
  public static function generate_xml($type, $args = array() ) {
242
  global $wpdb;
243
+
244
+ $type = (array)$type;
 
 
 
 
 
 
 
 
 
 
245
  $tables = array(
246
+ 'items' => $wpdb->prefix .'frm_items',
247
+ 'forms' => $wpdb->prefix .'frm_forms',
248
+ 'views' => $wpdb->posts
 
 
249
  );
250
+
251
+ $defaults = array('ids' => false);
252
  $args = wp_parse_args( $args, $defaults );
253
+
254
  $sitename = sanitize_key( get_bloginfo( 'name' ) );
255
+
256
+ if ( ! empty($sitename) ) $sitename .= '.';
 
 
257
  $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
258
 
259
  header( 'Content-Description: File Transfer' );
260
  header( 'Content-Disposition: attachment; filename=' . $filename );
261
  header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
262
+
263
  //make sure ids are numeric
264
+ if(is_array($args['ids']) && !empty($args['ids']))
265
+ $args['ids'] = implode(',', array_filter( $args['ids'], 'is_numeric' ));
266
+
 
267
  $records = array();
268
+
269
+ foreach($type as $tb_type){
270
+ $where = $join = '';
271
+ $table = $tables[$tb_type];
272
+
273
+ $select = "$table.id";
274
+
275
+ if($tb_type == 'forms'){
276
+ //add forms
277
+ $where = $wpdb->prepare( "$table.status != %s" , 'draft' );
278
+ if ( $args['ids'] )
279
+ $where .= " AND $table.id IN (". $args['ids'] .")";
280
+
281
+ } else if($tb_type == 'items') {
282
+ //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
283
+ if ( $args['ids'] ) {
284
+ $where = "$table.form_id IN (". $args['ids'] .")";
285
+ }
286
+ } else {
287
+ $select = "$table.ID";
288
+ $join = "INNER JOIN $wpdb->postmeta pm ON (pm.post_id=$table.ID)";
289
+ $where = "pm.meta_key='frm_form_id' AND pm.meta_value ";
290
+ if ( empty($args['ids']) ) {
291
+ $where .= "> 0";
292
+ } else {
293
+ $where .= "IN (". $args['ids'] .")";
294
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  }
296
 
297
+ if(!empty($where))
298
+ $where = "WHERE ". $where;
299
+
300
+ $records[$tb_type] = $wpdb->get_col( "SELECT $select FROM $table $join $where" );
301
  unset($tb_type);
302
  }
303
+
304
+ include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
305
 
306
+ $frm_field = new FrmField();
307
+
308
  echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
309
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
310
  }
311
+
312
+ function allow_mime($mimes) {
313
+ if ( !isset($mimes['csv']) ) {
314
  // allow csv files
315
  $mimes['csv'] = 'text/csv';
316
  }
317
+
318
+ if ( !isset($mimes['xml']) ) {
319
  // allow xml
320
  $mimes['xml'] = 'text/xml';
321
  }
322
 
323
  return $mimes;
324
  }
325
+
326
  }
classes/helpers/FrmAppHelper.php CHANGED
@@ -1,887 +1,277 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
-
6
- class FrmAppHelper {
7
- public static $db_version = 20; //version of the database we are moving to
8
- public static $pro_db_version = 27;
9
 
10
- /**
11
- * @since 2.0
12
- */
13
- public static $plug_version = '2.0rc9';
14
-
15
- /**
16
- * @since 1.07.02
17
- *
18
- * @param none
19
- * @return string The version of this plugin
20
- */
21
- public static function plugin_version() {
22
- return self::$plug_version;
23
- }
24
 
25
- public static function plugin_folder() {
26
- return basename(self::plugin_path());
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
-
29
- public static function plugin_path() {
30
  return dirname(dirname(dirname(__FILE__)));
31
  }
32
-
33
- public static function plugin_url( $url = '' ) {
34
  //prevously FRM_URL constant
35
- if ( empty($url) ) {
36
- $url = plugins_url('', self::plugin_folder() .'/formidable.php');
37
- }
38
-
39
- if ( is_ssl() && !preg_match('/^https:\/\/.*\..*$/', $url) ) {
40
  $url = str_replace('http://', 'https://', $url);
41
- }
42
-
43
  return $url;
44
  }
45
-
46
- /**
47
- * @return string Site URL
48
- */
49
- public static function site_url() {
50
  $url = self::plugin_url(site_url());
51
  return $url;
52
  }
53
-
54
- /**
55
- * Get the name of this site
56
- * Used for [sitename] shortcode
57
- *
58
- * @since 2.0
59
- * @return string
60
- */
61
- public static function site_name() {
62
- return get_option('blogname');
63
- }
64
-
65
- /**
66
- * Get the Formidable settings
67
- *
68
- * @since 2.0
69
- *
70
- * @param None
71
- * @return FrmSettings $frm_setings
72
- */
73
- public static function get_settings() {
74
- global $frm_settings;
75
- if ( empty($frm_settings) ) {
76
- $frm_settings = new FrmSettings();
77
- }
78
- return $frm_settings;
79
- }
80
-
81
- /**
82
- * Show a message in place of pro features
83
- *
84
- * @since 2.0
85
- */
86
- public static function update_message($features, $class = '') {
87
- return; // hide the upgrade messages for now
88
- if ( ! self::pro_is_installed() ) {
89
- include(self::plugin_path() .'/classes/views/shared/update_message.php');
90
- }
91
- }
92
-
93
- public static function pro_is_installed() {
94
- return apply_filters('frm_pro_installed', false);
95
- }
96
-
97
- /**
98
- * Check for certain page in Formidable settings
99
- *
100
- * @since 2.0
101
- *
102
- * @param string $page The name of the page to check
103
- * @return boolean
104
- */
105
- public static function is_admin_page($page = 'formidable' ) {
106
- global $pagenow;
107
- if ( $pagenow ) {
108
- return $pagenow == 'admin.php' && $_GET['page'] == $page;
109
- }
110
-
111
- return is_admin() && isset($_GET['page']) && $_GET['page'] == $page;
112
- }
113
-
114
- /**
115
- * Check for the form preview page
116
- *
117
- * @since 2.0
118
- *
119
- * @param None
120
- * @return boolean
121
- */
122
- public static function is_preview_page() {
123
- global $pagenow;
124
- return $pagenow && $pagenow == 'admin-ajax.php' && isset($_GET['action']) && $_GET['action'] == 'frm_forms_preview';
125
- }
126
-
127
- /**
128
- * Check for ajax except the form preview page
129
- *
130
- * @since 2.0
131
- *
132
- * @param None
133
- * @return boolean
134
- */
135
- public static function doing_ajax() {
136
- return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
137
- }
138
-
139
- /**
140
- * Check if on an admin page
141
- *
142
- * @since 2.0
143
- *
144
- * @param None
145
- * @return boolean
146
- */
147
- public static function is_admin() {
148
- return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
149
- }
150
-
151
- /**
152
- * Check if value contains blank value or empty array
153
- *
154
- * @since 2.0
155
- * @param $value - value to check
156
- * @return boolean
157
- */
158
- public static function is_empty_value( $value, $empty = '' ) {
159
- return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
160
- }
161
-
162
- /**
163
- * Get any value from the $_SERVER
164
- *
165
- * @since 2.0
166
- * @param string $value
167
- * @return string
168
- */
169
- public static function get_server_value($value) {
170
- return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
171
- }
172
-
173
- /**
174
- * Check for the IP address in several places
175
- * Used by [ip] shortcode
176
- *
177
- * @return string The IP address of the current user
178
- */
179
- public static function get_ip_address() {
180
- $ip = '';
181
- foreach ( array(
182
- 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
183
- 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
184
- ) as $key ) {
185
- if ( ! isset( $_SERVER[ $key ] ) ) {
186
- continue;
187
- }
188
-
189
- foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
190
- $ip = trim($ip); // just to be safe
191
-
192
- if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
193
- return $ip;
194
- }
195
- }
196
- }
197
-
198
- return sanitize_text_field( $ip );
199
- }
200
-
201
- public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
202
- if ( strpos($param, '[') ) {
203
  $params = explode('[', $param);
204
- $param = $params[0];
205
  }
206
 
207
- if ( $src == 'get' ) {
208
- $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
209
- if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
210
- $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
211
- }
212
- } else {
213
- $value = self::get_post_param( $param, $default, $sanitize );
214
  }
215
-
216
- if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
217
- foreach ( $params as $k => $p ) {
218
- if ( ! $k || ! is_array($value) ) {
219
  continue;
220
- }
221
-
222
  $p = trim($p, ']');
223
- $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
224
  }
225
  }
226
 
227
  return $value;
228
  }
229
-
230
- public static function get_post_param( $param, $default = '', $sanitize = '' ) {
231
- $val = $default;
232
- if ( isset( $_POST[ $param ] ) ) {
233
- $val = stripslashes_deep( maybe_unserialize( $_POST[ $param ] ) );
234
- if ( ! empty( $sanitize ) ) {
235
- $val = call_user_func( $sanitize, $val );
236
- }
237
- }
238
- return $val;
239
- }
240
-
241
- /**
242
- * @since 2.0
243
- * @param string $action
244
- */
245
- public static function simple_get( $action, $sanitize = 'sanitize_text_field' ) {
246
- $val = '';
247
- if ( $_GET && isset( $_GET[ $action ] ) ) {
248
- $val = call_user_func( $sanitize, $_GET[ $action ] );
249
- }
250
- return $val;
251
- }
252
-
253
- public static function sanitize_request( $sanitize_method, &$values ) {
254
- $temp_values = $values;
255
- foreach ( $temp_values as $k => $val ) {
256
- if ( isset( $sanitize_method[ $k ] ) ) {
257
- call_user_func( $sanitize_method[ $k ], $val );
258
- }
259
- }
260
  }
261
-
262
- /**
263
- * Used when switching the action for a bulk action
264
- * @since 2.0
265
- */
266
- public static function remove_get_action() {
267
- if ( ! isset($_GET) ) {
268
- return;
269
- }
270
-
271
- $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
272
- if ( ! empty( $new_action ) ) {
273
- $_SERVER['REQUEST_URI'] = str_replace( '&action='. $new_action, '', $_SERVER['REQUEST_URI'] );
274
- }
275
- }
276
-
277
- /**
278
- * Check the WP query for a parameter
279
- *
280
- * @since 2.0
281
- * @return string|array
282
- */
283
- public static function get_query_var( $value, $param ) {
284
- if ( $value != '' ) {
285
- return $value;
286
- }
287
-
288
- global $wp_query;
289
- if ( isset( $wp_query->query_vars[ $param ] ) ) {
290
- $value = $wp_query->query_vars[ $param ];
291
- }
292
-
293
- return $value;
294
- }
295
-
296
- /**
297
- * @param string $type
298
- */
299
- public static function trigger_hook_load( $type, $object = null ) {
300
- // only load the form hooks once
301
- $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object);
302
- if ( ! $hooks_loaded ) {
303
- do_action('frm_load_'. $type .'_hooks');
304
- }
305
- }
306
-
307
- /**
308
- * Check cache before fetching values and saving to cache
309
- *
310
- * @since 2.0
311
- *
312
- * @param string $cache_key The unique name for this cache
313
- * @param string $group The name of the cache group
314
- * @param string $query If blank, don't run a db call
315
- * @param string $type The wpdb function to use with this query
316
- * @return mixed $results The cache or query results
317
- */
318
- public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
319
- $results = wp_cache_get($cache_key, $group);
320
- if ( ! self::is_empty_value( $results, false ) || empty($query) ) {
321
- return $results;
322
- }
323
-
324
- if ( 'get_posts' == $type ) {
325
- $results = get_posts($query);
326
- } else {
327
- global $wpdb;
328
- $results = $wpdb->{$type}($query);
329
- }
330
-
331
- wp_cache_set($cache_key, $results, $group, $time);
332
-
333
- return $results;
334
- }
335
-
336
- /**
337
- * Data that should be stored for a long time can be stored in a transient.
338
- * First check the cache, then check the transient
339
- * @since 2.0
340
- * @return mixed The cached value or false
341
- */
342
- public static function check_cache_and_transient($cache_key) {
343
- // check caching layer first
344
- $results = self::check_cache( $cache_key );
345
- if ( $results ) {
346
- return $results;
347
- }
348
-
349
- // then check the transient
350
- $results = get_transient($cache_key);
351
- if ( $results ) {
352
- wp_cache_set($cache_key, $results);
353
- }
354
-
355
- return $results;
356
- }
357
-
358
- /**
359
- * @since 2.0
360
- * @param string $cache_key
361
- */
362
- public static function delete_cache_and_transient($cache_key) {
363
- delete_transient($cache_key);
364
- wp_cache_delete($cache_key);
365
- }
366
-
367
- /**
368
- * Delete all caching in a single group
369
- *
370
- * @since 2.0
371
- *
372
- * @param string $group The name of the cache group
373
- * @return boolean True or False
374
- */
375
- public static function cache_delete_group($group) {
376
- global $wp_object_cache;
377
-
378
- if ( isset( $wp_object_cache->cache[ $group ] ) ) {
379
- foreach ( $wp_object_cache->cache[ $group ] as $k => $v ) {
380
- wp_cache_delete($k, $group);
381
- }
382
- return true;
383
- }
384
-
385
- return false;
386
- }
387
-
388
- /**
389
- * Check a value from a shortcode to see if true or false.
390
- * True when value is 1, true, 'true', 'yes'
391
- *
392
- * @since 1.07.10
393
- *
394
- * @param string $value The value to compare
395
- * @return boolean True or False
396
- */
397
  public static function is_true($value) {
398
  return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
399
  }
400
-
401
- /**
402
- * Used to filter shortcode in text widgets
403
- */
404
- public static function widget_text_filter_callback( $matches ) {
405
- return do_shortcode( $matches[0] );
406
- }
407
-
408
- public static function load_scripts($scripts) {
409
- _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_script' );
410
  foreach ( (array) $scripts as $s ) {
411
  wp_enqueue_script($s);
412
  }
413
  }
414
-
415
- public static function load_styles($styles) {
416
- _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_style' );
417
  foreach ( (array) $styles as $s ) {
418
  wp_enqueue_style($s);
419
  }
420
  }
421
-
422
- public static function get_pages() {
423
- return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => 999, 'orderby' => 'title', 'order' => 'ASC' ) );
424
  }
425
-
426
- public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
427
- $pages = self::get_pages();
428
  ?>
429
- <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
430
- <option value=""> </option>
431
- <?php foreach ( $pages as $page ) { ?>
432
- <option value="<?php echo esc_attr($page->ID); ?>" <?php
433
- echo ( ( ( isset( $_POST[ $field_name ] ) && $_POST[ $field_name ] == $page->ID ) || ( ! isset( $_POST[ $field_name ] ) && $page_id == $page->ID ) ) ? ' selected="selected"' : '' );
434
- ?>><?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?> </option>
435
  <?php } ?>
436
  </select>
437
  <?php
438
  }
439
-
440
- public static function post_edit_link($post_id) {
441
- $post = get_post($post_id);
442
- if ( $post ) {
443
- return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. self::truncate($post->post_title, 50) .'</a>';
444
- }
445
- return '';
446
- }
447
-
448
- public static function wp_roles_dropdown($field_name, $capability, $multiple = 'single') {
449
- $capability = (array) self::get_param($field_name, $capability, 'post');
450
 
451
  ?>
452
- <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
453
- echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
454
- ?> class="frm_multiselect">
455
- <?php self::roles_options($capability); ?>
 
 
 
 
456
  </select>
457
  <?php
458
  }
459
-
460
- public static function roles_options($capability) {
461
  global $frm_vars;
462
- if ( isset($frm_vars['editable_roles']) ) {
463
- $editable_roles = $frm_vars['editable_roles'];
464
- } else {
465
- $editable_roles = get_editable_roles();
466
- $frm_vars['editable_roles'] = $editable_roles;
467
- }
468
-
469
- foreach ( $editable_roles as $role => $details ) {
470
- $name = translate_user_role($details['name'] ); ?>
471
- <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option>
472
- <?php
473
- unset($role, $details);
474
- }
475
- }
476
-
477
- public static function frm_capabilities($type = 'auto') {
478
  $cap = array(
479
- 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ),
480
- 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ),
481
- 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ),
482
- 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
483
- 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ),
484
- 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ),
485
  );
486
-
487
- if ( ! self::pro_is_installed() && 'pro' != $type) {
488
- return $cap;
 
 
 
 
489
  }
490
-
491
- $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
492
- $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
493
- $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
494
- $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
495
-
496
  return $cap;
497
  }
498
-
499
- public static function user_has_permission($needed_role) {
500
- if ( $needed_role == '-1' ) {
501
  return false;
502
- }
503
-
504
- // $needed_role will be equal to blank if "Logged-in users" is selected
505
- if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
506
  return true;
507
- }
508
-
509
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
510
- foreach ( $roles as $role ) {
511
- if ( current_user_can( $role ) ) {
512
  return true;
513
- }
514
- if ( $role == $needed_role ) {
515
  break;
516
- }
517
  }
518
  return false;
519
  }
520
-
521
- /**
522
- * Make sure administrators can see Formidable menu
523
- *
524
- * @since 2.0
525
- */
526
- public static function maybe_add_permissions() {
527
- if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
528
- return;
529
- }
530
-
531
- $user_id = get_current_user_id();
532
- $user = new WP_User( $user_id );
533
- $frm_roles = self::frm_capabilities();
534
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
535
- $user->add_cap( $frm_role );
536
- unset($frm_role, $frm_role_description);
537
- }
538
- }
539
-
540
- /**
541
- * Check if the user has permision for action.
542
- * Return permission message and stop the action if no permission
543
- * @since 2.0
544
- * @param string $permission
545
- */
546
- public static function permission_check($permission, $show_message = 'show') {
547
- $permission_error = self::permission_nonce_error($permission);
548
- if ( $permission_error !== false ) {
549
- if ( 'hide' == $show_message ) {
550
- $permission_error = '';
551
- }
552
- wp_die($permission_error);
553
- }
554
- }
555
-
556
- /**
557
- * Check user permission and nonce
558
- * @since 2.0
559
- * @param string $permission
560
- * @return false|string The permission message or false if allowed
561
- */
562
- public static function permission_nonce_error($permission, $nonce_name = '', $nonce = '') {
563
- if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
564
- $frm_settings = self::get_settings();
565
- return $frm_settings->admin_permission;
566
- }
567
-
568
- $error = false;
569
- if ( empty($nonce_name) ) {
570
- return $error;
571
- }
572
-
573
- if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
574
- $frm_settings = self::get_settings();
575
- $error = $frm_settings->admin_permission;
576
- }
577
-
578
- return $error;
579
- }
580
-
581
- public static function checked( $values, $current ) {
582
- if ( self::check_selected( $values, $current ) ) {
583
  echo ' checked="checked"';
584
- }
585
  }
586
-
587
- public static function check_selected($values, $current) {
588
- self::recursive_trim($values);
 
 
 
 
 
 
589
  $current = trim($current);
590
-
591
- return ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current );
592
- }
593
-
594
- /**
595
- * Check if current field option is an "other" option
596
- *
597
- * @since 2.0
598
- *
599
- * @param string $opt_key
600
- * @return boolean Returns true if current field option is an "Other" option
601
- */
602
- public static function is_other_opt( $opt_key ) {
603
- return $opt_key && strpos( $opt_key, 'other' ) !== false;
604
- }
605
-
606
- /**
607
- * Get value that belongs in "Other" text box
608
- *
609
- * @since 2.0
610
- *
611
- * @param string $opt_key
612
- * @param array $field
613
- * @return string $other_val
614
- */
615
- public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
616
- $other_val = '';
617
-
618
- //If option is an "other" option and there is a value set for this field, check if the value belongs in the current "Other" option text field
619
- if ( ! self::is_other_opt( $opt_key ) || ! isset( $field['value'] ) || ! $field['value'] ) {
620
- return $other_val;
621
- }
622
-
623
- // Check posted vals before checking saved values
624
-
625
- // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
626
- if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
627
- if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
628
- $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] : '';
629
- } else {
630
- $other_val = $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ];
631
- }
632
- return $other_val;
633
-
634
- } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
635
- // For normal fields
636
-
637
- if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
638
- $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] : '';
639
- } else {
640
- $other_val = $_POST['item_meta']['other'][ $field['id'] ];
641
- }
642
- return $other_val;
643
- }
644
-
645
- // For checkboxes
646
- if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
647
- // Check if there is an "other" val in saved value and make sure the "other" val is not equal to the Other checkbox option
648
- if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
649
- $other_val = $field['value'][ $opt_key ];
650
- }
651
- } else {
652
- /**
653
- * For radio buttons and dropdowns
654
- * Check if saved value equals any of the options. If not, set it as the other value.
655
- */
656
- foreach ( $field['options'] as $opt_key => $opt_val ) {
657
- $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
658
- // Multi-select dropdowns - key is not preserved
659
- if ( is_array( $field['value'] ) ) {
660
- $o_key = array_search( $temp_val, $field['value'] );
661
- if ( isset( $field['value'][ $o_key ] ) ) {
662
- unset( $field['value'][ $o_key ], $o_key );
663
- }
664
- } else if ( $temp_val == $field['value'] ) {
665
- // For radio and regular dropdowns
666
- return '';
667
- } else {
668
- $other_val = $field['value'];
669
- }
670
- unset($opt_key, $opt_val, $temp_val);
671
- }
672
- // For multi-select dropdowns only
673
- if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
674
- $other_val = reset( $field['value'] );
675
- }
676
- }
677
- return $other_val;
678
- }
679
-
680
- /**
681
- * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
682
- * Intended for front-end use
683
- *
684
- * @since 2.0
685
- *
686
- * @param array $field
687
- * @param boolean $other_opt
688
- * @param string $checked
689
- * @param array $args should include opt_key and field name
690
- * @return string $other_val
691
- */
692
- public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
693
- //Check if this is an "Other" option
694
- if ( !self::is_other_opt( $args['opt_key'] ) ) {
695
- return;
696
- }
697
-
698
- $other_opt = true;
699
- $other_args = array();
700
- $parent = $pointer = '';
701
-
702
- // Check for parent ID and pointer
703
- $temp_array = explode( '[', $args['field_name'] );
704
- // Count should only be greater than 3 if inside of a repeating section
705
- if ( count( $temp_array ) > 3 ) {
706
- $parent = str_replace( ']', '', $temp_array[1] );
707
- $pointer = str_replace( ']', '', $temp_array[2]);
708
- }
709
- unset( $temp_array );
710
-
711
- //Set up name for other field
712
- $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
713
- $other_args['name'] = preg_replace('/\[' . $field['id'] . '\]$/', '', $other_args['name']);
714
- $other_args['name'] = $other_args['name'] . '[other]' . '[' . $field['id'] . ']';
715
- //Converts item_meta[field_id] => item_meta[other][field_id] and
716
- //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
717
- if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
718
- $other_args['name'] .= '[' . $args['opt_key'] . ']';
719
- }
720
-
721
- // Get text for "other" text field
722
- $other_args['value'] = self::get_other_val( $args['opt_key'], $field, $parent, $pointer );
723
-
724
- if ( $other_args['value'] ) {
725
- $checked = 'checked="checked" ';
726
- }
727
-
728
- return $other_args;
729
  }
730
-
731
  public static function recursive_trim(&$value) {
732
- if ( is_array($value) ) {
733
- $value = array_map( array( 'FrmAppHelper', 'recursive_trim' ), $value);
734
- } else {
735
  $value = trim($value);
736
- }
737
-
738
  return $value;
739
  }
740
-
741
- /**
742
- * Flatten a multi-dimensional array
743
- */
744
- public static function array_flatten( $array ) {
745
- $return = array();
746
- foreach ( $array as $key => $value ) {
747
- if ( is_array($value) ) {
748
- $return = array_merge( $return, self::array_flatten($value) );
749
- } else {
750
- $return[ $key ] = $value;
751
- }
752
- }
753
- return $return;
754
- }
755
-
756
  public static function esc_textarea( $text ) {
757
  $safe_text = str_replace('&quot;', '"', $text);
758
  $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
759
  return apply_filters( 'esc_textarea', $safe_text, $text );
760
  }
761
-
762
- /**
763
- * Add auto paragraphs to text areas
764
- * @since 2.0
765
- */
766
- public static function use_wpautop($content) {
767
- if ( apply_filters('frm_use_wpautop', true) ) {
768
- $content = wpautop(str_replace( '<br>', '<br />', $content));
769
- }
770
- return $content;
771
- }
772
-
773
- public static function replace_quotes($val) {
774
- //Replace double quotes
775
- $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;'), '"', $val);
776
- //Replace single quotes
777
- $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
778
  return $val;
779
  }
780
-
781
- /**
782
- * @since 2.0
783
- * @return string The base Google APIS url for the current version of jQuery UI
784
- */
785
- public static function jquery_ui_base_url() {
786
- $url = 'http'. ( is_ssl() ? 's' : '' ) .'://ajax.googleapis.com/ajax/libs/jqueryui/'. self::script_version('jquery-ui-core');
787
- $url = apply_filters('frm_jquery_ui_base_url', $url);
788
- return $url;
789
- }
790
-
791
- /**
792
- * @param string $handle
793
- */
794
- public static function script_version($handle) {
795
  global $wp_scripts;
796
- if ( ! $wp_scripts ) {
797
  return false;
798
- }
799
-
800
  $ver = 0;
801
-
802
- if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
803
- return $ver;
804
- }
805
-
806
- $query = $wp_scripts->registered[ $handle ];
807
- if ( is_object( $query ) ) {
808
  $ver = $query->ver;
809
- }
810
 
811
  return $ver;
812
  }
813
-
814
- public static function js_redirect($url) {
815
- return '<script type="text/javascript">window.location="' . $url . '"</script>';
816
  }
817
-
818
- public static function get_user_id_param($user_id) {
819
- if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
820
- return $user_id;
 
 
 
 
821
  }
822
-
823
- if ( $user_id == 'current' ) {
824
- $user_ID = get_current_user_id();
825
- $user_id = $user_ID;
826
- } else {
827
- if ( is_email($user_id) ) {
828
- $user = get_user_by('email', $user_id);
829
- } else {
830
- $user = get_user_by('login', $user_id);
831
- }
832
-
833
- if ( $user ) {
834
- $user_id = $user->ID;
835
- }
836
- unset($user);
837
- }
838
-
839
- return $user_id;
840
- }
841
-
842
- public static function get_file_contents($filename, $atts = array()) {
843
- if ( ! is_file($filename) ) {
844
- return false;
845
- }
846
-
847
- extract($atts);
848
- ob_start();
849
- include($filename);
850
- $contents = ob_get_contents();
851
- ob_end_clean();
852
- return $contents;
853
  }
854
-
855
- /**
856
- * @param string $table_name
857
- * @param string $column
858
- */
859
- public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 6 ) {
860
  global $wpdb;
861
 
862
  $key = '';
863
-
864
- if ( ! empty( $name ) ) {
865
  $key = sanitize_key($name);
866
  }
867
-
868
- if ( empty( $key ) ) {
869
  $max_slug_value = pow(36, $num_chars);
870
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
871
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
872
  }
873
 
874
- if ( is_numeric($key) || in_array($key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')) ) {
875
  $key = $key .'a';
876
- }
877
-
878
- $key_check = FrmDb::get_var( $table_name, array($column => $key, 'ID !' => $id), $column );
879
-
880
- if ( $key_check || is_numeric($key_check) ) {
881
  $suffix = 2;
882
  do {
883
- $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
884
- $key_check = FrmDb::get_var( $table_name, array($column => $alt_post_name, 'ID !' => $id), $column );
885
  $suffix++;
886
  } while ($key_check || is_numeric($key_check));
887
  $key = $alt_post_name;
@@ -889,806 +279,545 @@ class FrmAppHelper {
889
  return $key;
890
  }
891
 
892
- /**
893
- * Editing a Form or Entry
894
- * @param string $table
895
- * @return bool|array
896
- */
897
- public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array() ) {
898
- if ( ! $record ) {
899
- return false;
900
- }
901
-
902
- global $frm_vars;
903
-
904
- if ( empty($post_values) ) {
905
  $post_values = stripslashes_deep($_POST);
906
- }
 
907
 
908
- $values = array( 'id' => $record->id, 'fields' => array());
909
-
910
- foreach ( array( 'name', 'description') as $var ) {
911
  $default_val = isset($record->{$var}) ? $record->{$var} : '';
912
- $values[ $var ] = self::get_param( $var, $default_val );
913
  unset($var, $default_val);
914
  }
915
-
916
- $values['description'] = self::use_wpautop($values['description']);
917
- $frm_settings = self::get_settings();
918
- $is_form_builder = self::is_admin_page('formidable' );
919
-
920
- foreach ( (array) $fields as $field ) {
921
- // Make sure to filter default values (for placeholder text), but not on the form builder page
922
- if ( ! $is_form_builder ) {
923
- $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
924
- }
925
- self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
926
- }
927
-
928
- self::fill_form_opts($record, $table, $post_values, $values);
929
-
930
- if ( $table == 'entries' ) {
931
- $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
932
- } else if ( $table == 'forms' ) {
933
- $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
934
  }
 
 
935
 
936
- return $values;
937
- }
938
-
939
- private static function fill_field_defaults($field, $record, array &$values, $args) {
940
- $post_values = $args['post_values'];
941
-
942
- if ( $args['default'] ) {
943
- $meta_value = $field->default_value;
944
- } else {
945
- if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
946
- if ( ! isset($field->field_options['custom_field']) ) {
947
- $field->field_options['custom_field'] = '';
948
  }
949
- $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
950
- } else {
951
- $meta_value = self::get_meta_value($field->id, $record);
952
- }
953
- }
954
-
955
- $field_type = isset( $post_values['field_options'][ 'type_'. $field->id ] ) ? $post_values['field_options'][ 'type_'. $field->id ] : $field->type;
956
- $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
957
-
958
- $field_array = array(
959
- 'id' => $field->id,
960
- 'value' => $new_value,
961
- 'default_value' => $field->default_value,
962
- 'name' => $field->name,
963
- 'description' => $field->description,
964
- 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
965
- 'options' => $field->options,
966
- 'required' => $field->required,
967
- 'field_key' => $field->field_key,
968
- 'field_order' => $field->field_order,
969
- 'form_id' => $field->form_id,
970
- );
971
-
972
- $args['field_type'] = $field_type;
973
- self::fill_field_opts($field, $field_array, $args);
974
-
975
- $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
976
-
977
- if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
978
- $field_array['unique_msg'] = '';
979
- }
980
-
981
- $field_array = array_merge( $field->field_options, $field_array );
982
-
983
- $values['fields'][ $field->id ] = $field_array;
984
- }
985
-
986
- private static function fill_field_opts($field, array &$field_array, $args) {
987
- $post_values = $args['post_values'];
988
- $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
989
-
990
- foreach ( $opt_defaults as $opt => $default_opt ) {
991
- $field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'] [ $opt .'_'. $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt .'_'. $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt );
992
- if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
993
- $field_array[ $opt ] = $args['frm_settings']->blank_msg;
994
- } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
995
- if ( $args['field_type'] == 'captcha' ) {
996
- $field_array[ $opt ] = $args['frm_settings']->re_msg;
997
- } else {
998
- $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
999
  }
1000
  }
1001
  }
1002
-
1003
- if ( $field_array['custom_html'] == '' ) {
1004
- $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1005
- }
1006
-
1007
- $field_array['size'] = self::get_field_size($field_array);
1008
- }
1009
-
1010
- /**
1011
- * @param string $table
1012
- */
1013
- private static function fill_form_opts($record, $table, $post_values, array &$values) {
1014
- if ( $table == 'entries' ) {
1015
- $form = $record->form_id;
1016
- FrmFormsHelper::maybe_get_form( $form );
1017
- } else {
1018
- $form = $record;
1019
- }
1020
-
1021
- if ( ! $form ) {
1022
- return;
1023
- }
1024
-
1025
- $values['form_name'] = isset($record->form_id) ? $form->name : '';
1026
- if ( ! is_array($form->options) ) {
1027
- return;
1028
- }
1029
-
1030
- foreach ( $form->options as $opt => $value ) {
1031
- $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1032
- }
1033
-
1034
- self::fill_form_defaults($post_values, $values);
1035
- }
1036
-
1037
- /**
1038
- * Set to POST value or default
1039
- */
1040
- private static function fill_form_defaults($post_values, array &$values) {
1041
  $form_defaults = FrmFormsHelper::get_default_opts();
1042
-
1043
- foreach ( $form_defaults as $opt => $default ) {
1044
- if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1045
- if ( $opt == 'notification' ) {
1046
- $values[ $opt ] = ( $post_values && isset( $post_values[ $opt ] ) ) ? $post_values[ $opt ] : $default;
1047
-
1048
- foreach ( $default as $o => $d ) {
1049
- if ( $o == 'email_to' ) {
 
1050
  $d = ''; //allow blank email address
1051
- }
1052
- $values[ $opt ][0][ $o ] = ( $post_values && isset( $post_values[ $opt ][0][ $o ]) ) ? $post_values[ $opt ][0][ $o ] : $d;
1053
- unset($o, $d);
1054
  }
1055
- } else {
1056
- $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1057
- }
1058
- } else if ( $values[ $opt ] == 'notification' ) {
1059
- foreach ( $values[ $opt ] as $k => $n ) {
1060
- foreach ( $default as $o => $d ) {
1061
- if ( ! isset( $n[ $o ] ) ) {
1062
- $values[ $opt ][ $k ][ $o ] = ( $post_values && isset( $post_values[ $opt ][ $k ][ $o ] ) ) ? $post_values[ $opt ][ $k ][ $o ] : $d;
1063
- }
1064
- unset($o, $d);
1065
  }
1066
- unset($k, $n);
 
1067
  }
1068
  }
1069
-
1070
- unset($opt, $defaut);
1071
- }
1072
-
1073
- if ( ! isset($values['custom_style']) ) {
1074
- $frm_settings = self::get_settings();
1075
- $values['custom_style'] = ( $post_values && isset($post_values['options']['custom_style']) ) ? $_POST['options']['custom_style'] : ( $frm_settings->load_style != 'none' );
1076
  }
 
 
 
1077
 
1078
- foreach ( array( 'before', 'after', 'submit') as $h ) {
1079
- if ( ! isset( $values[ $h .'_html' ] ) ) {
1080
- $values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) );
1081
- }
1082
  unset($h);
1083
  }
1084
- }
1085
-
1086
- /**
1087
- * @return string
1088
- */
1089
- public static function get_meta_value($field_id, $entry) {
1090
- if ( isset($entry->metas) ) {
1091
- return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false;
1092
- } else {
1093
- return FrmEntryMeta::get_entry_meta_by_field($entry->id, $field_id);
1094
- }
1095
- }
1096
 
1097
- /**
1098
- * @since 2.0
1099
- * @return string
1100
- */
1101
- public static function get_field_size($field) {
1102
- if ( '' == $field['size'] ) {
1103
- global $frm_vars;
1104
- $field['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
1105
- }
1106
- return $field['size'];
1107
  }
1108
-
1109
- public static function insert_opt_html($args) {
 
 
1110
  $class = '';
1111
- if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
 
1112
  $class .= 'show_frm_not_email_to';
1113
  }
1114
  ?>
1115
  <li>
1116
- <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a>
1117
- <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a>
1118
- <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a>
1119
  </li>
1120
  <?php
1121
  }
1122
-
1123
- public static function get_us_states() {
1124
- _deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_us_states' );
1125
- return FrmFieldsHelper::get_us_states();
1126
- }
1127
-
1128
- public static function get_countries() {
1129
- _deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_countries' );
1130
- return FrmFieldsHelper::get_countries();
1131
- }
1132
-
1133
- public static function truncate($str, $length, $minword = 3, $continue = '...') {
1134
- if ( is_array( $str ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1135
  return;
1136
- }
1137
-
1138
- $length = (int) $length;
1139
- $str = wp_strip_all_tags( $str );
1140
  $original_len = (function_exists('mb_strlen')) ? mb_strlen($str) : strlen($str);
1141
-
1142
- if ( $length == 0 ) {
1143
  return '';
1144
- } else if ( $length <= 10 ) {
1145
- $sub = function_exists( 'mb_substr' ) ? mb_substr( $str, 0, $length ) : substr( $str, 0, $length );
1146
  return $sub . (($length < $original_len) ? $continue : '');
1147
  }
1148
-
1149
  $sub = '';
1150
  $len = 0;
1151
 
1152
  $words = (function_exists('mb_split')) ? mb_split(' ', $str) : explode(' ', $str);
1153
-
1154
- foreach ( $words as $word ) {
1155
  $part = (($sub != '') ? ' ' : '') . $word;
1156
  $total_len = (function_exists('mb_strlen')) ? mb_strlen($sub . $part) : strlen($sub. $part);
1157
  if ( $total_len > $length && str_word_count($sub) ) {
1158
  break;
1159
  }
1160
-
1161
  $sub .= $part;
1162
  $len += (function_exists('mb_strlen')) ? mb_strlen($part) : strlen($part);
1163
-
1164
  if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1165
  break;
1166
  }
1167
-
1168
  unset($total_len, $word);
1169
  }
1170
-
1171
  return $sub . (($len < $original_len) ? $continue : '');
1172
  }
1173
-
1174
- public static function get_formatted_time($date, $date_format = '', $time_format = '' ) {
1175
- if ( empty($date) ) {
1176
- return $date;
1177
- }
1178
-
1179
- if ( empty($date_format) ) {
1180
- $date_format = get_option('date_format');
1181
- }
1182
-
1183
- if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1184
- $frmpro_settings = new FrmProSettings();
1185
- $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1186
- }
1187
-
1188
- $do_time = ( date('H:i:s', strtotime($date)) == '00:00:00' ) ? false : true;
1189
-
1190
- $date = get_date_from_gmt($date);
1191
-
1192
- $formatted = date_i18n($date_format, strtotime($date));
1193
-
1194
- if ( $do_time ) {
1195
-
1196
- if ( empty($time_format) ) {
1197
- $time_format = get_option('time_format');
1198
- }
1199
-
1200
- $trimmed_format = trim($time_format);
1201
- if ( $time_format && ! empty($trimmed_format) ) {
1202
- $formatted .= ' '. __( 'at', 'formidable' ) .' '. date_i18n($time_format, strtotime($date));
1203
- }
1204
- }
1205
-
1206
- return $formatted;
1207
- }
1208
-
1209
- /**
1210
- * @return string The time ago in words
1211
- */
1212
- public static function human_time_diff( $from, $to = '' ) {
1213
- if ( empty($to) ) {
1214
- $to = time();
1215
- }
1216
-
1217
- // Array of time period chunks
1218
- $chunks = array(
1219
- array( 60 * 60 * 24 * 365, __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
1220
- array( 60 * 60 * 24 * 30, __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
1221
- array( 60 * 60 * 24 * 7, __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
1222
- array( 60 * 60 * 24, __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
1223
- array( 60 * 60, __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
1224
- array( 60, __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
1225
- array( 1, __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ),
1226
- );
1227
-
1228
- // Difference in seconds
1229
- $diff = (int) ($to - $from);
1230
-
1231
- // Something went wrong with date calculation and we ended up with a negative date.
1232
- if ( $diff < 1) {
1233
- return '0 ' . __( 'seconds', 'formidable' );
1234
- }
1235
-
1236
- /**
1237
- * We only want to output one chunks of time here, eg:
1238
- * x years
1239
- * xx months
1240
- * so there's only one bit of calculation below:
1241
- */
1242
-
1243
- $count = 0;
1244
-
1245
- //Step one: the first chunk
1246
- for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
1247
- $seconds = $chunks[ $i ][0];
1248
-
1249
- // Finding the biggest chunk (if the chunk fits, break)
1250
- if ( ( $count = floor($diff / $seconds) ) != 0 ) {
1251
- break;
1252
- }
1253
- }
1254
-
1255
- // Set output var
1256
- $output = ( 1 == $count ) ? '1 '. $chunks[ $i ][1] : $count . ' ' . $chunks[ $i ][2];
1257
-
1258
- if ( ! (int) trim( $output ) ) {
1259
- $output = '0 ' . __( 'seconds', 'formidable' );
1260
- }
1261
-
1262
- return $output;
1263
- }
1264
-
1265
- /**
1266
- * Added for < WP 4.0 compatability
1267
- *
1268
- * @since 1.07.10
1269
- *
1270
- * @param string $term The value to escape
1271
- * @return string The escaped value
1272
- */
1273
  public static function esc_like($term) {
1274
  global $wpdb;
1275
- if ( method_exists($wpdb, 'esc_like') ) {
1276
- // WP 4.0
1277
  $term = $wpdb->esc_like( $term );
1278
  } else {
1279
  $term = like_escape( $term );
1280
  }
1281
-
1282
  return $term;
1283
  }
1284
-
1285
- /**
1286
- * @param string $order_query
1287
- */
1288
- public static function esc_order($order_query) {
1289
- if ( empty($order_query) ) {
1290
- return '';
1291
- }
1292
-
1293
- // remove ORDER BY before santizing
1294
- $order_query = strtolower($order_query);
1295
- if ( strpos($order_query, 'order by') !== false ) {
1296
- $order_query = str_replace('order by', '', $order_query);
1297
- }
1298
-
1299
- $order_query = explode(' ', trim($order_query));
1300
-
1301
- $order_fields = array(
1302
- 'id', 'form_key', 'name', 'description',
1303
- 'parent_form_id', 'logged_in', 'is_template',
1304
- 'default_template', 'status', 'created_at',
1305
- );
1306
-
1307
- $order = trim(trim(reset($order_query), ','));
1308
- if ( ! in_array($order, $order_fields) ) {
1309
- return '';
1310
- }
1311
-
1312
- $order_by = '';
1313
- if ( count($order_query) > 1 ) {
1314
- $order_by = end( $order_query );
1315
- self::esc_order_by( $order_by );
1316
- }
1317
-
1318
- return ' ORDER BY '. $order . ' '. $order_by;
1319
- }
1320
-
1321
- /**
1322
- * Make sure this is ordering by either ASC or DESC
1323
- */
1324
- public static function esc_order_by( &$order_by ) {
1325
- $sort_options = array( 'asc', 'desc' );
1326
- if ( ! in_array( strtolower( $order_by ), $sort_options ) ) {
1327
- $order_by = 'asc';
1328
- }
1329
- }
1330
-
1331
- /**
1332
- * @param string $limit
1333
- */
1334
- public static function esc_limit($limit) {
1335
- if ( empty($limit) ) {
1336
- return '';
1337
- }
1338
-
1339
- $limit = trim(str_replace(' limit', '', strtolower($limit)));
1340
- if ( is_numeric($limit) ) {
1341
- return ' LIMIT '. $limit;
1342
- }
1343
-
1344
- $limit = explode(',', trim($limit));
1345
- foreach ( $limit as $k => $l ) {
1346
- if ( is_numeric( $l ) ) {
1347
- $limit[ $k ] = $l;
1348
- }
1349
- }
1350
-
1351
- $limit = implode(',', $limit);
1352
- return ' LIMIT '. $limit;
1353
- }
1354
-
1355
- /**
1356
- * Get an array of values ready to go through $wpdb->prepare
1357
- * @since 2.0
1358
- */
1359
- public static function prepare_array_values( $array, $type = '%s' ) {
1360
- $placeholders = array_fill(0, count($array), $type);
1361
- return implode(', ', $placeholders);
1362
- }
1363
-
1364
- public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1365
  if ( empty($where) ) {
1366
  return '';
1367
  }
1368
-
1369
- if ( is_array( $where ) ) {
1370
- global $wpdb;
1371
- FrmDb::get_where_clause_and_values( $where, $starts_with );
1372
- $where = $wpdb->prepare( $where['where'], $where['values'] );
1373
- } else {
1374
  $where = $starts_with . $where;
1375
  }
1376
-
1377
  return $where;
1378
  }
1379
-
1380
  // Pagination Methods
1381
-
1382
- /**
1383
- * @param integer $current_p
1384
- */
1385
- public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1386
- return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1387
- }
1388
-
1389
- /**
1390
- * @param integer $current_p
1391
- */
1392
- public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1393
- if ( $current_p == 1 ) {
1394
- return 1;
1395
- } else {
1396
- return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1397
- }
1398
  }
1399
 
1400
- /**
1401
- * @param string $table_name
1402
- */
1403
- public static function &getRecordCount( $where = '', $table_name ) {
1404
- _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_count' );
1405
- $count = FrmDb::get_count( $table_name, $where );
1406
- return $count;
1407
  }
1408
-
1409
- public static function get_referer_info() {
1410
- _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::get_server_value' );
1411
- return self::get_server_value('HTTP_REFERER');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1412
  }
1413
-
1414
- /**
1415
- * @return array
1416
- */
1417
- public static function json_to_array( $json_vars ) {
1418
  $vars = array();
1419
- foreach ( $json_vars as $jv ) {
1420
  $jv_name = explode('[', $jv['name']);
1421
- $last = count($jv_name) - 1;
1422
- foreach ( $jv_name as $p => $n ) {
1423
  $name = trim($n, ']');
1424
- if ( ! isset($l1) ) {
 
 
1425
  $l1 = $name;
 
 
 
 
1426
  }
1427
-
1428
- if ( ! isset($l2) ) {
1429
  $l2 = $name;
 
 
 
 
1430
  }
1431
-
1432
- if ( ! isset($l3) ) {
1433
  $l3 = $name;
 
 
 
 
1434
  }
1435
-
1436
- $this_val = ( $p == $last ) ? $jv['value'] : array();
1437
-
1438
- switch ( $p ) {
1439
- case 0:
1440
- $l1 = $name;
1441
- self::add_value_to_array( $name, $l1, $this_val, $vars );
1442
- break;
1443
-
1444
- case 1:
1445
- $l2 = $name;
1446
- self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1447
- break;
1448
-
1449
- case 2:
1450
- $l3 = $name;
1451
- self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1452
- break;
1453
-
1454
- case 3:
1455
- $l4 = $name;
1456
- self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1457
- break;
1458
- }
1459
-
1460
- unset($this_val, $n);
1461
  }
1462
-
1463
- unset($last, $jv);
 
1464
  }
1465
-
1466
  return $vars;
1467
  }
1468
-
1469
- /**
1470
- * @param string $name
1471
- * @param string $l1
1472
- */
1473
- public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1474
- if ( $name == '' ) {
1475
- $vars[] = $val;
1476
- } else if ( ! isset( $vars[ $l1 ] ) ) {
1477
- $vars[ $l1 ] = $val;
1478
- }
1479
- }
1480
-
1481
- public static function maybe_add_tooltip($name, $class = 'closed', $form_name = '') {
1482
- $tooltips = array(
1483
- 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
1484
- 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
1485
- 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1486
- 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1487
- 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
1488
- 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
1489
- 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1490
- );
1491
-
1492
- if ( ! isset( $tooltips[ $name ] ) ) {
1493
- return;
1494
- }
1495
-
1496
- if ( 'open' == $class ) {
1497
- echo ' frm_help"';
1498
- } else {
1499
- echo ' class="frm_help"';
1500
- }
1501
-
1502
- echo ' title="'. esc_attr( $tooltips[ $name ] );
1503
-
1504
- if ( 'open' != $class ) {
1505
- echo '"';
1506
- }
1507
- }
1508
-
1509
- /**
1510
- * Add the current_page class to that page in the form nav
1511
- */
1512
- public static function select_current_page( $page, $current_page, $action = array() ) {
1513
- if ( $current_page != $page ) {
1514
- return;
1515
- }
1516
-
1517
- $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
1518
- if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
1519
- echo ' class="current_page"';
1520
- }
1521
- }
1522
-
1523
- /**
1524
- * Prepare and json_encode post content
1525
- *
1526
- * @since 2.0
1527
- *
1528
- * @param array $post_content
1529
- * @return string $post_content ( json encoded array )
1530
- */
1531
- public static function prepare_and_encode( $post_content ) {
1532
-
1533
- //Loop through array to strip slashes and add only the needed ones
1534
- foreach ( $post_content as $key => $val ) {
1535
- if ( isset( $post_content[ $key ] ) && ! is_array( $val ) ) {
1536
- // Strip all slashes so everything is the same, no matter where the value is coming from
1537
- $val = stripslashes( $val );
1538
-
1539
- // Add backslashes before double quotes and forward slashes only
1540
- $post_content[ $key ] = addcslashes( $val, '"\\/' );
1541
- }
1542
- unset( $key, $val );
1543
- }
1544
-
1545
- // json_encode the array
1546
- $post_content = json_encode( $post_content );
1547
-
1548
- // add extra slashes for \r\n since WP strips them
1549
- $post_content = str_replace( array( '\\r', '\\n', '\\u'), array( '\\\\r', '\\\\n', '\\\\u'), $post_content );
1550
-
1551
- // allow for &quot
1552
- $post_content = str_replace( '&quot;', '\\"', $post_content );
1553
-
1554
- return $post_content;
1555
- }
1556
-
1557
- public static function maybe_json_decode($string) {
1558
- if ( is_array($string) ) {
1559
- return $string;
1560
- }
1561
-
1562
  $new_string = json_decode($string, true);
1563
- if ( function_exists('json_last_error') ) {
1564
- // php 5.3+
1565
  if ( json_last_error() == JSON_ERROR_NONE ) {
1566
  $string = $new_string;
1567
  }
1568
- } else if ( isset($new_string) ) {
1569
- // php < 5.3 fallback
1570
  $string = $new_string;
1571
  }
1572
  return $string;
1573
  }
1574
-
1575
- /**
1576
- * @since 1.07.10
1577
- *
1578
- * @param string $post_type The name of the post type that may need to be highlighted
1579
- * @return echo The javascript to open and highlight the Formidable menu
1580
- */
 
 
 
 
 
 
 
1581
  public static function maybe_highlight_menu($post_type) {
1582
  global $post, $pagenow;
1583
 
1584
  if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1585
  return;
1586
  }
1587
-
1588
  if ( is_object($post) && $post->post_type != $post_type ) {
1589
  return;
1590
  }
1591
-
1592
- self::load_admin_wide_js();
1593
- echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1594
- }
1595
-
1596
- /**
1597
- * Load the JS file on non-Formidable pages in the admin area
1598
- * @since 2.0
1599
- */
1600
- public static function load_admin_wide_js( $load = true ) {
1601
- $version = FrmAppHelper::plugin_version();
1602
- wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery'), $version );
1603
-
1604
- wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1605
- 'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1606
- 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1607
- 'url' => FrmAppHelper::plugin_url(),
1608
- 'loading' => __( 'Loading&hellip;' ),
1609
- 'nonce' => wp_create_nonce( 'frm_ajax' ),
1610
- ) );
1611
-
1612
- if ( $load ) {
1613
- wp_enqueue_script( 'formidable_admin_global' );
1614
- }
1615
- }
1616
-
1617
- /**
1618
- * @since 1.07.10
1619
- *
1620
- * @param float $min_version The version the add-on requires
1621
- * @return echo The message on the plugins listing page
1622
- */
1623
  public static function min_version_notice($min_version) {
1624
  $frm_version = self::plugin_version();
1625
-
1626
  // check if Formidable meets minimum requirements
1627
  if ( version_compare($frm_version, $min_version, '>=') ) {
1628
  return;
1629
  }
1630
-
1631
  $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1632
  echo '<tr class="plugin-update-tr active"><th colspan="' . $wp_list_table->get_column_count() . '" class="check-column plugin-update colspanchange"><div class="update-message">'.
1633
- __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1634
  '</div></td></tr>';
1635
  }
1636
-
1637
- public static function locales( $type = 'date' ) {
1638
- $locales = array(
1639
- 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ),
1640
- 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ),
1641
- 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ),
1642
- 'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1643
- 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ),
1644
- 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1645
- 'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1646
- 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ),
1647
- 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ),
1648
- 'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1649
- 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ),
1650
- 'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1651
- 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ),
1652
- 'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1653
- 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ),
1654
- 'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1655
- 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ),
1656
- 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ),
1657
- 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ),
1658
- 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ),
1659
- 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ),
1660
- 'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1661
- 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ),
1662
- 'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1663
- 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1664
- 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ),
1665
- 'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1666
- 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ),
1667
- 'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1668
- 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ),
1669
- 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ),
1670
- 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ),
1671
- );
1672
-
1673
- if ( $type == 'captcha' ) {
1674
- // remove the languages unavailable for the captcha
1675
- $unset = array(
1676
- '', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1677
- 'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1678
- 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1679
- );
1680
- } else {
1681
- // remove the languages unavailable for the datepicker
1682
- $unset = array(
1683
- 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1684
- 'de-CH', 'iw', 'hi', 'id', 'pt', 'pt-PT',
1685
- 'es-419', 'tr',
1686
- );
1687
- }
1688
-
1689
- $locales = array_diff_key($locales, array_flip($unset));
1690
- $locales = apply_filters('frm_locales', $locales);
1691
-
1692
- return $locales;
1693
- }
1694
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
 
 
 
 
 
 
3
 
4
+ if(class_exists('FrmAppHelper'))
5
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ class FrmAppHelper{
8
+ public static $db_version = 11; //version of the database we are moving to (skip 12)
9
+ public static $pro_db_version = 25;
10
+
11
+ /*
12
+ * @since 1.07.02
13
+ *
14
+ * @param none
15
+ * @return float The version of this plugin
16
+ */
17
+ public static function plugin_version(){
18
+ $plugin_data = get_file_data( WP_PLUGIN_DIR .'/formidable/formidable.php', array('Version' => 'Version'), 'plugin' );
19
+ return $plugin_data['Version'];
20
  }
21
+
22
+ public static function plugin_path(){
23
  return dirname(dirname(dirname(__FILE__)));
24
  }
25
+
26
+ public static function plugin_url($url=''){
27
  //prevously FRM_URL constant
28
+ if(empty($url))
29
+ $url = plugins_url('', 'formidable/formidable.php');
30
+ if(is_ssl() and !preg_match('/^https:\/\/.*\..*$/', $url))
 
 
31
  $url = str_replace('http://', 'https://', $url);
32
+
 
33
  return $url;
34
  }
35
+
36
+ public static function site_url(){
 
 
 
37
  $url = self::plugin_url(site_url());
38
  return $url;
39
  }
40
+
41
+ public static function get_param($param, $default='', $src='get'){
42
+ if(strpos($param, '[')){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  $params = explode('[', $param);
44
+ $param = $params[0];
45
  }
46
 
47
+ if($src == 'get'){
48
+ $value = (isset($_POST[$param]) ? stripslashes_deep($_POST[$param]) : (isset($_GET[$param]) ? stripslashes_deep($_GET[$param]) : $default));
49
+ if(!isset($_POST[$param]) and isset($_GET[$param]) and !is_array($value))
50
+ $value = stripslashes_deep(htmlspecialchars_decode(urldecode($_GET[$param])));
51
+ }else{
52
+ $value = isset($_POST[$param]) ? stripslashes_deep(maybe_unserialize($_POST[$param])) : $default;
 
53
  }
54
+
55
+ if(isset($params) and is_array($value) and !empty($value)){
56
+ foreach($params as $k => $p){
57
+ if(!$k or !is_array($value))
58
  continue;
59
+
 
60
  $p = trim($p, ']');
61
+ $value = (isset($value[$p])) ? $value[$p] : $default;
62
  }
63
  }
64
 
65
  return $value;
66
  }
67
+
68
+ public static function get_post_param($param, $default=''){
69
+ return isset($_POST[$param]) ? stripslashes_deep(maybe_unserialize($_POST[$param])) : $default;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  }
71
+
72
+ /*
73
+ * Check a value from a shortcode to see if true or false.
74
+ * True when value is 1, true, 'true', 'yes'
75
+ *
76
+ * @since 1.07.10
77
+ *
78
+ * @param string $value The value to compare
79
+ * @return boolean True or False
80
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  public static function is_true($value) {
82
  return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
83
  }
84
+
85
+ public static function load_scripts($scripts){
 
 
 
 
 
 
 
 
86
  foreach ( (array) $scripts as $s ) {
87
  wp_enqueue_script($s);
88
  }
89
  }
90
+
91
+ public static function load_styles($styles){
 
92
  foreach ( (array) $styles as $s ) {
93
  wp_enqueue_style($s);
94
  }
95
  }
96
+
97
+ public static function get_pages(){
98
+ return get_posts( array('post_type' => 'page', 'post_status' => array('publish', 'private'), 'numberposts' => 999, 'orderby' => 'title', 'order' => 'ASC'));
99
  }
100
+
101
+ public static function wp_pages_dropdown($field_name, $page_id, $truncate=false){
102
+ $pages = FrmAppHelper::get_pages();
103
  ?>
104
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-pages-dropdown">
105
+ <option value=""></option>
106
+ <?php foreach($pages as $page){ ?>
107
+ <option value="<?php echo $page->ID; ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $page->ID) or (!isset($_POST[$field_name]) and $page_id == $page->ID))?' selected="selected"':''); ?>><?php echo ($truncate)? FrmAppHelper::truncate($page->post_title, $truncate) : $page->post_title; ?> </option>
 
 
108
  <?php } ?>
109
  </select>
110
  <?php
111
  }
112
+
113
+ public static function wp_roles_dropdown($field_name, $capability){
114
+ global $frm_vars;
115
+ $field_value = FrmAppHelper::get_param($field_name);
116
+ if(!isset($frm_vars['editable_roles']) or !$frm_vars['editable_roles'])
117
+ $frm_vars['editable_roles'] = get_editable_roles();
 
 
 
 
 
118
 
119
  ?>
120
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-pages-dropdown">
121
+ <?php foreach($frm_vars['editable_roles'] as $role => $details){
122
+ $name = translate_user_role($details['name'] ); ?>
123
+ <option value="<?php echo esc_attr($role) ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $role) or (!isset($_POST[$field_name]) and $capability == $role))?' selected="selected"':''); ?>><?php echo $name ?> </option>
124
+ <?php
125
+ unset($role);
126
+ unset($details);
127
+ } ?>
128
  </select>
129
  <?php
130
  }
131
+
132
+ public static function frm_capabilities($type = 'auto'){
133
  global $frm_vars;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  $cap = array(
135
+ 'frm_view_forms' => __('View Forms and Templates', 'formidable'),
136
+ 'frm_edit_forms' => __('Add/Edit Forms and Templates', 'formidable'),
137
+ 'frm_delete_forms' => __('Delete Forms and Templates', 'formidable'),
138
+ 'frm_change_settings' => __('Access this Settings Page', 'formidable')
 
 
139
  );
140
+ if ( $frm_vars['pro_is_installed'] || 'pro' == $type ) {
141
+ $cap['frm_view_entries'] = __('View Entries from Admin Area', 'formidable');
142
+ $cap['frm_create_entries'] = __('Add Entries from Admin Area', 'formidable');
143
+ $cap['frm_edit_entries'] = __('Edit Entries from Admin Area', 'formidable');
144
+ $cap['frm_delete_entries'] = __('Delete Entries from Admin Area', 'formidable');
145
+ $cap['frm_view_reports'] = __('View Reports', 'formidable');
146
+ $cap['frm_edit_displays'] = __('Add/Edit Views', 'formidable');
147
  }
 
 
 
 
 
 
148
  return $cap;
149
  }
150
+
151
+ public static function user_has_permission($needed_role){
152
+ if($needed_role == '-1')
153
  return false;
154
+
155
+ if($needed_role == '' or current_user_can($needed_role))
 
 
156
  return true;
157
+
 
158
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
159
+ foreach ($roles as $role){
160
+ if (current_user_can($role))
161
  return true;
162
+ if ($role == $needed_role)
 
163
  break;
 
164
  }
165
  return false;
166
  }
167
+
168
+ public static function checked($values, $current){
169
+ if(FrmAppHelper::check_selected($values, $current))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  echo ' checked="checked"';
 
171
  }
172
+
173
+ public static function check_selected($values, $current){
174
+ //if(is_array($current))
175
+ // $current = (isset($current['value'])) ? $current['value'] : $current['label'];
176
+
177
+ if(is_array($values))
178
+ $values = array_map(array('FrmAppHelper', 'recursive_trim'), $values);
179
+ else
180
+ $values = trim($values);
181
  $current = trim($current);
182
+
183
+ /*if(is_array($values))
184
+ $values = array_map('htmlentities', $values);
185
+ else
186
+ $values = htmlentities($values);
187
+
188
+ $values = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $values);
189
+ $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
190
+ */
191
+
192
+ if((is_array($values) && in_array($current, $values)) or (!is_array($values) and $values == $current))
193
+ return true;
194
+ else
195
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  }
197
+
198
  public static function recursive_trim(&$value) {
199
+ if (is_array($value))
200
+ $value = array_map(array('FrmAppHelper', 'recursive_trim'), $value);
201
+ else
202
  $value = trim($value);
203
+
 
204
  return $value;
205
  }
206
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  public static function esc_textarea( $text ) {
208
  $safe_text = str_replace('&quot;', '"', $text);
209
  $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
210
  return apply_filters( 'esc_textarea', $safe_text, $text );
211
  }
212
+
213
+ public static function replace_quotes($val){
214
+ $val = str_replace(array('&#8220;', '&#8221;', '&#8216;', '&#8217;'), array('"', '"', "'", "'"), $val);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  return $val;
216
  }
217
+
218
+ public static function script_version($handle, $list='scripts'){
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  global $wp_scripts;
220
+ if(!$wp_scripts)
221
  return false;
222
+
 
223
  $ver = 0;
224
+
225
+ if ( isset($wp_scripts->registered[$handle]) )
226
+ $query = $wp_scripts->registered[$handle];
227
+
228
+ if ( is_object( $query ) )
 
 
229
  $ver = $query->ver;
 
230
 
231
  return $ver;
232
  }
233
+
234
+ public static function js_redirect($url){
235
+ return '<script type="text/javascript">window.location="'. $url .'"</script>';
236
  }
237
+
238
+ public static function get_file_contents($filename){
239
+ if (is_file($filename)){
240
+ ob_start();
241
+ include $filename;
242
+ $contents = ob_get_contents();
243
+ ob_end_clean();
244
+ return $contents;
245
  }
246
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
+
249
+ public static function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
 
 
 
 
250
  global $wpdb;
251
 
252
  $key = '';
253
+
254
+ if (!empty($name)){
255
  $key = sanitize_key($name);
256
  }
257
+
258
+ if(empty($key)){
259
  $max_slug_value = pow(36, $num_chars);
260
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
261
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
262
  }
263
 
264
+ if (is_numeric($key) or in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
265
  $key = $key .'a';
266
+
267
+ $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
268
+ $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
269
+
270
+ if ($key_check or is_numeric($key_check)){
271
  $suffix = 2;
272
  do {
273
+ $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
274
+ $key_check = $wpdb->get_var($wpdb->prepare($query, $alt_post_name, $id));
275
  $suffix++;
276
  } while ($key_check || is_numeric($key_check));
277
  $key = $alt_post_name;
279
  return $key;
280
  }
281
 
282
+ //Editing a Form or Entry
283
+ public static function setup_edit_vars($record, $table, $fields='', $default=false, $post_values=array()){
284
+ if(!$record) return false;
285
+ global $frm_entry_meta, $frm_settings, $frm_vars;
286
+
287
+ if(empty($post_values))
 
 
 
 
 
 
 
288
  $post_values = stripslashes_deep($_POST);
289
+
290
+ $values = array('id' => $record->id, 'fields' => array());
291
 
292
+ foreach ( array('name', 'description') as $var ) {
 
 
293
  $default_val = isset($record->{$var}) ? $record->{$var} : '';
294
+ $values[$var] = FrmAppHelper::get_param($var, $default_val);
295
  unset($var, $default_val);
296
  }
297
+
298
+ if ( apply_filters('frm_use_wpautop', true) ) {
299
+ $values['description'] = wpautop(str_replace( '<br>', '<br />', $values['description']));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  }
301
+
302
+ foreach ( (array) $fields as $field ) {
303
 
304
+ if ($default){
305
+ $meta_value = $field->default_value;
306
+ }else{
307
+ if($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']){
308
+ if(!isset($field->field_options['custom_field']))
309
+ $field->field_options['custom_field'] = '';
310
+ $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
311
+ }else if(isset($record->metas)){
312
+ $meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false;
313
+ }else{
314
+ $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id);
315
+ }
316
  }
317
+
318
+ $field_type = isset($post_values['field_options']['type_'.$field->id]) ? $post_values['field_options']['type_'.$field->id] : $field->type;
319
+ $new_value = isset($post_values['item_meta'][$field->id]) ? maybe_unserialize($post_values['item_meta'][$field->id]) : $meta_value;
320
+
321
+ $field_array = array(
322
+ 'id' => $field->id,
323
+ 'value' => $new_value,
324
+ 'default_value' => $field->default_value,
325
+ 'name' => $field->name,
326
+ 'description' => $field->description,
327
+ 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
328
+ 'options' => $field->options,
329
+ 'required' => $field->required,
330
+ 'field_key' => $field->field_key,
331
+ 'field_order' => $field->field_order,
332
+ 'form_id' => $field->form_id
333
+ );
334
+
335
+ /*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){
336
+ foreach((array)$field_array['options'] as $opt_key => $opt){
337
+ if(!is_array($opt))
338
+ $field_array['options'][$opt_key] = array('label' => $opt);
339
+ unset($opt);
340
+ unset($opt_key);
341
+ }
342
+ }*/
343
+
344
+ $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
345
+
346
+ foreach ($opt_defaults as $opt => $default_opt){
347
+ $field_array[$opt] = ($post_values && isset($post_values['field_options'][$opt.'_'.$field->id]) ) ? maybe_unserialize($post_values['field_options'][$opt.'_'.$field->id]) : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt);
348
+ if($opt == 'blank' and $field_array[$opt] == ''){
349
+ $field_array[$opt] = $frm_settings->blank_msg;
350
+ }else if($opt == 'invalid' and $field_array[$opt] == ''){
351
+ if($field_type == 'captcha')
352
+ $field_array[$opt] = $frm_settings->re_msg;
353
+ else
354
+ $field_array[$opt] = sprintf(__('%s is invalid', 'formidable'), $field_array['name']);
355
+ }
356
+ }
357
+
358
+ unset($opt_defaults);
359
+
360
+ if ($field_array['custom_html'] == '')
361
+ $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
362
+
363
+ if ($field_array['size'] == '')
364
+ $field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
365
+
366
+ $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
367
+
368
+ if(!isset($field_array['unique']) or !$field_array['unique'])
369
+ $field_array['unique_msg'] = '';
370
+
371
+ foreach((array)$field->field_options as $k => $v){
372
+ if(!isset($field_array[$k]))
373
+ $field_array[$k] = $v;
374
+ unset($k);
375
+ unset($v);
376
+ }
377
+
378
+ $values['fields'][$field->id] = $field_array;
379
+
380
+ unset($field);
381
+ }
382
+
383
+ $frm_form = new FrmForm();
384
+ $form = $frm_form->getOne( $table == 'entries' ? $record->form_id : $record->id );
385
+ unset($frm_form);
386
+
387
+ if ($form){
388
+ $values['form_name'] = (isset($record->form_id)) ? $form->name : '';
389
+ if (is_array($form->options)){
390
+ foreach ($form->options as $opt => $value){
391
+ if(in_array($opt, array('email_to', 'reply_to', 'reply_to_name')))
392
+ $values['notification'][0][$opt] = isset($post_values["notification[0][$opt]"]) ? maybe_unserialize($post_values["notification[0][$opt]"]) : $value;
393
+
394
+ $values[$opt] = isset($post_values[$opt]) ? maybe_unserialize($post_values[$opt]) : $value;
395
  }
396
  }
397
  }
398
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  $form_defaults = FrmFormsHelper::get_default_opts();
400
+
401
+ //set to posted value or default
402
+ foreach ($form_defaults as $opt => $default){
403
+ if (!isset($values[$opt]) or $values[$opt] == ''){
404
+ if($opt == 'notification'){
405
+ $values[$opt] = ($post_values and isset($post_values[$opt])) ? $post_values[$opt] : $default;
406
+
407
+ foreach($default as $o => $d){
408
+ if($o == 'email_to')
409
  $d = ''; //allow blank email address
410
+ $values[$opt][0][$o] = ($post_values and isset($post_values[$opt][0][$o])) ? $post_values[$opt][0][$o] : $d;
411
+ unset($o);
412
+ unset($d);
413
  }
414
+ }else{
415
+ $values[$opt] = ($post_values and isset($post_values['options'][$opt])) ? $post_values['options'][$opt] : $default;
416
+ }
417
+ }else if($values[$opt] == 'notification'){
418
+ foreach($values[$opt] as $k => $n){
419
+ foreach($default as $o => $d){
420
+ if(!isset($n[$o]))
421
+ $values[$opt][$k][$o] = ($post_values and isset($post_values[$opt][$k][$o])) ? $post_values[$opt][$k][$o] : $d;
422
+ unset($o);
423
+ unset($d);
424
  }
425
+ unset($k);
426
+ unset($n);
427
  }
428
  }
429
+
430
+ unset($opt);
431
+ unset($defaut);
 
 
 
 
432
  }
433
+
434
+ if (!isset($values['custom_style']))
435
+ $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $_POST['options']['custom_style'] : ($frm_settings->load_style != 'none');
436
 
437
+ foreach(array('before', 'after', 'submit') as $h){
438
+ if (!isset($values[$h.'_html']))
439
+ $values[$h .'_html'] = (isset($post_values['options'][$h .'_html']) ? $post_values['options'][$h .'_html'] : FrmFormsHelper::get_default_html($h));
 
440
  unset($h);
441
  }
442
+
443
+ if ($table == 'entries')
444
+ $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
445
+ else if ($table == 'forms')
446
+ $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
 
 
 
 
 
 
 
447
 
448
+ return $values;
 
 
 
 
 
 
 
 
 
449
  }
450
+
451
+ public static function insert_opt_html($args){
452
+ extract($args);
453
+
454
  $class = '';
455
+
456
+ if ( in_array( $type, array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
457
  $class .= 'show_frm_not_email_to';
458
  }
459
  ?>
460
  <li>
461
+ <a class="frmids frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($id) ?>" href="javascript:void(0)">[<?php echo $id ?>]</a>
462
+ <a class="frmkeys frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($key) ?>" href="javascript:void(0)">[<?php echo FrmAppHelper::truncate($key, 10) ?>]</a>
463
+ <a class="frm_insert_code <?php echo $class ?>" data-code="<?php echo esc_attr($id) ?>" href="javascript:void(0)"><?php echo FrmAppHelper::truncate($name, 60) ?></a>
464
  </li>
465
  <?php
466
  }
467
+
468
+ public static function get_us_states(){
469
+ return apply_filters('frm_us_states', array(
470
+ 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
471
+ 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
472
+ 'DC' => 'District of Columbia',
473
+ 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
474
+ 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
475
+ 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
476
+ 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
477
+ 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
478
+ 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
479
+ 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
480
+ 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
481
+ 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
482
+ 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
483
+ 'WI' => 'Wisconsin', 'WY' => 'Wyoming'
484
+ ));
485
+ }
486
+
487
+ public static function get_countries(){
488
+ return apply_filters('frm_countries', array(
489
+ __('Afghanistan', 'formidable'), __('Albania', 'formidable'), __('Algeria', 'formidable'),
490
+ __('American Samoa', 'formidable'), __('Andorra', 'formidable'), __('Angola', 'formidable'),
491
+ __('Anguilla', 'formidable'), __('Antarctica', 'formidable'), __('Antigua and Barbuda', 'formidable'),
492
+ __('Argentina', 'formidable'), __('Armenia', 'formidable'), __('Aruba', 'formidable'),
493
+ __('Australia', 'formidable'), __('Austria', 'formidable'), __('Azerbaijan', 'formidable'),
494
+ __('Bahamas', 'formidable'), __('Bahrain', 'formidable'), __('Bangladesh', 'formidable'),
495
+ __('Barbados', 'formidable'), __('Belarus', 'formidable'), __('Belgium', 'formidable'),
496
+ __('Belize', 'formidable'), __('Benin', 'formidable'), __('Bermuda', 'formidable'),
497
+ __('Bhutan', 'formidable'), __('Bolivia', 'formidable'), __('Bosnia and Herzegovina', 'formidable'),
498
+ __('Botswana', 'formidable'), __('Brazil', 'formidable'), __('Brunei', 'formidable'),
499
+ __('Bulgaria', 'formidable'), __('Burkina Faso', 'formidable'), __('Burundi', 'formidable'),
500
+ __('Cambodia', 'formidable'), __('Cameroon', 'formidable'), __('Canada', 'formidable'),
501
+ __('Cape Verde', 'formidable'), __('Cayman Islands', 'formidable'), __('Central African Republic', 'formidable'),
502
+ __('Chad', 'formidable'), __('Chile', 'formidable'), __('China', 'formidable'),
503
+ __('Colombia', 'formidable'), __('Comoros', 'formidable'), __('Congo', 'formidable'),
504
+ __('Costa Rica', 'formidable'), __('C&ocirc;te d\'Ivoire', 'formidable'), __('Croatia', 'formidable'),
505
+ __('Cuba', 'formidable'), __('Cyprus', 'formidable'), __('Czech Republic', 'formidable'),
506
+ __('Denmark', 'formidable'), __('Djibouti', 'formidable'), __('Dominica', 'formidable'),
507
+ __('Dominican Republic', 'formidable'), __('East Timor', 'formidable'), __('Ecuador', 'formidable'),
508
+ __('Egypt', 'formidable'), __('El Salvador', 'formidable'), __('Equatorial Guinea', 'formidable'),
509
+ __('Eritrea', 'formidable'), __('Estonia', 'formidable'), __('Ethiopia', 'formidable'),
510
+ __('Fiji', 'formidable'), __('Finland', 'formidable'), __('France', 'formidable'),
511
+ __('French Guiana', 'formidable'), __('French Polynesia', 'formidable'), __('Gabon', 'formidable'),
512
+ __('Gambia', 'formidable'), __('Georgia', 'formidable'), __('Germany', 'formidable'),
513
+ __('Ghana', 'formidable'), __('Gibraltar', 'formidable'), __('Greece', 'formidable'),
514
+ __('Greenland', 'formidable'), __('Grenada', 'formidable'), __('Guam', 'formidable'),
515
+ __('Guatemala', 'formidable'), __('Guinea', 'formidable'), __('Guinea-Bissau', 'formidable'),
516
+ __('Guyana', 'formidable'), __('Haiti', 'formidable'), __('Honduras', 'formidable'),
517
+ __('Hong Kong', 'formidable'), __('Hungary', 'formidable'), __('Iceland', 'formidable'),
518
+ __('India', 'formidable'), __('Indonesia', 'formidable'), __('Iran', 'formidable'),
519
+ __('Iraq', 'formidable'), __('Ireland', 'formidable'), __('Israel', 'formidable'),
520
+ __('Italy', 'formidable'), __('Jamaica', 'formidable'), __('Japan', 'formidable'),
521
+ __('Jordan', 'formidable'), __('Kazakhstan', 'formidable'), __('Kenya', 'formidable'),
522
+ __('Kiribati', 'formidable'), __('North Korea', 'formidable'), __('South Korea', 'formidable'),
523
+ __('Kuwait', 'formidable'), __('Kyrgyzstan', 'formidable'), __('Laos', 'formidable'),
524
+ __('Latvia', 'formidable'), __('Lebanon', 'formidable'), __('Lesotho', 'formidable'),
525
+ __('Liberia', 'formidable'), __('Libya', 'formidable'), __('Liechtenstein', 'formidable'),
526
+ __('Lithuania', 'formidable'), __('Luxembourg', 'formidable'), __('Macedonia', 'formidable'),
527
+ __('Madagascar', 'formidable'), __('Malawi', 'formidable'), __('Malaysia', 'formidable'),
528
+ __('Maldives', 'formidable'), __('Mali', 'formidable'), __('Malta', 'formidable'),
529
+ __('Marshall Islands', 'formidable'), __('Mauritania', 'formidable'), __('Mauritius', 'formidable'),
530
+ __('Mexico', 'formidable'), __('Micronesia', 'formidable'), __('Moldova', 'formidable'),
531
+ __('Monaco', 'formidable'), __('Mongolia', 'formidable'), __('Montenegro', 'formidable'),
532
+ __('Montserrat', 'formidable'), __('Morocco', 'formidable'), __('Mozambique', 'formidable'),
533
+ __('Myanmar', 'formidable'), __('Namibia', 'formidable'), __('Nauru', 'formidable'),
534
+ __('Nepal', 'formidable'), __('Netherlands', 'formidable'), __('New Zealand', 'formidable'),
535
+ __('Nicaragua', 'formidable'), __('Niger', 'formidable'), __('Nigeria', 'formidable'),
536
+ __('Norway', 'formidable'), __('Northern Mariana Islands', 'formidable'), __('Oman', 'formidable'),
537
+ __('Pakistan', 'formidable'), __('Palau', 'formidable'), __('Palestine', 'formidable'),
538
+ __('Panama', 'formidable'), __('Papua New Guinea', 'formidable'), __('Paraguay', 'formidable'),
539
+ __('Peru', 'formidable'), __('Philippines', 'formidable'), __('Poland', 'formidable'),
540
+ __('Portugal', 'formidable'), __('Puerto Rico', 'formidable'), __('Qatar', 'formidable'),
541
+ __('Romania', 'formidable'), __('Russia', 'formidable'), __('Rwanda', 'formidable'),
542
+ __('Saint Kitts and Nevis', 'formidable'), __('Saint Lucia', 'formidable'),
543
+ __('Saint Vincent and the Grenadines', 'formidable'), __('Samoa', 'formidable'),
544
+ __('San Marino', 'formidable'), __('Sao Tome and Principe', 'formidable'), __('Saudi Arabia', 'formidable'),
545
+ __('Senegal', 'formidable'), __('Serbia and Montenegro', 'formidable'), __('Seychelles', 'formidable'),
546
+ __('Sierra Leone', 'formidable'), __('Singapore', 'formidable'), __('Slovakia', 'formidable'),
547
+ __('Slovenia', 'formidable'), __('Solomon Islands', 'formidable'), __('Somalia', 'formidable'),
548
+ __('South Africa', 'formidable'), __('Spain', 'formidable'), __('Sri Lanka', 'formidable'),
549
+ __('Sudan', 'formidable'), __('Suriname', 'formidable'), __('Swaziland', 'formidable'),
550
+ __('Sweden', 'formidable'), __('Switzerland', 'formidable'), __('Syria', 'formidable'),
551
+ __('Taiwan', 'formidable'), __('Tajikistan', 'formidable'), __('Tanzania', 'formidable'),
552
+ __('Thailand', 'formidable'), __('Togo', 'formidable'), __('Tonga', 'formidable'),
553
+ __('Trinidad and Tobago', 'formidable'), __('Tunisia', 'formidable'), __('Turkey', 'formidable'),
554
+ __('Turkmenistan', 'formidable'), __('Tuvalu', 'formidable'), __('Uganda', 'formidable'),
555
+ __('Ukraine', 'formidable'), __('United Arab Emirates', 'formidable'), __('United Kingdom', 'formidable'),
556
+ __('United States', 'formidable'), __('Uruguay', 'formidable'), __('Uzbekistan', 'formidable'),
557
+ __('Vanuatu', 'formidable'), __('Vatican City', 'formidable'), __('Venezuela', 'formidable'),
558
+ __('Vietnam', 'formidable'), __('Virgin Islands, British', 'formidable'),
559
+ __('Virgin Islands, U.S.', 'formidable'), __('Yemen', 'formidable'), __('Zambia', 'formidable'),
560
+ __('Zimbabwe', 'formidable')
561
+ ));
562
+ }
563
+
564
+ public static function truncate($str, $length, $minword = 3, $continue = '...'){
565
+ if(is_array($str))
566
  return;
567
+
568
+ $length = (int)$length;
569
+ $str = strip_tags($str);
 
570
  $original_len = (function_exists('mb_strlen')) ? mb_strlen($str) : strlen($str);
571
+
572
+ if($length == 0){
573
  return '';
574
+ }else if($length <= 10){
575
+ $sub = (function_exists('mb_substr')) ? mb_substr($str, 0, $length) : substr($str, 0, $length);
576
  return $sub . (($length < $original_len) ? $continue : '');
577
  }
578
+
579
  $sub = '';
580
  $len = 0;
581
 
582
  $words = (function_exists('mb_split')) ? mb_split(' ', $str) : explode(' ', $str);
583
+
584
+ foreach ($words as $word){
585
  $part = (($sub != '') ? ' ' : '') . $word;
586
  $total_len = (function_exists('mb_strlen')) ? mb_strlen($sub . $part) : strlen($sub. $part);
587
  if ( $total_len > $length && str_word_count($sub) ) {
588
  break;
589
  }
590
+
591
  $sub .= $part;
592
  $len += (function_exists('mb_strlen')) ? mb_strlen($part) : strlen($part);
593
+
594
  if ( str_word_count($sub) > $minword && $total_len >= $length ) {
595
  break;
596
  }
597
+
598
  unset($total_len, $word);
599
  }
600
+
601
  return $sub . (($len < $original_len) ? $continue : '');
602
  }
603
+
604
+ /*
605
+ * Added for < 4.0 compatability
606
+ *
607
+ * @since 1.07.10
608
+ *
609
+ * @param $term The value to escape
610
+ * @return string The escaped value
611
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
  public static function esc_like($term) {
613
  global $wpdb;
614
+ if ( method_exists($wpdb, 'esc_like') ) { // WP 4.0
 
615
  $term = $wpdb->esc_like( $term );
616
  } else {
617
  $term = like_escape( $term );
618
  }
619
+
620
  return $term;
621
  }
622
+
623
+ public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
624
  if ( empty($where) ) {
625
  return '';
626
  }
627
+
628
+ if(is_array($where)){
629
+ global $frmdb, $wpdb;
630
+ extract($frmdb->get_where_clause_and_values( $where ));
631
+ $where = $wpdb->prepare($where, $values);
632
+ }else{
633
  $where = $starts_with . $where;
634
  }
635
+
636
  return $where;
637
  }
638
+
639
  // Pagination Methods
640
+ public static function getLastRecordNum($r_count,$current_p,$p_size){
641
+ return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
  }
643
 
644
+ public static function getFirstRecordNum($r_count,$current_p,$p_size){
645
+ if($current_p == 1)
646
+ return 1;
647
+ else
648
+ return (self::getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
 
 
649
  }
650
+
651
+ public static function getRecordCount($where="", $table_name){
652
+ global $wpdb;
653
+ $query = 'SELECT COUNT(*) FROM ' . $table_name . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
654
+ return $wpdb->get_var($query);
655
+ }
656
+
657
+ public static function get_referer_query($query) {
658
+ if (strpos($query, "google.")) {
659
+ //$pattern = '/^.*\/search.*[\?&]q=(.*)$/';
660
+ $pattern = '/^.*[\?&]q=(.*)$/';
661
+ } else if (strpos($query, "bing.com")) {
662
+ $pattern = '/^.*q=(.*)$/';
663
+ } else if (strpos($query, "yahoo.")) {
664
+ $pattern = '/^.*[\?&]p=(.*)$/';
665
+ } else if (strpos($query, "ask.")) {
666
+ $pattern = '/^.*[\?&]q=(.*)$/';
667
+ } else {
668
+ return false;
669
+ }
670
+ preg_match($pattern, $query, $matches);
671
+ $querystr = substr($matches[1], 0, strpos($matches[1], '&'));
672
+ return urldecode($querystr);
673
+ }
674
+
675
+ public static function get_referer_info(){
676
+ $referrerinfo = '';
677
+ $keywords = array();
678
+ $i = 1;
679
+ if(isset($_SESSION) and isset($_SESSION['frm_http_referer']) and $_SESSION['frm_http_referer']){
680
+ foreach ($_SESSION['frm_http_referer'] as $referer) {
681
+ $referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
682
+ $keywords_used = FrmAppHelper::get_referer_query($referer);
683
+ if ($keywords_used)
684
+ $keywords[] = $keywords_used;
685
+
686
+ $i++;
687
+ }
688
+
689
+ $referrerinfo .= "\r\n";
690
+ }else{
691
+ $referrerinfo = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
692
+ }
693
+
694
+ $i = 1;
695
+ if(isset($_SESSION) and isset($_SESSION['frm_http_pages']) and $_SESSION['frm_http_pages']){
696
+ foreach ($_SESSION['frm_http_pages'] as $page) {
697
+ $referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
698
+ $i++;
699
+ }
700
+
701
+ $referrerinfo .= "\r\n";
702
+ }
703
+
704
+ $i = 1;
705
+ foreach ($keywords as $keyword) {
706
+ $referrerinfo .= str_pad("Keyword $i: ",20) . $keyword. "\r\n";
707
+ $i++;
708
+ }
709
+ $referrerinfo .= "\r\n";
710
+
711
+ return $referrerinfo;
712
  }
713
+
714
+ public static function json_to_array($json_vars){
 
 
 
715
  $vars = array();
716
+ foreach($json_vars as $jv){
717
  $jv_name = explode('[', $jv['name']);
718
+ $last = count($jv_name)-1;
719
+ foreach($jv_name as $p => $n){
720
  $name = trim($n, ']');
721
+ $this_val = ($p == $last) ? $jv['value'] : array();
722
+
723
+ if(!$p){
724
  $l1 = $name;
725
+ if($name == '')
726
+ $vars[] = $this_val;
727
+ else if(!isset($vars[$l1]))
728
+ $vars[$l1] = $this_val;
729
  }
730
+
731
+ if($p == 1){
732
  $l2 = $name;
733
+ if($name == '')
734
+ $vars[$l1][] = $this_val;
735
+ else if(!isset($vars[$l1][$l2]))
736
+ $vars[$l1][$l2] = $this_val;
737
  }
738
+
739
+ if($p == 2){
740
  $l3 = $name;
741
+ if($name == '')
742
+ $vars[$l1][$l2][] = $this_val;
743
+ else if(!isset($vars[$l1][$l2][$l3]))
744
+ $vars[$l1][$l2][$l3] = $this_val;
745
  }
746
+
747
+ unset($this_val);
748
+ unset($n);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
  }
750
+
751
+ unset($last);
752
+ unset($jv);
753
  }
754
+
755
  return $vars;
756
  }
757
+
758
+ public static function maybe_json_decode($string){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
759
  $new_string = json_decode($string, true);
760
+ if ( function_exists('json_last_error') ) { // php 5.3+
 
761
  if ( json_last_error() == JSON_ERROR_NONE ) {
762
  $string = $new_string;
763
  }
764
+ } else if ( isset($new_string) ) { // php < 5.3 fallback
 
765
  $string = $new_string;
766
  }
767
  return $string;
768
  }
769
+
770
+ public static function check_mem_use($function='', $start_mem=0) {
771
+ $mem = memory_get_usage(true) - $start_mem;
772
+
773
+ //error_log($mem .' '. $function);
774
+ return $start_mem + $mem;
775
+ }
776
+
777
+ /*
778
+ * @since 1.07.10
779
+ *
780
+ * @param string $post_type The name of the post type that may need to be highlighted
781
+ * @return echo The javascript to open and highlight the Formidable menu
782
+ */
783
  public static function maybe_highlight_menu($post_type) {
784
  global $post, $pagenow;
785
 
786
  if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
787
  return;
788
  }
789
+
790
  if ( is_object($post) && $post->post_type != $post_type ) {
791
  return;
792
  }
793
+
794
+ echo <<<HTML
795
+ <script type="text/javascript">
796
+ jQuery(document).ready(function(){
797
+ jQuery('#toplevel_page_formidable').removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu wp-menu-open');
798
+ jQuery('#toplevel_page_formidable a.wp-has-submenu').removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu wp-menu-open');
799
+ });
800
+ </script>
801
+ HTML;
802
+ }
803
+
804
+ /*
805
+ * @since 1.07.10
806
+ *
807
+ * @param float $min_version The version the add-on requires
808
+ * @return echo The message on the plugins listing page
809
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810
  public static function min_version_notice($min_version) {
811
  $frm_version = self::plugin_version();
812
+
813
  // check if Formidable meets minimum requirements
814
  if ( version_compare($frm_version, $min_version, '>=') ) {
815
  return;
816
  }
817
+
818
  $wp_list_table = _get_list_table('WP_Plugins_List_Table');
819
  echo '<tr class="plugin-update-tr active"><th colspan="' . $wp_list_table->get_column_count() . '" class="check-column plugin-update colspanchange"><div class="update-message">'.
820
+ __('You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable') .
821
  '</div></td></tr>';
822
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
  }
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -1,659 +1,193 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
 
6
- class FrmEntriesHelper {
7
 
8
- public static function setup_new_vars( $fields, $form = '', $reset = false ) {
9
- global $frm_vars;
10
- $values = array();
11
- foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) {
12
- $values[ $var ] = FrmAppHelper::get_post_param( $var, $default );
13
- }
14
 
 
 
 
 
 
 
15
  $values['fields'] = array();
16
- if ( empty($fields) ) {
17
  return apply_filters('frm_setup_new_entry', $values);
18
  }
19
-
20
  foreach ( (array) $fields as $field ) {
 
21
  $default = $field->default_value;
22
  $posted_val = false;
23
- $new_value = $default;
24
-
25
- if ( ! $reset && $_POST && isset( $_POST['item_meta'][ $field->id ] ) && $_POST['item_meta'][ $field->id ] != '' ) {
26
- $new_value = stripslashes_deep( $_POST['item_meta'][ $field->id ] );
 
27
  $posted_val = true;
28
  } else if ( isset($field->field_options['clear_on_focus']) && $field->field_options['clear_on_focus'] ) {
29
  $new_value = '';
 
 
30
  }
31
-
32
  $is_default = ($new_value == $default) ? true : false;
33
-
34
  //If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
35
- $return_array = FrmFieldsHelper::is_field_with_multiple_values( $field );
36
-
 
 
 
 
37
  $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
38
-
39
- if ( ! is_array( $new_value ) ) {
40
  if ( $is_default ) {
41
  $new_value = $field->default_value;
42
- } else if ( ! $posted_val ) {
43
  $new_value = apply_filters('frm_filter_default_value', $new_value, $field);
44
  }
45
-
46
  $new_value = str_replace('"', '&quot;', $new_value);
47
  }
48
-
49
- unset($is_default, $posted_val);
50
-
51
- $field_array = array(
52
- 'id' => $field->id,
53
- 'value' => $new_value,
54
- 'default_value' => $field->default_value,
55
- 'name' => $field->name,
56
- 'description' => $field->description,
57
- 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
58
- 'options' => $field->options,
59
- 'required' => $field->required,
60
- 'field_key' => $field->field_key,
61
- 'field_order' => $field->field_order,
62
- 'form_id' => $field->form_id,
63
- );
64
-
65
- $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
66
- $opt_defaults['required_indicator'] = '';
67
-
68
- foreach ( $opt_defaults as $opt => $default_opt ) {
69
- $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt;
70
- unset($opt, $default_opt);
71
- }
72
-
73
- unset($opt_defaults);
74
-
75
- $field_array['size'] = FrmAppHelper::get_field_size($field_array);
76
-
77
- if ( $field_array['custom_html'] == '' ) {
78
- $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
79
- }
80
-
81
- $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
82
- $field_array = array_merge( $field->field_options, $field_array );
83
-
84
- $values['fields'][] = $field_array;
85
-
86
- if ( ! $form || ! isset($form->id) ) {
87
- $form = FrmForm::getOne($field->form_id);
88
- }
89
- }
90
-
91
- $form->options = maybe_unserialize($form->options);
92
- if ( is_array($form->options) ) {
93
- foreach ( $form->options as $opt => $value ) {
94
- $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value );
95
- unset($opt, $value);
96
- }
97
- }
98
-
99
- $form_defaults = FrmFormsHelper::get_default_opts();
100
-
101
- $frm_settings = FrmAppHelper::get_settings();
102
- $form_defaults['custom_style'] = ( $frm_settings->load_style != 'none' );
103
-
104
- $values = array_merge( $form_defaults, $values );
105
-
106
- return apply_filters( 'frm_setup_new_entry', $values );
107
- }
108
-
109
- public static function setup_edit_vars($values, $record) {
110
- $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
111
- $values['form_id'] = $record->form_id;
112
- $values['is_draft'] = $record->is_draft;
113
- return apply_filters('frm_setup_edit_entry_vars', $values, $record);
114
- }
115
-
116
- public static function get_admin_params( $form = null ) {
117
- $form_id = $form;
118
- if ( $form === null ) {
119
- $form_id = self::get_current_form_id();
120
- } else if ( $form && is_object($form) ) {
121
- $form_id = $form->id;
122
- }
123
-
124
- $values = array();
125
- foreach ( array(
126
- 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form_id,
127
- 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
128
- 'keep_post' => '',
129
- ) as $var => $default ) {
130
- $values[ $var ] = FrmAppHelper::get_param( $var, $default );
131
- }
132
-
133
- return $values;
134
- }
135
-
136
- public static function set_current_form($form_id) {
137
- global $frm_vars;
138
-
139
- $query = array();
140
- if ( $form_id ) {
141
- $query['id'] = $form_id;
142
- }
143
-
144
- $frm_vars['current_form'] = FrmForm::get_published_forms( $query, 1 );
145
-
146
- return $frm_vars['current_form'];
147
- }
148
-
149
- public static function get_current_form($form_id = 0) {
150
- global $frm_vars, $wpdb;
151
-
152
- if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) {
153
- return $frm_vars['current_form'];
154
- }
155
-
156
- $form_id = (int) FrmAppHelper::get_param('form', $form_id);
157
- return self::set_current_form($form_id);
158
- }
159
-
160
- public static function get_current_form_id() {
161
- $form = self::get_current_form();
162
- $form_id = $form ? $form->id : 0;
163
-
164
- return $form_id;
165
- }
166
-
167
- /**
168
- * If $entry is numeric, get the entry object
169
- * @param int|object $entry by reference
170
- *
171
- */
172
- public static function maybe_get_entry( &$entry ) {
173
- if ( $entry && is_numeric($entry) ) {
174
- $entry = FrmEntry::getOne($entry);
175
- }
176
- }
177
-
178
- public static function fill_entry_values($atts, $f, array &$values) {
179
- if ( FrmFieldsHelper::is_no_save_field($f->type) ) {
180
- return;
181
- }
182
-
183
- if ( $atts['default_email'] ) {
184
- $values[ $f->id ] = array( 'label' => '['. $f->id .' show=field_label]', 'val' => '['. $f->id .']' );
185
- return;
186
- }
187
-
188
- //Remove signature from default-message shortcode
189
- if ( $f->type == 'signature' ) {
190
- return;
191
- }
192
-
193
- if ( $atts['entry'] && ! isset( $atts['entry']->metas[ $f->id ] ) ) {
194
- // In case include_blank is set
195
- $atts['entry']->metas[ $f->id ] = '';
196
-
197
- if ( FrmAppHelper::pro_is_installed() ) {
198
- // If field is a post field
199
- if ( $atts['entry']->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
200
- $p_val = FrmProEntryMetaHelper::get_post_value($atts['entry']->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
201
- 'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
202
- 'form_id' => $atts['entry']->form_id, 'field' => $f, 'type' => $f->type,
203
- 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
204
- ));
205
- if ( $p_val != '' ) {
206
- $atts['entry']->metas[ $f->id ] = $p_val;
207
- }
208
  }
209
-
210
- // If field is in a repeating section
211
- if ( $atts['entry']->form_id != $f->form_id ) {
212
- // get entry ids linked through repeat field or embeded form
213
- $child_entries = FrmProEntry::get_sub_entries($atts['entry']->id, true);
214
- $val = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $f);
215
- if ( ! empty( $val ) ) {
216
- //Flatten multi-dimensional array for multi-file upload field
217
- self::flatten_multi_file_upload( $val, $f );
218
- $atts['entry']->metas[ $f->id ] = $val;
219
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  }
221
- }
222
-
223
- // Don't include blank values
224
- if ( ! $atts['include_blank'] && FrmAppHelper::is_empty_value( $atts['entry']->metas[ $f->id ] ) ) {
225
- return;
226
- }
227
  }
228
 
229
- $val = '';
230
- if ( $atts['entry'] ) {
231
- $prev_val = maybe_unserialize( $atts['entry']->metas[ $f->id ] );
232
- $meta = array( 'item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
233
-
234
- //This filter applies to the default-message shortcode and frm-show-entry shortcode only
235
- if ( isset($atts['filter']) && $atts['filter'] == false ) {
236
- $val = $prev_val;
237
- } else {
238
- $val = apply_filters('frm_email_value', $prev_val, (object) $meta, $atts['entry']);
239
  }
240
- }
241
-
242
- self::textarea_display_value( $val, $f->type, $atts['plain_text'] );
243
-
244
- if ( is_array($val) && $atts['format'] == 'text' ) {
245
- $val = implode(', ', $val);
246
- }
247
 
248
- if ( $atts['format'] != 'text' ) {
249
- $values[ $f->field_key ] = $val;
250
- } else {
251
- $values[ $f->id ] = array( 'label' => $f->name, 'val' => $val );
252
- }
253
- }
254
 
255
- /**
256
- * Flatten multi-dimensional array for multi-file upload fields
257
- * @since 2.0
258
- */
259
- public static function flatten_multi_file_upload( &$val, $field ) {
260
- if ( $field->type == 'file' && isset( $field->field_options['multiple'] ) && $field->field_options['multiple'] ) {
261
- $val = FrmAppHelper::array_flatten( $val );
262
- }
263
- }
264
-
265
- /**
266
- * Replace returns with HTML line breaks for display
267
- * @since 2.0
268
- */
269
- public static function textarea_display_value( &$value, $type, $plain_text ) {
270
- if ( $type == 'textarea' && ! $plain_text ) {
271
- $value = str_replace( array("\r\n", "\r", "\n"), ' <br/>', $value);
272
- }
273
- }
274
 
275
- public static function fill_entry_user_info($atts, array &$values) {
276
- if ( ! $atts['user_info'] ) {
277
- return;
278
- }
279
 
280
- if ( isset($atts['entry']->description) ) {
281
- $data = maybe_unserialize($atts['entry']->description);
282
- } else if ( $atts['default_email'] ) {
283
- $atts['entry']->ip = '[ip]';
284
- $data = array(
285
- 'browser' => '[browser]',
286
- 'referrer' => '[referrer]',
287
- );
288
- } else {
289
- $data = array(
290
- 'browser' => '',
291
- 'referrer' => '',
292
- );
293
- }
294
 
295
- if ( $atts['format'] != 'text' ) {
296
- $values['ip'] = $atts['entry']->ip;
297
- $values['browser'] = self::get_browser($data['browser']);
298
- $values['referrer'] = $data['referrer'];
299
- } else {
300
- //$content .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n";
301
- $values['ip'] = array( 'label' => __( 'IP Address', 'formidable' ), 'val' => $atts['entry']->ip);
302
- $values['browser'] = array(
303
- 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
304
- 'val' => self::get_browser($data['browser']),
305
- );
306
- $values['referrer'] = array( 'label' => __( 'Referrer', 'formidable' ), 'val' => $data['referrer']);
307
- }
308
  }
309
-
310
- public static function convert_entry_to_content($values, $atts, array &$content) {
311
-
312
- if ( $atts['plain_text'] ) {
313
- $bg_color_alt = $row_style = '';
314
- } else {
315
- $default_settings = apply_filters('frm_show_entry_styles', array(
316
- 'border_color' => 'dddddd',
317
- 'bg_color' => 'f7f7f7',
318
- 'text_color' => '444444',
319
- 'font_size' => '12px',
320
- 'border_width' => '1px',
321
- 'alt_bg_color' => 'ffffff',
322
- ) );
323
-
324
- // merge defaults, global settings, and shortcode options
325
- foreach ( $default_settings as $key => $setting ) {
326
- if ( $atts[ $key ] != '' ) {
327
- continue;
328
- }
329
-
330
- $atts[ $key ] = $setting;
331
- unset($key, $setting);
332
- }
333
-
334
- unset($default_settings);
335
-
336
- $content[] = '<table cellspacing="0" style="font-size:'. $atts['font_size'] .';line-height:135%; border-bottom:'. $atts['border_width'] .' solid #'. $atts['border_color'] .';"><tbody>'."\r\n";
337
- $atts['bg_color'] = ' style="background-color:#'. $atts['bg_color'] .';"';
338
- $bg_color_alt = ' style="background-color:#'. $atts['alt_bg_color'] .';"';
339
- $row_style = 'style="text-align:'. ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) .';color:#'. $atts['text_color'] .';padding:7px 9px;border-top:'. $atts['border_width'] .' solid #'. $atts['border_color'] .'"';
340
- }
341
-
342
- $odd = true;
343
- foreach ( $values as $id => $value ) {
344
- if ( $atts['plain_text'] ) {
345
- if ( 'rtl' == $atts['direction'] ) {
346
- $content[] = $value['val'] . ' :'. $value['label'] ."\r\n";
347
- } else {
348
- $content[] = $value['label'] . ': '. $value['val'] ."\r\n";
349
- }
350
- continue;
351
- }
352
-
353
- if ( $atts['default_email'] && is_numeric($id) ) {
354
- $content[] = '[if '. $id .']<tr style="[frm-alt-color]">';
355
- } else {
356
- $content[] = '<tr'. ( $odd ? $atts['bg_color'] : $bg_color_alt ) .'>';
357
- }
358
-
359
- if ( 'rtl' == $atts['direction'] ) {
360
- $content[] = '<td '. $row_style .'>'. $value['val'] .'</td><th '. $row_style .'>'. $value['label'] . '</th>';
361
- } else {
362
- $content[] = '<th '. $row_style .'>'. $value['label'] .'</th><td '. $row_style .'>'. $value['val'] .'</td>';
363
- }
364
- $content[] = '</tr>'. "\r\n";
365
-
366
- if ( $atts['default_email'] && is_numeric($id) ) {
367
- $content[] = '[/if '. $id .']';
368
- }
369
- $odd = $odd ? false : true;
370
- }
371
-
372
- if ( ! $atts['plain_text'] ) {
373
- $content[] = '</tbody></table>';
374
- }
375
  }
376
-
377
  public static function replace_default_message($message, $atts) {
378
- if ( strpos($message, '[default-message') === false &&
379
- strpos($message, '[default_message') === false &&
380
- ! empty( $message ) ) {
381
  return $message;
382
  }
383
-
384
  if ( empty($message) ) {
385
  $message = '[default-message]';
386
  }
387
-
388
  preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
389
-
390
  foreach ( $shortcodes[0] as $short_key => $tag ) {
391
- $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
392
- if ( $add_atts ) {
393
  $this_atts = array_merge($atts, $add_atts);
394
  } else {
395
  $this_atts = $atts;
396
  }
397
-
398
  $default = FrmEntriesController::show_entry_shortcode($this_atts);
399
-
400
  // Add the default message
401
- $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
402
  }
403
 
404
  return $message;
405
  }
 
406
 
407
- public static function prepare_display_value($entry, $field, $atts) {
408
- $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
409
- if ( FrmAppHelper::pro_is_installed() ) {
410
- FrmProEntriesHelper::get_dfe_values($field, $entry, $field_value);
411
- }
412
-
413
- if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
414
- return self::display_value($field_value, $field, $atts);
415
- }
416
-
417
- // this is an embeded form
418
- $val = '';
419
-
420
- if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
421
- //this is a repeating section
422
- $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id) );
423
- } else {
424
- // get all values for this field
425
- $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
426
-
427
- if ( $child_values ) {
428
- $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
429
- //$atts['post_id']
430
- }
431
- }
432
-
433
- $field_value = array();
434
-
435
- if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
436
- return $val;
437
- }
438
-
439
- foreach ( $child_entries as $child_entry ) {
440
- $atts['item_id'] = $child_entry->id;
441
- $atts['post_id'] = $child_entry->post_id;
442
-
443
- // get the value for this field -- check for post values as well
444
- $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
445
-
446
- if ( $entry_val ) {
447
- // foreach entry get display_value
448
- $field_value[] = self::display_value($entry_val, $field, $atts);
449
- }
450
-
451
- unset($child_entry);
452
- }
453
-
454
- $val = implode(', ', (array) $field_value );
455
-
456
- return $val;
457
- }
458
-
459
- /**
460
- * Prepare the saved value for display
461
- * @return string
462
- */
463
- public static function display_value($value, $field, $atts = array()) {
464
-
465
- $defaults = array(
466
- 'type' => '', 'html' => false, 'show_filename' => true,
467
- 'truncate' => false, 'sep' => ', ', 'post_id' => 0,
468
- 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0,
469
- );
470
-
471
- $atts = wp_parse_args( $atts, $defaults );
472
- $atts = apply_filters('frm_display_value_atts', $atts, $field, $value);
473
-
474
- if ( ! isset($field->field_options['post_field']) ) {
475
- $field->field_options['post_field'] = '';
476
- }
477
-
478
- if ( ! isset($field->field_options['custom_field']) ) {
479
- $field->field_options['custom_field'] = '';
480
- }
481
-
482
- if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
483
- $atts['pre_truncate'] = $atts['truncate'];
484
- $atts['truncate'] = true;
485
- $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0;
486
-
487
- $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts);
488
- $atts['truncate'] = $atts['pre_truncate'];
489
- }
490
-
491
- if ( $value == '' ) {
492
- return $value;
493
- }
494
-
495
- $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts);
496
-
497
- $new_value = '';
498
-
499
- if ( is_array($value) && $atts['type'] != 'file' ) {
500
- foreach ( $value as $val ) {
501
- if ( is_array($val) ) {
502
- //TODO: add options for display (li or ,)
503
- $new_value .= implode($atts['sep'], $val);
504
- if ( $atts['type'] != 'data' ) {
505
- $new_value .= '<br/>';
506
- }
507
- }
508
- unset($val);
509
- }
510
- }
511
-
512
- if ( ! empty($new_value) ) {
513
- $value = $new_value;
514
- } else if ( is_array($value) && $atts['type'] != 'file' ) {
515
- $value = implode($atts['sep'], $value);
516
- }
517
-
518
- if ( $atts['truncate'] && $atts['type'] != 'image' ) {
519
- $value = FrmAppHelper::truncate($value, 50);
520
- }
521
 
522
- return apply_filters('frm_display_value', $value, $field, $atts);
523
- }
524
-
525
- public static function set_posted_value($field, $value, $args) {
526
- // If validating a field with "other" opt, set back to prev value now
527
- if ( isset( $args['other'] ) && $args['other'] ) {
528
- $value = $args['temp_value'];
529
- }
530
- if ( empty($args['parent_field_id']) ) {
531
- $_POST['item_meta'][ $field->id ] = $value;
532
- } else {
533
- $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
534
- }
535
- }
536
-
537
- public static function get_posted_value($field, &$value, $args) {
538
- $field_id = is_object( $field ) ? $field->id : $field;
539
-
540
- if ( empty($args['parent_field_id']) ) {
541
- $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : '';
542
- } else {
543
- $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : '';
544
- }
545
- }
546
-
547
- /**
548
- * Check if field has an "Other" option and if any other values are posted
549
- *
550
- * @since 2.0
551
- *
552
- * @param object $field
553
- * @param string|array $value
554
- * @param array $args
555
- */
556
- public static function maybe_set_other_validation( $field, &$value, &$args ) {
557
- $args['other'] = false;
558
- if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) {
559
- return;
560
- }
561
-
562
- // Get other value for fields in repeating section
563
- self::set_other_repeating_vals( $field, $value, $args );
564
-
565
- // Check if there are any posted "Other" values
566
- if ( isset( $field->field_options['other'] ) && $field->field_options['other'] && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
567
-
568
- // Save original value
569
- $args['temp_value'] = $value;
570
- $args['other'] = true;
571
- $other_vals = $_POST['item_meta']['other'][ $field->id ];
572
-
573
- // Set the validation value now
574
- self::set_other_validation_val( $value, $other_vals, $field, $args );
575
- }
576
- }
577
-
578
- /**
579
- * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
580
- *
581
- * @since 2.0
582
- *
583
- * @param object $field
584
- * @param string|array $value
585
- * @param array $args
586
- */
587
- public static function set_other_repeating_vals( $field, &$value, &$args ) {
588
- if ( ! $args['parent_field_id'] ) {
589
- return;
590
- }
591
-
592
- // Check if there are any other posted "other" values for this field
593
- if ( isset( $field->field_options['other'] ) && $field->field_options['other'] && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) {
594
- // Save original value
595
- $args['temp_value'] = $value;
596
- $args['other'] = true;
597
-
598
- $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ];
599
-
600
- // Set the validation value now
601
- self::set_other_validation_val( $value, $other_vals, $field, $args );
602
- }
603
- }
604
-
605
- /**
606
- * Modify value used for validation
607
- * This function essentially removes the "Other" radio or checkbox value from the $value being validated.
608
- * It also adds any text from the free text fields to the value
609
- *
610
- * Needs to accommodate for times when other opt is selected, but no other free text is entered
611
- *
612
- * @since 2.0
613
- *
614
- * @param string|array $value
615
- * @param string|array $other_vals (usually of posted values)
616
- * @param object $field
617
- * @param array $args
618
- */
619
- public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
620
- // Checkboxes and multi-select dropdowns
621
- if ( is_array( $value ) && $field->type == 'checkbox' ) {
622
- // Combine "Other" values with checked values. "Other" values will override checked box values.
623
- $value = array_merge( $value, $other_vals );
624
- $value = array_filter( $value );
625
- if ( count( $value ) == 0 ) {
626
- $value = '';
627
- }
628
- } else {
629
- // Radio and dropdowns
630
- $other_key = array_filter( array_keys($field->options), 'is_string');
631
- $other_key = reset( $other_key );
632
-
633
- // Multi-select dropdown
634
- if ( is_array( $value ) ) {
635
- $o_key = array_search( $field->options[ $other_key ], $value );
636
- if ( $o_key ) {
637
- // Modify original value so key is preserved
638
- $value[ $other_key ] = $value[ $o_key ];
639
- unset( $value[ $o_key ] );
640
- $args['temp_value'] = $value;
641
- $value[ $other_key ] = reset( $other_vals );
642
- }
643
- } else if ( $field->options[ $other_key ] == $value ) {
644
- $value = $other_vals;
645
- }
646
- }
647
- }
648
-
649
- public static function entries_dropdown() {
650
  _deprecated_function( __FUNCTION__, '1.07.09');
651
  }
652
-
653
- public static function enqueue_scripts($params) {
654
  do_action('frm_enqueue_form_scripts', $params);
655
  }
656
-
657
  // Add submitted values to a string for spam checking
658
  public static function entry_array_to_string($values) {
659
  $content = '';
@@ -661,78 +195,14 @@ class FrmEntriesHelper {
661
  if ( $content != '' ) {
662
  $content .= "\n\n";
663
  }
664
-
665
  if ( is_array($val) ) {
666
  $val = implode(',', $val);
667
  }
668
-
669
  $content .= $val;
670
  }
671
-
672
  return $content;
673
  }
674
-
675
- public static function get_browser($u_agent) {
676
- $bname = __( 'Unknown', 'formidable' );
677
- $platform = __( 'Unknown', 'formidable' );
678
- $ub = '';
679
-
680
- //First get the platform?
681
- if ( preg_match('/linux/i', $u_agent) ) {
682
- $platform = 'Linux';
683
- } else if ( preg_match('/macintosh|mac os x/i', $u_agent) ) {
684
- $platform = 'Mac';
685
- } else if ( preg_match('/windows|win32/i', $u_agent) ) {
686
- $platform = 'Windows';
687
- }
688
-
689
- $agent_options = array(
690
- 'Firefox' => 'Mozilla Firefox',
691
- 'Chrome' => 'Google Chrome',
692
- 'Safari' => 'Apple Safari',
693
- 'Opera' => 'Opera',
694
- 'Netscape' => 'Netscape',
695
- );
696
-
697
- // Next get the name of the useragent yes seperately and for good reason
698
- if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
699
- $bname = 'Internet Explorer';
700
- $ub = 'MSIE';
701
- } else {
702
- foreach ( $agent_options as $agent_key => $agent_name ) {
703
- if ( strpos( $u_agent, $agent_key ) !== false ) {
704
- $bname = $agent_name;
705
- $ub = $agent_key;
706
- break;
707
- }
708
- }
709
- }
710
-
711
- // finally get the correct version number
712
- $known = array( 'Version', $ub, 'other');
713
- $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
714
- preg_match_all($pattern, $u_agent, $matches); // get the matching numbers
715
-
716
- // see how many we have
717
- $i = count($matches['browser']);
718
- if ( $i != 1 ) {
719
- //we will have two since we are not using 'other' argument yet
720
- //see if version is before or after the name
721
- if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
722
- $version = $matches['version'][0];
723
- } else {
724
- $version = $matches['version'][1];
725
- }
726
- } else {
727
- $version = $matches['version'][0];
728
- }
729
-
730
- // check if we have a number
731
- if ( $version == '') {
732
- $version = '?';
733
- }
734
-
735
- return $bname .' '. $version .' / '. $platform;
736
- }
737
-
738
  }
1
  <?php
 
 
 
2
 
3
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
4
 
5
+ if(class_exists('FrmEntriesHelper'))
6
+ return;
7
+
8
+ class FrmEntriesHelper{
 
 
9
 
10
+ public static function setup_new_vars($fields, $form='', $reset=false){
11
+ global $frm_settings, $frm_vars;
12
+ $values = array();
13
+ foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default)
14
+ $values[$var] = FrmAppHelper::get_post_param($var, $default);
15
+
16
  $values['fields'] = array();
17
+ if (empty($fields)){
18
  return apply_filters('frm_setup_new_entry', $values);
19
  }
20
+
21
  foreach ( (array) $fields as $field ) {
22
+ $field->field_options = maybe_unserialize($field->field_options);
23
  $default = $field->default_value;
24
  $posted_val = false;
25
+
26
+ if ( $reset ) {
27
+ $new_value = $default;
28
+ } else if ( $_POST && isset($_POST['item_meta'][$field->id]) && $_POST['item_meta'][$field->id] != '' ) {
29
+ $new_value = stripslashes_deep($_POST['item_meta'][$field->id]);
30
  $posted_val = true;
31
  } else if ( isset($field->field_options['clear_on_focus']) && $field->field_options['clear_on_focus'] ) {
32
  $new_value = '';
33
+ } else {
34
+ $new_value = $default;
35
  }
36
+
37
  $is_default = ($new_value == $default) ? true : false;
38
+
39
  //If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
40
+ if ( $field && ( ( $field->type == 'data' && $field->field_options['data_type'] == 'checkbox' ) || $field->type == 'checkbox' || ( $field->type == 'select' && isset($field->field_options['multiple']) && $field->field_options['multiple'] == 1 ) ) ) {
41
+ $return_array = true;
42
+ } else {
43
+ $return_array = false;
44
+ }
45
+
46
  $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
47
+
48
+ if ( !is_array($new_value) ) {
49
  if ( $is_default ) {
50
  $new_value = $field->default_value;
51
+ } else if ( !$posted_val ) {
52
  $new_value = apply_filters('frm_filter_default_value', $new_value, $field);
53
  }
54
+
55
  $new_value = str_replace('"', '&quot;', $new_value);
56
  }
57
+
58
+ unset($is_default);
59
+ unset($posted_val);
60
+
61
+ $field_array = array(
62
+ 'id' => $field->id,
63
+ 'value' => $new_value,
64
+ 'default_value' => $field->default_value,
65
+ 'name' => $field->name,
66
+ 'description' => $field->description,
67
+ 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
68
+ 'options' => $field->options,
69
+ 'required' => $field->required,
70
+ 'field_key' => $field->field_key,
71
+ 'field_order' => $field->field_order,
72
+ 'form_id' => $field->form_id
73
+ );
74
+
75
+ $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
76
+ $opt_defaults['required_indicator'] = '';
77
+
78
+ foreach ($opt_defaults as $opt => $default_opt){
79
+ $field_array[$opt] = (isset($field->field_options[$opt]) && $field->field_options[$opt] != '') ? $field->field_options[$opt] : $default_opt;
80
+ unset($opt);
81
+ unset($default_opt);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  }
83
+
84
+ unset($opt_defaults);
85
+
86
+ if ($field_array['size'] == '')
87
+ $field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
88
+
89
+
90
+ if ($field_array['custom_html'] == '')
91
+ $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
92
+
93
+ $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
94
+
95
+ foreach((array)$field->field_options as $k => $v){
96
+ if(!isset($field_array[$k]))
97
+ $field_array[$k] = $v;
98
+ unset($k);
99
+ unset($v);
100
+ }
101
+
102
+ $values['fields'][] = $field_array;
103
+
104
+ if (!$form or !isset($form->id)){
105
+ $frm_form = new FrmForm();
106
+ $form = $frm_form->getOne($field->form_id);
107
  }
 
 
 
 
 
 
108
  }
109
 
110
+ $form->options = maybe_unserialize($form->options);
111
+ if (is_array($form->options)){
112
+ foreach ($form->options as $opt => $value)
113
+ $values[$opt] = FrmAppHelper::get_post_param($opt, $value);
 
 
 
 
 
 
114
  }
115
+
116
+ if (!isset($values['custom_style']))
117
+ $values['custom_style'] = ($frm_settings->load_style != 'none');
118
+
119
+ if (!isset($values['email_to']))
120
+ $values['email_to'] = '';
 
121
 
122
+ if (!isset($values['submit_value']))
123
+ $values['submit_value'] = $frm_settings->submit_value;
 
 
 
 
124
 
125
+ if (!isset($values['success_msg']))
126
+ $values['success_msg'] = $frm_settings->success_msg;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
+ if (!isset($values['akismet']))
129
+ $values['akismet'] = '';
 
 
130
 
131
+ if (!isset($values['before_html']))
132
+ $values['before_html'] = FrmFormsHelper::get_default_html('before');
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
+ if (!isset($values['after_html']))
135
+ $values['after_html'] = FrmFormsHelper::get_default_html('after');
136
+
137
+ if (!isset($values['submit_html']))
138
+ $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
139
+
140
+ return apply_filters('frm_setup_new_entry', $values);
 
 
 
 
 
 
141
  }
142
+
143
+ public static function setup_edit_vars($values, $record){
144
+ //$values['description'] = maybe_unserialize( $record->description );
145
+ $values['item_key'] = isset($_POST['item_key']) ? $_POST['item_key'] : $record->item_key;
146
+ $values['form_id'] = $record->form_id;
147
+ $values['is_draft'] = $record->is_draft;
148
+ return apply_filters('frm_setup_edit_entry_vars', $values, $record);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
150
+
151
  public static function replace_default_message($message, $atts) {
152
+ if ( strpos($message, '[default-message') === false &&
153
+ strpos($message, '[default_message') === false &&
154
+ !empty($message) ) {
155
  return $message;
156
  }
157
+
158
  if ( empty($message) ) {
159
  $message = '[default-message]';
160
  }
161
+
162
  preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
163
+
164
  foreach ( $shortcodes[0] as $short_key => $tag ) {
165
+ $add_atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
166
+ if ( $add_atts ){
167
  $this_atts = array_merge($atts, $add_atts);
168
  } else {
169
  $this_atts = $atts;
170
  }
171
+
172
  $default = FrmEntriesController::show_entry_shortcode($this_atts);
173
+
174
  // Add the default message
175
+ $message = str_replace($shortcodes[0][$short_key], $default, $message);
176
  }
177
 
178
  return $message;
179
  }
180
+
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
+ public static function entries_dropdown( $form_id, $field_name, $field_value='', $blank=true, $blank_label='', $onchange=false ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  _deprecated_function( __FUNCTION__, '1.07.09');
185
  }
186
+
187
+ public static function enqueue_scripts($params){
188
  do_action('frm_enqueue_form_scripts', $params);
189
  }
190
+
191
  // Add submitted values to a string for spam checking
192
  public static function entry_array_to_string($values) {
193
  $content = '';
195
  if ( $content != '' ) {
196
  $content .= "\n\n";
197
  }
198
+
199
  if ( is_array($val) ) {
200
  $val = implode(',', $val);
201
  }
202
+
203
  $content .= $val;
204
  }
205
+
206
  return $content;
207
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
classes/helpers/FrmEntriesListHelper.php DELETED
@@ -1,264 +0,0 @@
1
- <?php
2
-
3
- class FrmEntriesListHelper extends FrmListHelper {
4
-
5
- public function prepare_items() {
6
- global $wpdb, $per_page;
7
-
8
- $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page');
9
-
10
- $form_id = $this->params['form'];
11
- if ( ! $form_id ) {
12
- $this->items = array();
13
- $this->set_pagination_args( array(
14
- 'total_items' => 0,
15
- 'per_page' => $per_page,
16
- ) );
17
- return;
18
- }
19
-
20
- $default_orderby = 'id';
21
- $default_order = 'DESC';
22
-
23
- $s_query = array( 'it.form_id' => $form_id );
24
-
25
- $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
26
-
27
- if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
28
- $fid = isset( $_REQUEST['fid'] ) ? sanitize_text_field( $_REQUEST['fid'] ) : '';
29
- $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid);
30
- }
31
-
32
- $orderby = isset( $_REQUEST['orderby'] ) ? sanitize_title( $_REQUEST['orderby'] ) : $default_orderby;
33
- if ( strpos($orderby, 'meta') !== false ) {
34
- $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
35
- $orderby .= in_array( $order_field_type, array( 'number', 'scale') ) ? ' +0 ' : '';
36
- }
37
-
38
- $order = isset( $_REQUEST['order'] ) ? sanitize_title( $_REQUEST['order'] ) : $default_order;
39
- $order = ' ORDER BY ' . $orderby . ' ' . $order;
40
-
41
- $page = $this->get_pagenum();
42
- $start = (int) isset( $_REQUEST['start'] ) ? absint( $_REQUEST['start'] ) : ( ( $page - 1 ) * $per_page );
43
-
44
- $this->items = FrmEntry::getAll($s_query, $order, ' LIMIT '. $start .','. $per_page, true, false);
45
- $total_items = FrmEntry::getRecordCount($s_query);
46
-
47
- $this->set_pagination_args( array(
48
- 'total_items' => $total_items,
49
- 'per_page' => $per_page,
50
- ) );
51
- }
52
-
53
- public function no_items() {
54
- $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
55
- if ( ! empty($s) ) {
56
- _e( 'No Entries Found', 'formidable' );
57
- return;
58
- }
59
-
60
- $form_id = $form = $this->params['form'];
61
- if ( $form_id ) {
62
- $form = FrmForm::getOne($form_id);
63
- }
64
- $colspan = $this->get_column_count();
65
-
66
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php');
67
- }
68
-
69
- public function search_box( $text, $input_id ) {
70
- if ( ! $this->has_items() && ! isset( $_REQUEST['s'] ) ) {
71
- return;
72
- }
73
-
74
- if ( isset($this->params['form']) ) {
75
- $form = FrmForm::getOne($this->params['form']);
76
- } else {
77
- $form = FrmForm::get_published_forms( array(), 1 );
78
- }
79
-
80
- if ( $form ) {
81
- $field_list = FrmField::getAll( array( 'fi.form_id' => $form->id, 'fi.type not' => FrmFieldsHelper::no_save_fields() ), 'field_order');
82
- }
83
-
84
- $fid = isset($_REQUEST['fid']) ? esc_attr( stripslashes( $_REQUEST['fid'] ) ) : '';
85
- $input_id = $input_id . '-search-input';
86
- $search_str = isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
87
-
88
- foreach ( array( 'orderby', 'order') as $get_var ) {
89
- if ( ! empty( $_REQUEST[ $get_var ] ) ) {
90
- echo '<input type="hidden" name="'. esc_attr( $get_var ) .'" value="' . esc_attr( $_REQUEST[ $get_var ] ) . '" />';
91
- }
92
- }
93
-
94
- ?>
95
- <div class="search-box frm_sidebar">
96
- <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ) ?>"><?php echo esc_attr( $text ); ?>:</label>
97
- <input type="text" id="<?php echo esc_attr( $input_id ) ?>" name="s" value="<?php echo esc_attr( $search_str ); ?>" />
98
- <?php
99
- if ( isset( $field_list ) && ! empty( $field_list ) ) { ?>
100
- <select name="fid" class="hide-if-js">
101
- <option value="">&mdash; <?php _e( 'All Fields', 'formidable' ) ?> &mdash;</option>
102
- <option value="created_at" <?php selected($fid, 'created_at') ?>><?php _e( 'Entry creation date', 'formidable' ) ?></option>
103
- <option value="id" <?php selected($fid, 'id') ?>><?php _e( 'Entry ID', 'formidable' ) ?></option>
104
- <?php foreach ( $field_list as $f ) { ?>
105
- <option value="<?php echo ($f->type == 'user_id') ? 'user_id' : $f->id ?>" <?php selected($fid, $f->id) ?>><?php echo FrmAppHelper::truncate($f->name, 30); ?></option>
106
- <?php } ?>
107
- </select>
108
-
109
- <div class="button dropdown hide-if-no-js">
110
- <a href="#" id="frm-fid-search" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e( 'Search', 'formidable' ) ?> <b class="caret"></b></a>
111
- <ul class="frm-dropdown-menu pull-right" id="frm-fid-search-menu" role="menu" aria-labelledby="frm-fid-search">
112
- <li><a href="#" id="fid-">&mdash; <?php _e( 'All Fields', 'formidable' ) ?> &mdash;</a></li>
113
- <li><a href="#" id="fid-created_at"><?php _e( 'Entry creation date', 'formidable' ) ?></a></li>
114
- <li><a href="#" id="fid-id"><?php _e( 'Entry ID', 'formidable' ) ?></a></li>
115
- <?php
116
- foreach ( $field_list as $f ) { ?>
117
- <li><a href="#" id="fid-<?php echo ($f->type == 'user_id') ? 'user_id' : $f->id ?>"><?php echo FrmAppHelper::truncate($f->name, 30); ?></a></li>
118
- <?php
119
- unset($f);
120
- } ?>
121
- </ul>
122
- </div>
123
- <?php submit_button( $text, 'button hide-if-js', false, false, array( 'id' => 'search-submit') );
124
- } else {
125
- submit_button( $text, 'button', false, false, array( 'id' => 'search-submit') );
126
- if ( ! empty( $search_str ) ) { ?>
127
- <a href="<?php echo admin_url('admin.php?page=formidable-entries&frm_action=list&form='.$form->id) ?>"><?php _e( 'Reset', 'formidable' ) ?></a>
128
- <?php
129
- }
130
- } ?>
131
-
132
- </div>
133
- <?php
134
- }
135
-
136
- public function single_row( $item, $style = '' ) {
137
- // Set up the hover actions for this user
138
- $actions = array();
139
- $view_link = '?page=formidable-entries&frm_action=show&id='. $item->id;
140
-
141
- $this->get_actions( $actions, $item, $view_link );
142
-
143
- $action_links = $this->row_actions( $actions );
144
-
145
- // Set up the checkbox ( because the user is editable, otherwise its empty )
146
- $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
147
-
148
- $r = "<tr id='item-action-{$item->id}'$style>";
149
-
150
- list( $columns, $hidden ) = $this->get_column_info();
151
- $action_col = false;
152
-
153
- foreach ( $columns as $column_name => $column_display_name ) {
154
- $class = $column_name .' column-'. $column_name;
155
-
156
- if ( in_array( $column_name, $hidden ) ) {
157
- $class .= ' frm_hidden';
158
- } else if ( ! $action_col && ! in_array($column_name, array( 'cb', 'id', 'form_id', 'post_id')) ) {
159
- $action_col = $column_name;
160
- }
161
-
162
- $attributes = 'class="'. $class .'"';
163
- unset($class);
164
-
165
- $col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
166
-
167
- switch ( $col_name ) {
168
- case 'cb':
169
- $r .= "<th scope='row' class='check-column'>$checkbox</th>";
170
- break;
171
- case 'ip':
172
- case 'id':
173
- case 'item_key':
174
- $val = $item->{$col_name};
175
- break;
176
- case 'name':
177
- case 'description':
178
- $val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100);
179
- break;
180
- case 'created_at':
181
- case 'updated_at':
182
- $date = FrmAppHelper::get_formatted_time($item->{$col_name});
183
- $val = '<abbr title="' . FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) . '">' . $date . '</abbr>';
184
- break;
185
- case 'is_draft':
186
- $val = empty($item->is_draft) ? __( 'No') : __( 'Yes');
187
- break;
188
- case 'form_id':
189
- $val = FrmFormsHelper::edit_form_link($item->form_id);
190
- break;
191
- case 'post_id':
192
- $val = FrmAppHelper::post_edit_link($item->post_id);
193
- break;
194
- case 'user_id':
195
- $user = get_userdata($item->user_id);
196
- $val = $user->user_login;
197
- break;
198
- default:
199
- if ( strpos($col_name, 'frmsep_') === 0 ) {
200
- $sep_val = true;
201
- $col_name = str_replace('frmsep_', '', $col_name);
202
- } else {
203
- $sep_val = false;
204
- }
205
-
206
- if ( strpos($col_name, '-_-') ) {
207
- list($col_name, $embedded_field_id) = explode('-_-', $col_name);
208
- }
209
-
210
- $col = FrmField::getOne($col_name);
211
-
212
- $atts = array(
213
- 'type' => $col->type, 'truncate' => true,
214
- 'post_id' => $item->post_id, 'entry_id' => $item->id,
215
- 'embedded_field_id' => 0,
216
- );
217
-
218
- if ( $sep_val ) {
219
- $atts['saved_value'] = true;
220
- }
221
-
222
- if ( isset($embedded_field_id) ) {
223
- $atts['embedded_field_id'] = $embedded_field_id;
224
- unset($embedded_field_id);
225
- }
226
-
227
- $val = FrmEntriesHelper::prepare_display_value($item, $col, $atts);
228
-
229
- break;
230
- }
231
-
232
- if ( isset( $val ) ) {
233
- $r .= "<td $attributes>";
234
- if ( $column_name == $action_col ) {
235
- $edit_link = '?page=formidable-entries&frm_action=edit&id='. $item->id;
236
- $r .= '<a href="'. (isset($actions['edit']) ? $edit_link : $view_link) .'" class="row-title" >'. $val .'</a> ';
237
- $r .= $action_links;
238
- } else {
239
- $r .= $val;
240
- }
241
- $r .= '</td>';
242
- }
243
- unset($val);
244
- }
245
- $r .= '</tr>';
246
-
247
- return $r;
248
- }
249
-
250
- /**
251
- * @param string $view_link
252
- */
253
- private function get_actions( &$actions, $item, $view_link ) {
254
- $actions['view'] = '<a href="' . esc_url( $view_link ) . '">'. __( 'View', 'formidable' ) .'</a>';
255
-
256
- if ( current_user_can('frm_delete_entries') ) {
257
- $delete_link = '?page=formidable-entries&frm_action=destroy&id='. $item->id .'&form='. $this->params['form'];
258
- $actions['delete'] = '<a href="' . wp_nonce_url( $delete_link ) . '" class="submitdelete" onclick="return confirm(\''. __( 'Are you sure you want to delete that?', 'formidable' ) .'\')">' . __( 'Delete' ) . '</a>';
259
- }
260
-
261
- $actions = apply_filters('frm_row_actions', $actions, $item);
262
- }
263
-
264
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -1,296 +1,195 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
 
6
- class FrmFieldsHelper {
 
 
 
7
 
8
- public static function field_selection() {
 
 
9
  $fields = apply_filters('frm_available_fields', array(
10
- 'text' => __( 'Single Line Text', 'formidable' ),
11
- 'textarea' => __( 'Paragraph Text', 'formidable' ),
12
- 'checkbox' => __( 'Checkboxes', 'formidable' ),
13
- 'radio' => __( 'Radio Buttons', 'formidable' ),
14
- 'select' => __( 'Dropdown', 'formidable' ),
15
- 'email' => __( 'Email Address', 'formidable' ),
16
- 'url' => __( 'Website/URL', 'formidable' ),
17
- 'captcha' => __( 'reCAPTCHA', 'formidable' ),
18
  ));
19
-
20
  return $fields;
21
  }
22
-
23
- public static function pro_field_selection() {
24
  return apply_filters('frm_pro_available_fields', array(
25
- 'end_divider' => array(
26
- 'name' => __( 'End Section', 'formidable' ),
27
- 'switch_from' => 'divider',
28
- ),
29
- 'divider' => __( 'Section', 'formidable' ),
30
- 'break' => __( 'Page Break', 'formidable' ),
31
- 'file' => __( 'File Upload', 'formidable' ),
32
- 'rte' => __( 'Rich Text', 'formidable' ),
33
- 'number' => __( 'Number', 'formidable' ),
34
- 'phone' => __( 'Phone Number', 'formidable' ),
35
- 'date' => __( 'Date', 'formidable' ),
36
- 'time' => __( 'Time', 'formidable' ),
37
- 'image' => __( 'Image URL', 'formidable' ),
38
- 'scale' => __( 'Scale', 'formidable' ),
39
- 'data' => __( 'Dynamic Field', 'formidable' ),
40
- 'form' => __( 'Embed Form', 'formidable' ),
41
- 'hidden' => __( 'Hidden Field', 'formidable' ),
42
- 'user_id' => __( 'User ID (hidden)', 'formidable' ),
43
- 'password' => __( 'Password', 'formidable' ),
44
- 'html' => __( 'HTML', 'formidable' ),
45
- 'tag' => __( 'Tags', 'formidable' )
46
- //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
47
- //'city_selector' => 'US State/County/City selector',
48
- //'full_name' => 'First and Last Name',
49
- //'quiz' => 'Question and Answer' // for captcha alternative
50
  ));
51
  }
52
-
53
- public static function is_no_save_field($type) {
54
- return in_array($type, self::no_save_fields());
55
- }
56
-
57
- public static function no_save_fields() {
58
- return array( 'divider', 'end_divider', 'captcha', 'break', 'html' );
59
- }
60
-
61
- /**
62
- * Check if this is a multiselect dropdown field
63
- *
64
- * @since 2.0
65
- * @return boolean
66
- */
67
- public static function is_multiple_select($field) {
68
- if ( is_array($field) ) {
69
- return isset($field['multiple']) && $field['multiple'] && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'select') ) );
70
- } else {
71
- return isset($field->field_options['multiple']) && $field->field_options['multiple'] && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type']) && $field->field_options['data_type'] == 'select') ) );
72
- }
73
- }
74
-
75
- /**
76
- * Check if this field can hold an array of values
77
- *
78
- * @since 2.0
79
- *
80
- * @param array|object $field
81
- * @return boolean
82
- */
83
- public static function is_field_with_multiple_values( $field ) {
84
- if ( ! $field ) {
85
- return false;
86
- }
87
-
88
- if ( is_array( $field ) ) {
89
- // For field array
90
- return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field );
91
- } else {
92
- // For field object
93
- return $field->type == 'checkbox' || ( $field->type == 'data' && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select($field);
94
- }
95
- }
96
-
97
- /**
98
- * If $field is numeric, get the field object
99
- */
100
- public static function maybe_get_field( &$field ) {
101
- if ( ! is_object($field) ) {
102
- $field = FrmField::getOne($field);
103
- }
104
- }
105
-
106
- public static function setup_new_vars($type = '', $form_id = '') {
107
-
108
- if ( strpos($type, '|') ) {
109
- list($type, $setting) = explode('|', $type);
110
- }
111
-
112
- $defaults = self::get_default_field_opts($type, $form_id);
113
- $defaults['field_options']['custom_html'] = self::get_default_html($type);
114
 
115
  $values = array();
116
-
117
- foreach ( $defaults as $var => $default ) {
118
- if ( $var == 'field_options' ) {
119
  $values['field_options'] = array();
120
- foreach ( $default as $opt_var => $opt_default ) {
121
- $values['field_options'][ $opt_var ] = $opt_default;
122
- unset($opt_var, $opt_default);
 
123
  }
124
- } else {
125
- $values[ $var ] = $default;
126
- }
127
- unset($var, $default);
128
- }
129
-
130
- if ( isset( $setting ) && ! empty( $setting ) ) {
131
- if ( 'data' == $type ) {
132
- $values['field_options']['data_type'] = $setting;
133
- } else {
134
- $values['field_options'][ $setting ] = 1;
135
  }
136
- }
137
-
138
- if ( $type == 'radio' || $type == 'checkbox' ) {
139
- $values['options'] = serialize( array(
140
- __( 'Option 1', 'formidable' ),
141
- __( 'Option 2', 'formidable' ),
142
- ) );
143
- } else if ( $type == 'select' ) {
144
- $values['options'] = serialize( array(
145
- '', __( 'Option 1', 'formidable' ),
146
- ) );
147
- } else if ( $type == 'textarea' ) {
148
  $values['field_options']['max'] = '5';
149
- } else if ( $type == 'captcha' ) {
150
- $frm_settings = FrmAppHelper::get_settings();
151
  $values['invalid'] = $frm_settings->re_msg;
152
- } else if ( 'url' == $type ) {
153
- $values['name'] = __( 'Website', 'formidable' );
154
- }
155
-
156
  $fields = self::field_selection();
157
  $fields = array_merge($fields, self::pro_field_selection());
158
 
159
- if ( isset( $fields[ $type ] ) ) {
160
- $values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ];
161
- }
162
 
163
  unset($fields);
164
-
165
  return $values;
166
  }
167
-
168
- public static function get_html_id($field, $plus = '') {
169
- return apply_filters('frm_field_html_id', 'field_'. $field['field_key'] . $plus, $field);
170
- }
171
-
172
- public static function setup_edit_vars( $record, $doing_ajax = false ) {
173
- $values = array( 'id' => $record->id, 'form_id' => $record->form_id);
174
- $defaults = array( 'name' => $record->name, 'description' => $record->description);
175
  $default_opts = array(
176
- 'field_key' => $record->field_key, 'type' => $record->type,
177
- 'default_value'=> $record->default_value, 'field_order' => $record->field_order,
178
- 'required' => $record->required,
179
  );
180
-
181
- if ( $doing_ajax ) {
182
  $values = $values + $defaults + $default_opts;
183
  $values['form_name'] = '';
184
- } else {
185
- foreach ( $defaults as $var => $default ) {
186
- $values[ $var ] = htmlspecialchars( FrmAppHelper::get_param( $var, $default ) );
187
- unset($var, $default);
 
188
  }
189
-
190
- foreach ( array( 'field_key' => $record->field_key, 'type' => $record->type, 'default_value' => $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required ) as $var => $default ) {
191
- $values[ $var ] = FrmAppHelper::get_param( $var, $default );
192
- unset($var, $default);
 
193
  }
194
-
195
- $values['form_name'] = ($record->form_id) ? FrmForm::getName( $record->form_id ) : '';
196
- }
197
-
198
- unset($defaults, $default_opts);
199
-
 
 
 
200
  $values['options'] = $record->options;
201
  $values['field_options'] = $record->field_options;
202
-
203
  $defaults = self::get_default_field_opts($values['type'], $record, true);
204
-
205
- if ( $values['type'] == 'captcha' ) {
206
- $frm_settings = FrmAppHelper::get_settings();
207
  $defaults['invalid'] = $frm_settings->re_msg;
208
  }
209
-
210
- foreach ( $defaults as $opt => $default ) {
211
- $values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default;
212
- unset($opt, $default);
 
213
  }
214
 
215
  $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
216
-
217
- return apply_filters('frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax));
218
  }
219
-
220
- public static function get_default_field_opts( $type, $field, $limit = false ) {
221
  $field_options = array(
222
- 'size' => '', 'max' => '', 'label' => '', 'blank' => '',
223
  'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
224
  'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
225
- 'custom_html' => '',
226
  );
227
-
228
- if ( $limit ) {
229
  return $field_options;
230
- }
231
-
232
- global $wpdb;
233
-
234
  $form_id = (is_numeric($field)) ? $field : $field->form_id;
235
-
236
  $key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_fields', 'field_key') : $field->field_key;
237
-
238
- $field_count = FrmDb::get_count( $wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) );
239
-
240
- $frm_settings = FrmAppHelper::get_settings();
241
  return array(
242
- 'name' => __( 'Untitled', 'formidable' ), 'description' => '',
243
- 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'',
244
- 'field_order' => $field_count+1, 'required' => false,
245
  'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
246
- 'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id,
247
- 'field_options' => $field_options,
248
  );
249
  }
250
-
251
- public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
252
- global $wpdb;
253
-
254
- $values['field_key'] = FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_fields', 'field_key');
255
- $values['form_id'] = $form_id;
256
- $values['options'] = maybe_serialize($field->options);
257
- $values['default_value'] = maybe_serialize($field->default_value);
258
-
259
- foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
260
- $values[ $col ] = $field->{$col};
261
- }
262
- }
263
-
264
- /**
265
- * @since 2.0
266
- */
267
- public static function get_error_msg($field, $error) {
268
- $frm_settings = FrmAppHelper::get_settings();
269
- $default_settings = $frm_settings->default_options();
270
-
271
- $defaults = array(
272
- 'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => $field->name.' '. __( 'must be unique', 'formidable' )),
273
- 'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => $field->name.' '. __( 'is invalid', 'formidable' ))
274
- );
275
-
276
- $msg = ( $field->field_options[ $error ] == $defaults[ $error ]['full'] || empty( $field->field_options[ $error ] ) ) ? $defaults[ $error ]['part'] : $field->field_options[ $error ];
277
- return $msg;
278
- }
279
-
280
- public static function get_form_fields( $form_id, $error = false ) {
281
- $fields = FrmField::get_all_for_form($form_id);
282
- $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error);
283
  return $fields;
284
  }
285
-
286
- public static function get_default_html( $type = 'text' ) {
287
- if (apply_filters('frm_normal_field_type_html', true, $type)) {
288
- $input = (in_array($type, array( 'radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
289
  $for = '';
290
- if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale') ) ) {
291
  $for = 'for="field_[key]"';
292
- }
293
-
294
  $default_html = <<<DEFAULT_HTML
295
  <div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
296
  <label $for class="frm_primary_label">[field_name]
@@ -301,341 +200,198 @@ class FrmFieldsHelper {
301
  [if error]<div class="frm_error">[error]</div>[/if error]
302
  </div>
303
  DEFAULT_HTML;
304
- } else {
305
- $default_html = apply_filters('frm_other_custom_html', '', $type);
306
- }
307
 
308
  return apply_filters('frm_custom_html', $default_html, $type);
309
  }
310
-
311
- public static function replace_shortcodes($html, $field, $errors = array(), $form = false, $args = array()) {
312
  $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
313
-
314
- $defaults = array(
315
- 'field_name' => 'item_meta['. $field['id'] .']',
316
- 'field_id' => $field['id'],
317
- 'field_plus_id' => '',
318
- 'section_id' => '',
319
- );
320
- $args = wp_parse_args($args, $defaults);
321
- $field_name = $args['field_name'];
322
- $field_id = $args['field_id'];
323
- $html_id = self::get_html_id($field, $args['field_plus_id']);
324
-
325
- if ( self::is_multiple_select($field) ) {
326
  $field_name .= '[]';
327
- }
328
-
329
  //replace [id]
330
- $html = str_replace('[id]', $field_id, $html);
331
-
332
- // Remove the for attribute for captcha
333
- if ( $field['type'] == 'captcha' ) {
334
- $html = str_replace(' for="field_[key]"', '', $html);
335
- }
336
-
337
- // set the label for
338
- $html = str_replace('field_[key]', $html_id, $html);
339
-
340
- //replace [key]
341
  $html = str_replace('[key]', $field['field_key'], $html);
342
-
343
  //replace [description] and [required_label] and [error]
344
  $required = ($field['required'] == '0') ? '' : $field['required_indicator'];
345
- if ( ! is_array( $errors ) ) {
346
  $errors = array();
347
- }
348
- $error = isset($errors['field'. $field_id]) ? $errors['field'. $field_id] : false;
349
-
350
- //If field type is section heading, add class so a bottom margin can be added to either the h3 or description
351
- if ( $field['type'] == 'divider' ) {
352
- if ( isset( $field['description'] ) && $field['description'] ) {
353
- $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html );
354
- } else {
355
- $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html);
356
  }
357
- }
358
-
359
- foreach ( array( 'description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value) {
360
- self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html );
361
- }
362
 
 
 
 
363
  //replace [required_class]
364
- $required_class = ($field['required'] == '0') ? '' : ' frm_required_field';
365
- $html = str_replace('[required_class]', $required_class, $html);
366
-
367
  //replace [label_position]
368
- $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form);
369
- $field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top';
370
- $html = str_replace( '[label_position]', ( ( in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ) ? $field['label'] : ' frm_primary_label' ), $html );
371
-
372
  //replace [field_name]
373
  $html = str_replace('[field_name]', $field['name'], $html);
374
-
375
- //replace [error_class]
376
- $error_class = isset ( $errors['field'. $field_id] ) ? ' frm_blank_field' : '';
377
- self::get_more_field_classes( $error_class, $field, $field_id, $html );
 
 
 
 
 
 
378
  $html = str_replace('[error_class]', $error_class, $html);
379
-
380
  //replace [entry_key]
381
- $entry_key = ( $_GET && isset($_GET['entry']) ) ? $_GET['entry'] : '';
382
  $html = str_replace('[entry_key]', $entry_key, $html);
383
-
384
  //replace [input]
385
  preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
386
  global $frm_vars;
387
- $frm_settings = FrmAppHelper::get_settings();
388
-
389
- foreach ( $shortcodes[0] as $short_key => $tag ) {
390
- $atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] );
391
- $tag = self::get_shortcode_tag($shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false));
392
 
393
- $replace_with = '';
394
-
395
- if ( $tag == 'input' ) {
396
- if ( isset($atts['opt']) ) {
397
- $atts['opt']--;
398
- }
399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
401
- if ( isset($atts['class']) ) {
402
  unset($atts['class']);
403
- }
404
-
405
  $field['shortcodes'] = $atts;
406
  ob_start();
407
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/input.php');
408
  $replace_with = ob_get_contents();
409
  ob_end_clean();
410
- } else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
411
  $replace_with = FrmProEntriesController::entry_delete_link($atts);
412
- }
413
-
414
- $html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html );
415
  }
416
-
417
- if ( $form ) {
418
- $form = (array) $form;
419
-
420
  //replace [form_key]
421
  $html = str_replace('[form_key]', $form['form_key'], $html);
422
-
423
  //replace [form_name]
424
  $html = str_replace('[form_name]', $form['name'], $html);
425
  }
426
  $html .= "\n";
427
-
428
- //Return html if conf_field to prevent loop
429
- if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) {
430
- return $html;
431
- }
432
-
433
- //If field is in repeating section
434
- if ( $args['section_id'] ) {
435
- $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] ));
436
- } else {
437
- $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
438
- }
439
-
440
  // remove [collapse_this] when running the free version
441
- if (preg_match('/\[(collapse_this)\]/s', $html)) {
442
- $html = str_replace('[collapse_this]', '', $html);
443
- }
444
-
445
  return $html;
446
  }
447
-
448
- /**
449
- * Add more classes to certain fields (like confirmation fields, other fields, repeating fields, etc.)
450
- *
451
- * @since 2.0
452
- * @param $error_class string, pass by reference
453
- * @param $field array
454
- * @param $field_id int
455
- * @param $html string
456
- */
457
- private static function get_more_field_classes( &$error_class, $field, $field_id, $html ) {
458
- $error_class .= ' frm_'. $field['label'] .'_container';
459
- if ( $field['id'] != $field_id ) {
460
- // add a class for repeating/embedded fields
461
- $error_class .= ' frm_field_'. $field['id'] .'_container';
462
- }
463
-
464
- //Add classes to inline confirmation field (if it doesn't already have classes set)
465
- if ( isset ( $field['conf_field'] ) && $field['conf_field'] == 'inline' && ! $field['classes'] ) {
466
- $error_class .= ' frm_first_half';
467
- }
468
-
469
- //Add class if field includes other option
470
- if ( isset( $field['other'] ) && true == $field['other'] ) {
471
- $error_class .= ' frm_other_container';
472
- }
473
-
474
- // If this is a Section
475
- if ( $field['type'] == 'divider' ) {
476
-
477
- // If the top margin needs to be removed from a section heading
478
- if ( $field['label'] == 'none' ) {
479
- $error_class .= ' frm_hide_section';
480
- }
481
-
482
- // If this is a repeating section that should be hidden with exclude_fields or fields shortcode, hide it
483
- if ( $field['repeat'] ) {
484
- global $frm_vars;
485
- if ( isset( $frm_vars['show_fields'] ) && ! empty ( $frm_vars['show_fields'] ) && ! in_array( $field['id'], $frm_vars['show_fields'] ) && ! in_array( $field['field_key'], $frm_vars['show_fields'] ) ) {
486
- $error_class .= ' frm_hidden';
487
- }
488
- }
489
- }
490
-
491
- //insert custom CSS classes
492
- if ( ! empty( $field['classes'] ) ) {
493
- if ( ! strpos( $html, 'frm_form_field ') ) {
494
- $error_class .= ' frm_form_field';
495
- }
496
- $error_class .= ' '. $field['classes'];
497
- }
498
- }
499
-
500
- public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
501
- if ( $no_vars ) {
502
- $html = str_replace( '[if '. $code.']', '', $html );
503
- $html = str_replace( '[/if '. $code.']', '', $html );
504
- } else {
505
- $html = preg_replace( '/(\[if\s+'. $code .'\])(.*?)(\[\/if\s+'. $code .'\])/mis', '', $html );
506
- }
507
-
508
- $html = str_replace( '['. $code .']', $replace_with, $html );
509
- }
510
-
511
- public static function get_shortcode_tag($shortcodes, $short_key, $args) {
512
- $args = wp_parse_args($args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false));
513
- if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
514
- $args['conditional_check'] = true;
515
- }
516
-
517
- $prefix = '';
518
- if ( $args['conditional_check'] ) {
519
- if ( $args['conditional'] ) {
520
- $prefix = 'if ';
521
- } else if ( $args['foreach'] ) {
522
- $prefix = 'foreach ';
523
- }
524
- }
525
-
526
- $with_tags = $args['conditional_check'] ? 3 : 2;
527
- if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) {
528
- $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] );
529
- $tag = str_replace(']', '', $tag);
530
- $tags = explode(' ', $tag);
531
- if ( is_array($tags) ) {
532
- $tag = $tags[0];
533
- }
534
- } else {
535
- $tag = $shortcodes[ $with_tags - 1 ][ $short_key ];
536
- }
537
-
538
- return $tag;
539
- }
540
-
541
- public static function display_recaptcha($field) {
542
- $frm_settings = FrmAppHelper::get_settings();
543
  $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
544
-
545
- $api_js_url = 'https://www.google.com/recaptcha/api.js';
546
- if ( $lang != 'en' ) {
547
- $api_js_url .= '?hl='. $lang;
548
- }
549
- $api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url);
550
-
551
- wp_register_script('recaptcha-api', $api_js_url, '', true);
552
- wp_enqueue_script('recaptcha-api');
553
-
554
  ?>
555
- <div id="field_<?php echo esc_attr( $field['field_key'] ) ?>" class="g-recaptcha" data-sitekey="<?php echo esc_attr( $frm_settings->pubkey ) ?>"></div>
556
- <?php
557
- }
558
-
559
- public static function show_single_option($field) {
560
- $field_name = $field['name'];
561
- $html_id = self::get_html_id($field);
562
- foreach ( $field['options'] as $opt_key => $opt ) {
563
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
564
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
565
-
566
- // If this is an "Other" option, get the HTML for it
567
- if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
568
- // Get string for Other text field, if needed
569
- $other_val = FrmAppHelper::get_other_val( $opt_key, $field );
570
- require(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
571
- } else {
572
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
573
- }
574
  }
575
  }
576
-
577
- public static function dropdown_categories($args) {
578
- $defaults = array( 'field' => false, 'name' => false, 'show_option_all' => ' ' );
579
- $args = wp_parse_args($args, $defaults);
580
-
581
- if ( ! $args['field'] ) {
582
- return;
583
- }
584
-
585
- if ( ! $args['name'] ) {
586
- $args['name'] = 'item_meta['. $args['field']['id'] .']';
587
- }
588
-
589
- $id = self::get_html_id($args['field']);
590
- $class = $args['field']['type'];
591
-
592
- $exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat'];
593
- $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']);
594
-
595
- if ( is_array($args['field']['value']) ) {
596
- if ( ! empty($exclude) ) {
597
- $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude));
598
- }
599
- $selected = reset($args['field']['value']);
600
- } else {
601
- $selected = $args['field']['value'];
602
- }
603
-
604
- $tax_atts = array(
605
- 'show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'],
606
- 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected,
607
  'hide_empty' => false, 'echo' => 0, 'orderby' => 'name',
608
  );
609
-
610
- $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']);
611
-
612
- if ( FrmAppHelper::pro_is_installed() ) {
613
- $post_type = FrmProFormsHelper::post_type($args['field']['form_id']);
614
- $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']);
615
- if ( ! $tax_atts['taxonomy'] ) {
616
  return;
617
  }
618
-
619
- // If field type is dropdown (not Dynamic), exclude children when parent is excluded
620
- if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) {
621
- $tax_atts['exclude_tree'] = $exclude;
622
  }
623
  }
624
-
625
- $dropdown = wp_dropdown_categories($tax_atts);
626
-
627
- $add_html = FrmFieldsController::input_html($args['field'], false);
628
-
629
- if ( FrmAppHelper::pro_is_installed() ) {
630
- $add_html .= FrmProFieldsController::input_html($args['field'], false);
631
- }
632
-
633
- $dropdown = str_replace("<select name='". $args['name'] ."' id='$id' class='$class'", "<select name='". $args['name'] ."' id='$id' ". $add_html, $dropdown);
634
-
635
- if ( is_array($args['field']['value']) ) {
636
  $skip = true;
637
- foreach ( $args['field']['value'] as $v ) {
638
- if ( $skip ) {
639
  $skip = false;
640
  continue;
641
  }
@@ -643,370 +399,78 @@ DEFAULT_HTML;
643
  unset($v);
644
  }
645
  }
646
-
647
  return $dropdown;
648
  }
649
-
650
  public static function get_term_link($tax_id) {
651
  $tax = get_taxonomy($tax_id);
652
- if ( ! $tax ) {
653
  return;
654
  }
655
-
656
  $link = sprintf(
657
- __( 'Please add options from the WordPress "%1$s" page', 'formidable' ),
658
- '<a href="'. esc_url( admin_url( 'edit-tags.php?taxonomy='. $tax->name ) ) .'" target="_blank">'. ( empty($tax->labels->name) ? __( 'Categories' ) : $tax->labels->name ) .'</a>'
659
  );
660
  unset($tax);
661
-
662
  return $link;
663
  }
664
-
665
- public static function value_meets_condition($observed_value, $cond, $hide_opt) {
666
- if ( is_array($observed_value) ) {
667
- return self::array_value_condition($observed_value, $cond, $hide_opt);
668
- }
669
-
670
- $m = false;
671
- if ( $cond == '==' ) {
672
- $m = $observed_value == $hide_opt;
673
- } else if ( $cond == '!=' ) {
674
- $m = $observed_value != $hide_opt;
675
- } else if ( $cond == '>' ) {
676
- $m = $observed_value > $hide_opt;
677
- } else if ( $cond == '<' ) {
678
- $m = $observed_value < $hide_opt;
679
- } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
680
- $m = strpos($observed_value, $hide_opt);
681
- if ( $cond == 'not LIKE' ) {
682
- $m = ( $m === false ) ? true : false;
683
- } else {
684
- $m = ( $m === false ) ? false : true;
685
- }
686
- }
687
- return $m;
688
- }
689
-
690
- public static function array_value_condition($observed_value, $cond, $hide_opt) {
691
- $m = false;
692
- if ( $cond == '==' ) {
693
- if ( is_array($hide_opt) ) {
694
- $m = array_intersect($hide_opt, $observed_value);
695
- $m = empty($m) ? false : true;
696
- } else {
697
- $m = in_array($hide_opt, $observed_value);
698
- }
699
- } else if ( $cond == '!=' ) {
700
- $m = ! in_array($hide_opt, $observed_value);
701
- } else if ( $cond == '>' ) {
702
- $min = min($observed_value);
703
- $m = $min > $hide_opt;
704
- } else if ( $cond == '<' ) {
705
- $max = max($observed_value);
706
- $m = $max < $hide_opt;
707
- } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
708
- foreach ( $observed_value as $ob ) {
709
- $m = strpos($ob, $hide_opt);
710
- if ( $m !== false ) {
711
- $m = true;
712
- break;
713
- }
714
- }
715
-
716
- if ( $cond == 'not LIKE' ) {
717
- $m = ( $m === false ) ? true : false;
718
- }
719
- }
720
-
721
- return $m;
722
- }
723
-
724
- /**
725
- * Replace a few basic shortcodes and field ids
726
- * @since 2.0
727
- * @return string
728
- */
729
- public static function basic_replace_shortcodes($value, $form, $entry) {
730
- if ( strpos($value, '[sitename]') !== false ) {
731
- $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
732
- $value = str_replace('[sitename]', $new_value, $value);
733
- }
734
-
735
- $value = apply_filters('frm_content', $value, $form, $entry);
736
- $value = do_shortcode($value);
737
-
738
- return $value;
739
- }
740
-
741
- public static function get_shortcodes($content, $form_id) {
742
- if ( FrmAppHelper::pro_is_installed() ) {
743
- return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
744
- }
745
-
746
- $fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => self::no_save_fields() ) );
747
-
748
- $tagregexp = self::allowed_shortcodes($fields);
749
-
750
- preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER);
751
-
752
- return $matches;
753
- }
754
-
755
- public static function allowed_shortcodes($fields = array()) {
756
- $tagregexp = array(
757
- 'editlink', 'id', 'key', 'ip',
758
- 'siteurl', 'sitename', 'admin_email',
759
- 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by',
760
- );
761
-
762
- foreach ( $fields as $field ) {
763
- $tagregexp[] = $field->id;
764
- $tagregexp[] = $field->field_key;
765
- }
766
-
767
- $tagregexp = implode('|', $tagregexp);
768
- return $tagregexp;
769
- }
770
-
771
- public static function replace_content_shortcodes($content, $entry, $shortcodes) {
772
- $shortcode_values = array(
773
- 'id' => $entry->id,
774
- 'key' => $entry->item_key,
775
- 'ip' => $entry->ip,
776
  );
777
-
778
- foreach ( $shortcodes[0] as $short_key => $tag ) {
779
- $atts = shortcode_parse_atts( $shortcodes[3][ $short_key ] );
780
-
781
- if ( ! empty( $shortcodes[3][ $short_key ] ) ) {
782
- $tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] );
783
- $tags = explode(' ', $tag);
784
- if ( is_array($tags) ) {
785
- $tag = $tags[0];
786
- }
787
- } else {
788
- $tag = $shortcodes[2][ $short_key ];
789
  }
790
-
791
- switch ( $tag ) {
792
- case 'id':
793
- case 'key':
794
- case 'ip':
795
- $replace_with = $shortcode_values[ $tag ];
796
- break;
797
-
798
- case 'user_agent':
799
- case 'user-agent':
800
- $entry->description = maybe_unserialize($entry->description);
801
- $replace_with = FrmEntriesHelper::get_browser($entry->description['browser']);
802
- break;
803
-
804
- case 'created_at':
805
- case 'created-at':
806
- case 'updated_at':
807
- case 'updated-at':
808
- if ( isset($atts['format']) ) {
809
- $time_format = ' ';
810
- } else {
811
- $atts['format'] = get_option('date_format');
812
- $time_format = '';
813
- }
814
-
815
- $this_tag = str_replace('-', '_', $tag);
816
- $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
817
- unset($this_tag);
818
- break;
819
-
820
- case 'created_by':
821
- case 'created-by':
822
- case 'updated_by':
823
- case 'updated-by':
824
- $this_tag = str_replace('-', '_', $tag);
825
- $replace_with = self::get_display_value($entry->{$this_tag}, (object) array( 'type' => 'user_id'), $atts);
826
- unset($this_tag);
827
- break;
828
-
829
- case 'admin_email':
830
- case 'siteurl':
831
- case 'frmurl':
832
- case 'sitename':
833
- case 'get':
834
- $replace_with = self::dynamic_default_values( $tag, $atts );
835
- break;
836
-
837
- default:
838
- $field = FrmField::getOne( $tag );
839
- if ( ! $field ) {
840
- break;
841
- }
842
-
843
- $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
844
-
845
- $replace_with = FrmEntryMeta::get_entry_meta_by_field($entry->id, $field->id);
846
-
847
- $atts['entry_id'] = $entry->id;
848
- $atts['entry_key'] = $entry->item_key;
849
- //$replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
850
-
851
- if ( is_array($replace_with) ) {
852
- $replace_with = implode($sep, $replace_with);
853
- }
854
-
855
- if ( isset($atts['show']) && $atts['show'] == 'field_label' ) {
856
- $replace_with = $field->name;
857
- } else if ( isset($atts['show']) && $atts['show'] == 'description' ) {
858
- $replace_with = $field->description;
859
- } else if ( empty($replace_with) && $replace_with != '0' ) {
860
- $replace_with = '';
861
- } else {
862
- $replace_with = self::get_display_value($replace_with, $field, $atts);
863
- }
864
-
865
- unset($field);
866
- break;
867
  }
868
-
869
- if ( isset($replace_with) ) {
870
- $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
 
 
 
871
  }
872
-
873
- unset($atts, $conditional, $replace_with);
874
- }
875
-
876
- return $content;
877
- }
878
-
879
- /**
880
- * Get the value to replace a few standard shortcodes
881
- *
882
- * @since 2.0
883
- * @return string
884
- */
885
- public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
886
- $new_value = '';
887
- switch ( $tag ) {
888
- case 'admin_email':
889
- $new_value = get_option('admin_email');
890
- break;
891
- case 'siteurl':
892
- $new_value = FrmAppHelper::site_url();
893
- break;
894
- case 'frmurl':
895
- $new_value = FrmAppHelper::plugin_url();
896
- break;
897
- case 'sitename':
898
- $new_value = FrmAppHelper::site_name();
899
- break;
900
- case 'get':
901
- $new_value = self::process_get_shortcode( $atts, $return_array );
902
- break;
903
  }
904
-
905
- return $new_value;
906
- }
907
-
908
- /**
909
- * Process the [get] shortcode
910
- *
911
- * @since 2.0
912
- * @return string|array
913
- */
914
- public static function process_get_shortcode( $atts, $return_array = false ) {
915
- if ( ! isset($atts['param']) ) {
916
- return '';
917
- }
918
-
919
- if ( strpos($atts['param'], '&#91;') ) {
920
- $atts['param'] = str_replace('&#91;', '[', $atts['param']);
921
- $atts['param'] = str_replace('&#93;', ']', $atts['param']);
922
- }
923
-
924
- $new_value = FrmAppHelper::get_param($atts['param'], '');
925
- $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
926
-
927
- if ( $new_value == '' ) {
928
- if ( ! isset($atts['prev_val']) ) {
929
- $atts['prev_val'] = '';
930
- }
931
-
932
- $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val'];
933
- }
934
-
935
- if ( is_array($new_value) && ! $return_array ) {
936
- $new_value = implode(', ', $new_value);
937
- }
938
-
939
- return $new_value;
940
- }
941
-
942
- public static function get_display_value($replace_with, $field, $atts = array()) {
943
- $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
944
-
945
- $replace_with = apply_filters( 'frm_get_display_value', $replace_with, $field, $atts );
946
-
947
- if ( $field->type == 'textarea' || $field->type == 'rte' ) {
948
- $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
949
- if ( apply_filters('frm_use_wpautop', $autop) ) {
950
- if ( is_array($replace_with) ) {
951
- $replace_with = implode("\n", $replace_with);
952
- }
953
- $replace_with = wpautop($replace_with);
954
- }
955
- unset( $autop );
956
- } else if ( is_array( $replace_with ) ) {
957
- $replace_with = implode( $sep, $replace_with );
958
- }
959
-
960
- return $replace_with;
961
- }
962
-
963
- public static function get_field_types($type) {
964
- $single_input = array(
965
- 'text', 'textarea', 'rte', 'number', 'email', 'url',
966
- 'image', 'file', 'date', 'phone', 'hidden', 'time',
967
- 'user_id', 'tag', 'password',
968
- );
969
- $multiple_input = array( 'radio', 'checkbox', 'select', 'scale' );
970
- $other_type = array( 'divider', 'html', 'break' );
971
-
972
- $field_selection = array_merge( self::pro_field_selection(), self::field_selection() );
973
-
974
- $field_types = array();
975
- if ( in_array($type, $single_input) ) {
976
- self::field_types_for_input( $single_input, $field_selection, $field_types );
977
- } else if ( in_array($type, $multiple_input) ) {
978
- self::field_types_for_input( $multiple_input, $field_selection, $field_types );
979
- } else if ( in_array($type, $other_type) ) {
980
- self::field_types_for_input( $other_type, $field_selection, $field_types );
981
- } else if ( isset( $field_selection[ $type ] ) ) {
982
- $field_types[ $type ] = $field_selection[ $type ];
983
- }
984
-
985
  return $field_types;
986
  }
987
-
988
- private static function field_types_for_input( $inputs, $fields, &$field_types ) {
989
- foreach ( $inputs as $input ) {
990
- $field_types[ $input ] = $fields[ $input ];
991
- unset($input);
992
- }
993
- }
994
-
995
- public static function show_onfocus_js($clear_on_focus){ ?>
996
- <a href="javascript:void(0)" class="frm_bstooltip <?php echo ($clear_on_focus) ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_reload_icon frm_icon_font" title="<?php echo esc_attr($clear_on_focus ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' )); ?>"></a>
997
  <?php
998
  }
999
-
1000
- public static function show_default_blank_js($default_blank){ ?>
1001
- <a href="javascript:void(0)" class="frm_bstooltip <?php echo $default_blank ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_error_icon frm_icon_font" title="<?php echo $default_blank ? esc_attr( 'Default value will NOT pass form validation', 'formidable' ) : esc_attr( 'Default value will pass form validation', 'formidable' ); ?>"></a>
1002
  <?php
1003
  }
1004
-
1005
- public static function switch_field_ids($val) {
1006
  global $frm_duplicate_ids;
1007
  $replace = array();
1008
  $replace_with = array();
1009
- foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1010
  $replace[] = '[if '. $old .']';
1011
  $replace_with[] = '[if '. $new .']';
1012
  $replace[] = '[if '. $old .' ';
@@ -1017,151 +481,19 @@ DEFAULT_HTML;
1017
  $replace_with[] = '['. $new .']';
1018
  $replace[] = '['. $old .' ';
1019
  $replace_with[] = '['. $new .' ';
1020
- unset($old, $new);
 
1021
  }
1022
- if ( is_array( $val ) ) {
1023
- foreach ( $val as $k => $v ) {
1024
- $val[ $k ] = str_replace( $replace, $replace_with, $v );
1025
- unset($k, $v);
 
1026
  }
1027
- } else {
1028
  $val = str_replace($replace, $replace_with, $val);
1029
  }
1030
-
1031
  return $val;
1032
  }
1033
-
1034
- public static function get_us_states() {
1035
- return apply_filters( 'frm_us_states', array(
1036
- 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
1037
- 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
1038
- 'DC' => 'District of Columbia',
1039
- 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
1040
- 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
1041
- 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
1042
- 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
1043
- 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
1044
- 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
1045
- 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
1046
- 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
1047
- 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
1048
- 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
1049
- 'WI' => 'Wisconsin', 'WY' => 'Wyoming',
1050
- ) );
1051
- }
1052
-
1053
- public static function get_countries() {
1054
- return apply_filters( 'frm_countries', array(
1055
- __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ),
1056
- __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ),
1057
- __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ),
1058
- __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ),
1059
- __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ),
1060
- __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ),
1061
- __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ),
1062
- __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ),
1063
- __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ),
1064
- __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ),
1065
- __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ),
1066
- __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ),
1067
- __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ),
1068
- __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ),
1069
- __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ),
1070
- __( 'Costa Rica', 'formidable' ), __( 'C&ocirc;te d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ),
1071
- __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ),
1072
- __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ),
1073
- __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ),
1074
- __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ),
1075
- __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ),
1076
- __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ),
1077
- __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ),
1078
- __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ),
1079
- __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ),
1080
- __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ),
1081
- __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ),
1082
- __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ),
1083
- __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ),
1084
- __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ),
1085
- __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ),
1086
- __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ),
1087
- __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ),
1088
- __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ),
1089
- __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ),
1090
- __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ),
1091
- __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ),
1092
- __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ),
1093
- __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ),
1094
- __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ),
1095
- __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ),
1096
- __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ),
1097
- __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ),
1098
- __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ),
1099
- __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ),
1100
- __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ),
1101
- __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ),
1102
- __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ),
1103
- __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ),
1104
- __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ),
1105
- __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ),
1106
- __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ),
1107
- __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ),
1108
- __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ),
1109
- __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ),
1110
- __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ),
1111
- __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ),
1112
- __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ),
1113
- __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ),
1114
- __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ),
1115
- __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ),
1116
- __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ),
1117
- __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ),
1118
- __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ),
1119
- __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ),
1120
- __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ),
1121
- __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ),
1122
- __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ),
1123
- __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ),
1124
- __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ),
1125
- __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ),
1126
- __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ),
1127
- __( 'Zimbabwe', 'formidable' ),
1128
- ) );
1129
- }
1130
-
1131
- public static function get_bulk_prefilled_opts(array &$prepop) {
1132
- $prepop[__( 'Countries', 'formidable' )] = FrmFieldsHelper::get_countries();
1133
-
1134
- $states = FrmFieldsHelper::get_us_states();
1135
- $state_abv = array_keys($states);
1136
- sort($state_abv);
1137
- $prepop[__( 'U.S. State Abbreviations', 'formidable' )] = $state_abv;
1138
-
1139
- $states = array_values($states);
1140
- sort($states);
1141
- $prepop[__( 'U.S. States', 'formidable' )] = $states;
1142
- unset($state_abv, $states);
1143
-
1144
- $prepop[__( 'Age', 'formidable' )] = array(
1145
- __( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ),
1146
- __( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ),
1147
- __( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ),
1148
- );
1149
-
1150
- $prepop[__( 'Satisfaction', 'formidable' )] = array(
1151
- __( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ),
1152
- __( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ),
1153
- );
1154
-
1155
- $prepop[__( 'Importance', 'formidable' )] = array(
1156
- __( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ),
1157
- __( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ),
1158
- );
1159
-
1160
- $prepop[__( 'Agreement', 'formidable' )] = array(
1161
- __( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ),
1162
- __( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ),
1163
- );
1164
-
1165
- $prepop = apply_filters('frm_bulk_field_choices', $prepop);
1166
- }
1167
  }
1
  <?php
 
 
 
2
 
3
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
4
+
5
+ if(class_exists('FrmFieldsHelper'))
6
+ return;
7
 
8
+ class FrmFieldsHelper{
9
+
10
+ public static function field_selection(){
11
  $fields = apply_filters('frm_available_fields', array(
12
+ 'text' => __('Single Line Text', 'formidable'),
13
+ 'textarea' => __('Paragraph Text', 'formidable'),
14
+ 'checkbox' => __('Checkboxes', 'formidable'),
15
+ 'radio' => __('Radio Buttons', 'formidable'),
16
+ 'select' => __('Dropdown', 'formidable'),
17
+ 'captcha' => __('reCAPTCHA', 'formidable')
 
 
18
  ));
19
+
20
  return $fields;
21
  }
22
+
23
+ public static function pro_field_selection(){
24
  return apply_filters('frm_pro_available_fields', array(
25
+ 'email' => __('Email Address', 'formidable'),
26
+ 'url' => __('Website/URL', 'formidable'),
27
+ 'divider' => __('Section Heading', 'formidable'),
28
+ 'break' => __('Page Break', 'formidable'),
29
+ 'file' => __('File Upload', 'formidable'),
30
+ 'rte' => __('Rich Text', 'formidable'),
31
+ 'number' => __('Number', 'formidable'),
32
+ 'phone' => __('Phone Number', 'formidable'),
33
+ 'date' => __('Date', 'formidable'),
34
+ 'time' => __('Time', 'formidable'),
35
+ 'image' => __('Image URL', 'formidable'),
36
+ 'scale' => __('Scale', 'formidable'),
37
+ //'grid' => __('Grid', 'formidable'),
38
+ 'data' => __('Data from Entries', 'formidable'),
39
+ //'form' => __('SubForm', 'formidable'),
40
+ 'hidden' => __('Hidden Field', 'formidable'),
41
+ 'user_id' => __('User ID (hidden)', 'formidable'),
42
+ 'password' => __('Password', 'formidable'),
43
+ 'html' => __('HTML', 'formidable'),
44
+ 'tag' => __('Tags', 'formidable')
45
+ //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
46
+ //'city_selector' => 'US State/County/City selector',
47
+ //'full_name' => 'First and Last Name',
48
+ //'quiz' => 'Question and Answer' // for captcha alternative
 
49
  ));
50
  }
51
+
52
+ public static function setup_new_vars($type='', $form_id=''){
53
+ global $frm_settings;
54
+
55
+ $defaults = FrmFieldsHelper::get_default_field_opts($type, $form_id);
56
+ $defaults['field_options']['custom_html'] = FrmFieldsHelper::get_default_html($type);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  $values = array();
59
+
60
+ foreach ($defaults as $var => $default){
61
+ if($var == 'field_options'){
62
  $values['field_options'] = array();
63
+ foreach ($default as $opt_var => $opt_default){
64
+ $values['field_options'][$opt_var] = $opt_default;
65
+ unset($opt_var);
66
+ unset($opt_default);
67
  }
68
+ }else{
69
+ $values[$var] = $default;
 
 
 
 
 
 
 
 
 
70
  }
71
+ unset($var);
72
+ unset($default);
73
+ }
74
+
75
+ if ($type == 'radio' || ($type == 'checkbox'))
76
+ $values['options'] = serialize(array(__('Option 1', 'formidable'), __('Option 2', 'formidable')));
77
+ else if ( $type == 'select')
78
+ $values['options'] = serialize(array('', __('Option 1', 'formidable')));
79
+ else if ($type == 'textarea')
 
 
 
80
  $values['field_options']['max'] = '5';
81
+ else if ($type == 'captcha')
 
82
  $values['invalid'] = $frm_settings->re_msg;
83
+
 
 
 
84
  $fields = self::field_selection();
85
  $fields = array_merge($fields, self::pro_field_selection());
86
 
87
+ if(isset($fields[$type]))
88
+ $values['name'] = $fields[$type];
 
89
 
90
  unset($fields);
91
+
92
  return $values;
93
  }
94
+
95
+ public static function setup_edit_vars($record, $doing_ajax=false){
96
+ global $frm_entry_meta;
97
+
98
+ $values = array('id' => $record->id, 'form_id' => $record->form_id);
99
+ $defaults = array('name' => $record->name, 'description' => $record->description);
 
 
100
  $default_opts = array(
101
+ 'field_key' => $record->field_key, 'type' => $record->type,
102
+ 'default_value'=> $record->default_value, 'field_order' => $record->field_order,
103
+ 'required' => $record->required
104
  );
105
+
106
+ if($doing_ajax){
107
  $values = $values + $defaults + $default_opts;
108
  $values['form_name'] = '';
109
+ }else{
110
+ foreach ($defaults as $var => $default){
111
+ $values[$var] = htmlspecialchars(FrmAppHelper::get_param($var, $default));
112
+ unset($var);
113
+ unset($default);
114
  }
115
+
116
+ foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default){
117
+ $values[$var] = FrmAppHelper::get_param($var, $default);
118
+ unset($var);
119
+ unset($default);
120
  }
121
+
122
+ $frm_form = new FrmForm();
123
+ $values['form_name'] = ($record->form_id) ? $frm_form->getName( $record->form_id ) : '';
124
+ unset($frm_form);
125
+ }
126
+
127
+ unset($defaults);
128
+ unset($default_opts);
129
+
130
  $values['options'] = $record->options;
131
  $values['field_options'] = $record->field_options;
132
+
133
  $defaults = self::get_default_field_opts($values['type'], $record, true);
134
+
135
+ if($values['type'] == 'captcha'){
136
+ global $frm_settings;
137
  $defaults['invalid'] = $frm_settings->re_msg;
138
  }
139
+
140
+ foreach($defaults as $opt => $default){
141
+ $values[$opt] = (isset($record->field_options[$opt])) ? $record->field_options[$opt] : $default;
142
+ unset($opt);
143
+ unset($default);
144
  }
145
 
146
  $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
147
+
148
+ return apply_filters('frm_setup_edit_field_vars', $values, array('doing_ajax' => $doing_ajax));
149
  }
150
+
151
+ public static function get_default_field_opts($type, $field, $limit=false){
152
  $field_options = array(
153
+ 'size' => '', 'max' => '', 'label' => '', 'blank' => '',
154
  'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
155
  'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
156
+ 'custom_html' => ''
157
  );
158
+
159
+ if($limit)
160
  return $field_options;
161
+
162
+ global $wpdb, $frm_settings;
163
+
 
164
  $form_id = (is_numeric($field)) ? $field : $field->form_id;
165
+
166
  $key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_fields', 'field_key') : $field->field_key;
167
+ $field_count = FrmAppHelper::getRecordCount(array('form_id' => $form_id), $wpdb->prefix .'frm_fields');
168
+
 
 
169
  return array(
170
+ 'name' => __('Untitled', 'formidable'), 'description' => '',
171
+ 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'',
172
+ 'field_order' => $field_count+1, 'required' => false,
173
  'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
174
+ 'invalid' => __('This field is invalid', 'formidable'), 'form_id' => $form_id,
175
+ 'field_options' => $field_options
176
  );
177
  }
178
+
179
+ public static function get_form_fields($form_id, $error=false){
180
+ global $frm_field;
181
+ $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
182
+ $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  return $fields;
184
  }
185
+
186
+ public static function get_default_html($type='text'){
187
+ if (apply_filters('frm_normal_field_type_html', true, $type)){
188
+ $input = (in_array($type, array('radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
189
  $for = '';
190
+ if(!in_array($type, array('radio', 'checkbox', 'data', 'scale')))
191
  $for = 'for="field_[key]"';
192
+
 
193
  $default_html = <<<DEFAULT_HTML
194
  <div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
195
  <label $for class="frm_primary_label">[field_name]
200
  [if error]<div class="frm_error">[error]</div>[/if error]
201
  </div>
202
  DEFAULT_HTML;
203
+ }else
204
+ $default_html = apply_filters('frm_other_custom_html', '', $type);
 
205
 
206
  return apply_filters('frm_custom_html', $default_html, $type);
207
  }
208
+
209
+ public static function replace_shortcodes($html, $field, $errors=array(), $form=false){
210
  $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
211
+
212
+ $field_name = 'item_meta['. $field['id'] .']';
213
+ if(isset($field['multiple']) and $field['multiple'] and ($field['type'] == 'select' or ($field['type'] == 'data' and isset($field['data_type']) and $field['data_type'] == 'select')))
 
 
 
 
 
 
 
 
 
 
214
  $field_name .= '[]';
215
+
 
216
  //replace [id]
217
+ $html = str_replace('[id]', $field['id'], $html);
218
+
219
+ //replace [key]
 
 
 
 
 
 
 
 
220
  $html = str_replace('[key]', $field['field_key'], $html);
221
+
222
  //replace [description] and [required_label] and [error]
223
  $required = ($field['required'] == '0') ? '' : $field['required_indicator'];
224
+ if(!is_array($errors))
225
  $errors = array();
226
+ $error = isset($errors['field'. $field['id']]) ? $errors['field'. $field['id']] : false;
227
+ foreach (array('description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value){
228
+ if (!$value or $value == '')
229
+ $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
230
+ else{
231
+ $html = str_replace('[if '.$code.']', '', $html);
232
+ $html = str_replace('[/if '.$code.']', '', $html);
 
 
233
  }
 
 
 
 
 
234
 
235
+ $html = str_replace('['.$code.']', $value, $html);
236
+ }
237
+
238
  //replace [required_class]
239
+ $required_class = ($field['required'] == '0') ? '' : ' frm_required_field';
240
+ $html = str_replace('[required_class]', $required_class, $html);
241
+
242
  //replace [label_position]
243
+ $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field);
244
+ $field['label'] = ($field['label'] and $field['label'] != '') ? $field['label'] : 'top';
245
+ $html = str_replace('[label_position]', (($field['type'] == 'divider' or $field['type'] == 'break') ? $field['label'] : ' frm_primary_label'), $html);
246
+
247
  //replace [field_name]
248
  $html = str_replace('[field_name]', $field['name'], $html);
249
+
250
+ //replace [error_class]
251
+ $error_class = isset($errors['field'. $field['id']]) ? ' frm_blank_field' : '';
252
+ $error_class .= ' frm_'. $field['label'] .'_container' ;
253
+ //insert custom CSS classes
254
+ if(!empty($field['classes'])){
255
+ if(!strpos($html, 'frm_form_field '))
256
+ $error_class .= ' frm_form_field';
257
+ $error_class .= ' '. $field['classes'];
258
+ }
259
  $html = str_replace('[error_class]', $error_class, $html);
260
+
261
  //replace [entry_key]
262
+ $entry_key = (isset($_GET) and isset($_GET['entry'])) ? $_GET['entry'] : '';
263
  $html = str_replace('[entry_key]', $entry_key, $html);
264
+
265
  //replace [input]
266
  preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
267
  global $frm_vars;
 
 
 
 
 
268
 
269
+ foreach ($shortcodes[0] as $short_key => $tag){
270
+ $atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
 
 
 
 
271
 
272
+ if(!empty($shortcodes[2][$short_key])){
273
+ $tag = str_replace('[', '',$shortcodes[0][$short_key]);
274
+ $tag = str_replace(']', '', $tag);
275
+ $tags = explode(' ', $tag);
276
+ if(is_array($tags))
277
+ $tag = $tags[0];
278
+ }else
279
+ $tag = $shortcodes[1][$short_key];
280
+
281
+ $replace_with = '';
282
+
283
+ if($tag == 'input'){
284
+ if(isset($atts['opt'])) $atts['opt']--;
285
  $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
286
+ if(isset($atts['class']))
287
  unset($atts['class']);
 
 
288
  $field['shortcodes'] = $atts;
289
  ob_start();
290
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/input.php');
291
  $replace_with = ob_get_contents();
292
  ob_end_clean();
293
+ }else if($tag == 'deletelink' and class_exists('FrmProEntriesController'))
294
  $replace_with = FrmProEntriesController::entry_delete_link($atts);
295
+
296
+ $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
 
297
  }
298
+
299
+ if($form){
300
+ $form = (array)$form;
301
+
302
  //replace [form_key]
303
  $html = str_replace('[form_key]', $form['form_key'], $html);
304
+
305
  //replace [form_name]
306
  $html = str_replace('[form_name]', $form['name'], $html);
307
  }
308
  $html .= "\n";
309
+
310
+ $html = apply_filters('frm_replace_shortcodes', $html, $field, array('errors' => $errors, 'form' => $form));
311
+
 
 
 
 
 
 
 
 
 
 
312
  // remove [collapse_this] when running the free version
313
+ if (preg_match('/\[(collapse_this)\]/s', $html))
314
+ $html = str_replace('[collapse_this]', '', $html);
315
+
 
316
  return $html;
317
  }
318
+
319
+ public static function display_recaptcha($field, $error=null){
320
+ global $frm_settings, $frm_vars;
321
+
322
+ if(!function_exists('recaptcha_get_html'))
323
+ require(FrmAppHelper::plugin_path().'/classes/recaptchalib.php');
324
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
326
+
327
+ if(defined('DOING_AJAX') and (!isset($frm_vars['preview']) or !$frm_vars['preview'])){
328
+ if(!isset($frm_vars['recaptcha_loaded']) or !$frm_vars['recaptcha_loaded'])
329
+ $frm_vars['recaptcha_loaded'] = '';
330
+
331
+ $frm_vars['recaptcha_loaded'] .= "Recaptcha.create('". $frm_settings->pubkey ."','field_". $field['field_key'] ."',{theme:'". $frm_settings->re_theme ."',lang:'". $lang ."'". apply_filters('frm_recaptcha_custom', '', $field) ."});";
 
 
 
 
332
  ?>
333
+ <div id="field_<?php echo $field['field_key'] ?>"></div>
334
+ <?php }else{ ?>
335
+ <script type="text/javascript">var RecaptchaOptions={theme:'<?php echo $frm_settings->re_theme ?>',lang:'<?php echo $lang ?>'<?php echo apply_filters('frm_recaptcha_custom', '', $field) ?>};</script>
336
+ <?php echo recaptcha_get_html($frm_settings->pubkey .'&hl='. $lang, $error, is_ssl());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
  }
339
+
340
+ public static function dropdown_categories($args){
341
+ global $frm_vars;
342
+
343
+ $defaults = array('field' => false, 'name' => false, 'show_option_all' => ' ');
344
+ extract(wp_parse_args($args, $defaults));
345
+
346
+ if(!$field) return;
347
+ if(!$name) $name = "item_meta[$field[id]]";
348
+ $id = 'field_'. $field['field_key'];
349
+ $class = $field['type'];
350
+
351
+ $exclude = (is_array($field['exclude_cat'])) ? implode(',', $field['exclude_cat']) : $field['exclude_cat'];
352
+ $exclude = apply_filters('frm_exclude_cats', $exclude, $field);
353
+
354
+ if(is_array($field['value'])){
355
+ if(!empty($exclude))
356
+ $field['value'] = array_diff($field['value'], explode(',', $exclude));
357
+ $selected = reset($field['value']);
358
+ }else{
359
+ $selected = $field['value'];
360
+ }
361
+
362
+ $args = array(
363
+ 'show_option_all' => $show_option_all, 'hierarchical' => 1, 'name' => $name,
364
+ 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected,
 
 
 
 
 
365
  'hide_empty' => false, 'echo' => 0, 'orderby' => 'name',
366
  );
367
+
368
+ $args = apply_filters('frm_dropdown_cat', $args, $field);
369
+
370
+ if ( class_exists('FrmProFormsHelper') ) {
371
+ $post_type = FrmProFormsHelper::post_type($field['form_id']);
372
+ $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field);
373
+ if ( ! $args['taxonomy'] ) {
374
  return;
375
  }
376
+
377
+ if ( is_taxonomy_hierarchical($args['taxonomy']) ) {
378
+ $args['exclude_tree'] = $exclude;
 
379
  }
380
  }
381
+
382
+ $dropdown = wp_dropdown_categories($args);
383
+
384
+ $add_html = FrmFieldsController::input_html($field, false);
385
+
386
+ if($frm_vars['pro_is_installed'])
387
+ $add_html .= FrmProFieldsController::input_html($field, false);
388
+
389
+ $dropdown = str_replace("<select name='$name' id='$id' class='$class'", "<select name='$name' id='$id' ". $add_html, $dropdown);
390
+
391
+ if(is_array($field['value'])){
 
392
  $skip = true;
393
+ foreach($field['value'] as $v){
394
+ if($skip){
395
  $skip = false;
396
  continue;
397
  }
399
  unset($v);
400
  }
401
  }
402
+
403
  return $dropdown;
404
  }
405
+
406
  public static function get_term_link($tax_id) {
407
  $tax = get_taxonomy($tax_id);
408
+ if ( !$tax ) {
409
  return;
410
  }
411
+
412
  $link = sprintf(
413
+ __('Please add options from the WordPress "%1$s" page', 'formidable'),
414
+ '<a href="'. esc_url(admin_url('edit-tags.php?taxonomy='. $tax->name)) .'" target="_blank">'. ( empty($tax->labels->name) ? __('Categories') : $tax->labels->name ) .'</a>'
415
  );
416
  unset($tax);
417
+
418
  return $link;
419
  }
420
+
421
+ public static function get_field_types($type){
422
+ $frm_field_selection = FrmFieldsHelper::field_selection();
423
+ $field_types = array();
424
+ $single_input = array(
425
+ 'text', 'textarea', 'rte', 'number', 'email', 'url',
426
+ 'image', 'file', 'date', 'phone', 'hidden', 'time',
427
+ 'user_id', 'tag', 'password'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  );
429
+ $multiple_input = array('radio', 'checkbox', 'select', 'scale');
430
+ $other_type = array('divider', 'html', 'break');
431
+ $frm_pro_field_selection = FrmFieldsHelper::pro_field_selection();
432
+
433
+ if (in_array($type, $single_input)){
434
+ foreach($single_input as $input){
435
+ if (isset($frm_pro_field_selection[$input]))
436
+ $field_types[$input] = $frm_pro_field_selection[$input];
437
+ else
438
+ $field_types[$input] = $frm_field_selection[$input];
 
 
439
  }
440
+ }else if (in_array($type, $multiple_input)){
441
+ foreach($multiple_input as $input){
442
+ if (isset($frm_pro_field_selection[$input]))
443
+ $field_types[$input] = $frm_pro_field_selection[$input];
444
+ else
445
+ $field_types[$input] = $frm_field_selection[$input];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  }
447
+ }else if (in_array($type, $other_type)){
448
+ foreach($other_type as $input){
449
+ if (isset($frm_pro_field_selection[$input]))
450
+ $field_types[$input] = $frm_pro_field_selection[$input];
451
+ else
452
+ $field_types[$input] = $frm_field_selection[$input];
453
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  }
455
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  return $field_types;
457
  }
458
+
459
+ public static function show_onfocus_js($field_id, $clear_on_focus){ ?>
460
+ <a class="frm_bstooltip <?php echo ($clear_on_focus) ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_reload_icon frm_icon_font" id="clear_field_<?php echo $field_id; ?>" title="<?php echo esc_attr($clear_on_focus ? __('Clear default value when typing', 'formidable') : __('Do not clear default value when typing', 'formidable')); ?>"></a>
 
 
 
 
 
 
 
461
  <?php
462
  }
463
+
464
+ public static function show_default_blank_js($field_id, $default_blank){ ?>
465
+ <a class="frm_bstooltip <?php echo ($default_blank) ? '' :'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_error_icon frm_icon_font" id="default_blank_<?php echo $field_id; ?>" title="<?php echo $default_blank ? __('Default value will NOT pass form validation', 'formidable') : __('Default value will pass form validation', 'formidable'); ?>"></a>
466
  <?php
467
  }
468
+
469
+ public static function switch_field_ids($val){
470
  global $frm_duplicate_ids;
471
  $replace = array();
472
  $replace_with = array();
473
+ foreach((array)$frm_duplicate_ids as $old => $new){
474
  $replace[] = '[if '. $old .']';
475
  $replace_with[] = '[if '. $new .']';
476
  $replace[] = '[if '. $old .' ';
481
  $replace_with[] = '['. $new .']';
482
  $replace[] = '['. $old .' ';
483
  $replace_with[] = '['. $new .' ';
484
+ unset($old);
485
+ unset($new);
486
  }
487
+ if(is_array($val)){
488
+ foreach($val as $k => $v){
489
+ $val[$k] = str_replace($replace, $replace_with, $v);
490
+ unset($k);
491
+ unset($v);
492
  }
493
+ }else{
494
  $val = str_replace($replace, $replace_with, $val);
495
  }
496
+
497
  return $val;
498
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
  }
classes/helpers/FrmFormActionsHelper.php DELETED
@@ -1,107 +0,0 @@
1
- <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
-
6
- class FrmFormActionsHelper {
7
-
8
- public static function get_action_for_form($form_id, $type = 'all', $limit = 99) {
9
- $action_controls = FrmFormActionsController::get_form_actions( $type );
10
- if ( empty($action_controls) ) {
11
- // don't continue if there are no available actions
12
- return array();
13
- }
14
-
15
- if ( 'all' != $type ) {
16
- return $action_controls->get_all( $form_id, $limit );
17
- }
18
-
19
- $args = array(
20
- 'post_type' => FrmFormActionsController::$action_post_type,
21
- 'post_status' => 'publish',
22
- 'numberposts' => 99,
23
- 'orderby' => 'title',
24
- 'order' => 'ASC',
25
- );
26
-
27
- if ( $form_id ) {
28
- $args['menu_order'] = $form_id;
29
- }
30
-
31
- $actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
32
-
33
- if ( ! $actions ) {
34
- return array();
35
- }
36
-
37
- $settings = array();
38
- foreach ( $actions as $action ) {
39
- if ( ! isset( $action_controls[ $action->post_excerpt ] ) || count( $settings ) >= $limit ) {
40
- continue;
41
- }
42
-
43
- $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
44
-
45
- $settings[ $action->ID ] = $action;
46
- }
47
-
48
- if ( 1 === $limit ) {
49
- $settings = reset($settings);
50
- }
51
-
52
- return $settings;
53
- }
54
-
55
- public static function action_conditions_met($action, $entry) {
56
- $notification = $action->post_content;
57
- $stop = false;
58
- $met = array();
59
-
60
- if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
61
- return $stop;
62
- }
63
-
64
- foreach ( $notification['conditions'] as $k => $condition ) {
65
- if ( ! is_numeric( $k ) ) {
66
- continue;
67
- }
68
-
69
- if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
70
- continue;
71
- }
72
-
73
- if ( is_array($condition['hide_opt']) ) {
74
- $condition['hide_opt'] = reset($condition['hide_opt']);
75
- }
76
-
77
- $observed_value = isset( $entry->metas[ $condition['hide_field'] ] ) ? $entry->metas[ $condition['hide_field'] ] : '';
78
- if ( $condition['hide_opt'] == 'current_user' ) {
79
- $condition['hide_opt'] = get_current_user_id();
80
- }
81
-
82
- $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']);
83
-
84
- if ( $notification['conditions']['send_stop'] == 'send' ) {
85
- $stop = $stop ? false : true;
86
- }
87
-
88
- $met[ $stop ] = $stop;
89
- }
90
-
91
- if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
92
- $stop = ($notification['conditions']['send_stop'] == 'send') ? true : false;
93
- } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) {
94
- $stop = false;
95
- }
96
-
97
- return $stop;
98
- }
99
-
100
- public static function default_action_opts($class = '') {
101
- return array(
102
- 'classes' => 'frm_icon_font '. $class,
103
- 'active' => false,
104
- 'limit' => 0,
105
- );
106
- }
107
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/helpers/FrmFormsHelper.php CHANGED
@@ -1,582 +1,296 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
 
6
- class FrmFormsHelper {
7
- /**
8
- * If $form is numeric, get the form object
9
- * @param object|int $form
10
- */
11
- public static function maybe_get_form( &$form ) {
12
- if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) {
13
- $form = FrmForm::getOne($form);
14
- }
15
- }
16
 
 
17
  public static function get_direct_link($key, $form = false ) {
18
  $target_url = esc_url(admin_url('admin-ajax.php') . '?action=frm_forms_preview&form='. $key);
19
  $target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
20
 
21
  return $target_url;
22
  }
23
-
24
- public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) {
25
- $defaults = array(
26
- 'blank' => true,
27
- 'field_id' => false,
28
- 'onchange' => false,
29
- 'exclude' => false,
30
- 'class' => '',
31
- );
32
- $args = wp_parse_args( $args, $defaults );
33
-
34
- if ( ! $args['field_id'] ) {
35
- $args['field_id'] = $field_name;
36
- }
37
-
38
- $query = array();
39
- if ( $args['exclude'] ) {
40
- $query['id !'] = $args['exclude'];
41
  }
42
-
43
- $where = apply_filters('frm_forms_dropdown', $query, $field_name);
44
- $forms = FrmForm::get_published_forms( $where );
45
  ?>
46
- <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $args['field_id'] ) ?>" <?php
47
- if ( $args['onchange'] ) {
48
- echo ' onchange="' . esc_attr( $args['onchange'] ) . '"';
49
- }
50
- if ( ! empty( $args['class'] ) ) {
51
- echo ' class="' . esc_attr( $args['class'] ) . '"';
52
- } ?>>
53
- <?php if ( $args['blank'] ) { ?>
54
- <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
55
- <?php } ?>
56
- <?php foreach ( $forms as $form ) { ?>
57
- <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>><?php
58
- echo '' == $form->name ? __( '(no title)', 'formidable' ) : esc_attr( FrmAppHelper::truncate( $form->name, 33 ) );
59
- ?></option>
60
- <?php } ?>
 
 
 
 
 
 
 
 
 
61
  </select>
62
  <?php
63
  }
64
-
65
- public static function form_switcher() {
66
- $where = apply_filters( 'frm_forms_dropdown', array(), '' );
67
- $forms = FrmForm::get_published_forms( $where );
68
-
69
- $args = array( 'id' => 0, 'form' => 0);
70
- if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
71
- unset( $args['form'] );
72
- } else if ( isset( $_GET['form']) && ! isset( $_GET['id'] ) ) {
73
- unset( $args['id'] );
74
- }
75
-
76
- if ( FrmAppHelper::is_admin_page('formidable-entries') && isset($_GET['frm_action']) && in_array($_GET['frm_action'], array( 'edit', 'show', 'destroy_all')) ) {
 
 
77
  $args['frm_action'] = 'list';
78
  $args['form'] = 0;
79
- } else if ( FrmAppHelper::is_admin_page('formidable' ) && isset( $_GET['frm_action'] ) && in_array( $_GET['frm_action'], array( 'new', 'duplicate' ) ) ) {
80
  $args['frm_action'] = 'edit';
81
- } else if ( isset( $_GET['post'] ) ) {
82
  $args['form'] = 0;
83
  $base = admin_url('edit.php?post_type=frm_display');
84
  }
85
 
86
  ?>
87
  <li class="dropdown last" id="frm_bs_dropdown">
88
- <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e( 'Switch Form', 'formidable' ) ?> <b class="caret"></b></a>
89
- <ul class="frm-dropdown-menu frm-on-top" role="menu" aria-labelledby="frm-navbarDrop">
90
- <?php
91
- foreach ( $forms as $form ) {
92
- if ( isset( $args['id'] ) ) {
93
  $args['id'] = $form->id;
94
- }
95
- if ( isset( $args['form'] ) ) {
96
  $args['form'] = $form->id;
97
- }
98
  ?>
99
- <li><a href="<?php echo isset($base) ? add_query_arg($args, $base) : add_query_arg($args); ?>" tabindex="-1"><?php echo empty($form->name) ? __( '(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
100
  <?php
101
- unset( $form );
102
- } ?>
103
  </ul>
104
  </li>
105
  <?php
106
  }
107
-
108
- public static function get_sortable_classes($col, $sort_col, $sort_dir) {
109
- echo ($sort_col == $col) ? 'sorted' : 'sortable';
110
- echo ($sort_col == $col && $sort_dir == 'desc') ? ' asc' : ' desc';
111
  }
112
-
113
- /**
114
- * Used when a form is created
115
- */
116
- public static function setup_new_vars( $values = array() ) {
117
- global $wpdb;
118
-
119
- if ( ! empty( $values ) ) {
120
  $post_values = $values;
121
- } else {
122
  $values = array();
123
  $post_values = isset($_POST) ? $_POST : array();
124
  }
125
-
126
- foreach ( array( 'name' => '', 'description' => '') as $var => $default) {
127
- if ( ! isset( $values[ $var ] ) ) {
128
- $values[ $var ] = FrmAppHelper::get_param( $var, $default );
129
- }
130
- }
131
-
132
- $values['description'] = FrmAppHelper::use_wpautop($values['description']);
133
-
134
- foreach ( array( 'form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0, 'status' => 'draft', 'parent_form_id' => 0) as $var => $default) {
135
- if ( ! isset( $values[ $var ] ) ) {
136
- $values[ $var ] = FrmAppHelper::get_param( $var, $default );
137
- }
138
  }
139
-
140
- if ( ! isset( $values['form_key'] ) ) {
141
- $values['form_key'] = ($post_values && isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
 
 
 
 
142
  }
143
-
 
 
 
144
  $values = self::fill_default_opts($values, false, $post_values);
145
-
146
- if ( $post_values && isset($post_values['options']['custom_style']) ) {
147
- $values['custom_style'] = $post_values['options']['custom_style'];
148
- } else {
149
- $frm_settings = FrmAppHelper::get_settings();
150
- $values['custom_style'] = ( $frm_settings->load_style != 'none' );
151
- }
152
-
153
  return apply_filters('frm_setup_new_form_vars', $values);
154
  }
155
-
156
- /**
157
- * Used when editing a form
158
- */
159
- public static function setup_edit_vars( $values, $record, $post_values = array() ) {
160
- if ( empty( $post_values ) ) {
161
- $post_values = stripslashes_deep( $_POST );
162
- }
163
 
164
  $values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
165
  $values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
166
  $values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
167
- $values['status'] = $record->status;
168
-
169
  $values = self::fill_default_opts($values, $record, $post_values);
170
 
171
  return apply_filters('frm_setup_edit_form_vars', $values);
172
  }
173
-
174
  public static function fill_default_opts($values, $record, $post_values) {
175
-
176
- $defaults = self::get_default_opts();
177
- foreach ( $defaults as $var => $default ) {
178
  if ( is_array($default) ) {
179
- if ( ! isset( $values[ $var ] ) ) {
180
- $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
181
- }
182
-
183
- foreach ( $default as $k => $v ) {
184
- $values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v);
185
-
186
- if ( is_array( $v ) ) {
187
  foreach ( $v as $k1 => $v1 ) {
188
- $values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
189
- unset( $k1, $v1 );
 
190
  }
191
  }
192
-
193
- unset($k, $v);
 
194
  }
195
- } else {
 
196
  $values[$var] = ($post_values && isset($post_values['options'][$var])) ? $post_values['options'][$var] : (($record && isset($record->options[$var])) ? $record->options[$var] : $default);
197
  }
198
-
199
- unset($var, $default);
 
200
  }
201
-
202
  return $values;
203
  }
204
-
205
- public static function get_default_opts() {
206
- $frm_settings = FrmAppHelper::get_settings();
207
-
208
  return array(
 
 
 
 
 
 
 
 
209
  'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
210
  'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
211
- 'no_save' => 0, 'ajax_load' => 0, 'form_class' => '', 'custom_style' => 1,
212
- 'before_html' => self::get_default_html('before'),
213
- 'after_html' => '',
214
- 'submit_html' => self::get_default_html('submit'),
215
  );
216
  }
217
-
218
- /**
219
- * @param string $loc
220
- */
221
- public static function get_default_html($loc) {
222
- if ( $loc == 'submit' ) {
223
- $sending = __( 'Sending', 'formidable' );
224
  $draft_link = self::get_draft_link();
225
  $img = '[frmurl]/images/ajax_loader.gif';
226
  $default_html = <<<SUBMIT_HTML
227
  <div class="frm_submit">
228
  [if back_button]<input type="button" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook] />[/if back_button]
229
  <input type="submit" value="[button_label]" [button_action] />
230
- <img class="frm_ajax_loading" src="$img" alt="$sending"/>
231
  $draft_link
232
  </div>
233
  SUBMIT_HTML;
234
- } else if ( $loc == 'before' ) {
235
  $default_html = <<<BEFORE_HTML
236
  [if form_name]<h3>[form_name]</h3>[/if form_name]
237
  [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
238
  BEFORE_HTML;
239
- } else {
240
  $default_html = '';
241
  }
242
-
243
  return $default_html;
244
  }
245
-
246
- public static function get_draft_link() {
247
- $link = '[if save_draft]<a href="javascript:void(0)" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
248
  return $link;
249
  }
250
-
251
- public static function get_custom_submit($html, $form, $submit, $form_action, $values) {
252
- $button = self::replace_shortcodes($html, $form, $submit, $form_action, $values);
253
- if ( ! strpos($button, '[button_action]') ) {
254
- return;
255
- }
256
-
257
- $button_parts = explode('[button_action]', $button);
258
- echo $button_parts[0];
259
- //echo ' id="frm_submit_"';
260
-
261
- $classes = apply_filters('frm_submit_button_class', array(), $form);
262
- if ( ! empty($classes) ) {
263
- echo ' class="'. implode(' ', $classes) .'"';
264
- }
265
-
266
- do_action('frm_submit_button_action', $form, $form_action);
267
- echo $button_parts[1];
268
- }
269
-
270
- /**
271
- * Automatically add end section fields if they don't exist (2.0 migration)
272
- * @since 2.0
273
- *
274
- * @param boolean $reset_fields
275
- */
276
- public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
277
- if ( empty( $fields ) ) {
278
- return;
279
- }
280
-
281
- $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) );
282
- $open = $prev_order = false;
283
- $add_order = 0;
284
- foreach ( $fields as $field ) {
285
- if ( $prev_order === $field->field_order ) {
286
- $add_order++;
287
- }
288
-
289
- if ( $add_order ) {
290
- $reset_fields = true;
291
- $field->field_order = $field->field_order + $add_order;
292
- FrmField::update( $field->id, array( 'field_order' => $field->field_order ) );
293
- }
294
-
295
- switch ( $field->type ) {
296
- case 'divider':
297
- // create an end section if open
298
- self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field );
299
-
300
- // mark it open for the next end section
301
- $open = true;
302
- break;
303
- case 'break';
304
- self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $field );
305
- break;
306
- case 'end_divider':
307
- if ( ! $open ) {
308
- // the section isn't open, so this is an extra field that needs to be removed
309
- FrmField::destroy( $field->id );
310
- $reset_fields = true;
311
- }
312
-
313
- // There is already an end section here, so there is no need to create one
314
- $open = false;
315
- }
316
- $prev_order = $field->field_order;
317
- }
318
-
319
- self::maybe_create_end_section($open, $reset_fields, $add_order, $end_section_values, $field );
320
- }
321
-
322
- /**
323
- * Create end section field if it doesn't exist. This is for migration from < 2.0
324
- * Fix any ordering that may be messed up
325
- */
326
- public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field ) {
327
- if ( ! $open ) {
328
- return;
329
  }
330
-
331
- $end_section_values['field_order'] = $field->field_order + 1;
332
-
333
- FrmField::create( $end_section_values );
334
-
335
- $add_order += 2;
336
-
337
- // bump the order of current field
338
- FrmField::update( $field->id, array( 'field_order' => $field->field_order + $add_order ) );
339
-
340
- $open = false;
341
- $reset_fields = true;
342
  }
343
-
344
- public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
345
- foreach ( array( 'form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show) {
346
- if ( $code == 'form_name' ) {
347
  $replace_with = $form->name;
348
- } else if ( $code == 'form_description' ) {
349
- $replace_with = FrmAppHelper::use_wpautop($form->description);
350
- } else if ( $code == 'entry_key' && isset($_GET) && isset($_GET['entry']) ) {
351
- $replace_with = sanitize_text_field( $_GET['entry'] );
352
- } else {
353
- $replace_with = '';
 
354
  }
355
-
356
- FrmFieldsHelper::remove_inline_conditions( ( FrmAppHelper::is_true($show) && $replace_with != '' ), $code, $replace_with, $html );
 
 
 
 
 
 
357
  }
358
-
359
  //replace [form_key]
360
  $html = str_replace('[form_key]', $form->form_key, $html);
361
-
362
  //replace [frmurl]
363
- $html = str_replace('[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html);
364
-
365
- if ( strpos( $html, '[button_label]' ) ) {
366
- add_filter('frm_submit_button', 'FrmFormsHelper::submit_button_label');
367
  $replace_with = apply_filters('frm_submit_button', $title, $form);
368
  $html = str_replace('[button_label]', $replace_with, $html);
369
  }
370
-
371
  $html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
372
-
373
- if ( strpos( $html, '[if back_button]' ) ) {
374
- $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html );
375
- }
376
-
377
- if ( strpos( $html, '[if save_draft]' ) ) {
378
- $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
379
- }
380
-
381
  return $html;
382
  }
383
-
384
- public static function submit_button_label($submit) {
385
- if ( ! $submit || empty($submit) ) {
386
- $frm_settings = FrmAppHelper::get_settings();
387
- $submit = $frm_settings->submit_value;
388
- }
389
-
390
- return $submit;
391
- }
392
-
393
- public static function get_form_style_class($form = false) {
394
- $style = self::get_form_style($form);
395
- $class = ' with_frm_style';
396
-
397
- if ( empty($style) ) {
398
- if ( FrmAppHelper::is_admin_page('formidable-entries') ) {
399
- return $class;
400
- } else {
401
- return;
402
- }
403
- }
404
-
405
- //If submit button needs to be inline or centered
406
- if ( is_object($form) ) {
407
- $form = $form->options;
408
- }
409
-
410
- $submit_align = isset( $form['submit_align'] ) ? $form['submit_align'] : '';
411
-
412
- if ( $submit_align == 'inline' ) {
413
- $class .= ' frm_inline_form';
414
- } else if ( $submit_align == 'center' ) {
415
- $class .= ' frm_center_submit';
416
- }
417
-
418
- $class = apply_filters('frm_add_form_style_class', $class, $style);
419
-
420
- return $class;
421
- }
422
-
423
- /**
424
- * @param string|boolean $form
425
- *
426
- * @return boolean
427
- */
428
- public static function get_form_style( $form ) {
429
- if ( empty($form) ) {
430
- $style = 1;
431
- } else if ( is_object($form) ) {
432
- $style = isset($form->options['custom_style']) ? $form->options['custom_style'] : 1;
433
- } else if ( is_array($form) ) {
434
- $style = isset($form['custom_style']) ? $form['custom_style'] : 1;
435
- } else if ( 'default' == 'form' ) {
436
- $style = 1;
437
- } else {
438
- $form = FrmForm::getOne($form);
439
- $style = ( $form && isset($form->options['custom_style']) ) ? $form->options['custom_style'] : 1;
440
- }
441
-
442
- return $style;
443
- }
444
-
445
- public static function form_loaded($form, $this_load, $global_load) {
446
  global $frm_vars;
447
  $small_form = new stdClass();
448
- foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
449
  $small_form->{$var} = $form->{$var};
450
  unset($var);
451
  }
452
-
453
  $frm_vars['forms_loaded'][] = $small_form;
454
-
455
- if ( $this_load && empty($global_load) ) {
456
- $global_load = $frm_vars['load_css'] = true;
457
- }
458
-
459
- if ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ) {
460
- echo FrmAppController::footer_js('header');
461
- $frm_vars['css_loaded'] = true;
462
- }
463
- }
464
-
465
- public static function get_scroll_js($form_id) {
466
- ?><script type="text/javascript">jQuery(document).ready(function(){frmFrontForm.scrollMsg(<?php echo (int) $form_id ?>);})</script><?php
467
- }
468
-
469
- public static function edit_form_link($form_id) {
470
- if ( is_object($form_id) ) {
471
- $form = $form_id;
472
- $name = $form->name;
473
- $form_id = $form->id;
474
- } else {
475
- $name = FrmForm::getName($form_id);
476
- }
477
-
478
- if ( $form_id ) {
479
- $val = '<a href="'. admin_url('admin.php') .'?page=formidable&frm_action=edit&id='. $form_id .'">'. ( '' == $name ? __( '(no title)') : FrmAppHelper::truncate($name, 40) ) .'</a>';
480
- } else {
481
- $val = '';
482
- }
483
-
484
- return $val;
485
- }
486
-
487
- public static function delete_trash_link($id, $status, $length = 'long') {
488
- $link = '';
489
- $labels = array(
490
- 'restore' => array(
491
- 'long' => __( 'Restore from Trash', 'formidable' ),
492
- 'short' => __( 'Restore', 'formidable' ),
493
- ),
494
- 'trash' => array(
495
- 'long' => __( 'Move to Trash', 'formidable' ),
496
- 'short' => __( 'Trash', 'formidable' ),
497
- ),
498
- 'delete' => array(
499
- 'long' => __( 'Delete Permanently', 'formidable' ),
500
- 'short' => __( 'Delete', 'formidable' ),
501
- ),
502
- );
503
-
504
- $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
505
- $base_url = '?page=formidable&form_type='. $current_page .'&id='. $id;
506
- if ( 'trash' == $status ) {
507
- $link = '<a href="'. esc_url(wp_nonce_url( $base_url .'&frm_action=untrash', 'untrash_form_' . $id )) .'" class="submitdelete deletion">'. $labels['restore'][$length] .'</a>';
508
- } else if ( current_user_can('frm_delete_forms') ) {
509
- if ( EMPTY_TRASH_DAYS ) {
510
- $link = '<a href="'. wp_nonce_url( $base_url .'&frm_action=trash', 'trash_form_' . $id ) .'" class="submitdelete deletion">'. $labels['trash'][$length] .'</a>';
511
- } else {
512
- $link = '<a href="'. wp_nonce_url( $base_url .'&frm_action=destroy', 'destroy_form_' . $id ) .'" class="submitdelete deletion" onclick="return confirm(\''. __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ) .'\')">'. $labels['delete'][$length] .'</a>';
513
- }
514
- }
515
-
516
- return $link;
517
- }
518
-
519
- public static function status_nice_name($status) {
520
- $nice_names = array(
521
- 'draft' => __( 'Draft', 'formidable' ),
522
- 'trash' => __( 'Trash', 'formidable' ),
523
- 'publish' => __( 'Published', 'formidable' ),
524
- );
525
-
526
- if ( ! in_array($status, array_keys($nice_names)) ) {
527
- $status = 'publish';
528
- }
529
-
530
- $name = $nice_names[$status];
531
-
532
- return $name;
533
- }
534
-
535
- public static function get_params() {
536
- $values = array();
537
- foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default ) {
538
- $values[$var] = FrmAppHelper::get_param($var, $default);
539
- }
540
-
541
- return $values;
542
  }
543
 
544
- /**
545
- * @param string $status
546
- *
547
- * @return int The number of forms changed
548
- */
549
- public static function change_form_status( $status ) {
550
- $available_status = array(
551
- 'untrash' => array(
552
- 'permission' => 'frm_edit_forms', 'new_status' => 'published',
553
- ),
554
- 'trash' => array(
555
- 'permission' => 'frm_delete_forms', 'new_status' => 'trash',
556
- ),
557
- );
558
-
559
- if ( ! isset($available_status[$status]) ) {
560
- return;
561
- }
562
-
563
- FrmAppHelper::permission_check($available_status[$status]['permission']);
564
-
565
- $params = self::get_params();
566
-
567
- //check nonce url
568
- check_admin_referer($status .'_form_' . $params['id']);
569
-
570
- $count = 0;
571
- if ( FrmForm::set_status( $params['id'], $available_status[$status]['new_status'] ) ) {
572
- $count++;
573
- }
574
-
575
- $available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
576
- $available_status['trash']['message'] = sprintf(_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="'. esc_url(wp_nonce_url( '?page=formidable&frm_action=untrash&form_type='. ( isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '' ) .'&id='. $params['id'], 'untrash_form_' . $params['id'] )) .'">', '</a>' );
577
-
578
- $message = $available_status[$status]['message'];
579
-
580
- FrmFormsController::display_forms_list($params, $message, 1);
581
- }
582
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
 
 
3
 
4
+ if(class_exists('FrmFormsHelper'))
5
+ return;
 
 
 
 
 
 
 
 
6
 
7
+ class FrmFormsHelper{
8
  public static function get_direct_link($key, $form = false ) {
9
  $target_url = esc_url(admin_url('admin-ajax.php') . '?action=frm_forms_preview&form='. $key);
10
  $target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
11
 
12
  return $target_url;
13
  }
14
+
15
+ public static function get_template_dropdown($templates) {
16
+ if ( ! current_user_can('frm_edit_forms') ) {
17
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
 
 
 
19
  ?>
20
+ <select id="select_form" name="select_form" onChange="frmAddNewForm(this.value,'duplicate')">
21
+ <option value="">&mdash; <?php _e('Create Form from Template', 'formidable') ?> &mdash;</option>
22
+ <?php foreach ($templates as $temp){ ?>
23
+ <option value="<?php echo $temp->id ?>"><?php echo FrmAppHelper::truncate($temp->name, 40) ?></option>
24
+ <?php }?>
25
+ </select>
26
+ <?php
27
+ }
28
+
29
+ public static function forms_dropdown( $field_name, $field_value='', $blank=true, $field_id=false, $onchange=false ){
30
+ if (!$field_id)
31
+ $field_id = $field_name;
32
+
33
+ $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", $field_name);
34
+ $frm_form = new FrmForm();
35
+ $forms = $frm_form->getAll($where, ' ORDER BY name');
36
+ ?>
37
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_id ?>" <?php if ($onchange) echo 'onchange="'. $onchange .'"'; ?>>
38
+ <?php if ($blank){ ?>
39
+ <option value=""><?php echo ($blank == 1) ? '' : '- '. $blank .' -'; ?></option>
40
+ <?php } ?>
41
+ <?php foreach($forms as $form){ ?>
42
+ <option value="<?php echo $form->id; ?>" <?php selected($field_value, $form->id); ?>><?php echo FrmAppHelper::truncate($form->name, 33); ?></option>
43
+ <?php } ?>
44
  </select>
45
  <?php
46
  }
47
+
48
+ public static function form_switcher(){
49
+ $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", '');
50
+
51
+ $frm_form = new FrmForm();
52
+ $forms = $frm_form->getAll($where, ' ORDER BY name');
53
+ unset($frm_form);
54
+
55
+ $args = array('id' => 0, 'form' => 0);
56
+ if(isset($_GET['id']) and !isset($_GET['form']))
57
+ unset($args['form']);
58
+ else if(isset($_GET['form']) and !isset($_GET['id']))
59
+ unset($args['id']);
60
+
61
+ if(isset($_GET['page']) and $_GET['page'] == 'formidable-entries' and isset($_GET['frm_action']) and in_array($_GET['frm_action'], array('edit', 'show', 'destroy_all'))){
62
  $args['frm_action'] = 'list';
63
  $args['form'] = 0;
64
+ }else if(isset($_GET['page']) and $_GET['page'] == 'formidable' and isset($_GET['frm_action']) and $_GET['frm_action'] == 'new'){
65
  $args['frm_action'] = 'edit';
66
+ }else if(isset($_GET['post'])){
67
  $args['form'] = 0;
68
  $base = admin_url('edit.php?post_type=frm_display');
69
  }
70
 
71
  ?>
72
  <li class="dropdown last" id="frm_bs_dropdown">
73
+ <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Switch Form', 'formidable') ?> <b class="caret"></b></a>
74
+ <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-navbarDrop">
75
+ <?php foreach($forms as $form){
76
+ if(isset($args['id']))
 
77
  $args['id'] = $form->id;
78
+ if(isset($args['form']))
 
79
  $args['form'] = $form->id;
 
80
  ?>
81
+ <li><a href="<?php echo isset($base) ? add_query_arg($args, $base) : add_query_arg($args); ?>" tabindex="-1"><?php echo empty($form->name) ? __('(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
82
  <?php
83
+ unset($form);
84
+ } ?>
85
  </ul>
86
  </li>
87
  <?php
88
  }
89
+
90
+ public static function get_sortable_classes($col, $sort_col, $sort_dir){
91
+ echo ($sort_col == $col) ? 'sorted' : 'sortable';
92
+ echo ($sort_col == $col and $sort_dir == 'desc') ? ' asc' : ' desc';
93
  }
94
+
95
+ public static function setup_new_vars($values=array()){
96
+ global $wpdb, $frmdb, $frm_settings;
97
+
98
+ if(!empty($values)){
 
 
 
99
  $post_values = $values;
100
+ }else{
101
  $values = array();
102
  $post_values = isset($_POST) ? $_POST : array();
103
  }
104
+
105
+ foreach (array('name' => '', 'description' => '') as $var => $default){
106
+ if(!isset($values[$var]))
107
+ $values[$var] = FrmAppHelper::get_param($var, $default);
 
 
 
 
 
 
 
 
 
108
  }
109
+
110
+ if(apply_filters('frm_use_wpautop', true))
111
+ $values['description'] = wpautop(str_replace( '<br>', '<br />', $values['description']));
112
+
113
+ foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default){
114
+ if(!isset($values[$var]))
115
+ $values[$var] = FrmAppHelper::get_param($var, $default);
116
  }
117
+
118
+ if(!isset($values['form_key']))
119
+ $values['form_key'] = ($post_values and isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
120
+
121
  $values = self::fill_default_opts($values, false, $post_values);
122
+
123
+ $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $post_values['options']['custom_style'] : ($frm_settings->load_style != 'none');
124
+ $values['before_html'] = FrmFormsHelper::get_default_html('before');
125
+ $values['after_html'] = FrmFormsHelper::get_default_html('after');
126
+ $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
127
+
 
 
128
  return apply_filters('frm_setup_new_form_vars', $values);
129
  }
130
+
131
+ public static function setup_edit_vars($values, $record, $post_values=array()){
132
+ if(empty($post_values))
133
+ $post_values = stripslashes_deep($_POST);
 
 
 
 
134
 
135
  $values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
136
  $values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
137
  $values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
138
+
 
139
  $values = self::fill_default_opts($values, $record, $post_values);
140
 
141
  return apply_filters('frm_setup_edit_form_vars', $values);
142
  }
143
+
144
  public static function fill_default_opts($values, $record, $post_values) {
145
+
146
+ $defaults = FrmFormsHelper::get_default_opts();
147
+ foreach ($defaults as $var => $default){
148
  if ( is_array($default) ) {
149
+ if(!isset($values[$var]))
150
+ $values[$var] = ($record && isset($record->options[$var])) ? $record->options[$var] : array();
151
+
152
+ foreach($default as $k => $v){
153
+ $values[$var][$k] = ($post_values && isset($post_values[$var][$k])) ? $post_values[$var][$k] : (($record && isset($record->options[$var]) && isset($record->options[$var][$k])) ? $record->options[$var][$k] : $v);
154
+
155
+ if ( is_array($v) ) {
 
156
  foreach ( $v as $k1 => $v1 ) {
157
+ $values[$var][$k][$k1] = ($post_values && isset($post_values[$var][$k][$k1])) ? $post_values[$var][$k][$k1] : (($record && isset($record->options[$var]) && isset($record->options[$var][$k]) && isset($record->options[$var][$k][$k1])) ? $record->options[$var][$k][$k1] : $v1);
158
+ unset($k1);
159
+ unset($v1);
160
  }
161
  }
162
+
163
+ unset($k);
164
+ unset($v);
165
  }
166
+
167
+ }else{
168
  $values[$var] = ($post_values && isset($post_values['options'][$var])) ? $post_values['options'][$var] : (($record && isset($record->options[$var])) ? $record->options[$var] : $default);
169
  }
170
+
171
+ unset($var);
172
+ unset($default);
173
  }
174
+
175
  return $values;
176
  }
177
+
178
+ public static function get_default_opts(){
179
+ global $frm_settings;
180
+
181
  return array(
182
+ 'notification' => array(
183
+ array(
184
+ 'email_to' => $frm_settings->email_to, 'reply_to' => '', 'reply_to_name' => '',
185
+ 'cust_reply_to' => '', 'cust_reply_to_name' => '',
186
+ 'email_subject' => '', 'email_message' => '[default-message]',
187
+ 'inc_user_info' => 0, 'plain_text' => 0,
188
+ )
189
+ ),
190
  'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
191
  'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
192
+ 'no_save' => 0, 'ajax_load' => 0
 
 
 
193
  );
194
  }
195
+
196
+ public static function get_default_html($loc){
197
+ if($loc == 'submit'){
198
+ $sending = __('Sending', 'formidable');
 
 
 
199
  $draft_link = self::get_draft_link();
200
  $img = '[frmurl]/images/ajax_loader.gif';
201
  $default_html = <<<SUBMIT_HTML
202
  <div class="frm_submit">
203
  [if back_button]<input type="button" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook] />[/if back_button]
204
  <input type="submit" value="[button_label]" [button_action] />
205
+ <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
206
  $draft_link
207
  </div>
208
  SUBMIT_HTML;
209
+ }else if ($loc == 'before'){
210
  $default_html = <<<BEFORE_HTML
211
  [if form_name]<h3>[form_name]</h3>[/if form_name]
212
  [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
213
  BEFORE_HTML;
214
+ }else{
215
  $default_html = '';
216
  }
217
+
218
  return $default_html;
219
  }
220
+
221
+ public static function get_draft_link(){
222
+ $link = '[if save_draft]<a class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
223
  return $link;
224
  }
225
+
226
+ public static function get_custom_submit($html, $form, $submit, $form_action, $values){
227
+ $button = FrmFormsHelper::replace_shortcodes($html, $form, $submit, $form_action, $values);
228
+ if(strpos($button, '[button_action]')){
229
+ $button_parts = explode('[button_action]', $button);
230
+ echo $button_parts[0];
231
+ //echo ' id="frm_submit_"';
232
+ $classes = apply_filters('frm_submit_button_class', array(), $form);
233
+ if(!empty($classes))
234
+ echo ' class="'. implode(' ', $classes) .'"';
235
+
236
+ do_action('frm_submit_button_action', $form, $form_action);
237
+ echo $button_parts[1];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
 
 
 
 
 
 
 
 
 
 
 
 
239
  }
240
+
241
+ public static function replace_shortcodes($html, $form, $title=false, $description=false, $values=array()){
242
+ foreach (array('form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show){
243
+ if ($code == 'form_name'){
244
  $replace_with = $form->name;
245
+ }else if ($code == 'form_description'){
246
+ if(apply_filters('frm_use_wpautop', true))
247
+ $replace_with = wpautop(str_replace( '<br>', '<br />', $form->description));
248
+ else
249
+ $replace_with = $form->description;
250
+ }else if($code == 'entry_key' and isset($_GET) and isset($_GET['entry'])){
251
+ $replace_with = $_GET['entry'];
252
  }
253
+
254
+ if ( FrmAppHelper::is_true($show) && $replace_with != '' ) {
255
+ $html = str_replace('[if '.$code.']', '', $html);
256
+ $html = str_replace('[/if '.$code.']', '', $html);
257
+ }else{
258
+ $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
259
+ }
260
+ $html = str_replace('['.$code.']', $replace_with, $html);
261
  }
262
+
263
  //replace [form_key]
264
  $html = str_replace('[form_key]', $form->form_key, $html);
265
+
266
  //replace [frmurl]
267
+ $html = str_replace('[frmurl]', FrmAppHelper::plugin_url(), $html);
268
+
269
+ if(strpos($html, '[button_label]')){
 
270
  $replace_with = apply_filters('frm_submit_button', $title, $form);
271
  $html = str_replace('[button_label]', $replace_with, $html);
272
  }
273
+
274
  $html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
275
+
276
+ if(strpos($html, '[if back_button]'))
277
+ $html = preg_replace('/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html);
278
+
279
+ if(strpos($html, '[if save_draft]'))
280
+ $html = preg_replace('/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html);
281
+
 
 
282
  return $html;
283
  }
284
+
285
+ public static function form_loaded($form) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  global $frm_vars;
287
  $small_form = new stdClass();
288
+ foreach ( array('id', 'form_key', 'name' ) as $var ) {
289
  $small_form->{$var} = $form->{$var};
290
  unset($var);
291
  }
292
+
293
  $frm_vars['forms_loaded'][] = $small_form;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  }
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  }
classes/helpers/FrmFormsListHelper.php DELETED
@@ -1,370 +0,0 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
-
6
- class FrmFormsListHelper extends FrmListHelper {
7
- var $status = '';
8
-
9
- public function __construct( $args ) {
10
- $this->status = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
11
-
12
- parent::__construct( $args );
13
- }
14
-
15
- public function prepare_items() {
16
- global $wpdb, $per_page, $mode;
17
-
18
- $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
19
-
20
- $default_orderby = 'name';
21
- $default_order = 'ASC';
22
-
23
- $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
24
- $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
25
-
26
- $page = $this->get_pagenum();
27
- $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
28
-
29
- $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
30
-
31
- $s_query = array();
32
- $s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 );
33
- switch ( $this->status ) {
34
- case 'template':
35
- $s_query['is_template'] = 1;
36
- $s_query['status !'] = 'trash';
37
- break;
38
- case 'draft':
39
- $s_query['is_template'] = 0;
40
- $s_query['status'] = 'draft';
41
- break;
42
- case 'trash':
43
- $s_query['status'] = 'trash';
44
- break;
45
- default:
46
- $s_query['is_template'] = 0;
47
- $s_query['status !'] = 'trash';
48
- break;
49
- }
50
-
51
- $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
52
- if ( $s != '' ) {
53
- preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
54
- $search_terms = array_map('trim', $matches[0]);
55
- foreach ( (array) $search_terms as $term ) {
56
- $s_query[] = array(
57
- 'or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term,
58
- );
59
- unset($term);
60
- }
61
- }
62
-
63
- $this->items = FrmForm::getAll($s_query, $orderby .' '. $order, $start .','. $per_page);
64
- $total_items = FrmDb::get_count( 'frm_forms', $s_query );
65
-
66
- $this->set_pagination_args( array(
67
- 'total_items' => $total_items,
68
- 'per_page' => $per_page,
69
- ) );
70
- }
71
-
72
- public function no_items() {
73
- if ( 'template' == $this->status ) {
74
- _e( 'No Templates Found.', 'formidable' ) ?>
75
- <br/><br/><?php _e( 'To add a new template:', 'formidable' ) ?>
76
- <ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="'. esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li>
77
- <li><?php printf(__( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>') ?></li>
78
- <li><?php _e( 'Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable' ) ?></li>
79
- </ol>
80
- <?php } else {
81
- _e( 'No Forms Found.', 'formidable' ) ?>
82
- <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) ?>"><?php _e( 'Add New', 'formidable' ); ?></a>
83
- <?php }
84
- }
85
-
86
- public function get_bulk_actions() {
87
- $actions = array();
88
-
89
- if ( in_array($this->status, array( '', 'published')) ) {
90
- $actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
91
- }
92
-
93
- if ( 'trash' == $this->status ) {
94
- if ( current_user_can('frm_edit_forms') ) {
95
- $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
96
- }
97
-
98
- if ( current_user_can('frm_delete_forms') ) {
99
- $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
100
- }
101
- } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
102
- $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
103
- } else if ( current_user_can('frm_delete_forms') ) {
104
- $actions['bulk_delete'] = __( 'Delete');
105
- }
106
-
107
- return $actions;
108
- }
109
-
110
- public function extra_tablenav( $which ) {
111
- if ( 'top' != $which ) {
112
- return;
113
- }
114
-
115
- if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) {
116
- ?>
117
- <div class="alignleft actions frm_visible_overflow">
118
- <?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?>
119
- </div>
120
- <?php
121
- return;
122
- }
123
-
124
- if ( 'template' != $this->status ) {
125
- return;
126
- }
127
-
128
- $where = apply_filters( 'frm_forms_dropdown', array(), '' );
129
- $forms = FrmForm::get_published_forms( $where );
130
-
131
- $base = admin_url('admin.php?page=formidable&form_type=template');
132
- $args = array(
133
- 'frm_action' => 'duplicate',
134
- 'template' => true,
135
- );
136
-
137
- ?>
138
- <div class="alignleft actions frm_visible_overflow">
139
- <div class="dropdown frm_tiny_top_margin">
140
- <a href="#" id="frm-templateDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php _e( 'Create New Template', 'formidable' ) ?> <b class="caret"></b></a>
141
- <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-templateDrop">
142
- <?php
143
- if ( empty( $forms ) ) { ?>
144
- <li class="frm_dropdown_li"><?php _e( 'You have not created any forms yet. <br/>You must create a form before you can make a template.', 'formidable' ) ?></li>
145
- <?php
146
- } else {
147
- foreach ( $forms as $form ) {
148
- $args['id'] = $form->id; ?>
149
- <li><a href="<?php echo add_query_arg($args, $base); ?>" tabindex="-1"><?php echo empty($form->name) ? __( '(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
150
- <?php
151
- unset($form);
152
- }
153
- }
154
- ?>
155
- </ul>
156
- </div>
157
- </div>
158
- <?php
159
- }
160
-
161
- public function get_views() {
162
-
163
- $statuses = array(
164
- 'published' => __( 'My Forms', 'formidable' ),
165
- 'template' => __( 'Templates', 'formidable' ),
166
- 'draft' => __( 'Drafts', 'formidable' ),
167
- 'trash' => __( 'Trash', 'formidable' ),
168
- );
169
-
170
- $links = array();
171
- $counts = FrmForm::get_count();
172
- $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : 'published';
173
-
174
- foreach ( $statuses as $status => $name ) {
175
-
176
- if ( $status == $form_type ) {
177
- $class = ' class="current"';
178
- } else {
179
- $class = '';
180
- }
181
-
182
- if ( $counts->{$status} || 'published' == $status ) {
183
- $links[$status] = '<a href="?page=formidable&form_type='. $status .'" '. $class .'>'. sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) .'</a>';
184
- }
185
-
186
- unset($status, $name);
187
- }
188
-
189
- return $links;
190
- }
191
-
192
- public function pagination( $which ) {
193
- global $mode;
194
-
195
- parent::pagination( $which );
196
-
197
- if ( 'top' == $which ) {
198
- $this->view_switcher( $mode );
199
- }
200
- }
201
-
202
- public function single_row( $item, $style = '' ) {
203
- global $frm_vars, $mode;
204
-
205
- // Set up the hover actions for this user
206
- $actions = array();
207
- $edit_link = '?page=formidable&frm_action=edit&id='. $item->id;
208
- $duplicate_link = '?page=formidable&frm_action=duplicate&id='. $item->id;
209
-
210
- $this->get_actions($actions, $item, $edit_link, $duplicate_link);
211
-
212
- $action_links = $this->row_actions( $actions );
213
-
214
- // Set up the checkbox ( because the user is editable, otherwise its empty )
215
- $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
216
-
217
- $r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
218
-
219
- list( $columns, $hidden ) = $this->get_column_info();
220
-
221
- $format = 'Y/m/d';
222
- if ( 'list' != $mode ) {
223
- $format .= ' \<\b\r \/\> g:i:s a';
224
- }
225
-
226
- foreach ( $columns as $column_name => $column_display_name ) {
227
- $class = $column_name .' column-'. $column_name . ( ('name' == $column_name) ? ' post-title page-title column-title' : '' );
228
-
229
- $style = '';
230
- if ( in_array( $column_name, $hidden ) ) {
231
- $class .= ' frm_hidden';
232
- }
233
-
234
- $class = 'class="' . $class . '"';
235
- $attributes = $class . $style;
236
-
237
- switch ( $column_name ) {
238
- case 'cb':
239
- $r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
240
- break;
241
- case 'id':
242
- case 'form_key':
243
- $val = $item->{$column_name};
244
- break;
245
- case 'name':
246
- $val = $this->get_form_name( $item, $actions, $edit_link );
247
- $val .= $action_links;
248
-
249
- break;
250
- case 'created_at':
251
- $date = date($format, strtotime($item->created_at));
252
- $val = '<abbr title="'. date('Y/m/d g:i:s A', strtotime($item->created_at)) .'">'. $date .'</abbr>';
253
- break;
254
- case 'shortcode':
255
- $val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
256
- if ( 'excerpt' == $mode ) {
257
- $val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
258
- }
259
- break;
260
- case 'entries':
261
- if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
262
- $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="'. esc_attr('Entries are not being saved', 'formidable' ) .'"></i>';
263
- } else {
264
- $text = FrmEntry::getRecordCount($item->id);
265
- $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
266
- unset($text);
267
- }
268
- break;
269
- case 'type':
270
- $val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
271
- break;
272
- }
273
-
274
- if ( isset($val) ) {
275
- $r .= "<td $attributes>";
276
- $r .= $val;
277
- $r .= '</td>';
278
- }
279
- unset($val);
280
- }
281
- $r .= '</tr>';
282
-
283
- return $r;
284
- }
285
-
286
- /**
287
- * @param string $edit_link
288
- * @param string $duplicate_link
289
- */
290
- private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
291
- if ( 'trash' == $this->status ) {
292
- if ( current_user_can('frm_edit_forms') ) {
293
- $actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
294
- }
295
-
296
- if ( current_user_can('frm_delete_forms') ) {
297
- $actions['trash'] = '<a href="' . esc_url(wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id='. $item->id, 'destroy_form_'. $item->id )) .'" class="submitdelete" onclick="return confirm(\''. __( 'Are you sure you want to permanently delete that?', 'formidable' ) .'\')">' . __( 'Delete Permanently' ) . '</a>';
298
- }
299
- return;
300
- }
301
-
302
- if ( current_user_can('frm_edit_forms') ) {
303
- if ( ! $item->is_template || ! $item->default_template ) {
304
- $actions['frm_edit'] = '<a href="'. esc_url( $edit_link ) . '">'. __( 'Edit') .'</a>';
305
- }
306
-
307
- if ( $item->is_template ) {
308
- $actions['frm_duplicate'] = '<a href="'. wp_nonce_url( $duplicate_link ) .'">'. __( 'Create Form from Template', 'formidable' ) .'</a>';
309
- } else {
310
- $actions['frm_settings'] = '<a href="'. esc_url('?page=formidable&frm_action=settings&id='. $item->id ) . '">'. __( 'Settings', 'formidable' ) .'</a>';
311
-
312
- if ( FrmAppHelper::pro_is_installed() ) {
313
- $actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __( 'Duplicate', 'formidable' ) .'</a>';
314
- }
315
- }
316
- }
317
-
318
- $actions['trash'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
319
- if ( empty( $actions['trash'] ) ) {
320
- // the user doesn't have permission
321
- unset( $actions['trash'] );
322
- }
323
-
324
- $actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __( 'Preview') .'</a>';
325
- }
326
-
327
- /**
328
- * @param string $edit_link
329
- */
330
- private function get_form_name( $item, $actions, $edit_link ) {
331
- $form_name = $item->name;
332
- if ( trim($form_name) == '' ) {
333
- $form_name = __( '(no title)');
334
- }
335
- $form_name = FrmAppHelper::truncate(strip_tags($form_name), 50);
336
-
337
- $val = '<strong>';
338
- if ( 'trash' == $this->status ) {
339
- $val .= $form_name;
340
- } else {
341
- $val .= '<a href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'" class="row-title">'. $form_name .'</a> ';
342
- }
343
-
344
- $this->add_draft_label( $item, $val );
345
- $val .= '</strong>';
346
-
347
- $this->add_form_description( $item, $val );
348
-
349
- return $val;
350
- }
351
-
352
- /**
353
- * @param string $val
354
- */
355
- private function add_draft_label( $item, &$val ) {
356
- if ( 'draft' == $item->status && 'draft' != $this->status ) {
357
- $val .= ' - <span class="post-state">'. __( 'Draft', 'formidable' ) .'</span>';
358
- }
359
- }
360
-
361
- /**
362
- * @param string $val
363
- */
364
- private function add_form_description( $item, &$val ) {
365
- global $mode;
366
- if ( 'excerpt' == $mode ) {
367
- $val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
368
- }
369
- }
370
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/helpers/FrmListHelper.php CHANGED
@@ -1,31 +1,228 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
 
6
- class FrmListHelper extends WP_List_Table {
7
- var $params;
 
 
8
 
9
- public function __construct( $args ) {
 
 
 
 
10
  $args = wp_parse_args( $args, array(
 
 
 
11
  'params' => array()
12
  ) );
13
-
 
14
  $this->params = $args['params'];
 
 
15
 
16
  parent::__construct( $args );
17
  }
18
 
19
- public function ajax_user_can() {
20
  return current_user_can( 'administrator' );
21
  }
22
 
23
- public function display_rows() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  $style = '';
25
  foreach ( $this->items as $item ) {
26
  $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
27
  echo "\n\t", $this->single_row( $item, $style );
28
  }
29
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
1
  <?php
 
 
 
2
 
3
+ if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
4
+
5
+ if(class_exists('FrmListHelper'))
6
+ return;
7
 
8
+ class FrmListHelper extends WP_List_Table {
9
+
10
+ function __construct($args) {
11
+ global $frm_settings;
12
+
13
  $args = wp_parse_args( $args, array(
14
+ 'ajax' => false,
15
+ 'table_name' => '',
16
+ 'page_name' => '',
17
  'params' => array()
18
  ) );
19
+ $this->table_name = $args['table_name'];
20
+ $this->page_name = $args['page_name'];
21
  $this->params = $args['params'];
22
+
23
+ $screen = get_current_screen();
24
 
25
  parent::__construct( $args );
26
  }
27
 
28
+ function ajax_user_can() {
29
  return current_user_can( 'administrator' );
30
  }
31
 
32
+ function prepare_items() {
33
+ global $wpdb, $per_page, $frm_settings;
34
+ $paged = $this->get_pagenum();
35
+ $default_orderby = 'name';
36
+ $default_order = 'ASC';
37
+
38
+ $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
39
+ $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
40
+
41
+ $page = $this->get_pagenum();
42
+ $default_count = empty($this->page_name) ? 20 : 10;
43
+ $per_page = $this->get_items_per_page( 'formidable_page_formidable'. str_replace('-', '_', $this->page_name) .'_per_page', $default_count);
44
+
45
+ $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
46
+ $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
47
+ $fid = isset( $_REQUEST['fid'] ) ? $_REQUEST['fid'] : '';
48
+ if($s != ''){
49
+ preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
50
+ $search_terms = array_map('trim', $matches[0]);
51
+ }
52
+
53
+ $s_query = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ". (int)$this->params['template'];
54
+
55
+ if($s != ''){
56
+ foreach ( (array) $search_terms as $term ) {
57
+ if ( !empty($s_query) ) {
58
+ $s_query .= " AND";
59
+ }
60
+
61
+ $term = FrmAppHelper::esc_like($term);
62
+
63
+ $s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%'. $term .'%', '%'. $term .'%', '%'. $term .'%');
64
+
65
+ unset($term);
66
+ }
67
+ }
68
+
69
+ $frm_form = new FrmForm();
70
+ $this->items = $frm_form->getAll($s_query, " ORDER BY $orderby $order", " LIMIT $start, $per_page", true, false);
71
+ $total_items = FrmAppHelper::getRecordCount($s_query, $this->table_name);
72
+
73
+
74
+ $this->set_pagination_args( array(
75
+ 'total_items' => $total_items,
76
+ 'per_page' => $per_page
77
+ ) );
78
+ }
79
+
80
+ function no_items() {
81
+ if ($this->params['template']){
82
+ _e('No Templates Found', 'formidable') ?>.
83
+ <br/><br/><?php _e('To add a new template','formidable') ?>:
84
+ <ol><li><?php printf(__('Create a new %1$sform%2$s.', 'formidable'), '<a href="?page=formidable&amp;frm_action=new-selection">', '</a>') ?></li>
85
+ <li><?php printf(__('After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable'), '<a href="?page=formidable">', '</a>') ?></li>
86
+ <li><?php _e('Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable') ?></li>
87
+ </ol>
88
+ <?php }else{
89
+ _e('No Forms Found', 'formidable') ?>.
90
+ <a href="?page=formidable&amp;frm_action=new-selection"><?php _e('Add New', 'formidable'); ?></a>
91
+ <?php }
92
+ }
93
+
94
+ function get_bulk_actions(){
95
+ $actions = array();
96
+ if ( current_user_can('frm_delete_forms') ) {
97
+ $actions['bulk_delete'] = __('Delete');
98
+ }
99
+
100
+ return $actions;
101
+ }
102
+
103
+ function display_rows() {
104
  $style = '';
105
  foreach ( $this->items as $item ) {
106
  $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
107
  echo "\n\t", $this->single_row( $item, $style );
108
  }
109
  }
110
+
111
+ function single_row( $item, $style='') {
112
+ global $frm_vars, $frm_entry;
113
+ $checkbox = '';
114
+
115
+ // Set up the hover actions for this user
116
+ $actions = array();
117
+ $title = esc_attr(strip_tags($item->name));
118
+
119
+ if ( current_user_can('frm_edit_forms') ) {
120
+ $edit_link = "?page=formidable&frm_action=edit&id={$item->id}";
121
+ $duplicate_link = "?page=formidable&frm_action=duplicate&id={$item->id}";
122
+
123
+ $actions['frm_edit'] = "<a href='" . esc_url( $edit_link ) . "'>". __('Edit') ."</a>";
124
+
125
+ if ( $this->params['template'] ) {
126
+ $actions['frm_duplicate'] = "<a href='" . wp_nonce_url( $duplicate_link ) . "'>". __('Create Form from Template', 'formidable') ."</a>";
127
+ } else {
128
+ $actions['frm_settings'] = "<a href='" . wp_nonce_url( "?page=formidable&frm_action=settings&id={$item->id}" ) . "'>". __('Settings', 'formidable') ."</a>";
129
+
130
+ if ( $frm_vars['pro_is_installed'] ) {
131
+ $actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __('Duplicate', 'formidable') .'</a>';
132
+ }
133
+ }
134
+ }
135
+
136
+ $delete_link = "?page=formidable&frm_action=destroy&id={$item->id}";
137
+ if(current_user_can('frm_delete_forms'))
138
+ $actions['trash'] = '<a class="submitdelete" href="' . wp_nonce_url( $delete_link ) .'" onclick="return confirm(\''. __('Are you sure you want to delete that?', 'formidable') .'\')">' . __( 'Delete' ) . '</a>';
139
+
140
+ $actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __('Preview') .'</a>';
141
+
142
+ $action_links = $this->row_actions( $actions );
143
+
144
+ // Set up the checkbox ( because the user is editable, otherwise its empty )
145
+ $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
146
+
147
+ $r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
148
+
149
+ list( $columns, $hidden ) = $this->get_column_info();
150
+ $action_col = false;
151
+
152
+ foreach ( $columns as $column_name => $column_display_name ) {
153
+ $class = 'class="'. $column_name .' column-'. $column_name .'"';
154
 
155
+ $style = '';
156
+ if ( in_array( $column_name, $hidden ) )
157
+ $style = ' style="display:none;"';
158
+ else if(!$action_col and !in_array($column_name, array('cb', 'id')))
159
+ $action_col = $column_name;
160
+
161
+ $attributes = "$class$style";
162
+
163
+ switch ( $column_name ) {
164
+ case 'cb':
165
+ $r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
166
+ break;
167
+ case 'id':
168
+ case 'form_key':
169
+ $val = $item->{$column_name};
170
+ break;
171
+ case 'name':
172
+ if(trim($item->{$column_name}) == '')
173
+ $val = __('(no title)');
174
+ else
175
+ $val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
176
+ break;
177
+ case 'description':
178
+ $val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
179
+ break;
180
+ case 'created_at':
181
+ $format = 'Y/m/d'; //get_option('date_format');
182
+ $date = date($format, strtotime($item->{$column_name}));
183
+ $val = "<abbr title='". date($format .' g:i:s A', strtotime($item->{$column_name})) ."'>". $date ."</abbr>";
184
+ break;
185
+ case 'shortcode':
186
+ $val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
187
+ $val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
188
+ break;
189
+ case 'entries':
190
+ $text = $frm_entry->getRecordCount($item->id);
191
+ //$text = sprintf(_n( '%1$s Entry', '%1$s Entries', $text, 'formidable' ), $text);
192
+ $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
193
+ unset($text);
194
+ break;
195
+ case 'link':
196
+ $links = array();
197
+ if($frm_vars['pro_is_installed'] and current_user_can('frm_create_entries'))
198
+ $links[] = '<a href="'. wp_nonce_url( "?page=formidable-entries&frm_action=new&form={$item->id}" ) .'" class="frm_add_entry_icon frm_icon_font frm_bstooltip" title="'. __('Add Entry', 'formidable'). '" data-toggle="tooltip"> </a>';
199
+
200
+ if ( current_user_can('frm_edit_forms') ){
201
+ $links[] = '<a href="' . wp_nonce_url( "?page=formidable&frm_action=duplicate&id={$item->id}&template=1" ) .'" class="frm_icon_font frm_new_template_icon frm_bstooltip" title="'. __('Create template from form', 'formidable') .'" data-toggle="tooltip"> </a>';
202
+ }
203
+
204
+ $val = implode(' ', $links);
205
+ break;
206
+ default:
207
+ $val = $column_name;
208
+ break;
209
+ }
210
+
211
+ if(isset($val)){
212
+ $r .= "<td $attributes>";
213
+ if($column_name == $action_col){
214
+ $r .= '<a class="row-title" href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'">'. $val .'</a> ';
215
+ $r .= $action_links;
216
+ }else{
217
+ $r .= $val;
218
+ }
219
+ $r .= '</td>';
220
+ }
221
+ unset($val);
222
+ }
223
+ $r .= '</tr>';
224
+
225
+ return $r;
226
+ }
227
+
228
  }
classes/helpers/FrmStylesHelper.php DELETED
@@ -1,193 +0,0 @@
1
- <?php
2
- class FrmStylesHelper {
3
-
4
- public static function jquery_themes() {
5
- $themes = array(
6
- 'ui-lightness' => 'UI Lightness',
7
- 'ui-darkness' => 'UI Darkness',
8
- 'smoothness' => 'Smoothness',
9
- 'start' => 'Start',
10
- 'redmond' => 'Redmond',
11
- 'sunny' => 'Sunny',
12
- 'overcast' => 'Overcast',
13
- 'le-frog' => 'Le Frog',
14
- 'flick' => 'Flick',
15
- 'pepper-grinder'=> 'Pepper Grinder',
16
- 'eggplant' => 'Eggplant',
17
- 'dark-hive' => 'Dark Hive',
18
- 'cupertino' => 'Cupertino',
19
- 'south-street' => 'South Street',
20
- 'blitzer' => 'Blitzer',
21
- 'humanity' => 'Humanity',
22
- 'hot-sneaks' => 'Hot Sneaks',
23
- 'excite-bike' => 'Excite Bike',
24
- 'vader' => 'Vader',
25
- 'dot-luv' => 'Dot Luv',
26
- 'mint-choc' => 'Mint Choc',
27
- 'black-tie' => 'Black Tie',
28
- 'trontastic' => 'Trontastic',
29
- 'swanky-purse' => 'Swanky Purse',
30
- );
31
-
32
- $themes = apply_filters('frm_jquery_themes', $themes);
33
- return $themes;
34
- }
35
-
36
- public static function jquery_css_url($theme_css) {
37
- if ( $theme_css == -1 ) {
38
- return;
39
- }
40
-
41
- if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42
- $css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
- } else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
44
- $css_file = $theme_css;
45
- } else {
46
- $uploads = self::get_upload_base();
47
- $file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
- if ( file_exists($uploads['basedir'] . $file_path) ) {
49
- $css_file = $uploads['baseurl'] . $file_path;
50
- } else {
51
- $css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.css';
52
- }
53
- }
54
-
55
- return $css_file;
56
- }
57
-
58
- public static function enqueue_jquery_css() {
59
- $theme_css = FrmStylesController::get_style_val('theme_css');
60
- if ( $theme_css != -1 ) {
61
- wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
62
- }
63
- }
64
-
65
- public static function get_upload_base() {
66
- $uploads = wp_upload_dir();
67
- if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
68
- $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
69
- }
70
-
71
- return $uploads;
72
- }
73
-
74
- public static function style_menu($active = '') {
75
- ?>
76
- <h2 class="nav-tab-wrapper">
77
- <a href="<?php echo admin_url('admin.php?page=formidable-styles') ?>" class="nav-tab <?php echo ( '' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Edit Styles', 'formidable' ) ?></a>
78
- <a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=manage') ?>" class="nav-tab <?php echo ( 'manage' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Manage Form Styles', 'formidable' ) ?></a>
79
- <a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=custom_css') ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Custom CSS', 'formidable' ) ?></a>
80
- </h2>
81
- <?php
82
- }
83
-
84
- public static function minus_icons() {
85
- return array(
86
- 0 => array( '-' => '62e', '+' => '62f'),
87
- 1 => array( '-' => '600', '+' => '602'),
88
- 2 => array( '-' => '604', '+' => '603'),
89
- 3 => array( '-' => '633', '+' => '632'),
90
- 4 => array( '-' => '613', '+' => '60f'),
91
- );
92
- }
93
-
94
- public static function arrow_icons() {
95
- $minus_icons = self::minus_icons();
96
-
97
- return array(
98
- 6 => array( '-' => '62d', '+' => '62a'),
99
- 0 => array( '-' => '60d', '+' => '609'),
100
- 1 => array( '-' => '60e', '+' => '60c'),
101
- 2 => array( '-' => '630', '+' => '631'),
102
- 3 => array( '-' => '62b', '+' => '628'),
103
- 4 => array( '-' => '62c', '+' => '629'),
104
- 5 => array( '-' => '635', '+' => '634'),
105
- 'p0' => $minus_icons[0],
106
- 'p1' => $minus_icons[1],
107
- 'p2' => $minus_icons[2],
108
- 'p3' => $minus_icons[3],
109
- 'p4' => $minus_icons[4],
110
- );
111
- }
112
-
113
- /**
114
- * @since 2.0
115
- * @return The class for this icon
116
- */
117
- public static function icon_key_to_class($key, $icon = '+', $type = 'arrow') {
118
- if ( 'arrow' == $type && is_numeric($key) ) {
119
- //frm_arrowup6_icon
120
- $arrow = array( '-' => 'down', '+' => 'up');
121
- $class = 'frm_arrow'. $arrow[$icon];
122
- } else {
123
- //frm_minus1_icon
124
- $key = str_replace('p', '', $key);
125
- $plus = array( '-' => 'minus', '+' => 'plus');
126
- $class = 'frm_'. $plus[$icon];
127
- }
128
-
129
- if ( $key ) {
130
- $class .= $key;
131
- }
132
- $class .= '_icon';
133
-
134
- return $class;
135
- }
136
-
137
- public static function bs_icon_select($style, $frm_style, $type = 'arrow') {
138
- $function_name = $type . '_icons';
139
- $icons = self::$function_name();
140
- unset( $function_name );
141
-
142
- $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
143
- ?>
144
- <select name="<?php echo esc_attr( $frm_style->get_field_name($name) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js">
145
- <?php foreach ( $icons as $key => $icon ) { ?>
146
- <option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[$name], $key ) ?>>
147
- <?php echo '&#xe'. $icon['+'] .'; &#xe'. $icon['-'] .';'; ?>
148
- </option>
149
- <?php } ?>
150
- </select>
151
-
152
- <div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ) ?>_select">
153
- <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
154
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[$name], '+', $type ) ) ?>"></i>
155
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[$name], '-', $type ) ) ?>"></i>
156
- <b class="caret"></b>
157
- </button>
158
- <ul class="multiselect-container frm-dropdown-menu">
159
- <?php foreach ( $icons as $key => $icon ) { ?>
160
- <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : '' ?>>
161
- <a href="javascript:void(0);">
162
- <label>
163
- <input type="radio" value="<?php echo esc_attr( $key ) ?>"/>
164
- <span>
165
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '+', $type ) ) ?>"></i>
166
- <i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $key, '-', $type ) ) ?>"></i>
167
- </span>
168
- </label>
169
- </a>
170
- </li>
171
- <?php } ?>
172
- </ul>
173
- </div>
174
- <?php
175
- }
176
-
177
- public static function hex2rgb($hex) {
178
- $hex = str_replace('#', '', $hex);
179
-
180
- if ( strlen($hex) == 3 ) {
181
- $r = hexdec( substr($hex,0,1).substr($hex,0,1) );
182
- $g = hexdec( substr($hex,1,1).substr($hex,1,1) );
183
- $b = hexdec( substr($hex,2,1).substr($hex,2,1) );
184
- } else {
185
- $r = hexdec( substr($hex,0,2) );
186
- $g = hexdec( substr($hex,2,2) );
187
- $b = hexdec( substr($hex,4,2) );
188
- }
189
- $rgb = array($r, $g, $b);
190
- return implode(',', $rgb); // returns the rgb values separated by commas
191
- //return $rgb; // returns an array with the rgb values
192
- }
193
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/helpers/FrmXMLHelper.php CHANGED
@@ -1,148 +1,138 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
-
6
- class FrmXMLHelper {
7
-
8
- public static function get_xml_values( $opt, $padding ) {
9
- if ( is_array( $opt ) ) {
10
- foreach ( $opt as $ok => $ov ) {
11
- echo "\n" . $padding;
12
- echo '<' . ( is_numeric( $ok ) ? 'key:' : '' ) . $ok . '>';
13
- self::get_xml_values( $ov, $padding .' ' );
14
- if ( is_array( $ov ) ) {
15
- echo "\n" . $padding;
16
- }
17
- echo '</' . ( is_numeric( $ok ) ? 'key:' : '' ) . $ok . '>';
18
- }
19
- } else {
20
- echo self::cdata( $opt );
21
- }
22
- }
23
-
24
- public static function import_xml($file) {
25
  $defaults = array(
26
  'forms' => 0, 'fields' => 0, 'terms' => 0,
27
- 'posts' => 0, 'views' => 0, 'actions' => 0,
28
- 'styles' => 0,
29
  );
30
-
31
  $imported = array(
32
  'imported' => $defaults,
33
  'updated' => $defaults,
34
  'forms' => array(),
35
  );
36
-
37
  unset($defaults);
38
-
39
  if ( !defined('WP_IMPORTING') ) {
40
  define('WP_IMPORTING', true);
41
  }
42
-
43
  if ( !class_exists('DOMDocument') ) {
44
  return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
45
  }
46
-
47
  $dom = new DOMDocument;
48
  $success = $dom->loadXML( file_get_contents( $file ) );
49
- if ( ! $success ) {
50
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
51
  }
52
-
53
  $xml = simplexml_import_dom( $dom );
54
  unset( $dom );
55
 
56
  // halt if loading produces an error
57
- if ( ! $xml ) {
58
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
59
  }
60
-
61
  // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
62
- foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
63
- // grab cats, tags, and terms, or forms or posts
64
- if ( isset($xml->{$item_type} ) ) {
65
- $function_name = 'import_xml_' . $item_type . 's';
66
- $imported = self::$function_name( $xml->{$item_type}, $imported );
67
- unset( $function_name, $xml->{$item_type} );
68
- }
69
- }
70
-
 
 
 
71
  $return = apply_filters('frm_importing_xml', $imported, $xml );
72
-
73
  return $return;
74
  }
75
-
76
  public static function import_xml_terms($terms, $imported) {
77
  foreach ( $terms as $t ) {
78
  if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
79
  continue;
80
  }
81
-
82
  $term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
83
  'slug' => (string) $t->term_slug,
84
  'description' => (string) $t->term_description,
85
  'term_parent' => (string) $t->term_parent,
86
  'slug' => (string) $t->term_slug,
87
  ));
88
-
89
  if ( $term_id ) {
90
  $imported['imported']['terms']++;
91
  }
92
-
93
- unset($term_id, $t);
 
94
  }
95
-
96
  return $imported;
97
  }
98
-
99
  public static function import_xml_forms($forms, $imported) {
100
-
101
- // Keep track of repeating sections that are created
102
- $repeat_fields = array();
103
-
104
  foreach ( $forms as $item ) {
105
- $form = array(
106
- 'id' => (int) $item->id,
107
- 'form_key' => (string) $item->form_key,
108
- 'name' => (string) $item->name,
109
- 'description' => (string) $item->description,
110
- 'options' => (string) $item->options,
111
- 'logged_in' => (int) $item->logged_in,
112
- 'is_template' => (int) $item->is_template,
113
- 'default_template' => (int) $item->default_template,
114
- 'editable' => (int) $item->editable,
115
- 'status' => (string) $item->status,
116
- 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
117
- 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
118
- );
119
-
120
- $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
121
-
122
- // if template, allow to edit if form keys match, otherwise, creation date must also match
123
- $edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template']);
124
- if ( ! $form['is_template'] ) {
125
  $edit_query['created_at'] = $form['created_at'];
126
  }
127
-
128
- if ( ! empty($form['parent_form_id']) && isset($imported['forms'][$form['parent_form_id']]) ) {
129
- // replace the old parent id with the new one
130
- $form['parent_form_id'] = $imported['forms'][$form['parent_form_id']];
131
- }
132
-
133
- $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
134
-
135
- $this_form = FrmForm::getAll($edit_query, '', 1);
136
  unset($edit_query);
137
-
138
- if ( ! empty( $this_form ) ) {
139
- $old_id = $form_id = $this_form->id;
140
- FrmForm::update($form_id, $form );
141
  $imported['updated']['forms']++;
142
- // Keep track of whether this specific form was updated or not
143
- $imported['form_status'][$form_id] = 'updated';
144
-
145
- $form_fields = FrmField::get_all_for_form( $form_id );
146
  $old_fields = array();
147
  foreach ( $form_fields as $f ) {
148
  $old_fields[$f->id] = $f;
@@ -152,27 +142,12 @@ class FrmXMLHelper {
152
  $form_fields = $old_fields;
153
  unset($old_fields);
154
  } else {
155
- $old_id = false;
156
  //form does not exist, so create it
157
- $form_id = FrmForm::create( $form );
158
- if ( $form_id ) {
159
  $imported['imported']['forms']++;
160
- // Keep track of whether this specific form was updated or not
161
- $imported['form_status'][$form_id] = 'imported';
162
-
163
- // Check if any repeating sections form_select need to be updated
164
- if ( isset( $repeat_fields[ $form['id'] ] ) ) {
165
- // Get section field
166
- $section_field = FrmField::getOne( $repeat_fields[ $form['id'] ] );
167
- $field_opts = maybe_unserialize( $section_field->field_options );
168
- $field_opts['form_select'] = $form_id;
169
-
170
- // update form_select now
171
- FrmField::update( $repeat_fields[ $form['id'] ], array( 'field_options' => maybe_serialize( $field_opts ) ) );
172
- }
173
  }
174
  }
175
-
176
  foreach ( $item->field as $field ) {
177
  $f = array(
178
  'id' => (int) $field->id,
@@ -187,29 +162,25 @@ class FrmXMLHelper {
187
  'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
188
  'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
189
  );
190
-
191
- if ( is_array($f['default_value']) && in_array($f['type'], array(
192
- 'text', 'email', 'url', 'textarea',
193
- 'number','phone', 'date', 'time',
194
- 'hidden', 'password', 'tag', 'image',
195
- )) ) {
196
  if ( count($f['default_value']) === 1 ) {
197
  $f['default_value'] = '['. reset($f['default_value']) .']';
198
  } else {
199
  $f['default_value'] = reset($f['default_value']);
200
  }
201
  }
202
-
203
  $f = apply_filters('frm_duplicated_field', $f);
204
-
205
- if ( ! empty($this_form) ) {
206
  // check for field to edit by field id
207
  if ( isset($form_fields[$f['id']]) ) {
208
- FrmField::update( $f['id'], $f );
209
  $imported['updated']['fields']++;
210
-
211
  unset($form_fields[$f['id']]);
212
-
213
  //unset old field key
214
  if ( isset($form_fields[$f['field_key']]) ) {
215
  unset($form_fields[$f['field_key']]);
@@ -217,358 +188,51 @@ class FrmXMLHelper {
217
  } else if ( isset($form_fields[$f['field_key']]) ) {
218
  // check for field to edit by field key
219
  unset($f['id']);
220
-
221
- FrmField::update( $form_fields[$f['field_key']], $f );
222
  $imported['updated']['fields']++;
223
-
224
  unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id
225
  unset($form_fields[$f['field_key']]); //unset old field key
226
- } else {
227
- $new_id = FrmField::create( $f );
228
- if ( $new_id == false ) {
229
- continue;
230
- }
231
-
232
  // if no matching field id or key in this form, create the field
233
  $imported['imported']['fields']++;
234
  }
235
- } else {
236
- $new_id = FrmField::create( $f );
237
- if ( $new_id == false ) {
238
- continue;
239
- }
240
  $imported['imported']['fields']++;
241
  }
242
-
243
- // Check if a repeating section was just created
244
- if ( isset( $new_id ) && $f['type'] == 'divider' && isset( $f['field_options']['repeat'] ) && $f['field_options']['repeat'] ) {
245
- $repeat_fields[ $f['field_options']['form_select'] ] = $new_id;
246
- }
247
-
248
- unset($field, $new_id);
249
  }
250
-
 
251
  // Delete any fields attached to this form that were not included in the template
252
- if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
253
- foreach ( $form_fields as $field ) {
254
  if ( is_object($field) ) {
255
- FrmField::destroy($field->id);
256
  }
257
  unset($field);
258
  }
259
  unset($form_fields);
260
  }
261
-
 
262
  // Update field ids/keys to new ones
263
- do_action('frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id));
264
-
265
  $imported['forms'][ (int) $item->id] = $form_id;
266
-
267
- // Send pre 2.0 form options through function that creates actions
268
- self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
269
-
270
- unset($form, $item);
271
- }
272
-
273
- return $imported;
274
- }
275
-
276
- public static function import_xml_views($views, $imported) {
277
- $imported['posts'] = array();
278
- $form_action_type = FrmFormActionsController::$action_post_type;
279
-
280
- $post_types = array(
281
- 'frm_display' => 'views',
282
- $form_action_type => 'actions',
283
- 'frm_styles' => 'styles',
284
- );
285
-
286
- foreach ( $views as $item ) {
287
- $post = array(
288
- 'post_title' => (string) $item->title,
289
- 'post_name' => (string) $item->post_name,
290
- 'post_type' => (string) $item->post_type,
291
- 'post_password' => (string) $item->post_password,
292
- 'guid' => (string) $item->guid,
293
- 'post_status' => (string) $item->status,
294
- 'post_author' => FrmAppHelper::get_user_id_param( (string) $item->post_author ),
295
- 'post_id' => (int) $item->post_id,
296
- 'post_parent' => (int) $item->post_parent,
297
- 'menu_order' => (int) $item->menu_order,
298
- 'post_content' => FrmFieldsHelper::switch_field_ids((string) $item->content),
299
- 'post_excerpt' => FrmFieldsHelper::switch_field_ids((string) $item->excerpt),
300
- 'is_sticky' => (string) $item->is_sticky,
301
- 'comment_status' => (string) $item->comment_status,
302
- 'post_date' => (string) $item->post_date,
303
- 'post_date_gmt' => (string) $item->post_date_gmt,
304
- 'ping_status' => (string) $item->ping_status,
305
- 'postmeta' => array(),
306
- 'tax_input' => array(),
307
- );
308
-
309
- $old_id = $post['post_id'];
310
- self::populate_post($post, $item, $imported);
311
-
312
- unset($item);
313
-
314
- if ( $post['post_type'] == $form_action_type ) {
315
- $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
316
- $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
317
- unset($action_control);
318
- } else if ( $post['post_type'] == 'frm_styles' ) {
319
- // Properly encode post content before inserting the post
320
- $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
321
- $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
322
-
323
- // Create/update post now
324
- $post_id = wp_insert_post( $post );
325
- } else {
326
- // Create/update post now
327
- $post_id = wp_insert_post( $post );
328
- }
329
-
330
- if ( ! is_numeric($post_id) ) {
331
- continue;
332
- }
333
-
334
- self::update_postmeta($post, $post_id);
335
-
336
- $this_type = 'posts';
337
- if ( isset($post_types[$post['post_type']]) ) {
338
- $this_type = $post_types[$post['post_type']];
339
- }
340
-
341
- if ( isset($post['ID']) && $post_id == $post['ID'] ) {
342
- $imported['updated'][ $this_type ]++;
343
- } else {
344
- $imported['imported'][ $this_type ]++;
345
- }
346
-
347
- unset($post);
348
-
349
- $imported['posts'][ (int) $old_id] = $post_id;
350
  }
351
-
 
 
 
352
  return $imported;
353
  }
354
-
355
- private static function populate_post( &$post, $item, $imported ) {
356
- if ( isset($item->attachment_url) ) {
357
- $post['attachment_url'] = (string) $item->attachment_url;
358
- }
359
-
360
- if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
361
- // update to new form id
362
- $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
363
- }
364
-
365
- foreach ( $item->postmeta as $meta ) {
366
- self::populate_postmeta($post, $meta, $imported);
367
- unset($meta);
368
- }
369
-
370
- self::populate_taxonomies($post, $item);
371
-
372
- self::maybe_editing_post($post);
373
- }
374
-
375
- private static function populate_postmeta( &$post, $meta, $imported ) {
376
- global $frm_duplicate_ids;
377
-
378
- $m = array(
379
- 'key' => (string) $meta->meta_key,
380
- 'value' => (string) $meta->meta_value,
381
- );
382
-
383
- //switch old form and field ids to new ones
384
- if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
385
- $m['value'] = $imported['forms'][ (int) $m['value'] ];
386
- } else {
387
- $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
388
-
389
- if ( ! empty($frm_duplicate_ids) ) {
390
-
391
- if ( $m['key'] == 'frm_dyncontent' ) {
392
- $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
393
- } else if ( $m['key'] == 'frm_options' ) {
394
-
395
- foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
396
- if ( isset($m['value'][$setting_name]) && is_numeric($m['value'][$setting_name]) && isset($frm_duplicate_ids[$m['value'][$setting_name]]) ) {
397
- $m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]];
398
- }
399
- }
400
-
401
- $check_dup_array = array();
402
- if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
403
- if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
404
- $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
405
- } else if ( is_array( $m['value']['order_by'] ) ) {
406
- $check_dup_array[] = 'order_by';
407
- }
408
- }
409
-
410
- if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
411
- $check_dup_array[] = 'where';
412
- }
413
-
414
- foreach ( $check_dup_array as $check_k ) {
415
- foreach ( (array) $m['value'][$check_k] as $mk => $mv ) {
416
- if ( isset($frm_duplicate_ids[$mv]) ) {
417
- $m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv];
418
- }
419
- unset($mk, $mv);
420
- }
421
- }
422
- }
423
- }
424
- }
425
-
426
- if ( ! is_array($m['value']) ) {
427
- $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
428
- }
429
-
430
- $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
431
- }
432
-
433
- /**
434
- * Add terms to post
435
- * @param array $post by reference
436
- * @param object $item The XML object data
437
- */
438
- private static function populate_taxonomies( &$post, $item ) {
439
- foreach ( $item->category as $c ) {
440
- $att = $c->attributes();
441
- if ( ! isset( $att['nicename'] ) ) {
442
- continue;
443
- }
444
-
445
- $taxonomy = (string) $att['domain'];
446
- if ( is_taxonomy_hierarchical($taxonomy) ) {
447
- $name = (string) $att['nicename'];
448
- $h_term = get_term_by('slug', $name, $taxonomy);
449
- if ( $h_term ) {
450
- $name = $h_term->term_id;
451
- }
452
- unset($h_term);
453
- } else {
454
- $name = (string) $c;
455
- }
456
-
457
- if ( ! isset($post['tax_input'][$taxonomy]) ) {
458
- $post['tax_input'][$taxonomy] = array();
459
- }
460
-
461
- $post['tax_input'][$taxonomy][] = $name;
462
- unset($name);
463
- }
464
- }
465
-
466
- /**
467
- * Edit post if the key and created time match
468
- */
469
- private static function maybe_editing_post( &$post ) {
470
- $match_by = array(
471
- 'post_type' => $post['post_type'],
472
- 'name' => $post['post_name'],
473
- 'post_status' => $post['post_status'],
474
- 'posts_per_page' => 1,
475
- );
476
-
477
- if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
478
- $match_by['include'] = $post['post_id'];
479
- unset($match_by['name']);
480
- }
481
-
482
- $editing = get_posts($match_by);
483
-
484
- if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
485
- // set the id of the post to edit
486
- $post['ID'] = current($editing)->ID;
487
- }
488
- }
489
-
490
- private static function update_postmeta( &$post, $post_id ) {
491
- foreach ( $post['postmeta'] as $k => $v ) {
492
- if ( '_edit_last' == $k ) {
493
- $v = FrmAppHelper::get_user_id_param($v);
494
- } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
495
- //change the attachment ID
496
- $v = FrmProXMLHelper::get_file_id($v);
497
- }
498
-
499
- update_post_meta($post_id, $k, $v);
500
-
501
- unset($k, $v);
502
- }
503
- }
504
-
505
- /**
506
- * @param string $message
507
- */
508
- public static function parse_message($result, &$message, &$errors) {
509
- if ( is_wp_error($result) ) {
510
- $errors[] = $result->get_error_message();
511
- } else if ( ! $result ) {
512
- return;
513
- }
514
-
515
- if ( ! is_array($result) ) {
516
- $message = $result;
517
- return;
518
- }
519
-
520
- $t_strings = array(
521
- 'imported' => __( 'Imported', 'formidable' ),
522
- 'updated' => __( 'Updated', 'formidable' ),
523
- );
524
-
525
- $message = '<ul>';
526
- foreach ( $result as $type => $results ) {
527
- if ( ! isset($t_strings[$type]) ) {
528
- // only print imported and updated
529
- continue;
530
- }
531
-
532
- $s_message = array();
533
- foreach ( $results as $k => $m ) {
534
- self::item_count_message($m, $k, $s_message);
535
- unset($k, $m);
536
- }
537
-
538
- if ( ! empty($s_message) ) {
539
- $message .= '<li><strong>'. $t_strings[$type] .':</strong> ';
540
- $message .= implode(', ', $s_message);
541
- $message .= '</li>';
542
- }
543
- }
544
-
545
- if ( $message == '<ul>' ) {
546
- $message = '';
547
- $errors[] = __( 'Nothing was imported or updated', 'formidable' );
548
- } else {
549
- $message .= '</ul>';
550
- }
551
- }
552
-
553
- public static function item_count_message($m, $type, &$s_message) {
554
- if ( ! $m ) {
555
- return;
556
- }
557
-
558
- $strings = array(
559
- 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
560
- 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
561
- 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
562
- 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
563
- 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
564
- 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
565
- 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
566
- 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
567
- );
568
-
569
- $s_message[] = isset($strings[$type]) ? $strings[$type] : ' '. $m .' '. ucfirst($type);
570
- }
571
-
572
  public static function cdata( $str ) {
573
  $str = maybe_unserialize($str);
574
  if ( is_array($str) ) {
@@ -576,336 +240,15 @@ class FrmXMLHelper {
576
  } else if (seems_utf8( $str ) == false ) {
577
  $str = utf8_encode( $str );
578
  }
579
-
580
  if ( is_numeric($str) ) {
581
  return $str;
582
  }
583
-
584
  // $str = ent2ncr(esc_html($str));
585
  $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
586
 
587
  return $str;
588
  }
589
 
590
- public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
591
- // Get post type
592
- $post_type = FrmFormActionsController::$action_post_type;
593
-
594
- // Set up imported index, if not set up yet
595
- if ( ! isset( $imported['imported']['actions'] ) ) {
596
- $imported['imported']['actions'] = 0;
597
- }
598
-
599
- // Migrate post settings to action
600
- self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
601
-
602
- // Migrate email settings to action
603
- self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
604
- }
605
-
606
- /**
607
- * Migrate post settings to form action
608
- *
609
- * @param string $post_type
610
- */
611
- private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
612
- if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
613
- return;
614
- }
615
-
616
- $new_action = array(
617
- 'post_type' => $post_type,
618
- 'post_excerpt' => 'wppost',
619
- 'post_title' => __( 'Create Posts', 'formidable' ),
620
- 'menu_order' => $form_id,
621
- 'post_status' => 'publish',
622
- 'post_content' => array(),
623
- 'post_name' => $form_id .'_wppost_1',
624
- );
625
-
626
- $post_settings = array(
627
- 'post_type', 'post_category', 'post_content',
628
- 'post_excerpt', 'post_title', 'post_name', 'post_date',
629
- 'post_status', 'post_custom_fields', 'post_password',
630
- );
631
-
632
- foreach ( $post_settings as $post_setting ) {
633
- if ( isset( $form_options[$post_setting] ) ) {
634
- $new_action['post_content'][$post_setting] = $form_options[$post_setting];
635
- }
636
- unset($post_setting);
637
- }
638
-
639
- $new_action['event'] = array( 'create', 'update');
640
-
641
- if ( $switch ) {
642
- $new_action['post_content'] = self::switch_post_setting_field_ids( $new_action['post_content'] );
643
- }
644
- $new_action['post_content'] = json_encode($new_action['post_content']);
645
-
646
- $exists = get_posts( array(
647
- 'name' => $new_action['post_name'],
648
- 'post_type' => $new_action['post_type'],
649
- 'post_status' => $new_action['post_status'],
650
- 'numberposts' => 1,
651
- ) );
652
-
653
- if ( ! $exists ) {
654
- // Remove the balanceTags filter in case WordPress is trying to validate the XHTML
655
- remove_filter( 'content_save_pre', 'balanceTags', 50 );
656
-
657
- wp_insert_post( $new_action );
658
- $imported['imported']['actions']++;
659
- }
660
- }
661
-
662
- private static function switch_post_setting_field_ids( $post_content ) {
663
- global $frm_duplicate_ids;
664
-
665
- // If there aren't IDs that were switched, end now
666
- if ( ! $frm_duplicate_ids ) {
667
- return;
668
- }
669
-
670
- // Fields with string or int saved
671
- $basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' );
672
-
673
- // Fields with arrays saved
674
- $array_fields = array( 'post_category', 'post_custom_fields' );
675
-
676
- // Get old IDs
677
- $old = array_keys( $frm_duplicate_ids );
678
-
679
- // Get new IDs
680
- $new = array_values( $frm_duplicate_ids );
681
-
682
- // Do a str_replace with each item to set the new IDs
683
- foreach ( $post_content as $key => $setting ) {
684
- if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
685
- // Replace old IDs with new IDs
686
- $post_content[$key] = str_replace( $old, $new, $setting );
687
- } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
688
- foreach ( $setting as $k => $val ) {
689
- // Replace old IDs with new IDs
690
- $post_content[$key][$k] = str_replace( $old, $new, $val );
691
- }
692
- }
693
- unset( $key, $setting );
694
- }
695
- return $post_content;
696
- }
697
-
698
- private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
699
- // No old notifications or autoresponders to carry over
700
- if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) ) {
701
- return;
702
- }
703
-
704
- // Initialize notifications array
705
- $notifications = array();
706
-
707
- // Migrate regular notifications
708
- self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
709
-
710
- // Migrate autoresponders
711
- self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
712
-
713
- if ( empty( $notifications ) ) {
714
- return;
715
- }
716
-
717
- foreach ( $notifications as $new_notification ) {
718
- $new_notification['post_type'] = $post_type;
719
- $new_notification['post_excerpt'] = 'email';
720
- $new_notification['post_title'] = __( 'Email Notification', 'formidable' );
721
- $new_notification['menu_order'] = $form_id;
722
- $new_notification['post_status'] = 'publish';
723
-
724
- // Switch field IDs and keys, if needed
725
- if ( $switch ) {
726
- $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
727
- }
728
- $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
729
-
730
- $exists = get_posts( array(
731
- 'name' => $new_notification['post_name'],
732
- 'post_type' => $new_notification['post_type'],
733
- 'post_status' => $new_notification['post_status'],
734
- 'numberposts' => 1,
735
- ) );
736
-
737
- if ( empty($exists) ) {
738
- // Remove the balancTags filter in case WordPress is trying to validate the XHTML
739
- remove_filter( 'content_save_pre', 'balanceTags', 50 );
740
-
741
- wp_insert_post( $new_notification );
742
- $imported['imported']['actions']++;
743
- }
744
- unset($new_notification);
745
- }
746
- }
747
-
748
- private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
749
- if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
750
- // add old settings into notification array
751
- $form_options['notification'] = array(0 => $form_options);
752
- } else if ( isset( $form_options['notification']['email_to'] ) ) {
753
- // make sure it's in the correct format
754
- $form_options['notification'] = array(0 => $form_options['notification']);
755
- }
756
-
757
- if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
758
- foreach ( $form_options['notification'] as $email_key => $notification ) {
759
-
760
- $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
761
-
762
- // Format the email data
763
- self::format_email_data( $atts, $notification );
764
-
765
- if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
766
- do_action( 'frm_create_twilio_action', $atts, $notification );
767
- }
768
-
769
- // Setup the new notification
770
- $new_notification = array();
771
- self::setup_new_notification( $new_notification, $notification, $atts );
772
-
773
- $notifications[] = $new_notification;
774
- }
775
- }
776
- }
777
-
778
- private static function format_email_data( &$atts, $notification ) {
779
- // Format email_to
780
- self::format_email_to_data( $atts, $notification );
781
-
782
- // Format the reply to email and name
783
- $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
784
- foreach ( $reply_fields as $f => $val ) {
785
- if ( isset( $notification[$f] ) ) {
786
- $atts[$f] = $notification[$f];
787
- if ( 'custom' == $notification[$f] ) {
788
- $atts[$f] = $notification['cust_' . $f];
789
- } else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) {
790
- $atts[$f] = '['. $atts[$f] .']';
791
- }
792
- }
793
- unset( $f, $val );
794
- }
795
-
796
- // Format event
797
- $atts['event'] = array( 'create');
798
- if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
799
- $atts['event'][] = 'update';
800
- } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
801
- $atts['event'] = array( 'update');
802
- }
803
- }
804
-
805
- private static function format_email_to_data( &$atts, $notification ) {
806
- if ( isset( $notification['email_to'] ) ) {
807
- $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
808
- } else {
809
- $atts['email_to'] = array();
810
- }
811
-
812
- if ( isset( $notification['also_email_to'] ) ) {
813
- $email_fields = (array) $notification['also_email_to'];
814
- $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
815
- unset( $email_fields );
816
- }
817
-
818
- foreach ( $atts['email_to'] as $key => $email_field ) {
819
-
820
- if ( is_numeric( $email_field ) ) {
821
- $atts['email_to'][$key] = '['. $email_field .']';
822
- }
823
-
824
- if ( strpos( $email_field, '|') ) {
825
- $email_opt = explode( '|', $email_field );
826
- if ( isset( $email_opt[0] ) ) {
827
- $atts['email_to'][$key] = '['. $email_opt[0] .' show='. $email_opt[1] .']';
828
- }
829
- unset( $email_opt );
830
- }
831
- }
832
- $atts['email_to'] = implode(', ', $atts['email_to']);
833
- }
834
-
835
- private static function setup_new_notification( &$new_notification, $notification, $atts ) {
836
- // Set up new notification
837
- $new_notification = array(
838
- 'post_content' => array(
839
- 'email_to' => $atts['email_to'],
840
- 'event' => $atts['event'],
841
- ),
842
- 'post_name' => $atts['form_id'] .'_email_'. $atts['email_key'],
843
- );
844
-
845
- // Add more fields to the new notification
846
- $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
847
- foreach ( $add_fields as $add_field ) {
848
- if ( isset ( $notification[$add_field] ) ) {
849
- $new_notification['post_content'][$add_field] = $notification[$add_field];
850
- } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
851
- $new_notification['post_content'][$add_field] = 0;
852
- } else {
853
- $new_notification['post_content'][$add_field] = '';
854
- }
855
- unset( $add_field );
856
- }
857
-
858
- // Set reply to
859
- $new_notification['post_content']['reply_to'] = $atts['reply_to'];
860
-
861
- // Set from
862
- if ( !empty( $atts['reply_to'] ) || !empty( $atts['reply_to_name'] ) ) {
863
- $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
864
- }
865
- }
866
-
867
- private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
868
- if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
869
- // migrate autoresponder
870
-
871
- $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
872
- if ( strpos($email_field, '|') ) {
873
- // data from entries field
874
- $email_field = explode('|', $email_field);
875
- if ( isset($email_field[1]) ) {
876
- $email_field = $email_field[1];
877
- }
878
- }
879
- if ( is_numeric($email_field) && ! empty($email_field) ) {
880
- $email_field = '['. $email_field .']';
881
- }
882
-
883
- $notification = $form_options;
884
- $new_notification2 = array(
885
- 'post_content' => array(
886
- 'email_message' => $notification['ar_email_message'],
887
- 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
888
- 'email_to' => $email_field,
889
- 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
890
- 'inc_user_info' => 0,
891
- ),
892
- 'post_name' => $form_id .'_email_'. count( $notifications ),
893
- );
894
-
895
- $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
896
- $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
897
-
898
- if ( ! empty( $reply_to ) ) {
899
- $new_notification2['post_content']['reply_to'] = $reply_to;
900
- }
901
-
902
- if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
903
- $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
904
- }
905
-
906
- $notifications[] = $new_notification2;
907
- unset( $new_notification2 );
908
- }
909
- }
910
-
911
  }
1
  <?php
2
+ if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
+
4
+ class FrmXMLHelper{
5
+
6
+ public static function get_xml_values($opt, $padding){
7
+ if(is_array($opt)){
8
+ foreach($opt as $ok => $ov){
9
+ echo "\n". $padding;
10
+ echo '<'. (is_numeric($ok) ? 'key:' : '') . $ok .'>';
11
+ self::get_xml_values($ov, $padding .' ');
12
+ if(is_array($ov))
13
+ echo "\n". $padding;
14
+ echo '</'. (is_numeric($ok) ? 'key:' : '') . $ok .'>';
15
+ }
16
+ }else{
17
+ echo self::cdata($opt);
18
+ }
19
+ }
20
+
21
+ public static function import_xml($file){
 
 
 
22
  $defaults = array(
23
  'forms' => 0, 'fields' => 0, 'terms' => 0,
 
 
24
  );
25
+
26
  $imported = array(
27
  'imported' => $defaults,
28
  'updated' => $defaults,
29
  'forms' => array(),
30
  );
31
+
32
  unset($defaults);
33
+
34
  if ( !defined('WP_IMPORTING') ) {
35
  define('WP_IMPORTING', true);
36
  }
37
+
38
  if ( !class_exists('DOMDocument') ) {
39
  return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
40
  }
41
+
42
  $dom = new DOMDocument;
43
  $success = $dom->loadXML( file_get_contents( $file ) );
44
+ if ( !$success ) {
45
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
46
  }
47
+
48
  $xml = simplexml_import_dom( $dom );
49
  unset( $dom );
50
 
51
  // halt if loading produces an error
52
+ if ( !$xml ) {
53
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
54
  }
55
+
56
  // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
57
+
58
+ // grab cats, tags and terms
59
+ if ( isset($xml->term) ) {
60
+ $imported = self::import_xml_terms($xml->term, $imported);
61
+ unset($xml->term);
62
+ }
63
+
64
+ if ( isset($xml->form) ) {
65
+ $imported = self::import_xml_forms($xml->form, $imported);
66
+ unset($xml->form);
67
+ }
68
+
69
  $return = apply_filters('frm_importing_xml', $imported, $xml );
70
+
71
  return $return;
72
  }
73
+
74
  public static function import_xml_terms($terms, $imported) {
75
  foreach ( $terms as $t ) {
76
  if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
77
  continue;
78
  }
79
+
80
  $term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
81
  'slug' => (string) $t->term_slug,
82
  'description' => (string) $t->term_description,
83
  'term_parent' => (string) $t->term_parent,
84
  'slug' => (string) $t->term_slug,
85
  ));
86
+
87
  if ( $term_id ) {
88
  $imported['imported']['terms']++;
89
  }
90
+
91
+ unset($term_id);
92
+ unset($t);
93
  }
94
+
95
  return $imported;
96
  }
97
+
98
  public static function import_xml_forms($forms, $imported) {
99
+ $frm_form = new FrmForm();
100
+ $frm_field = new FrmField();
101
+
 
102
  foreach ( $forms as $item ) {
103
+ $form = array(
104
+ 'id' => (int) $item->id,
105
+ 'form_key' => (string) $item->form_key,
106
+ 'name' => (string) $item->name,
107
+ 'description' => (string) $item->description,
108
+ 'options' => (string) $item->options,
109
+ 'logged_in' => (int) $item->logged_in,
110
+ 'is_template' => (int) $item->is_template,
111
+ 'default_template' => (int) $item->default_template,
112
+ 'editable' => (int) $item->editable,
113
+ 'status' => (string) $item->status,
114
+ 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
115
+ );
116
+
117
+ $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
118
+
119
+ // if template, allow to edit if form keys match, otherwise, creation date must also match
120
+ $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
121
+ if ( !$form['is_template'] ) {
 
122
  $edit_query['created_at'] = $form['created_at'];
123
  }
124
+
125
+ $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
126
+
127
+ $this_form = $frm_form->getAll($edit_query, '', 1);
 
 
 
 
 
128
  unset($edit_query);
129
+
130
+ if ( !empty($this_form) ) {
131
+ $form_id = $this_form->id;
132
+ $frm_form->update($form_id, $form );
133
  $imported['updated']['forms']++;
134
+
135
+ $form_fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
 
 
136
  $old_fields = array();
137
  foreach ( $form_fields as $f ) {
138
  $old_fields[$f->id] = $f;
142
  $form_fields = $old_fields;
143
  unset($old_fields);
144
  } else {
 
145
  //form does not exist, so create it
146
+ if ( $form_id = $frm_form->create( $form ) ) {
 
147
  $imported['imported']['forms']++;
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
149
  }
150
+
151
  foreach ( $item->field as $field ) {
152
  $f = array(
153
  'id' => (int) $field->id,
162
  'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
163
  'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
164
  );
165
+
166
+ if ( is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'image', 'hidden', 'password', 'tag')) ) {
 
 
 
 
167
  if ( count($f['default_value']) === 1 ) {
168
  $f['default_value'] = '['. reset($f['default_value']) .']';
169
  } else {
170
  $f['default_value'] = reset($f['default_value']);
171
  }
172
  }
173
+
174
  $f = apply_filters('frm_duplicated_field', $f);
175
+
176
+ if ( $this_form ) {
177
  // check for field to edit by field id
178
  if ( isset($form_fields[$f['id']]) ) {
179
+ $frm_field->update( $f['id'], $f );
180
  $imported['updated']['fields']++;
181
+
182
  unset($form_fields[$f['id']]);
183
+
184
  //unset old field key
185
  if ( isset($form_fields[$f['field_key']]) ) {
186
  unset($form_fields[$f['field_key']]);
188
  } else if ( isset($form_fields[$f['field_key']]) ) {
189
  // check for field to edit by field key
190
  unset($f['id']);
191
+
192
+ $frm_field->update( $form_fields[$f['field_key']], $f );
193
  $imported['updated']['fields']++;
194
+
195
  unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id
196
  unset($form_fields[$f['field_key']]); //unset old field key
197
+ } else if ( $frm_field->create( $f ) ) {
 
 
 
 
 
198
  // if no matching field id or key in this form, create the field
199
  $imported['imported']['fields']++;
200
  }
201
+ } else if ( $frm_field->create( $f ) ) {
 
 
 
 
202
  $imported['imported']['fields']++;
203
  }
204
+
205
+ unset($field);
 
 
 
 
 
206
  }
207
+
208
+
209
  // Delete any fields attached to this form that were not included in the template
210
+ if ( isset($form_fields) && !empty($form_fields) ) {
211
+ foreach ($form_fields as $field){
212
  if ( is_object($field) ) {
213
+ $frm_field->destroy($field->id);
214
  }
215
  unset($field);
216
  }
217
  unset($form_fields);
218
  }
219
+
220
+
221
  // Update field ids/keys to new ones
222
+ do_action('frm_after_duplicate_form', $form_id, $form);
223
+
224
  $imported['forms'][ (int) $item->id] = $form_id;
225
+
226
+ unset($form);
227
+ unset($item);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
+
230
+ unset($frm_form);
231
+ unset($frm_field);
232
+
233
  return $imported;
234
  }
235
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  public static function cdata( $str ) {
237
  $str = maybe_unserialize($str);
238
  if ( is_array($str) ) {
240
  } else if (seems_utf8( $str ) == false ) {
241
  $str = utf8_encode( $str );
242
  }
243
+
244
  if ( is_numeric($str) ) {
245
  return $str;
246
  }
247
+
248
  // $str = ent2ncr(esc_html($str));
249
  $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
250
 
251
  return $str;
252
  }
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  }
classes/models/FrmDb.php CHANGED
@@ -1,78 +1,42 @@
1
  <?php
 
2
 
3
- class FrmDb {
4
- var $fields;
5
- var $forms;
6
- var $entries;
7
- var $entry_metas;
8
-
9
- public function __construct() {
10
- if ( ! defined('ABSPATH') ) {
11
- die('You are not allowed to call this page directly.');
12
- }
13
 
 
 
 
14
  global $wpdb;
15
- $this->fields = $wpdb->prefix . 'frm_fields';
16
- $this->forms = $wpdb->prefix . 'frm_forms';
17
- $this->entries = $wpdb->prefix . 'frm_items';
18
- $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
19
  }
20
-
21
- public function upgrade( $old_db_version = false ) {
22
  global $wpdb;
23
  //$frm_db_version is the version of the database we're moving to
24
  $frm_db_version = FrmAppHelper::$db_version;
25
- $old_db_version = (float) $old_db_version;
26
- if ( ! $old_db_version ) {
27
  $old_db_version = get_option('frm_db_version');
28
- }
29
 
30
- if ( $frm_db_version != $old_db_version ) {
31
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
32
-
33
- $this->create_tables();
34
- $this->migrate_data($frm_db_version, $old_db_version);
35
-
36
- /**** ADD/UPDATE DEFAULT TEMPLATES ****/
37
- FrmXMLController::add_default_templates();
38
-
39
- /***** SAVE DB VERSION *****/
40
- update_option('frm_db_version', $frm_db_version);
41
- }
42
-
43
- do_action('frm_after_install');
44
-
45
- /**** update the styling settings ****/
46
- $frm_style = new FrmStyle();
47
- $frm_style->update( 'default' );
48
- }
49
-
50
- public function collation() {
51
- global $wpdb;
52
- if ( ! $wpdb->has_cap( 'collation' ) ) {
53
- return '';
54
- }
55
-
56
  $charset_collate = '';
57
- if ( ! empty($wpdb->charset) ) {
58
- $charset_collate = ' DEFAULT CHARACTER SET '. $wpdb->charset;
 
 
 
59
  }
60
 
61
- if ( ! empty($wpdb->collate) ) {
62
- $charset_collate .= ' COLLATE '. $wpdb->collate;
63
- }
64
-
65
- return $charset_collate;
66
- }
67
-
68
- private function create_tables() {
69
- $charset_collate = $this->collation();
70
- $sql = array();
71
-
72
  /* Create/Upgrade Fields Table */
73
- $sql[] = 'CREATE TABLE '. $this->fields .' (
74
  id int(11) NOT NULL auto_increment,
75
- field_key varchar(100) default NULL,
76
  name text default NULL,
77
  description text default NULL,
78
  type text default NULL,
@@ -86,37 +50,42 @@ class FrmDb {
86
  PRIMARY KEY (id),
87
  KEY form_id (form_id),
88
  UNIQUE KEY field_key (field_key)
89
- )';
90
 
 
 
91
  /* Create/Upgrade Forms Table */
92
- $sql[] = 'CREATE TABLE '. $this->forms .' (
93
  id int(11) NOT NULL auto_increment,
94
- form_key varchar(100) default NULL,
95
  name varchar(255) default NULL,
96
  description text default NULL,
97
- parent_form_id int(11) default 0,
98
  logged_in tinyint(1) default NULL,
99
  editable tinyint(1) default NULL,
100
  is_template tinyint(1) default 0,
101
  default_template tinyint(1) default 0,
102
  status varchar(255) default NULL,
 
103
  options longtext default NULL,
104
  created_at datetime NOT NULL,
105
  PRIMARY KEY (id),
106
  UNIQUE KEY form_key (form_key)
107
- )';
 
 
108
 
109
  /* Create/Upgrade Items Table */
110
- $sql[] = 'CREATE TABLE '. $this->entries .' (
111
  id int(11) NOT NULL auto_increment,
112
- item_key varchar(100) default NULL,
113
  name varchar(255) default NULL,
114
  description text default NULL,
115
  ip text default NULL,
116
  form_id int(11) default NULL,
117
  post_id int(11) default NULL,
118
  user_id int(11) default NULL,
119
- parent_item_id int(11) default 0,
120
  is_draft tinyint(1) default 0,
121
  updated_by int(11) default NULL,
122
  created_at datetime NOT NULL,
@@ -127,10 +96,12 @@ class FrmDb {
127
  KEY user_id (user_id),
128
  KEY parent_item_id (parent_item_id),
129
  UNIQUE KEY item_key (item_key)
130
- )';
 
 
131
 
132
  /* Create/Upgrade Meta Table */
133
- $sql[] = 'CREATE TABLE '. $this->entry_metas .' (
134
  id int(11) NOT NULL auto_increment,
135
  meta_value longtext default NULL,
136
  field_id int(11) NOT NULL,
@@ -139,520 +110,219 @@ class FrmDb {
139
  PRIMARY KEY (id),
140
  KEY field_id (field_id),
141
  KEY item_id (item_id)
142
- )';
143
-
144
- foreach ( $sql as $q ) {
145
- dbDelta($q . $charset_collate .';');
146
- unset($q);
147
- }
148
- }
149
-
150
- /**
151
- * @param integer $frm_db_version
152
- */
153
- private function migrate_data($frm_db_version, $old_db_version) {
154
- $migrations = array(4, 6, 11, 16, 17);
155
- foreach ( $migrations as $migration ) {
156
- if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
157
- $function_name = 'migrate_to_'. $migration;
158
- $this->$function_name();
159
  }
160
  }
161
- }
162
-
163
- /**
164
- * Change array into format $wpdb->prepare can use
165
- */
166
- public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
167
- if ( empty($args) ) {
168
- // add an arg to prevent prepare from failing
169
- $args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
170
- return;
171
  }
172
-
173
- $where = '';
174
- $values = array();
175
-
176
- if ( is_array( $args ) ) {
177
- $base_where = $starts_with;
178
- self::parse_where_from_array( $args, $base_where, $where, $values );
179
- }
180
-
181
- $args = compact( 'where', 'values' );
182
- }
183
-
184
- /**
185
- * @param string $base_where
186
- * @param string $where
187
- */
188
- public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
189
- $condition = ' AND';
190
- if ( isset( $args['or'] ) ) {
191
- $condition = ' OR';
192
- unset( $args['or'] );
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
194
-
195
- foreach ( $args as $key => $value ) {
196
- $where .= empty( $where ) ? $base_where : $condition;
197
- $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
198
- if ( is_numeric( $key ) || $array_inc_null ) {
199
- $where .= ' ( ';
200
- $nested_where = '';
201
- if ( $array_inc_null ) {
202
- foreach ( $value as $val ) {
203
- self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
204
- }
205
- } else {
206
- self::parse_where_from_array( $value, '', $nested_where, $values );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  }
208
- $where .= $nested_where;
209
- $where .= ' ) ';
210
- } else {
211
- self::interpret_array_to_sql( $key, $value, $where, $values );
212
  }
 
213
  }
214
- }
 
215
 
216
- /**
217
- * @param string $key
218
- * @param string $where
219
- */
220
- private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
221
- if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
222
- $k = explode(' ', $key);
223
- $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
224
- $values[] = '%Y-%m-%d %H:%i:%s';
225
- } else {
226
- $where .= ' '. $key;
227
  }
228
 
229
- $lowercase_key = explode( ' ', strtolower( $key ) );
230
- $lowercase_key = end( $lowercase_key );
231
- if ( is_array( $value ) ) {
232
- // translate array of values to "in"
233
- if ( strpos( $lowercase_key, 'like' ) !== false ) {
234
- $where = rtrim( $where, $key );
235
- $where .= '(';
236
- $start = true;
237
- foreach ( $value as $v ) {
238
- if ( ! $start ) {
239
- $where .= ' OR ';
240
- }
241
- $start = false;
242
- $where .= $key . ' %s';
243
- $values[] = '%' . FrmAppHelper::esc_like( $v ) . '%';
244
- }
245
- $where .= ')';
246
- } else {
247
- $where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
248
- $values = array_merge( $values, $value );
249
- }
250
- } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
251
- /**
252
- * Allow string to start or end with the value
253
- * If the key is like% then skip the first % for starts with
254
- * If the key is %like then skip the last % for ends with
255
- */
256
- $start = $end = '%';
257
- if ( $lowercase_key == 'like%' ) {
258
- $start = '';
259
- $where = rtrim( $where, '%' );
260
- } else if ( $lowercase_key == '%like' ) {
261
- $end = '';
262
- $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
263
- $where .= 'like';
264
- }
265
-
266
- $where .= ' %s';
267
- $values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
268
-
269
- } else if ( $value === null ) {
270
- $where .= ' IS NULL';
271
- } else {
272
- // allow a - to prevent = from being added
273
- if ( substr( $key, -1 ) == '-' ) {
274
- $where = rtrim( $where, '-' );
275
- } else {
276
- $where .= '=';
277
- }
278
-
279
- $where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
280
- $values[] = $value;
281
  }
282
- }
283
-
284
- /**
285
- * @param string $table
286
- */
287
- public static function get_count( $table, $where = array(), $args = array() ) {
288
- $count = self::get_var( $table, $where, 'COUNT(*)', $args );
289
- return $count;
290
- }
291
-
292
- public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
293
- $group = '';
294
- self::get_group_and_table_name( $table, $group );
295
- self::convert_options_to_array( $args, '', $limit );
296
 
297
- $query = 'SELECT ' . $field . ' FROM ' . $table;
298
- if ( is_array( $where ) || empty( $where ) ) {
299
- // only separate into array values and query string if is array
300
- self::get_where_clause_and_values( $where );
301
- global $wpdb;
302
- $query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
303
- } else {
304
- /**
305
- * Allow the $where to be prepared before we recieve it here.
306
- * This is a fallback for reverse compatability, but is not recommended
307
- */
308
- _deprecated_argument( 'where', '2.0', __( 'Use the query in an array format so it can be properly prepared.', 'formidable' ) );
309
- $query .= $where . ' ' . implode( ' ', $args );
310
- }
311
-
312
- $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
313
- $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
314
- return $results;
315
  }
 
 
 
 
316
 
317
- /**
318
- * @param string $table
319
- * @param array $where
320
- */
321
- public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
322
- return self::get_var( $table, $where, $field, $args, $limit, 'col' );
323
  }
324
 
325
- /**
326
- * @since 2.0
327
- * @param string $table
328
- */
329
- public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
330
- $args['limit'] = 1;
331
- return self::get_var( $table, $where, $fields, $args, '', 'row' );
332
- }
 
 
 
 
333
 
334
- /**
335
- * @param string $table
336
- */
337
- public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
338
- _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
339
- return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1), '', 'row' );
340
  }
 
 
 
341
 
342
- public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
343
- _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
344
- return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
345
- }
346
 
347
- /**
348
- * Prepare a key/value array before DB call
349
- * @since 2.0
350
- * @param string $table
351
- */
352
- public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
353
- return self::get_var( $table, $where, $fields, $args, '', 'results' );
354
  }
 
 
 
355
 
356
- /**
357
- * Check for like, not like, in, not in, =, !=, >, <, <=, >=
358
- * Return a value to append to the where array key
359
- *
360
- * @return string
361
- */
362
- public static function append_where_is( $where_is ) {
363
- $switch_to = array(
364
- '=' => '',
365
- '!=' => '!',
366
- '<=' => '<',
367
- '>=' => '>',
368
- 'like' => 'like',
369
- 'not like' => 'not like',
370
- 'in' => '',
371
- 'not in' => 'not',
372
- 'like%' => 'like%',
373
- '%like' => '%like',
374
- );
375
-
376
- $where_is = strtolower( $where_is );
377
- if ( isset( $switch_to[ $where_is ] ) ) {
378
- return ' ' . $switch_to[ $where_is ];
379
- }
380
-
381
- // > and < need a little more work since we don't want them switched to >= and <=
382
- if ( $where_is == '>' || $where_is == '<' ) {
383
- return ' ' . $where_is . '-'; // the - indicates that the = should not be added later
384
- }
385
 
386
- // fallback to = if the query is none of these
387
- return '';
388
- }
389
 
390
- /**
391
- * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
392
- * Also add the wpdb->prefix to the table if it's missing
393
- *
394
- * @param string $table
395
- * @param string $group
396
- */
397
- private static function get_group_and_table_name( &$table, &$group ) {
398
  global $wpdb;
399
 
400
- $table_parts = explode(' ', $table);
401
- $group = reset($table_parts);
402
- $group = str_replace( $wpdb->prefix, '', $group );
 
403
 
404
- if ( $group == $table ) {
405
- $table = $wpdb->prefix . $table;
406
- }
407
-
408
- // switch to singular group name
409
- $group = rtrim( $group, 's' );
410
  }
411
 
412
- private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
413
- if ( ! is_array($args) ) {
414
- $args = array( 'order_by' => $args);
415
- }
416
 
417
- if ( ! empty( $order_by ) ) {
418
- $args['order_by'] = $order_by;
419
- }
420
 
421
- if ( ! empty( $limit ) ) {
422
- $args['limit'] = $limit;
423
  }
424
 
425
- $temp_args = $args;
426
- foreach ( $temp_args as $k => $v ) {
427
- if ( $v == '' ) {
428
- unset($args[$k]);
429
- continue;
430
- }
431
-
432
- if ( $k == 'limit' ) {
433
- $args[$k] = FrmAppHelper::esc_limit( $v );
434
- }
435
- $db_name = strtoupper( str_replace( '_', ' ', $k ) );
436
- if ( strpos( $v, $db_name ) === false ) {
437
- $args[$k] = $db_name .' '. $v;
438
- }
439
  }
440
- }
441
 
442
- public function uninstall() {
 
 
 
 
 
443
  if ( !current_user_can('administrator') ) {
444
- $frm_settings = FrmAppHelper::get_settings();
445
  wp_die($frm_settings->admin_permission);
446
  }
447
-
448
  global $wpdb, $wp_roles;
449
-
450
- $wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
451
- $wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
452
- $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
453
- $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
454
-
455
  delete_option('frm_options');
456
- delete_option('frm_db_version');
457
-
458
  //delete roles
459
  $frm_roles = FrmAppHelper::frm_capabilities();
460
  $roles = get_editable_roles();
461
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
462
- foreach ( $roles as $role => $details ) {
463
  $wp_roles->remove_cap( $role, $frm_role );
464
- unset($role, $details);
 
465
  }
466
- unset($frm_role, $frm_role_description);
 
467
  }
468
- unset($roles, $frm_roles);
469
-
470
- // delete actions, views, and styles
471
- $post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts .' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
472
- foreach( $post_ids as $post_id ) {
473
- // Delete's each post.
474
- wp_delete_post( $post_id, true );
475
- }
476
- unset( $post_ids );
477
-
478
  do_action('frm_after_uninstall');
479
- return true;
480
- }
481
-
482
- /**
483
- * Change field size from character to pixel -- Multiply by 7.08
484
- */
485
- private function migrate_to_17() {
486
- global $wpdb;
487
-
488
- // Get query arguments
489
- $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
490
- $query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
491
-
492
- // Get results
493
- $fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
494
-
495
- $updated = 0;
496
- foreach ( $fields as $f ) {
497
- $f->field_options = maybe_unserialize($f->field_options);
498
- if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
499
- continue;
500
- }
501
-
502
- $f->field_options['size'] = round(7.08 * (int) $f->field_options['size']);
503
- $f->field_options['size'] .= 'px';
504
- $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
505
- if ( $u ) {
506
- $updated++;
507
- }
508
- unset($f);
509
- }
510
-
511
- // Change the characters in widgets to pixels
512
- $widgets = get_option('widget_frm_show_form');
513
- if ( empty($widgets) ) {
514
- return;
515
- }
516
-
517
- $widgets = maybe_unserialize($widgets);
518
- foreach ( $widgets as $k => $widget ) {
519
- if ( ! is_array($widget) || ! isset($widget['size']) ) {
520
- continue;
521
- }
522
- $size = round(7.08 * (int) $widget['size']);
523
- $size .= 'px';
524
- $widgets[$k]['size'] = $size;
525
- }
526
- update_option('widget_frm_show_form', $widgets);
527
- }
528
-
529
- /**
530
- * Migrate post and email notification settings into actions
531
- */
532
- private function migrate_to_16() {
533
- global $wpdb;
534
-
535
- $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
536
-
537
- /**
538
- * Old email settings format:
539
- * email_to: Email or field id
540
- * also_email_to: array of fields ids
541
- * reply_to: Email, field id, 'custom'
542
- * cust_reply_to: string
543
- * reply_to_name: field id, 'custom'
544
- * cust_reply_to_name: string
545
- * plain_text: 0|1
546
- * email_message: string or ''
547
- * email_subject: string or ''
548
- * inc_user_info: 0|1
549
- * update_email: 0, 1, 2
550
- *
551
- * Old autoresponder settings format:
552
- * auto_responder: 0|1
553
- * ar_email_message: string or ''
554
- * ar_email_to: field id
555
- * ar_plain_text: 0|1
556
- * ar_reply_to_name: string
557
- * ar_reply_to: string
558
- * ar_email_subject: string
559
- * ar_update_email: 0, 1, 2
560
- *
561
- * New email settings:
562
- * post_content: json settings
563
- * post_title: form id
564
- * post_excerpt: message
565
- *
566
- */
567
-
568
- foreach ( $forms as $form ) {
569
- // Format form options
570
- $form_options = maybe_unserialize($form->options);
571
-
572
- // Migrate settings to actions
573
- FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
574
- }
575
- }
576
-
577
- private function migrate_to_11() {
578
- global $wpdb;
579
-
580
- $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
581
-
582
- $sending = __( 'Sending', 'formidable' );
583
- $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
584
- $old_default_html = <<<DEFAULT_HTML
585
- <div class="frm_submit">
586
- [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
587
- <input type="submit" value="[button_label]" [button_action] />
588
- <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
589
- </div>
590
- DEFAULT_HTML;
591
- unset($sending, $img);
592
-
593
- $new_default_html = FrmFormsHelper::get_default_html('submit');
594
- $draft_link = FrmFormsHelper::get_draft_link();
595
- foreach ( $forms as $form ) {
596
- $form->options = maybe_unserialize($form->options);
597
- if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
598
- continue;
599
- }
600
-
601
- if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
602
- $form->options['submit_html'] = $new_default_html;
603
- $wpdb->update($this->forms, array( 'options' => serialize($form->options)), array( 'id' => $form->id ));
604
- } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
605
- $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
606
- $wpdb->update($this->forms, array( 'options' => serialize($form->options)), array( 'id' => $form->id ));
607
- }
608
- unset($form);
609
- }
610
- unset($forms);
611
- }
612
-
613
- private function migrate_to_6() {
614
- global $wpdb;
615
-
616
- $no_save = array_merge( FrmFieldsHelper::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
617
- $fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save), 'id, field_options' );
618
-
619
- $default_html = <<<DEFAULT_HTML
620
- <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
621
- <label class="frm_pos_[label_position]">[field_name]
622
- <span class="frm_required">[required_label]</span>
623
- </label>
624
- [input]
625
- [if description]<div class="frm_description">[description]</div>[/if description]
626
- </div>
627
- DEFAULT_HTML;
628
-
629
- $old_default_html = <<<DEFAULT_HTML
630
- <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
631
- <label class="frm_pos_[label_position]">[field_name]
632
- <span class="frm_required">[required_label]</span>
633
- </label>
634
- [input]
635
- [if description]<p class="frm_description">[description]</p>[/if description]
636
- </div>
637
- DEFAULT_HTML;
638
-
639
- $new_default_html = FrmFieldsHelper::get_default_html('text');
640
- foreach ( $fields as $field ) {
641
- $field->field_options = maybe_unserialize($field->field_options);
642
- if ( ! isset( $field->field_options['custom_html'] ) || empty( $field->field_options['custom_html'] ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
643
- $field->field_options['custom_html'] = $new_default_html;
644
- $wpdb->update($this->fields, array( 'field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
645
- }
646
- unset($field);
647
- }
648
- unset($default_html, $old_default_html, $fields);
649
- }
650
-
651
- private function migrate_to_4() {
652
- global $wpdb;
653
- $user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
654
- foreach ( $user_ids as $user_id ) {
655
- $wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value), array( 'id' => $user_id->item_id) );
656
- }
657
  }
658
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
 
4
+ if(class_exists('FrmDb'))
5
+ return;
 
 
 
 
 
 
 
 
6
 
7
+ class FrmDb{
8
+
9
+ function __construct(){
10
  global $wpdb;
11
+ $this->fields = $wpdb->prefix . "frm_fields";
12
+ $this->forms = $wpdb->prefix . "frm_forms";
13
+ $this->entries = $wpdb->prefix . "frm_items";
14
+ $this->entry_metas = $wpdb->prefix . "frm_item_metas";
15
  }
16
+
17
+ function upgrade($old_db_version=false){
18
  global $wpdb;
19
  //$frm_db_version is the version of the database we're moving to
20
  $frm_db_version = FrmAppHelper::$db_version;
21
+ $old_db_version = (float)$old_db_version;
22
+ if(!$old_db_version)
23
  $old_db_version = get_option('frm_db_version');
 
24
 
25
+ if ($frm_db_version != $old_db_version){
26
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
27
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  $charset_collate = '';
29
+ if( $wpdb->has_cap( 'collation' ) ){
30
+ if( !empty($wpdb->charset) )
31
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
32
+ if( !empty($wpdb->collate) )
33
+ $charset_collate .= " COLLATE $wpdb->collate";
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
 
36
  /* Create/Upgrade Fields Table */
37
+ $sql = "CREATE TABLE {$this->fields} (
38
  id int(11) NOT NULL auto_increment,
39
+ field_key varchar(255) default NULL,
40
  name text default NULL,
41
  description text default NULL,
42
  type text default NULL,
50
  PRIMARY KEY (id),
51
  KEY form_id (form_id),
52
  UNIQUE KEY field_key (field_key)
53
+ ) {$charset_collate};";
54
 
55
+ dbDelta($sql);
56
+
57
  /* Create/Upgrade Forms Table */
58
+ $sql = "CREATE TABLE {$this->forms} (
59
  id int(11) NOT NULL auto_increment,
60
+ form_key varchar(255) default NULL,
61
  name varchar(255) default NULL,
62
  description text default NULL,
63
+ parent_form_id int(11) default NULL,
64
  logged_in tinyint(1) default NULL,
65
  editable tinyint(1) default NULL,
66
  is_template tinyint(1) default 0,
67
  default_template tinyint(1) default 0,
68
  status varchar(255) default NULL,
69
+ prli_link_id int(11) default NULL,
70
  options longtext default NULL,
71
  created_at datetime NOT NULL,
72
  PRIMARY KEY (id),
73
  UNIQUE KEY form_key (form_key)
74
+ ) {$charset_collate};";
75
+
76
+ dbDelta($sql);
77
 
78
  /* Create/Upgrade Items Table */
79
+ $sql = "CREATE TABLE {$this->entries} (
80
  id int(11) NOT NULL auto_increment,
81
+ item_key varchar(255) default NULL,
82
  name varchar(255) default NULL,
83
  description text default NULL,
84
  ip text default NULL,
85
  form_id int(11) default NULL,
86
  post_id int(11) default NULL,
87
  user_id int(11) default NULL,
88
+ parent_item_id int(11) default NULL,
89
  is_draft tinyint(1) default 0,
90
  updated_by int(11) default NULL,
91
  created_at datetime NOT NULL,
96
  KEY user_id (user_id),
97
  KEY parent_item_id (parent_item_id),
98
  UNIQUE KEY item_key (item_key)
99
+ ) {$charset_collate};";
100
+
101
+ dbDelta($sql);
102
 
103
  /* Create/Upgrade Meta Table */
104
+ $sql = "CREATE TABLE {$this->entry_metas} (
105
  id int(11) NOT NULL auto_increment,
106
  meta_value longtext default NULL,
107
  field_id int(11) NOT NULL,
110
  PRIMARY KEY (id),
111
  KEY field_id (field_id),
112
  KEY item_id (item_id)
113
+ ) {$charset_collate};";
114
+
115
+ dbDelta($sql);
116
+
117
+ /**** MIGRATE DATA ****/
118
+ if ($frm_db_version >= 1.03 and $old_db_version < 1.03){
119
+ global $frm_entry;
120
+ $all_entries = $frm_entry->getAll();
121
+ foreach($all_entries as $ent){
122
+ $opts = maybe_unserialize($ent->description);
123
+ if(is_array($opts) and in_array($opts['ip']))
124
+ $wpdb->update( $this->entries, array('ip' => $opts['ip']), array( 'id' => $ent->id ) );
 
 
 
 
 
125
  }
126
  }
127
+
128
+ if($frm_db_version >= 4 and $old_db_version < 4){
129
+ global $frm_entry_meta;
130
+ $user_ids = $frm_entry_meta->getAll("fi.type='user_id'");
131
+ foreach($user_ids as $user_id)
132
+ $wpdb->update( $this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id) );
 
 
 
 
133
  }
134
+
135
+ if($frm_db_version >= 6 and $old_db_version < 6){
136
+ $fields = $wpdb->get_results("SELECT id, field_options FROM $this->fields WHERE type not in ('hidden', 'user_id', 'break', 'divider', 'html', 'captcha', 'form')");
137
+ $default_html = <<<DEFAULT_HTML
138
+ <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
139
+ <label class="frm_pos_[label_position]">[field_name]
140
+ <span class="frm_required">[required_label]</span>
141
+ </label>
142
+ [input]
143
+ [if description]<div class="frm_description">[description]</div>[/if description]
144
+ </div>
145
+ DEFAULT_HTML;
146
+ $old_default_html = <<<DEFAULT_HTML
147
+ <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
148
+ <label class="frm_pos_[label_position]">[field_name]
149
+ <span class="frm_required">[required_label]</span>
150
+ </label>
151
+ [input]
152
+ [if description]<p class="frm_description">[description]</p>[/if description]
153
+ </div>
154
+ DEFAULT_HTML;
155
+ $new_default_html = FrmFieldsHelper::get_default_html('text');
156
+ foreach($fields as $field){
157
+ $field->field_options = maybe_unserialize($field->field_options);
158
+ if ( !isset($field->field_options['custom_html']) || empty($field->field_options['custom_html']) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
159
+ $field->field_options['custom_html'] = $new_default_html;
160
+ $wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
161
+ }
162
+ unset($field);
163
+ }
164
+ unset($default_html);
165
+ unset($old_default_html);
166
+ unset($fields);
167
  }
168
+
169
+ if($frm_db_version >= 11 and $old_db_version < 11){
170
+ $forms = $wpdb->get_results("SELECT id, options FROM $this->forms");
171
+ $sending = __('Sending', 'formidable');
172
+ $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
173
+ $old_default_html = <<<DEFAULT_HTML
174
+ <div class="frm_submit">
175
+ [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
176
+ <input type="submit" value="[button_label]" [button_action] />
177
+ <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
178
+ </div>
179
+ DEFAULT_HTML;
180
+ unset($sending);
181
+ unset($img);
182
+
183
+ $new_default_html = FrmFormsHelper::get_default_html('submit');
184
+ $draft_link = FrmFormsHelper::get_draft_link();
185
+ foreach($forms as $form){
186
+ $form->options = maybe_unserialize($form->options);
187
+ if(!isset($form->options['submit_html']) or empty($form->options['submit_html']))
188
+ continue;
189
+
190
+ if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
191
+ $form->options['submit_html'] = $new_default_html;
192
+ $wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
193
+ }else if(!strpos($form->options['submit_html'], 'save_draft')){
194
+ $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
195
+ $wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
196
  }
197
+ unset($form);
 
 
 
198
  }
199
+ unset($forms);
200
  }
201
+
202
+
203
 
204
+ /**** ADD/UPDATE DEFAULT TEMPLATES ****/
205
+ if ( class_exists('FrmXMLController') ) {
206
+ FrmXMLController::add_default_templates();
 
 
 
 
 
 
 
 
207
  }
208
 
209
+
210
+ /***** SAVE DB VERSION *****/
211
+ update_option('frm_db_version', $frm_db_version);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
+ do_action('frm_after_install');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  }
216
+
217
+ function get_count($table, $args=array()){
218
+ global $wpdb;
219
+ extract(FrmDb::get_where_clause_and_values( $args ));
220
 
221
+ $query = "SELECT COUNT(*) FROM {$table}{$where}";
222
+ $query = $wpdb->prepare($query, $values);
223
+ return $wpdb->get_var($query);
 
 
 
224
  }
225
 
226
+ function get_where_clause_and_values( $args ){
227
+ $where = '';
228
+ $values = array();
229
+ if(is_array($args)){
230
+ foreach($args as $key => $value){
231
+ $where .= (!empty($where)) ? ' AND' : ' WHERE';
232
+ $where .= " {$key}=";
233
+ $where .= is_numeric($value) ? (strpos($value, ".") !== false ? '%f' : '%d') : '%s';
234
+
235
+ $values[] = $value;
236
+ }
237
+ }
238
 
239
+ return compact('where', 'values');
 
 
 
 
 
240
  }
241
+
242
+ function get_var($table, $args=array(), $field='id', $order_by=''){
243
+ global $wpdb;
244
 
245
+ extract(FrmDb::get_where_clause_and_values( $args ));
246
+ if(!empty($order_by))
247
+ $order_by = " ORDER BY {$order_by}";
 
248
 
249
+ $query = $wpdb->prepare("SELECT {$field} FROM {$table}{$where}{$order_by} LIMIT 1", $values);
250
+ return $wpdb->get_var($query);
 
 
 
 
 
251
  }
252
+
253
+ function get_col($table, $args=array(), $field='id', $order_by=''){
254
+ global $wpdb;
255
 
256
+ extract(FrmDb::get_where_clause_and_values( $args ));
257
+ if(!empty($order_by))
258
+ $order_by = " ORDER BY {$order_by}";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
+ $query = $wpdb->prepare("SELECT {$field} FROM {$table}{$where}{$order_by}", $values);
261
+ return $wpdb->get_col($query);
262
+ }
263
 
264
+ function get_one_record($table, $args=array(), $fields='*', $order_by=''){
 
 
 
 
 
 
 
265
  global $wpdb;
266
 
267
+ extract(FrmDb::get_where_clause_and_values( $args ));
268
+
269
+ if(!empty($order_by))
270
+ $order_by = " ORDER BY {$order_by}";
271
 
272
+ $query = "SELECT {$fields} FROM {$table}{$where} {$order_by} LIMIT 1";
273
+ $query = $wpdb->prepare($query, $values);
274
+ return $wpdb->get_row($query);
 
 
 
275
  }
276
 
277
+ function get_records($table, $args=array(), $order_by='', $limit='', $fields='*'){
278
+ global $wpdb;
 
 
279
 
280
+ extract(FrmDb::get_where_clause_and_values( $args ));
 
 
281
 
282
+ if ( !empty($order_by) && strpos($order_by, ' ORDER BY ') === false ) {
283
+ $order_by = " ORDER BY {$order_by}";
284
  }
285
 
286
+ if ( !empty($limit) && strpos($order_by, ' LIMIT ') === false ) {
287
+ $limit = " LIMIT {$limit}";
 
 
 
 
 
 
 
 
 
 
 
 
288
  }
 
289
 
290
+ $query = "SELECT {$fields} FROM {$table}{$where}{$order_by}{$limit}";
291
+ $query = $wpdb->prepare($query, $values);
292
+ return $wpdb->get_results($query);
293
+ }
294
+
295
+ function uninstall(){
296
  if ( !current_user_can('administrator') ) {
297
+ global $frm_settings;
298
  wp_die($frm_settings->admin_permission);
299
  }
300
+
301
  global $wpdb, $wp_roles;
302
+
303
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
304
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->forms);
305
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->entries);
306
+ $wpdb->query('DROP TABLE IF EXISTS '. $this->entry_metas);
307
+
308
  delete_option('frm_options');
309
+ delete_option('frm_db_version');
310
+
311
  //delete roles
312
  $frm_roles = FrmAppHelper::frm_capabilities();
313
  $roles = get_editable_roles();
314
+ foreach($frm_roles as $frm_role => $frm_role_description){
315
+ foreach ($roles as $role => $details){
316
  $wp_roles->remove_cap( $role, $frm_role );
317
+ unset($role);
318
+ unset($details);
319
  }
320
+ unset($frm_role);
321
+ unset($frm_role_description);
322
  }
323
+ unset($roles);
324
+ unset($frm_roles);
325
+
 
 
 
 
 
 
 
326
  do_action('frm_after_uninstall');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  }
328
  }
classes/models/FrmEntry.php CHANGED
@@ -1,190 +1,152 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
-
6
- class FrmEntry {
7
-
8
- public static function create( $values ) {
9
- global $wpdb;
10
 
11
- self::sanitize_entry_post( $values );
 
12
 
13
- $values = apply_filters('frm_pre_create_entry', $values);
14
-
15
- if ( ! isset( $values['item_key'] ) ) {
16
- $values['item_key'] = '';
17
- }
18
 
 
 
 
19
  $new_values = array(
20
  'item_key' => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
21
  'name' => isset($values['name']) ? $values['name'] : $values['item_key'],
22
- 'ip' => FrmAppHelper::get_ip_address(),
23
  'is_draft' => ( ( isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 ) || ( isset($values['is_draft']) && $values['is_draft'] == 1) ) ? 1 : 0,
24
  'form_id' => isset($values['form_id']) ? (int) $values['form_id']: null,
25
  'post_id' => isset($values['post_id']) ? (int) $values['post_id']: null,
26
- 'parent_item_id' => isset($values['parent_item_id']) ? (int) $values['parent_item_id']: null,
27
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
28
  'updated_at' => isset($values['updated_at']) ? $values['updated_at'] : ( isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1) ),
29
  );
30
-
31
- if ( is_array($new_values['name']) ) {
32
  $new_values['name'] = reset($new_values['name']);
33
- }
34
-
35
- if ( isset($values['description']) && ! empty($values['description']) ) {
36
  $new_values['description'] = maybe_serialize($values['description']);
37
- } else {
38
- $referrerinfo = FrmAppHelper::get_server_value('HTTP_REFERER');
39
-
40
- $new_values['description'] = serialize( array(
41
- 'browser' => FrmAppHelper::get_server_value('HTTP_USER_AGENT'),
42
- 'referrer' => $referrerinfo,
43
- ) );
44
  }
45
-
46
  //if(isset($values['id']) and is_numeric($values['id']))
47
  // $new_values['id'] = $values['id'];
48
-
49
- if ( isset($values['frm_user_id']) && ( is_numeric($values['frm_user_id']) || FrmAppHelper::is_admin() ) ) {
50
  $new_values['user_id'] = $values['frm_user_id'];
51
- } else {
52
  $user_ID = get_current_user_id();
53
  $new_values['user_id'] = $user_ID ? $user_ID : 0;
54
  }
55
-
56
  $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
57
-
58
- // don't create duplicate entry
59
- if ( self::is_duplicate($new_values, $values) ) {
60
- return false;
61
- }
62
-
63
- $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
64
-
65
- if ( ! $query_results ) {
66
- return false;
67
- }
68
-
69
- $entry_id = $wpdb->insert_id;
70
-
71
- global $frm_vars;
72
- if ( ! isset($frm_vars['saved_entries']) ) {
73
- $frm_vars['saved_entries'] = array();
74
- }
75
- $frm_vars['saved_entries'][] = (int) $entry_id;
76
-
77
- if ( isset($values['item_meta']) ) {
78
- FrmEntryMeta::update_entry_metas($entry_id, $values['item_meta']);
79
- }
80
-
81
- do_action('frm_after_create_entry', $entry_id, $new_values['form_id']);
82
- do_action('frm_after_create_entry_'. $new_values['form_id'], $entry_id);
83
- return $entry_id;
84
- }
85
-
86
- /**
87
- * check for duplicate entries created in the last minute
88
- * @return boolean
89
- */
90
- public static function is_duplicate($new_values, $values) {
91
- if ( defined('WP_IMPORTING') ) {
92
- return false;
93
- }
94
-
95
- $check_val = $new_values;
96
- $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - 60 ) );
97
-
98
- unset($check_val['created_at'], $check_val['updated_at']);
99
- unset($check_val['is_draft'], $check_val['id'], $check_val['item_key']);
100
-
101
- if ( $new_values['item_key'] == $new_values['name'] ) {
102
- unset($check_val['name']);
103
- }
104
-
105
- global $wpdb;
106
-
107
- $entry_exists = FrmDb::get_col( $wpdb->prefix .'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC') );
108
-
109
- if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
110
- return false;
111
- }
112
-
113
- $is_duplicate = false;
114
- foreach ( $entry_exists as $entry_exist ) {
115
- $is_duplicate = true;
116
-
117
- //add more checks here to make sure it's a duplicate
118
- $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
119
- $field_metas = array();
120
- foreach ( $metas as $meta ) {
121
- $field_metas[$meta->field_id] = $meta->meta_value;
122
  }
123
-
124
- // If prev entry is empty and current entry is not, they are not duplicates
125
- $filtered_vals = array_filter( $values['item_meta'] );
126
- if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
127
  return false;
128
  }
129
-
130
- $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
131
- foreach ( $diff as $field_id => $meta_value ) {
132
- if ( ! empty($meta_value) ) {
133
- $is_duplicate = false;
134
- continue;
135
- }
136
- }
137
-
138
- if ( $is_duplicate ) {
139
- return $is_duplicate;
 
 
 
140
  }
 
 
 
 
 
 
141
  }
142
-
143
- return $is_duplicate;
144
  }
 
 
 
145
 
146
- public static function duplicate( $id ) {
147
- global $wpdb;
148
-
149
- $values = self::getOne( $id );
150
 
151
  $new_values = array();
152
  $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
153
  $new_values['name'] = $values->name;
154
  $new_values['is_draft'] = $values->is_draft;
155
- $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
156
- $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
157
  $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
158
 
159
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
160
- if ( ! $query_results ) {
 
 
 
 
 
 
 
 
 
 
 
 
161
  return false;
162
- }
163
-
164
- $entry_id = $wpdb->insert_id;
165
-
166
- global $frm_vars;
167
- if ( ! isset($frm_vars['saved_entries']) ) {
168
- $frm_vars['saved_entries'] = array();
169
- }
170
- $frm_vars['saved_entries'][] = (int) $entry_id;
171
-
172
- FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
173
-
174
- do_action('frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id));
175
- return $entry_id;
176
  }
177
 
178
- public static function update( $id, $values ) {
179
- global $wpdb, $frm_vars;
180
- if ( isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
181
  return;
182
- }
183
-
184
- $values = apply_filters('frm_pre_update_entry', $values, $id);
185
 
186
  $user_ID = get_current_user_id();
187
-
188
  $new_values = array(
189
  'name' => isset($values['name']) ? $values['name'] : '',
190
  'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null,
@@ -192,7 +154,7 @@ class FrmEntry {
192
  'updated_at' => current_time('mysql', 1),
193
  'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID,
194
  );
195
-
196
  if ( isset($values['post_id']) ) {
197
  $new_values['post_id'] = (int) $values['post_id'];
198
  }
@@ -200,465 +162,289 @@ class FrmEntry {
200
  if ( isset($values['item_key']) ) {
201
  $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
202
  }
203
-
204
- if ( isset($values['parent_item_id']) ) {
205
- $new_values['parent_item_id'] = (int) $values['parent_item_id'];
206
- }
207
-
208
- if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
209
  $new_values['user_id'] = $values['frm_user_id'];
210
- }
211
 
212
  $new_values = apply_filters('frm_update_entry', $new_values, $id);
213
  $query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
214
-
215
- if ( $query_results ) {
216
- wp_cache_delete( $id .'_nometa', 'frm_entry');
217
  wp_cache_delete( $id, 'frm_entry');
218
- }
219
-
220
- if ( ! isset( $frm_vars['saved_entries'] ) ) {
221
  $frm_vars['saved_entries'] = array();
222
- }
223
-
224
- $frm_vars['saved_entries'][] = (int) $id;
225
-
226
- if ( isset($values['item_meta']) ) {
227
- FrmEntryMeta::update_entry_metas($id, $values['item_meta']);
228
- }
229
  do_action('frm_after_update_entry', $id, $new_values['form_id']);
230
  do_action('frm_after_update_entry_'. $new_values['form_id'], $id);
231
  return $query_results;
232
  }
233
 
234
- public static function &destroy( $id ){
235
  global $wpdb;
236
- $id = (int) $id;
237
-
238
- $entry = self::getOne( $id );
239
- if ( ! $entry ) {
240
  $result = false;
241
  return $result;
242
  }
243
-
244
  do_action('frm_before_destroy_entry', $id, $entry);
245
-
246
- wp_cache_delete( $id .'_nometa', 'frm_entry');
247
  wp_cache_delete( $id, 'frm_entry');
248
- $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
249
- $result = $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=%d', $id) );
250
  return $result;
251
  }
252
-
253
- public static function &update_form( $id, $value, $form_id ){
254
  global $wpdb;
255
- $form_id = isset($value) ? $form_id : null;
256
- $result = $wpdb->update( $wpdb->prefix .'frm_items', array( 'form_id' => $form_id), array( 'id' => $id ) );
257
- if ( $result ) {
258
  wp_cache_delete( $id, 'frm_entry');
259
- }
260
  return $result;
261
  }
262
-
263
- public static function getOne( $id, $meta = false) {
264
  global $wpdb;
265
-
266
- $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
267
- LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
268
-
269
- $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
270
- $query_args = array( $id );
271
- $query = $wpdb->prepare( $query, $query_args );
272
-
273
- if ( ! $meta ) {
274
- $entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
275
  return stripslashes_deep($entry);
276
- }
277
-
278
- $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279
- if ( $entry !== false ) {
280
- return stripslashes_deep($entry);
281
- }
282
-
283
- $entry = $wpdb->get_row( $query );
284
- $entry = self::get_meta($entry);
285
-
286
- return stripslashes_deep($entry);
287
- }
288
-
289
- public static function get_meta($entry) {
290
- if ( ! $entry ) {
291
- return $entry;
292
- }
293
-
294
- global $wpdb;
295
- $metas = FrmDb::get_results( $wpdb->prefix .'frm_item_metas m LEFT JOIN '. $wpdb->prefix .'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0), 'field_id, meta_value, field_key, item_id' );
296
-
297
- $entry->metas = array();
298
-
299
- foreach ( $metas as $meta_val ) {
300
- if ( $meta_val->item_id == $entry->id ) {
301
- $entry->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
302
- continue;
303
- }
304
 
305
- // include sub entries in an array
306
- if ( ! isset( $entry_metas[$meta_val->field_id]) ) {
307
- $entry->metas[$meta_val->field_id] = array();
 
 
 
 
 
 
 
 
 
 
 
 
308
  }
 
309
 
310
- $entry->metas[$meta_val->field_id][] = maybe_unserialize($meta_val->meta_value);
311
 
312
- unset($meta_val);
313
  }
314
- unset($metas);
315
 
316
- wp_cache_set( $entry->id, $entry, 'frm_entry');
317
-
318
- return $entry;
319
  }
320
-
321
- /**
322
- * @param string $id
323
- */
324
- public static function &exists( $id ){
325
  global $wpdb;
326
-
327
- if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
328
  $exists = true;
329
  return $exists;
330
  }
 
 
331
 
332
- if ( is_numeric($id) ) {
333
- $where = array( 'id' => $id );
334
- } else {
335
- $where = array( 'item_key' => $id );
336
- }
337
- $id = FrmDb::get_var( $wpdb->prefix .'frm_items', $where );
338
-
339
  $exists = ($id && $id > 0) ? true : false;
340
  return $exists;
341
  }
342
 
343
- public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
344
  global $wpdb;
345
-
346
- $limit = FrmAppHelper::esc_limit($limit);
347
-
348
- $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
349
- $entries = wp_cache_get($cache_key, 'frm_entry');
350
-
351
- if ( false === $entries ) {
352
- $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
353
- $table = $wpdb->prefix .'frm_items it ';
354
-
355
- if ( $inc_form ) {
356
- $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
357
- $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  }
359
-
360
- if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
361
- // sort by a requested field
362
- $field_id = (int) $order_matches[1];
363
- $fields .= ', (SELECT meta_value FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id = '. $field_id .' AND item_id = it.id) as meta_'. $field_id;
364
- unset( $order_matches, $field_id );
365
- }
366
-
367
- // prepare the query
368
- $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
369
-
370
- $entries = $wpdb->get_results($query, OBJECT_K);
371
  unset($query);
372
-
373
- wp_cache_set($cache_key, $entries, 'frm_entry', 300);
374
- }
375
-
376
- if ( ! $meta || ! $entries ) {
377
- return stripslashes_deep($entries);
378
- }
379
- unset($meta);
380
-
381
- if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
382
- $where = array( 'it.form_id' => substr($where, 11));
383
- }
384
-
385
- $meta_where = array( 'field_id !' => 0 );
386
- if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
387
- $meta_where['fi.form_id'] = $where['it.form_id'];
388
- } else {
389
- $meta_where['item_id'] = array_keys( $entries );
390
- }
391
-
392
- $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
393
-
394
- unset( $meta_where );
395
-
396
- if ( ! $metas ) {
397
- return stripslashes_deep($entries);
398
- }
399
-
400
- foreach ( $metas as $m_key => $meta_val ) {
401
- if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
402
- continue;
403
- }
404
-
405
- if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
406
- $entries[$meta_val->item_id]->metas = array();
407
  }
408
-
409
- $entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
410
-
411
- unset($m_key, $meta_val);
412
  }
413
-
414
- foreach ( $entries as $entry ) {
415
- wp_cache_set( $entry->id, $entry, 'frm_entry');
416
- unset($entry);
417
- }
418
-
419
  return stripslashes_deep($entries);
420
  }
421
 
422
  // Pagination Methods
423
- public static function getRecordCount( $where = '' ) {
424
  global $wpdb;
425
- $table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
426
-
427
- if ( is_numeric($where) ) {
428
- $table_join = 'frm_items';
429
- $where = array( 'form_id' => $where );
430
  }
431
-
432
- if ( is_array( $where ) ) {
433
- $count = FrmDb::get_count( $table_join, $where );
434
- } else {
435
- global $wpdb;
436
- $cache_key = 'count_'. maybe_serialize($where);
437
- $query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
438
- $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
439
- }
440
-
441
- return $count;
442
  }
443
 
444
- public static function getPageCount( $p_size, $where = '' ) {
445
- if ( is_numeric($where) ) {
446
- return ceil( (int) $where / (int) $p_size );
447
- } else {
448
- return ceil( (int) self::getRecordCount($where) / (int) $p_size );
449
- }
450
  }
451
 
452
- public static function validate( $values, $exclude = false ) {
453
- global $wpdb;
454
-
455
- self::sanitize_entry_post( $values );
456
  $errors = array();
457
-
458
  if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
459
- $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
460
  return $errors;
461
  }
462
-
463
- if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_'. $values['form_id'] ] ) || ! wp_verify_nonce($values['frm_submit_entry_'. $values['form_id']], 'frm_submit_entry_nonce') ) ) {
464
- $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
465
  }
466
-
467
- if ( ! isset($values['item_key']) || $values['item_key'] == '' ) {
468
  $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
469
  }
470
-
471
- $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
472
- // Don't get subfields
473
- $where['fr.parent_form_id'] = array( null, 0 );
474
- // Don't get excluded fields (like file upload fields in the ajax validation)
475
- if ( ! empty( $exclude ) ) {
476
- $where['fi.type not'] = $exclude;
477
- }
478
-
479
- $posted_fields = FrmField::getAll($where, 'field_order');
480
-
481
- // Pass exclude value to validate_field function so it can be used for repeating sections
482
- $args = array( 'exclude' => $exclude );
483
-
484
- foreach ( $posted_fields as $posted_field ) {
485
- self::validate_field($posted_field, $errors, $values, $args);
486
- unset($posted_field);
487
- }
488
-
489
- // check for spam
490
- self::spam_check($exclude, $values, $errors);
491
-
492
- $errors = apply_filters('frm_validate_entry', $errors, $values, compact('exclude'));
493
-
494
- return $errors;
495
- }
496
-
497
- /**
498
- * Sanitize the POST values before we use them
499
- *
500
- * @since 2.0
501
- * @param array $values The POST values by reference
502
- */
503
- public static function sanitize_entry_post( &$values ) {
504
- $sanitize_method = array(
505
- 'form_id' => 'absint',
506
- 'frm_action' => 'sanitize_title',
507
- 'form_key' => 'sanitize_title',
508
- 'item_key' => 'sanitize_title',
509
- 'name' => 'sanitize_text_field',
510
- 'frm_saving_draft' => 'absint',
511
- 'is_draft' => 'absint',
512
- 'post_id' => 'absint',
513
- 'parent_item_id' => 'absint',
514
- 'created_at' => 'sanitize_title',
515
- 'updated_at' => 'sanitize_title',
516
- );
517
-
518
- FrmAppHelper::sanitize_request( $sanitize_method, $values );
519
- }
520
-
521
- public static function validate_field($posted_field, &$errors, $values, $args = array()) {
522
- $defaults = array(
523
- 'id' => $posted_field->id,
524
- 'parent_field_id' => '', // the id of the repeat or embed form
525
- 'key_pointer' => '', // the pointer in the posted array
526
- 'exclude' => array(), // exclude these field types from validation
527
- );
528
- $args = wp_parse_args( $args, $defaults );
529
-
530
- if ( empty($args['parent_field_id']) ) {
531
- $value = isset($values['item_meta'][$args['id']]) ? $values['item_meta'][$args['id']] : '';
532
- } else {
533
- // value is from a nested form
534
- $value = $values;
535
- }
536
-
537
- // Check for values in "Other" fields
538
- FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
539
-
540
- if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
541
  $value = '';
542
- }
543
-
544
- // Check for an array with only one value
545
- // Don't reset values in "Other" fields because array keys need to be preserved
546
- if ( is_array($value) && count( $value ) == 1 && $args['other'] !== true ) {
547
- $value = reset($value);
548
- }
549
-
550
- if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
551
- $frm_settings = FrmAppHelper::get_settings();
552
- $errors['field'. $args['id']] = ( ! isset( $posted_field->field_options['blank'] ) || $posted_field->field_options['blank'] == '') ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
553
- } else if ( $posted_field->type == 'text' && ! isset( $_POST['name'] ) ) {
554
- $_POST['name'] = $value;
555
- }
556
-
557
- self::validate_url_field($errors, $posted_field, $value, $args);
558
- self::validate_email_field($errors, $posted_field, $value, $args);
559
-
560
- FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
561
-
562
- self::validate_recaptcha($errors, $posted_field, $args);
563
-
564
- $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
565
- }
566
-
567
- public static function validate_url_field(&$errors, $field, &$value, $args) {
568
- if ( $value == '' || ! in_array($field->type, array( 'website', 'url', 'image')) ) {
569
- return;
570
- }
571
-
572
- if ( trim($value) == 'http://' ) {
573
- $value = '';
574
- } else {
575
- $value = esc_url_raw( $value );
576
- $value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://'. $value;
577
- }
578
-
579
- //validate the url format
580
- if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) {
581
- $errors['field'. $args['id']] = FrmFieldsHelper::get_error_msg($field, 'invalid');
582
- }
583
- }
584
-
585
- public static function validate_email_field(&$errors, $field, $value, $args) {
586
- if ( $value == '' || $field->type != 'email' ) {
587
- return;
588
- }
589
-
590
- //validate the email format
591
- if ( ! is_email($value) ) {
592
- $errors['field'. $args['id']] = FrmFieldsHelper::get_error_msg($field, 'invalid');
593
- }
594
- }
595
-
596
- public static function validate_recaptcha(&$errors, $field, $args) {
597
- if ( $field->type != 'captcha' || FrmAppHelper::is_admin() ) {
598
- return;
599
- }
600
-
601
- if ( ! isset($_POST['g-recaptcha-response']) ) {
602
- // If captcha is missing, check if it was already verified
603
- if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) {
604
- // There was no captcha submitted
605
- $errors['field'. $args['id']] = __( 'The captcha is missing from this form', 'formidable' );
606
  }
607
- return;
608
- }
609
-
610
- $frm_settings = FrmAppHelper::get_settings();
611
-
612
- $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify?secret='. $frm_settings->privkey .'&response='. $_POST['g-recaptcha-response'] .'&remoteip='. FrmAppHelper::get_ip_address() );
613
- $response = json_decode(wp_remote_retrieve_body( $resp ), true);
614
-
615
- if ( ! $response['success'] ) {
616
- // What happens when the CAPTCHA was entered incorrectly
617
- $errors['field'. $args['id']] = ( ! isset($field->field_options['invalid']) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid'];
618
- }
619
- }
 
 
 
 
 
620
 
621
- /**
622
- * check for spam
623
- * @param boolean $exclude
624
- * @param array $values
625
- * @param array $errors by reference
626
- */
627
- public static function spam_check($exclude, $values, &$errors) {
628
- if ( ! empty($exclude) || ! isset($values['item_meta']) || empty($values['item_meta']) || ! empty($errors) ) {
629
- // only check spam if there are no other errors
630
- return;
631
  }
632
-
633
- global $wpcom_api_key;
634
- if ( ( function_exists( 'akismet_http_post' ) || is_callable('Akismet::http_post') ) && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet($values) ) {
635
- $form = FrmForm::getOne($values['form_id']);
636
-
637
- if ( isset($form->options['akismet']) && ! empty($form->options['akismet']) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ) {
638
- $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
639
- }
640
- }
641
-
642
- // check for blacklist keys
643
- if ( self::blacklist_check($values) ) {
644
- $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
 
 
 
 
 
645
  }
646
- }
647
 
 
 
 
 
 
648
  // check the blacklisted words
649
- public static function blacklist_check( $values ) {
650
  if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
651
  return false;
652
  }
653
-
654
  $mod_keys = trim( get_option( 'blacklist_keys' ) );
655
 
656
  if ( empty( $mod_keys ) ) {
657
  return false;
658
  }
659
-
660
  $content = FrmEntriesHelper::entry_array_to_string($values);
661
-
662
  if ( empty($content) ) {
663
  return false;
664
  }
@@ -679,21 +465,35 @@ class FrmEntry {
679
 
680
  return false;
681
  }
682
-
683
- /**
684
- * Check entries for spam
685
- *
686
- * @return boolean true if is spam
687
- */
688
- public static function akismet($values) {
689
  $content = FrmEntriesHelper::entry_array_to_string($values);
690
-
691
  if ( empty($content) ) {
692
  return false;
693
  }
694
-
695
  $datas = array();
696
- self::parse_akismet_array($datas, $content);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697
 
698
  $query_string = '';
699
  foreach ( $datas as $key => $data ) {
@@ -707,36 +507,8 @@ class FrmEntry {
707
  global $akismet_api_host, $akismet_api_port;
708
  $response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
709
  }
710
-
711
- return ( is_array($response) && $response[1] == 'true' ) ? true : false;
712
- }
713
-
714
- /**
715
- * Called by FrmEntry::akismet
716
- * @since 2.0
717
- *
718
- * @param string $content
719
- */
720
- private static function parse_akismet_array( &$datas, $content ) {
721
- $datas['blog'] = FrmAppHelper::site_url();
722
- $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
723
- $datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
724
- $datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
725
- $datas['comment_type'] = 'formidable';
726
- $datas['comment_content'] = $content;
727
-
728
- if ( $permalink = get_permalink() ) {
729
- $datas['permalink'] = $permalink;
730
- }
731
-
732
- foreach ( $_SERVER as $key => $value ) {
733
- if ( ! in_array($key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value) ) {
734
- $datas[$key] = $value;
735
- } else {
736
- $datas[$key] = '';
737
- }
738
-
739
- unset($key, $value);
740
- }
741
  }
 
742
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
 
 
 
 
 
 
 
3
 
4
+ if(class_exists('FrmEntry'))
5
+ return;
6
 
7
+ class FrmEntry{
 
 
 
 
8
 
9
+ function create( $values ){
10
+ global $wpdb, $frm_entry_meta;
11
+
12
  $new_values = array(
13
  'item_key' => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
14
  'name' => isset($values['name']) ? $values['name'] : $values['item_key'],
15
+ 'ip' => $_SERVER['REMOTE_ADDR'],
16
  'is_draft' => ( ( isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 ) || ( isset($values['is_draft']) && $values['is_draft'] == 1) ) ? 1 : 0,
17
  'form_id' => isset($values['form_id']) ? (int) $values['form_id']: null,
18
  'post_id' => isset($values['post_id']) ? (int) $values['post_id']: null,
 
19
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
20
  'updated_at' => isset($values['updated_at']) ? $values['updated_at'] : ( isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1) ),
21
  );
22
+
23
+ if(is_array($new_values['name']))
24
  $new_values['name'] = reset($new_values['name']);
25
+
26
+ if(isset($values['description']) and !empty($values['description'])){
 
27
  $new_values['description'] = maybe_serialize($values['description']);
28
+ }else{
29
+ $referrerinfo = FrmAppHelper::get_referer_info();
30
+
31
+ $new_values['description'] = serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'],
32
+ 'referrer' => $referrerinfo));
 
 
33
  }
34
+
35
  //if(isset($values['id']) and is_numeric($values['id']))
36
  // $new_values['id'] = $values['id'];
37
+
38
+ if(isset($values['frm_user_id']) and (is_numeric($values['frm_user_id']) or (is_admin() and !defined('DOING_AJAX')))){
39
  $new_values['user_id'] = $values['frm_user_id'];
40
+ }else{
41
  $user_ID = get_current_user_id();
42
  $new_values['user_id'] = $user_ID ? $user_ID : 0;
43
  }
44
+
45
  $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
46
+
47
+ //check for duplicate entries created in the last 5 minutes
48
+ if(!defined('WP_IMPORTING')){
49
+ $create_entry = true;
50
+
51
+ $check_val = $new_values;
52
+ $check_val['created_at >'] = date('Y-m-d H:i:s', (strtotime($new_values['created_at']) - (60*5)));
53
+ unset($check_val['created_at']);
54
+ unset($check_val['updated_at']);
55
+ unset($check_val['is_draft']);
56
+ unset($check_val['id']);
57
+ unset($check_val['item_key']);
58
+ if($new_values['item_key'] == $new_values['name'])
59
+ unset($check_val['name']);
60
+
61
+ global $frmdb;
62
+ $entry_exists = $frmdb->get_records($wpdb->prefix .'frm_items', $check_val, 'created_at DESC', '', 'id');
63
+ unset($frmdb);
64
+
65
+ if($entry_exists and !empty($entry_exists)){
66
+ foreach($entry_exists as $entry_exist){
67
+ if($create_entry){
68
+ $create_entry = false;
69
+ //add more checks here to make sure it's a duplicate
70
+ if (isset($values['item_meta'])){
71
+ $metas = $frm_entry_meta->get_entry_meta_info($entry_exist->id);
72
+ $field_metas = array();
73
+ foreach($metas as $meta)
74
+ $field_metas[$meta->field_id] = $meta->meta_value;
75
+
76
+ $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
77
+ foreach($diff as $field_id => $meta_value){
78
+ if(!empty($meta_value) and !$create_entry)
79
+ $create_entry = true;
80
+ }
81
+ }
82
+ }
83
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
+
86
+ if ( !$create_entry ) {
 
 
87
  return false;
88
  }
89
+ }
90
+
91
+ $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
92
+
93
+ if ( $query_results ) {
94
+ $entry_id = $wpdb->insert_id;
95
+
96
+ global $frm_vars;
97
+ if(!isset($frm_vars['saved_entries']))
98
+ $frm_vars['saved_entries'] = array();
99
+ $frm_vars['saved_entries'][] = (int)$entry_id;
100
+
101
+ if ( isset($values['item_meta']) ) {
102
+ $frm_entry_meta->update_entry_metas($entry_id, $values['item_meta']);
103
  }
104
+
105
+ do_action('frm_after_create_entry', $entry_id, $new_values['form_id']);
106
+ do_action('frm_after_create_entry_'. $new_values['form_id'], $entry_id);
107
+ return $entry_id;
108
+ } else {
109
+ return false;
110
  }
 
 
111
  }
112
+
113
+ function duplicate( $id ){
114
+ global $wpdb, $frm_entry, $frm_entry_meta;
115
 
116
+ $values = $frm_entry->getOne( $id );
 
 
 
117
 
118
  $new_values = array();
119
  $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
120
  $new_values['name'] = $values->name;
121
  $new_values['is_draft'] = $values->is_draft;
122
+ $new_values['user_id'] = $new_values['updated_by'] = (int)$values->user_id;
123
+ $new_values['form_id'] = $values->form_id ? (int)$values->form_id: null;
124
  $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
125
 
126
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
127
+ if($query_results){
128
+ $entry_id = $wpdb->insert_id;
129
+
130
+ global $frm_vars;
131
+ if(!isset($frm_vars['saved_entries']))
132
+ $frm_vars['saved_entries'] = array();
133
+ $frm_vars['saved_entries'][] = (int)$entry_id;
134
+
135
+ $frm_entry_meta->duplicate_entry_metas($id, $entry_id);
136
+
137
+ do_action('frm_after_duplicate_entry', $entry_id, $new_values['form_id']);
138
+ return $entry_id;
139
+ }else
140
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
+ function update( $id, $values ){
144
+ global $wpdb, $frm_entry_meta, $frm_field, $frm_vars;
145
+ if(isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array((int)$id, (array)$frm_vars['saved_entries']))
146
  return;
 
 
 
147
 
148
  $user_ID = get_current_user_id();
149
+
150
  $new_values = array(
151
  'name' => isset($values['name']) ? $values['name'] : '',
152
  'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null,
154
  'updated_at' => current_time('mysql', 1),
155
  'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID,
156
  );
157
+
158
  if ( isset($values['post_id']) ) {
159
  $new_values['post_id'] = (int) $values['post_id'];
160
  }
162
  if ( isset($values['item_key']) ) {
163
  $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
164
  }
165
+
166
+ if(isset($values['frm_user_id']) and is_numeric($values['frm_user_id']))
 
 
 
 
167
  $new_values['user_id'] = $values['frm_user_id'];
 
168
 
169
  $new_values = apply_filters('frm_update_entry', $new_values, $id);
170
  $query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
171
+ if($query_results)
 
 
172
  wp_cache_delete( $id, 'frm_entry');
173
+
174
+ if(!isset($frm_vars['saved_entries']))
 
175
  $frm_vars['saved_entries'] = array();
176
+
177
+ $frm_vars['saved_entries'][] = (int)$id;
178
+
179
+ if (isset($values['item_meta']))
180
+ $frm_entry_meta->update_entry_metas($id, $values['item_meta']);
 
 
181
  do_action('frm_after_update_entry', $id, $new_values['form_id']);
182
  do_action('frm_after_update_entry_'. $new_values['form_id'], $id);
183
  return $query_results;
184
  }
185
 
186
+ function &destroy( $id ){
187
  global $wpdb;
188
+ $id = (int)$id;
189
+
190
+ $entry = $this->getOne($id);
191
+ if ( !$entry ) {
192
  $result = false;
193
  return $result;
194
  }
195
+
196
  do_action('frm_before_destroy_entry', $id, $entry);
197
+
 
198
  wp_cache_delete( $id, 'frm_entry');
199
+ $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=' . $id);
200
+ $result = $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=' . $id);
201
  return $result;
202
  }
203
+
204
+ function &update_form( $id, $value, $form_id ){
205
  global $wpdb;
206
+ $form_id = isset($value) ? $form_id : NULL;
207
+ $result = $wpdb->update( $wpdb->prefix .'frm_items', array('form_id' => $form_id), array( 'id' => $id ) );
208
+ if($result)
209
  wp_cache_delete( $id, 'frm_entry');
 
210
  return $result;
211
  }
212
+
213
+ function getOne( $id, $meta=false){
214
  global $wpdb;
215
+
216
+ $entry = wp_cache_get( $id, 'frm_entry' );
217
+ if($entry)
 
 
 
 
 
 
 
218
  return stripslashes_deep($entry);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
+ $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
221
+ LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
222
+
223
+ $query .= $wpdb->prepare( is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s', $id);
224
+
225
+ $entry = $wpdb->get_row($query);
226
+
227
+ if($meta and $entry){
228
+ $metas = $wpdb->get_results($wpdb->prepare("SELECT field_id, meta_value, field_key FROM {$wpdb->prefix}frm_item_metas m LEFT JOIN {$wpdb->prefix}frm_fields f ON m.field_id=f.id WHERE item_id=%d and field_id != %d", $entry->id, 0));
229
+
230
+ $entry_metas = array();
231
+
232
+ foreach($metas as $meta_val){
233
+ $entry_metas[$meta_val->field_id] = $entry_metas[$meta_val->field_key] = maybe_unserialize($meta_val->meta_value);
234
+ unset($meta_val);
235
  }
236
+ unset($metas);
237
 
238
+ $entry->metas = $entry_metas;
239
 
240
+ wp_cache_set( $entry->id, $entry, 'frm_entry');
241
  }
 
242
 
243
+ return stripslashes_deep($entry);
 
 
244
  }
245
+
246
+ function &exists( $id ){
 
 
 
247
  global $wpdb;
248
+
249
+ if(wp_cache_get( $id, 'frm_entry' )){
250
  $exists = true;
251
  return $exists;
252
  }
253
+
254
+ $where = (is_numeric($id)) ? 'id=%d' : 'item_key=%s';
255
 
256
+ $id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE $where", $id));
257
+
 
 
 
 
 
258
  $exists = ($id && $id > 0) ? true : false;
259
  return $exists;
260
  }
261
 
262
+ function getAll($where = '', $order_by = '', $limit = '', $meta=false, $inc_form=true){
263
  global $wpdb;
264
+
265
+ if(is_numeric($limit))
266
+ $limit = " LIMIT {$limit}";
267
+
268
+ if($inc_form){
269
+ $query = "SELECT it.*, fr.name as form_name,fr.form_key as form_key
270
+ FROM {$wpdb->prefix}frm_items it LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id" .
271
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
272
+ }else{
273
+ $query = "SELECT it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.updated_by,
274
+ it.created_at, it.updated_at, it.is_draft FROM {$wpdb->prefix}frm_items it" .
275
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
276
+ }
277
+
278
+ if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
279
+ // sort by a requested field
280
+ $query = str_replace( " FROM {$wpdb->prefix}frm_items ", ", (SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id = {$order_matches[1]} AND item_id = it.id) as meta_{$order_matches[1]} FROM {$wpdb->prefix}frm_items ", $query );
281
+ }
282
+
283
+ $entries = $wpdb->get_results($query, OBJECT_K);
284
+ unset($query);
285
+
286
+ if($meta and $entries){
287
+ if($limit == '' and !is_array($where) and preg_match('/^it\.form_id=\d+$/', $where)){
288
+ $meta_where = $wpdb->prepare('fi.form_id=%d', substr($where, 11));
289
+ }else if($limit == '' and is_array($where) and count($where) == 1 and isset($where['it.form_id'])){
290
+ $meta_where = $wpdb->prepare('fi.form_id=%d', $where['it.form_id']);
291
+ }else{
292
+ $meta_where = "item_id in (". implode(',', array_filter(array_keys($entries), 'is_numeric')) .")";
293
  }
294
+ $query = "SELECT item_id, meta_value, field_id, field_key FROM {$wpdb->prefix}frm_item_metas it
295
+ LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id
296
+ WHERE $meta_where and field_id != 0";
297
+
298
+ $metas = $wpdb->get_results($query);
 
 
 
 
 
 
 
299
  unset($query);
300
+
301
+ if($metas){
302
+ foreach($metas as $m_key => $meta_val){
303
+ if(!isset($entries[$meta_val->item_id]))
304
+ continue;
305
+
306
+ if(!isset($entries[$meta_val->item_id]->metas))
307
+ $entries[$meta_val->item_id]->metas = array();
308
+
309
+ $entries[$meta_val->item_id]->metas[$meta_val->field_id] = $entries[$meta_val->item_id]->metas[$meta_val->field_key] = maybe_unserialize($meta_val->meta_value);
310
+ }
311
+
312
+ foreach($entries as $entry){
313
+ wp_cache_set( $entry->id, $entry, 'frm_entry');
314
+ unset($entry);
315
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  }
 
 
 
 
317
  }
318
+
 
 
 
 
 
319
  return stripslashes_deep($entries);
320
  }
321
 
322
  // Pagination Methods
323
+ function getRecordCount($where=''){
324
  global $wpdb;
325
+ if(is_numeric($where)){
326
+ $query = "SELECT COUNT(*) FROM {$wpdb->prefix}frm_items WHERE form_id=". $where;
327
+ }else{
328
+ $query = "SELECT COUNT(*) FROM {$wpdb->prefix}frm_items it LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id" .
329
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
330
  }
331
+ return $wpdb->get_var($query);
 
 
 
 
 
 
 
 
 
 
332
  }
333
 
334
+ function getPageCount($p_size, $where=''){
335
+ if(is_numeric($where))
336
+ return ceil((int)$where / (int)$p_size);
337
+ else
338
+ return ceil((int)$this->getRecordCount($where) / (int)$p_size);
 
339
  }
340
 
341
+ function validate( $values, $exclude=false ){
342
+ global $wpdb, $frm_field, $frm_entry_meta, $frm_settings;
343
+
 
344
  $errors = array();
345
+
346
  if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
347
+ $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable');
348
  return $errors;
349
  }
350
+
351
+ if ( is_admin() && is_user_logged_in() && ( ! isset($values['frm_submit_entry_'. $values['form_id']]) || ! wp_verify_nonce($values['frm_submit_entry_'. $values['form_id']], 'frm_submit_entry_nonce') ) ) {
352
+ $errors['form'] = __('You do not have permission to do that', 'formidable');
353
  }
354
+
355
+ if( !isset($values['item_key']) or $values['item_key'] == '' ){
356
  $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
357
  }
358
+
359
+ $where = apply_filters('frm_posted_field_ids', 'fi.form_id='. (int)$values['form_id']);
360
+ if($exclude)
361
+ $where .= " and fi.type not in ('". implode("','", array_filter($exclude, 'esc_sql')) ."')";
362
+
363
+ $posted_fields = $frm_field->getAll($where, 'field_order');
364
+
365
+ foreach($posted_fields as $posted_field){
366
+ $posted_field->field_options = maybe_unserialize($posted_field->field_options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  $value = '';
368
+ if (isset($values['item_meta'][$posted_field->id]))
369
+ $value = $values['item_meta'][$posted_field->id];
370
+
371
+ if (isset($posted_field->field_options['default_blank']) and $posted_field->field_options['default_blank'] and $value == $posted_field->default_value)
372
+ $value = '';
373
+
374
+ if(is_array($value) and count($value) === 1)
375
+ $value = reset($value);
376
+
377
+ if($posted_field->type == 'rte' and !is_array($value) and (trim($value) == '<br>'))
378
+ $value = '';
379
+
380
+ if ($posted_field->required == '1' and !is_array($value) and trim($value) == ''){
381
+ $errors['field'. $posted_field->id] = (!isset($posted_field->field_options['blank']) or $posted_field->field_options['blank'] == '' or $posted_field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
382
+ }else if ($posted_field->type == 'text' and !isset($_POST['name'])){
383
+ $_POST['name'] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  }
385
+
386
+ $_POST['item_meta'][$posted_field->id] = $value;
387
+
388
+ if ($posted_field->type == 'captcha' and isset($_POST['recaptcha_challenge_field'])){
389
+ global $frm_settings;
390
+
391
+ if(!function_exists('recaptcha_check_answer'))
392
+ require(FrmAppHelper::plugin_path().'/classes/recaptchalib.php');
393
+
394
+ $response = recaptcha_check_answer($frm_settings->privkey,
395
+ $_SERVER['REMOTE_ADDR'],
396
+ $_POST['recaptcha_challenge_field'],
397
+ $_POST['recaptcha_response_field']);
398
+
399
+ if (!$response->is_valid) {
400
+ // What happens when the CAPTCHA was entered incorrectly
401
+ $errors['captcha-'. $response->error] = $errors['field'. $posted_field->id] = (!isset($posted_field->field_options['invalid']) or $posted_field->field_options['invalid'] == '') ? $frm_settings->re_msg : $posted_field->field_options['invalid'];
402
+ }
403
 
404
+ }
405
+
406
+ $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value);
407
+
 
 
 
 
 
 
408
  }
409
+
410
+
411
+ // check for spam
412
+ if ( empty($exclude) && isset($values['item_meta']) && !empty($values['item_meta']) && empty($errors) ) {
413
+ global $wpcom_api_key;
414
+ if ( (function_exists( 'akismet_http_post' ) || is_callable('Akismet::http_post')) && ((get_option('wordpress_api_key') || $wpcom_api_key)) && $this->akismet($values) ) {
415
+ $frm_form = new FrmForm();
416
+ $form = $frm_form->getOne($values['form_id']);
417
+
418
+ if ( isset($form->options['akismet']) && !empty($form->options['akismet']) && ($form->options['akismet'] != 'logged' || !is_user_logged_in()) ) {
419
+ $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
420
+ }
421
+ }
422
+
423
+ // check for blacklist keys
424
+ if ( $this->blacklist_check($values) ) {
425
+ $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
426
+ }
427
  }
 
428
 
429
+
430
+ $errors = apply_filters('frm_validate_entry', $errors, $values);
431
+ return $errors;
432
+ }
433
+
434
  // check the blacklisted words
435
+ function blacklist_check( $values ) {
436
  if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
437
  return false;
438
  }
439
+
440
  $mod_keys = trim( get_option( 'blacklist_keys' ) );
441
 
442
  if ( empty( $mod_keys ) ) {
443
  return false;
444
  }
445
+
446
  $content = FrmEntriesHelper::entry_array_to_string($values);
447
+
448
  if ( empty($content) ) {
449
  return false;
450
  }
465
 
466
  return false;
467
  }
468
+
469
+ //Check entries for spam -- returns true if is spam
470
+ function akismet($values) {
 
 
 
 
471
  $content = FrmEntriesHelper::entry_array_to_string($values);
472
+
473
  if ( empty($content) ) {
474
  return false;
475
  }
476
+
477
  $datas = array();
478
+ $datas['blog'] = FrmAppHelper::site_url();
479
+ $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
480
+ $datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
481
+ $datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
482
+ $datas['comment_type'] = 'formidable';
483
+ if ( $permalink = get_permalink() )
484
+ $datas['permalink'] = $permalink;
485
+
486
+ $datas['comment_content'] = $content;
487
+
488
+ foreach ( $_SERVER as $key => $value ) {
489
+ if ( !in_array($key, array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value) ) {
490
+ $datas["$key"] = $value;
491
+ } else {
492
+ $datas["$key"] = '';
493
+ }
494
+
495
+ unset($key, $value);
496
+ }
497
 
498
  $query_string = '';
499
  foreach ( $datas as $key => $data ) {
507
  global $akismet_api_host, $akismet_api_port;
508
  $response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
509
  }
510
+
511
+ return ( is_array($response) and $response[1] == 'true' ) ? true : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  }
513
+
514
  }
classes/models/FrmEntryMeta.php CHANGED
@@ -1,348 +1,275 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
5
 
6
- class FrmEntryMeta {
 
7
 
8
- /**
9
- * @param string $meta_key
10
- */
11
- public static function add_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
12
- global $wpdb;
13
 
14
- if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
 
 
 
15
  // don't save blank fields
16
  return;
17
  }
18
-
19
  $new_values = array(
20
  'meta_value' => is_array($meta_value) ? serialize(array_filter($meta_value)) : trim($meta_value),
21
  'item_id' => $entry_id,
22
  'field_id' => $field_id,
23
  'created_at' => current_time('mysql', 1),
24
  );
25
-
26
  $new_values = apply_filters('frm_add_entry_meta', $new_values);
27
 
28
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values );
29
-
30
  $id = $query_results ? $wpdb->insert_id : 0;
31
-
32
  return $id;
33
  }
34
 
35
- /**
36
- * @param string $meta_key
37
- */
38
- public static function update_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
39
  if ( ! $field_id ) {
40
  return false;
41
  }
42
-
43
  global $wpdb;
44
-
45
  $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
46
  $values['meta_value'] = $meta_value;
47
  $values = apply_filters('frm_update_entry_meta', $values);
48
- if ( is_array($values['meta_value']) ) {
49
- $values['meta_value'] = array_filter($values['meta_value']);
50
  }
51
  $meta_value = maybe_serialize($values['meta_value']);
52
-
53
- wp_cache_delete( $entry_id, 'frm_entry');
54
-
55
  return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
56
  }
57
-
58
- public static function update_entry_metas($entry_id, $values) {
59
- global $wpdb;
60
-
61
- $prev_values = FrmDb::get_col( $wpdb->prefix .'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0), 'field_id' );
62
-
63
  foreach ( $values as $field_id => $meta_value ) {
64
- // set the value for the file upload field and add new tags (in Pro version)
65
- $values = apply_filters( 'frm_prepare_data_before_db', $values, $field_id, $entry_id );
66
-
67
  if ( $prev_values && in_array($field_id, $prev_values) ) {
68
- if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
69
  // remove blank fields
70
  unset($values[$field_id]);
71
  } else {
72
  // if value exists, then update it
73
- self::update_entry_meta($entry_id, $field_id, '', $values[$field_id]);
74
  }
75
  } else {
76
  // if value does not exist, then create it
77
- self::add_entry_meta($entry_id, $field_id, '', $values[$field_id]);
78
  }
 
79
  }
80
-
81
  if ( empty($prev_values) ) {
82
  return;
83
  }
84
-
85
  $prev_values = array_diff($prev_values, array_keys($values));
86
-
87
  if ( empty($prev_values) ) {
88
  return;
89
  }
90
-
91
- // prepare the query
92
- $where = array( 'item_id' => $entry_id, 'field_id' => $prev_values );
93
- FrmDb::get_where_clause_and_values( $where );
94
-
95
  // Delete any leftovers
96
- $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
97
  }
98
-
99
- public static function duplicate_entry_metas($old_id, $new_id) {
100
- $metas = self::get_entry_meta_info($old_id);
101
  foreach ( $metas as $meta ) {
102
- self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
103
  unset($meta);
104
  }
105
  }
106
 
107
- public static function delete_entry_meta($entry_id, $field_id) {
108
  global $wpdb;
109
  return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
110
  }
111
-
112
- public static function get_entry_meta_by_field($entry_id, $field_id) {
 
 
 
 
113
  global $wpdb;
114
-
115
- $entry_id = (int) $entry_id;
116
-
117
- $cached = FrmAppHelper::check_cache( $entry_id, 'frm_entry' );
118
- if ( $cached && isset($cached->metas) && isset($cached->metas[$field_id]) ) {
119
  $result = $cached->metas[$field_id];
120
  return stripslashes_deep($result);
121
  }
122
-
123
- $get_table = $wpdb->prefix .'frm_item_metas';
124
- $query = array( 'item_id' => $entry_id );
125
- if ( is_numeric($field_id) ) {
126
- $query['field_id'] = $field_id;
127
- } else {
128
- $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
129
- $query['fi.field_key'] = $field_id;
130
- }
131
-
132
- $result = FrmDb::get_var( $get_table, $query, 'meta_value' );
133
- $result = maybe_unserialize($result);
134
-
135
- if ( $cached ) {
136
- if ( ! isset( $cached->metas ) ) {
137
- $cached->metas = array();
138
  }
139
- $cached->metas[$field_id] = $result;
140
- wp_cache_set($entry_id, $cached, 'frm_entry');
 
141
  }
142
- $result = stripslashes_deep($result);
143
-
144
  return $result;
145
  }
146
-
147
- public static function get_entry_metas($entry_id) {
148
- _deprecated_function( __FUNCTION__, '1.07.10');
149
-
150
  global $wpdb;
151
- return FrmDb::get_col( $wpdb->prefix .'frm_item_metas', array( 'item_id' => $entry_id), 'meta_value' );
152
- }
153
-
154
- public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
155
- $defaults = array( 'value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false);
156
- $args = wp_parse_args( $args, $defaults );
157
-
158
- $query = array();
159
- self::meta_field_query($field_id, $order, $limit, $args, $query);
160
- $query = implode(' ', $query);
161
-
162
- $cache_key = 'entry_metas_for_field_'. $field_id . $order . $limit . maybe_serialize($args);
163
- $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
164
-
165
- if ( ! $args['stripslashes'] ) {
166
- return $values;
167
  }
168
-
169
- foreach ( $values as $k => $v ) {
170
- $values[$k] = maybe_unserialize($v);
171
- unset($k, $v);
 
 
 
 
 
172
  }
173
-
174
- return stripslashes_deep($values);
175
  }
176
 
177
- /**
178
- * @param string $order
179
- * @param string $limit
180
- */
181
- private static function meta_field_query($field_id, $order, $limit, $args, array &$query) {
182
  global $wpdb;
183
- $query[] = 'SELECT';
184
- $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
185
- $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas em ';
186
-
187
- if ( ! $args['is_draft'] ) {
188
- $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=em.item_id)';
189
- }
190
-
191
- if ( is_numeric($field_id) ) {
192
- $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
193
- } else {
194
- $query[] = $wpdb->prepare('LEFT JOIN '. $wpdb->prefix .'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id);
195
- }
196
-
197
- if ( ! $args['is_draft'] ) {
198
- $query[] = 'AND e.is_draft=0';
199
- }
200
-
201
- if ( $args['value'] ) {
202
- $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
203
- }
204
- $query[] = $order . $limit;
205
  }
206
-
207
- public static function get_entry_meta_info($entry_id) {
208
- return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id) );
209
- }
210
-
211
- public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
212
  global $wpdb;
213
- $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
214
- fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
215
- FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id' .
216
- FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
217
-
218
- $cache_key = 'all_'. maybe_serialize($where) . $order_by . $limit;
219
- $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
220
-
221
- if ( ! $results || ! $stripslashes ) {
222
- return $results;
223
- }
224
-
225
- foreach ( $results as $k => $result ) {
226
- $results[$k]->meta_value = stripslashes_deep(maybe_unserialize($result->meta_value));
227
- unset($k, $result);
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
 
230
- return $results;
231
  }
232
-
233
- public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
234
- $defaults = array(
235
- 'is_draft' => false, 'user_id' => '',
236
- 'group_by' => '',
237
- );
238
- $args = wp_parse_args($args, $defaults);
239
-
240
- $query = array();
241
- self::get_ids_query($where, $order_by, $limit, $unique, $args, $query);
242
- $query = implode(' ', $query);
243
-
244
- $cache_key = 'ids_'. maybe_serialize($where) . $order_by . 'l'. $limit . 'u'. $unique . maybe_serialize($args);
245
- $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
246
-
247
- return $results;
248
  }
249
-
250
- /**
251
- * @param string $where
252
- * @param string $order_by
253
- * @param string $limit
254
- * @param boolean $unique
255
- */
256
- private static function get_ids_query($where, $order_by, $limit, $unique, $args, array &$query) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  global $wpdb;
258
- $query[] = 'SELECT';
259
- $query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id';
260
- $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id';
261
-
262
- $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=it.item_id)';
263
- if ( is_array($where) ) {
264
- if ( ! $args['is_draft'] ) {
265
  $where['e.is_draft'] = 0;
266
- } else if ( $args['is_draft'] == 1 ) {
267
- $where['e.is_draft'] = 1;
268
- }
269
-
270
- if ( ! empty($args['user_id']) ) {
271
- $where['e.user_id'] = $args['user_id'];
 
 
 
 
272
  }
273
- $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
274
-
275
- if ( $args['group_by'] ) {
276
- $query[] = ' GROUP BY '. sanitize_text_field( $args['group_by'] );
277
- }
278
- return;
279
  }
280
 
281
- $draft_where = $user_where = '';
282
- if ( ! $args['is_draft'] ) {
283
- $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
284
- } else if ( $args['is_draft'] == 1 ) {
285
- $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
286
- }
287
-
288
- if ( ! empty($args['user_id']) ) {
289
- $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
290
- }
291
 
292
- if ( strpos($where, ' GROUP BY ') ) {
293
- // don't inject WHERE filtering after GROUP BY
294
- $parts = explode(' GROUP BY ', $where);
295
- $where = $parts[0];
296
- $where .= $draft_where . $user_where;
297
- $where .= ' GROUP BY '. $parts[1];
298
- } else {
299
- $where .= $draft_where . $user_where;
300
- }
301
-
302
- // The query has already been prepared
303
- $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
304
  }
305
-
306
- public static function search_entry_metas( $search, $field_id = '', $operator ) {
307
- $cache_key = 'search_'. maybe_serialize($search) . $field_id . $operator;
308
- $results = wp_cache_get($cache_key, 'frm_entry');
309
- if ( false !== $results ) {
310
- return $results;
311
- }
312
-
313
  global $wpdb;
314
- if (is_array($search)) {
315
  $where = '';
316
- foreach ( $search as $field => $value ) {
317
- if ( $value <= 0 || ! in_array($field, array( 'year', 'month', 'day')) ) {
318
- continue;
319
- }
320
-
321
- switch ( $field ) {
322
- case 'year':
323
- $value = '%'. $value;
324
- break;
325
- case 'month':
326
- $value .= '%';
327
- break;
328
- case 'day':
329
- $value = '%'. $value .'%';
330
- }
331
- $where .= $wpdb->prepare(' meta_value '. $operator .' %s and', $value);
332
  }
333
- $where .= $wpdb->prepare(' field_id=%d', $field_id);
334
  $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
335
- } else {
336
- if ( $operator == 'LIKE' ) {
337
- $search = '%' . $search . '%';
338
- }
339
  $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
340
  }
341
-
342
- $results = $wpdb->get_col($query, 0);
343
- wp_cache_set($cache_key, $results, 'frm_entry', 300);
344
-
345
- return $results;
346
  }
347
 
348
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
 
 
3
 
4
+ if(class_exists('FrmEntryMeta'))
5
+ return;
6
 
7
+ class FrmEntryMeta{
 
 
 
 
8
 
9
+ function add_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
10
+ global $wpdb;
11
+
12
+ if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
13
  // don't save blank fields
14
  return;
15
  }
16
+
17
  $new_values = array(
18
  'meta_value' => is_array($meta_value) ? serialize(array_filter($meta_value)) : trim($meta_value),
19
  'item_id' => $entry_id,
20
  'field_id' => $field_id,
21
  'created_at' => current_time('mysql', 1),
22
  );
23
+
24
  $new_values = apply_filters('frm_add_entry_meta', $new_values);
25
 
26
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values );
27
+
28
  $id = $query_results ? $wpdb->insert_id : 0;
29
+
30
  return $id;
31
  }
32
 
33
+ function update_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value){
 
 
 
34
  if ( ! $field_id ) {
35
  return false;
36
  }
37
+
38
  global $wpdb;
39
+
40
  $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
41
  $values['meta_value'] = $meta_value;
42
  $values = apply_filters('frm_update_entry_meta', $values);
43
+ if ( is_array($meta_value) ) {
44
+ $meta_value = array_filter($meta_value);
45
  }
46
  $meta_value = maybe_serialize($values['meta_value']);
47
+
 
 
48
  return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
49
  }
50
+
51
+ function update_entry_metas($entry_id, $values){
52
+ global $frm_field, $wpdb;
53
+
54
+ $prev_values = $wpdb->get_col($wpdb->prepare("SELECT field_id FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d AND field_id != %d", $entry_id, 0));
55
+
56
  foreach ( $values as $field_id => $meta_value ) {
57
+
 
 
58
  if ( $prev_values && in_array($field_id, $prev_values) ) {
59
+ if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
60
  // remove blank fields
61
  unset($values[$field_id]);
62
  } else {
63
  // if value exists, then update it
64
+ $this->update_entry_meta($entry_id, $field_id, '', $values[$field_id]);
65
  }
66
  } else {
67
  // if value does not exist, then create it
68
+ $this->add_entry_meta($entry_id, $field_id, '', $values[$field_id]);
69
  }
70
+
71
  }
72
+
73
  if ( empty($prev_values) ) {
74
  return;
75
  }
76
+
77
  $prev_values = array_diff($prev_values, array_keys($values));
78
+
79
  if ( empty($prev_values) ) {
80
  return;
81
  }
82
+
 
 
 
 
83
  // Delete any leftovers
84
+ $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d AND field_id in", $entry_id) ." (". implode(',', $prev_values) .")");
85
  }
86
+
87
+ function duplicate_entry_metas($old_id, $new_id){
88
+ $metas = $this->get_entry_meta_info($old_id);
89
  foreach ( $metas as $meta ) {
90
+ $this->add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
91
  unset($meta);
92
  }
93
  }
94
 
95
+ function delete_entry_meta($entry_id, $field_id){
96
  global $wpdb;
97
  return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
98
  }
99
+
100
+ function delete_entry_metas($entry_id, $where=''){
101
+ _deprecated_function( __FUNCTION__, '1.07.05', '$frm_entry_meta->delete_entry_meta()' );
102
+ }
103
+
104
+ function get_entry_meta_by_field($entry_id, $field_id, $return_var=true){
105
  global $wpdb;
106
+
107
+ $entry_id = (int)$entry_id;
108
+
109
+ $cached = wp_cache_get( $entry_id, 'frm_entry' );
110
+ if($cached and isset($cached->metas) and isset($cached->metas[$field_id])){
111
  $result = $cached->metas[$field_id];
112
  return stripslashes_deep($result);
113
  }
114
+
115
+ if (is_numeric($field_id))
116
+ $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d and item_id=%d", $field_id, $entry_id);
117
+ else
118
+ $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id WHERE fi.field_key=%s and item_id=%d", $field_id, $entry_id);
119
+
120
+ if($return_var){
121
+ $result = maybe_unserialize($wpdb->get_var("{$query} LIMIT 1"));
122
+ if($cached){
123
+ if(!isset($cached->metas))
124
+ $cached->metas = array();
125
+ $cached->metas[$field_id] = $result;
126
+ wp_cache_set($entry_id, $cached, 'frm_entry');
 
 
 
127
  }
128
+ $result = stripslashes_deep($result);
129
+ }else{
130
+ $result = $wpdb->get_col($query, 0);
131
  }
132
+
 
133
  return $result;
134
  }
135
+
136
+ function get_entry_meta($entry_id, $field_id, $return_var=true){
 
 
137
  global $wpdb;
138
+
139
+ $entry = wp_cache_get($entry_id, 'frm_entry');
140
+ if($return_var and $entry and isset($entry->metas) and isset($entry->metas[$field_id])){
141
+ $var = $entry->metas[$field_id];
142
+ return stripslashes_deep($var);
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
+
145
+ $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d and item_id=%d", $field_id, $entry_id);
146
+
147
+ if($return_var){
148
+ $var = $wpdb->get_var("{$query} LIMIT 1");
149
+ if($var)
150
+ $var = stripslashes_deep(maybe_unserialize($var));
151
+ }else{
152
+ $var = $wpdb->get_col($query, 0);
153
  }
154
+ return $var;
 
155
  }
156
 
157
+ function get_entry_metas($entry_id){
 
 
 
 
158
  global $wpdb;
159
+ return $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  }
161
+
162
+ function get_entry_metas_for_field($field_id, $order='', $limit='', $args=array()){
 
 
 
 
163
  global $wpdb;
164
+
165
+ $defaults = array('value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false);
166
+ extract(wp_parse_args( $args, $defaults ));
167
+
168
+ $query = "SELECT ";
169
+ $query .= ($unique) ? "DISTINCT(em.meta_value)" : "em.meta_value";
170
+ $query .= " FROM {$wpdb->prefix}frm_item_metas em ";
171
+
172
+ if(!$is_draft)
173
+ $query .= " INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=em.item_id) ";
174
+ $query .= (is_numeric($field_id)) ? "WHERE em.field_id='{$field_id}'" : "LEFT JOIN {$wpdb->prefix}frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key='{$field_id}'";
175
+
176
+ if(!$is_draft)
177
+ $query .= " AND e.is_draft=0";
178
+
179
+ if($value)
180
+ $query .= " AND meta_value='$value'";
181
+ $query .= "{$order}{$limit}";
182
+
183
+ $values = $wpdb->get_col($query);
184
+ if($stripslashes){
185
+ foreach($values as $k => $v){
186
+ $values[$k] = maybe_unserialize($v);
187
+ unset($k);
188
+ unset($v);
189
+ }
190
+ $values = stripslashes_deep($values);
191
  }
192
 
193
+ return $values;
194
  }
195
+
196
+ function get_entry_meta_info($entry_id){
197
+ global $wpdb;
198
+ return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
 
 
 
 
 
 
 
 
 
 
 
 
199
  }
200
+
201
+ function getAll($where = '', $order_by = '', $limit = '', $stripslashes = false){
202
+ global $wpdb, $frm_field;
203
+ $query = "SELECT it.*, fi.type as field_type, fi.field_key as field_key,
204
+ fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
205
+ FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id" .
206
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
207
+
208
+ $results = ($limit == ' LIMIT 1') ? $wpdb->get_row($query) : $wpdb->get_results($query);
209
+
210
+ if($results and $stripslashes){
211
+ foreach($results as $k => $result){
212
+ $results[$k]->meta_value = stripslashes_deep(maybe_unserialize($result->meta_value));
213
+ unset($k);
214
+ unset($result);
215
+ }
216
+ }
217
+
218
+ return $results;
219
+ }
220
+
221
+ function getEntryIds($where = '', $order_by = '', $limit = '', $unique=true, $drafts=false){
222
  global $wpdb;
223
+ $query = "SELECT ";
224
+ $query .= ($unique) ? "DISTINCT(it.item_id)" : "it.item_id";
225
+ $query .= " FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id ";
226
+
227
+ if ( !$drafts ) {
228
+ $query .= "INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=it.item_id) ";
229
+ if ( is_array($where) ) {
230
  $where['e.is_draft'] = 0;
231
+ } else {
232
+ if ( strpos($where, ' GROUP BY ') ) {
233
+ // don't inject WHERE filtering after GROUP BY
234
+ $parts = explode(' GROUP BY ', $where);
235
+ $where = $parts[0];
236
+ $where .= ' AND e.is_draft=0';
237
+ $where .= ' GROUP BY '. $parts[1];
238
+ } else {
239
+ $where .= ' AND e.is_draft=0';
240
+ }
241
  }
 
 
 
 
 
 
242
  }
243
 
244
+ $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
245
+ if ($limit == ' LIMIT 1')
246
+ $results = $wpdb->get_var($query);
247
+ else
248
+ $results = $wpdb->get_col($query);
 
 
 
 
 
249
 
250
+ return $results;
 
 
 
 
 
 
 
 
 
 
 
251
  }
252
+
253
+ function search_entry_metas($search, $field_id='', $operator){
 
 
 
 
 
 
254
  global $wpdb;
255
+ if (is_array($search)){
256
  $where = '';
257
+ foreach ($search as $field => $value){
258
+ if ($field == 'year' and $value > 0)
259
+ $where .= " meta_value {$operator} '%{$value}' and";
260
+ if ($field == 'month' and $value > 0)
261
+ $where .= " meta_value {$operator} '{$value}%' and";
262
+ if ($field == 'day' and $value > 0)
263
+ $where .= " meta_value {$operator} '%/{$value}/%' and";
 
 
 
 
 
 
 
 
 
264
  }
265
+ $where .= " field_id='{$field_id}'";
266
  $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
267
+ }else{
268
+ if ($operator == 'LIKE')
269
+ $search = "%{$search}%";
 
270
  $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
271
  }
272
+ return $wpdb->get_col($query, 0);
 
 
 
 
273
  }
274
 
275
  }
classes/models/FrmField.php CHANGED
@@ -1,441 +1,257 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die( 'You are not allowed to call this page directly.' );
4
- }
 
5
 
6
  class FrmField{
7
- static $use_cache = true;
8
 
9
- public static function create( $values, $return = true ) {
10
- global $wpdb, $frm_duplicate_ids;
11
 
12
  $new_values = array();
13
  $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
14
  $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
15
 
16
- foreach ( array( 'name', 'description', 'type', 'default_value') as $col ) {
17
  $new_values[$col] = $values[$col];
18
  }
19
-
20
  $new_values['options'] = $values['options'];
21
 
22
- $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
23
- $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
24
- $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
25
  $new_values['field_options'] = $values['field_options'];
26
  $new_values['created_at'] = current_time('mysql', 1);
27
-
28
- if ( isset( $values['id'] ) ) {
29
  $frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
30
  $new_values = apply_filters('frm_duplicated_field', $new_values);
31
  }
32
-
33
- foreach ( $new_values as $k => $v ) {
34
- if ( is_array( $v ) ) {
35
- $new_values[ $k ] = serialize( $v );
36
- }
37
- unset( $k, $v );
38
  }
39
-
40
  //if(isset($values['id']) and is_numeric($values['id']))
41
  // $new_values['id'] = $values['id'];
42
-
43
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
44
- if ( $query_results ) {
45
- self::delete_form_transient( $new_values['form_id'] );
46
- $new_id = $wpdb->insert_id;
47
- }
48
-
49
- if ( ! $return ) {
50
- return;
51
- }
52
-
53
- if ( $query_results ) {
54
- if ( isset( $values['id'] ) ) {
55
- $frm_duplicate_ids[ $values['id'] ] = $new_id;
56
- }
57
- return $new_id;
58
- } else {
59
- return false;
60
- }
61
  }
62
 
63
- public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
64
- global $frm_duplicate_ids;
65
- $fields = self::getAll( array( 'fi.form_id' => $old_form_id), 'field_order', '', $blog_id);
66
- foreach ( (array) $fields as $field ) {
 
67
  $new_key = ($copy_keys) ? $field->field_key : '';
68
- if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
69
  $new_key = rtrim($new_key, 2);
70
- }
71
-
72
- $values = array();
73
- FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
74
-
75
- // If this is a repeating section, create new form
76
- if ( $field->type == 'divider' && isset( $field->field_options['repeat'] ) && $field->field_options['repeat'] ) {
77
- // create the repeatable form
78
- $repeat_form_values = FrmFormsHelper::setup_new_vars( array( 'parent_form_id' => $form_id ) );
79
- $new_repeat_form_id = FrmForm::create( $repeat_form_values );
80
-
81
- // Save old form_select
82
- $old_repeat_form_id = $field->field_options['form_select'];
83
-
84
- // Update form_select for repeating field
85
- $values['field_options']['form_select'] = $new_repeat_form_id;
86
- }
87
-
88
- // If this is a field inside of a repeating section, associate it with the correct form
89
- if ( $field->form_id != $old_form_id && isset( $old_repeat_form_id ) && isset( $new_repeat_form_id ) && $field->form_id == $old_repeat_form_id ) {
90
- $values['form_id'] = $new_repeat_form_id;
91
- }
92
-
93
  $values = apply_filters('frm_duplicated_field', $values);
94
- $new_id = self::create($values);
95
- $frm_duplicate_ids[ $field->id ] = $new_id;
96
- $frm_duplicate_ids[ $field->field_key ] = $new_id;
97
  unset($field);
98
  }
99
  }
100
 
101
- public static function update( $id, $values ){
102
  global $wpdb;
103
-
104
- $id = absint( $id );
105
-
106
- if ( isset( $values['field_key'] ) ) {
107
  $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
108
- }
109
 
110
  if ( isset($values['required']) ) {
111
  $values['required'] = (int) $values['required'];
112
  }
113
-
114
- // serialize array values
115
- foreach ( array( 'default_value', 'field_options', 'options') as $opt ) {
116
- if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
117
- $values[ $opt ] = serialize( $values[ $opt ] );
118
- }
119
- }
120
-
 
 
121
  $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
122
-
123
- $form_id = 0;
124
- if ( isset( $values['form_id'] ) ) {
125
- $form_id = absint( $values['form_id'] );
126
- } else {
127
- $field = self::getOne($id);
128
- if ( $field ) {
129
  $form_id = $field->form_id;
130
- }
131
  unset($field);
132
  }
133
  unset($values);
134
-
135
- if ( $query_results ) {
136
  wp_cache_delete( $id, 'frm_field' );
137
- if ( $form_id ) {
138
- self::delete_form_transient($form_id);
139
- }
140
  }
141
-
142
  return $query_results;
143
  }
144
 
145
- public static function destroy( $id ) {
146
- global $wpdb;
147
-
148
- do_action( 'frm_before_destroy_field', $id );
149
-
150
- wp_cache_delete( $id, 'frm_field' );
151
- $field = self::getOne( $id );
152
- if ( ! $field ) {
153
- return false;
154
- }
155
-
156
- self::delete_form_transient( $field->form_id );
157
-
158
- $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
159
- return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
160
- }
161
-
162
- public static function delete_form_transient($form_id) {
163
- $form_id = absint( $form_id );
164
- delete_transient('frm_all_form_fields_'. $form_id .'exclude');
165
- delete_transient('frm_all_form_fields_'. $form_id .'include');
166
-
167
- $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb';
168
- wp_cache_delete($cache_key, 'frm_field');
169
-
170
- // this cache key is autogenerated in FrmDb::get_var
171
- wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' );
172
-
173
- $form = FrmForm::getOne($form_id);
174
- if ( $form && $form->parent_form_id ) {
175
- self::delete_form_transient( $form->parent_form_id );
176
- }
177
  }
178
 
179
- public static function getOne( $id ){
180
- if ( empty( $id ) ) {
181
- return;
182
- }
183
-
184
  global $wpdb;
185
-
186
- $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
187
- $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
188
-
189
- $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
190
-
191
- if ( empty($results) ) {
192
- return $results;
193
- }
194
-
195
- if ( is_numeric($id) ) {
196
- wp_cache_set( $results->field_key, $results, 'frm_field' );
197
- } else if ( $results ) {
198
- wp_cache_set( $results->id, $results, 'frm_field' );
199
- }
200
-
201
- self::prepare_options( $results );
202
-
203
- return stripslashes_deep($results);
204
- }
205
-
206
- /**
207
- * Get the field type by key or id
208
- * @param int|string The field id or key
209
- */
210
- public static function &get_type( $id ) {
211
- $field = FrmAppHelper::check_cache( $id, 'frm_field' );
212
- if ( $field ) {
213
- $type = $field->type;
214
- } else {
215
- $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), 'type' );
216
- }
217
-
218
- return $type;
219
- }
220
-
221
- public static function get_all_types_in_form($form_id, $type, $limit = '', $inc_sub = 'exclude') {
222
- if ( ! $form_id ) {
223
- return array();
224
- }
225
-
226
- $results = get_transient('frm_all_form_fields_'. $form_id . $inc_sub);
227
- if ( $results !== false ) {
228
- $fields = array();
229
- $count = 0;
230
- foreach ( $results as $result ) {
231
- if ( $type != $result->type ) {
232
- continue;
233
- }
234
-
235
- $fields[$result->id] = $result;
236
- $count++;
237
- if ( $limit == 1 ) {
238
- $fields = $result;
239
- break;
240
- }
241
-
242
- if ( ! empty($limit) && $count >= $limit ) {
243
- break;
244
- }
245
-
246
- unset($result);
247
- }
248
- return stripslashes_deep($fields);
249
- }
250
-
251
- self::$use_cache = false;
252
- $results = self::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type), 'field_order', $limit);
253
- self::$use_cache = true;
254
- self::include_sub_fields($results, $inc_sub, $type);
255
-
256
- return $results;
257
- }
258
-
259
- public static function get_all_for_form( $form_id, $limit = '', $inc_sub = 'exclude' ) {
260
- if ( ! (int) $form_id ) {
261
- return array();
262
- }
263
-
264
- $results = get_transient('frm_all_form_fields_'. $form_id . $inc_sub);
265
- if ( $results !== false ) {
266
- if ( empty($limit) ) {
267
- return stripslashes_deep($results);
268
  }
269
-
270
- $fields = array();
271
- $count = 0;
272
- foreach ( $results as $result ) {
273
- $fields[$result->id] = $result;
274
- if ( ! empty($limit) && $count >= $limit ) {
275
- break;
276
- }
277
- }
278
-
279
- return stripslashes_deep($fields);
280
  }
281
-
282
- self::$use_cache = false;
283
-
284
- // get the fields, but make sure to not get the subfields if set to exclude
285
- $results = self::getAll( array( 'fi.form_id' => absint( $form_id ) ), 'field_order', $limit );
286
- self::$use_cache = true;
287
-
288
- self::include_sub_fields( $results, $inc_sub, 'all' );
289
-
290
- if ( empty($limit) ) {
291
- set_transient('frm_all_form_fields_'. $form_id . $inc_sub, $results, 60*60*6);
292
- }
293
-
294
- return $results;
295
- }
296
-
297
- public static function include_sub_fields(&$results, $inc_sub, $type = 'all') {
298
- if ( 'include' != $inc_sub ) {
299
- return;
300
- }
301
-
302
- $form_fields = $results;
303
- foreach ( $form_fields as $k => $field ) {
304
- if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
305
- continue;
306
- }
307
-
308
- if ( $type == 'all' ) {
309
- $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
310
- } else {
311
- $sub_fields = self::get_all_types_in_form($field->form_id, $type);
312
- }
313
-
314
- if ( ! empty($sub_fields) ) {
315
- array_splice($results, $k, 1, $sub_fields);
316
- }
317
- unset($field, $sub_fields);
318
  }
 
 
319
  }
320
 
321
- public static function getAll($where = array(), $order_by = '', $limit = '', $blog_id = false) {
322
- $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
323
- if ( self::$use_cache ) {
324
- // make sure old cache doesn't get saved as a transient
325
- $results = wp_cache_get($cache_key, 'frm_field');
326
- if ( false !== $results ) {
327
- return stripslashes_deep($results);
328
- }
329
- }
330
-
331
  global $wpdb;
332
-
333
- if ( $blog_id && is_multisite() ) {
334
  global $wpmuBaseTablePrefix;
335
- if ( $wpmuBaseTablePrefix ) {
336
- $prefix = $wpmuBaseTablePrefix . $blog_id .'_';
337
- } else {
338
  $prefix = $wpdb->get_blog_prefix( $blog_id );
339
- }
340
-
341
- $table_name = $prefix .'frm_fields';
342
- $form_table_name = $prefix .'frm_forms';
343
  }else{
344
  $table_name = $wpdb->prefix .'frm_fields';
345
  $form_table_name = $wpdb->prefix .'frm_forms';
346
  }
 
 
 
347
 
348
- if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
349
- $order_by = ' ORDER BY '. $order_by;
350
- }
351
-
352
- $limit = FrmAppHelper::esc_limit($limit);
353
-
354
  $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
355
- $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
356
-
357
- if ( is_array($where) ) {
358
- if ( isset( $where['fi.form_id'] ) && count( $where ) == 1 ) {
359
- // add sub fields to query
360
- $form_id = $where['fi.form_id'];
361
- $where[] = array( 'or' => 1, 'fi.form_id' => $form_id, 'fr.parent_form_id' => $form_id );
362
- unset( $where['fi.form_id'] );
363
- }
364
 
365
- $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
 
366
  }else{
367
- // if the query is not an array, then it has already been prepared
368
  $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
369
-
370
- $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
371
- $results = $wpdb->$function_name( $query );
372
  }
373
- unset( $where );
374
-
375
- if ( ! $results ) {
376
- stripslashes_deep($results);
 
 
 
 
 
 
 
 
 
 
377
  }
378
-
379
- if ( is_array($results) ) {
380
- foreach ( $results as $r_key => $result ) {
381
- wp_cache_set($result->id, $result, 'frm_field');
382
- wp_cache_set($result->field_key, $result, 'frm_field');
383
-
384
- $results[$r_key]->field_options = maybe_unserialize($result->field_options);
385
- if ( isset( $results[ $r_key ]->field_options['format'] ) && ! empty( $results[ $r_key ]->field_options['format'] ) ) {
386
- $results[ $r_key ]->field_options['format'] = addslashes( $results[ $r_key ]->field_options['format'] );
 
 
 
 
 
387
  }
388
-
389
- $results[ $r_key ]->options = maybe_unserialize( $result->options );
390
- $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
391
- $form_id = $result->form_id;
392
-
393
- unset($r_key, $result);
 
 
 
 
 
394
  }
395
-
396
- unset($form_id);
397
- } else if ( $results ) {
398
- wp_cache_set($results->id, $results, 'frm_field');
399
- wp_cache_set($results->field_key, $results, 'frm_field');
400
-
401
- self::prepare_options( $results );
402
  }
403
-
404
- wp_cache_set($cache_key, $results, 'frm_field', 300);
405
-
406
  return stripslashes_deep($results);
407
  }
408
 
409
- /**
410
- * Unserialize all the serialized field data
411
- * @since 2.0
412
- */
413
- private static function prepare_options( &$results ) {
414
- $results->field_options = maybe_unserialize( $results->field_options );
415
- if ( isset( $results->field_options['format'] ) && ! empty( $results->field_options['format'] ) ) {
416
- $results->field_options['format'] = addslashes( $results->field_options['format'] );
417
- }
418
-
419
- $results->options = maybe_unserialize($results->options);
420
- $results->default_value = maybe_unserialize($results->default_value);
421
- }
422
-
423
- public static function getIds($where = '', $order_by = '', $limit = ''){
424
- _deprecated_function( __FUNCTION__, '2.0' );
425
  global $wpdb;
426
- if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
 
427
  $order_by = ' ORDER BY '. $order_by;
428
  }
429
-
430
- $query = 'SELECT fi.id FROM '. $wpdb->prefix .'frm_fields fi ' .
431
- 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
432
  FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
433
-
434
- $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
435
- $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
436
- $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
437
-
438
  return $results;
439
  }
440
-
441
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
+
4
+ if(class_exists('FrmField'))
5
+ return;
6
 
7
  class FrmField{
 
8
 
9
+ function create( $values, $return=true ){
10
+ global $wpdb;
11
 
12
  $new_values = array();
13
  $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
14
  $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
15
 
16
+ foreach ( array('name', 'description', 'type', 'default_value') as $col ) {
17
  $new_values[$col] = $values[$col];
18
  }
19
+
20
  $new_values['options'] = $values['options'];
21
 
22
+ $new_values['field_order'] = isset($values['field_order']) ? (int)$values['field_order'] : NULL;
23
+ $new_values['required'] = isset($values['required']) ? (int)$values['required'] : 0;
24
+ $new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id'] : NULL;
25
  $new_values['field_options'] = $values['field_options'];
26
  $new_values['created_at'] = current_time('mysql', 1);
27
+ if(isset($values['id'])){
28
+ global $frm_duplicate_ids;
29
  $frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
30
  $new_values = apply_filters('frm_duplicated_field', $new_values);
31
  }
32
+
33
+ foreach($new_values as $k => $v){
34
+ if(is_array($v))
35
+ $new_values[$k] = serialize($v);
36
+ unset($k);
37
+ unset($v);
38
  }
39
+
40
  //if(isset($values['id']) and is_numeric($values['id']))
41
  // $new_values['id'] = $values['id'];
42
+
43
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
44
+ if($return){
45
+ if($query_results){
46
+ delete_transient('frm_all_form_fields_'. $new_values['form_id']);
47
+ $new_id = $wpdb->insert_id;
48
+ if(isset($values['id']))
49
+ $frm_duplicate_ids[$values['id']] = $new_id;
50
+ return $new_id;
51
+ }else{
52
+ return false;
53
+ }
54
+ }
 
 
 
 
 
 
55
  }
56
 
57
+ function duplicate($old_form_id, $form_id, $copy_keys=false, $blog_id=false){
58
+ global $frm_duplicate_ids, $wpdb;
59
+ $fields = $this->getAll(array('fi.form_id' => $old_form_id), 'field_order', '', $blog_id);
60
+ foreach ((array)$fields as $field){
61
+ $values = array();
62
  $new_key = ($copy_keys) ? $field->field_key : '';
63
+ if($copy_keys and substr($field->field_key, -1) == 2)
64
  $new_key = rtrim($new_key, 2);
65
+ $values['field_key'] = FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_fields', 'field_key');
66
+ $values['options'] = maybe_serialize($field->options);
67
+ $values['form_id'] = $form_id;
68
+ foreach (array('name', 'description', 'type', 'default_value', 'field_order', 'required', 'field_options') as $col)
69
+ $values[$col] = $field->{$col};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  $values = apply_filters('frm_duplicated_field', $values);
71
+ $new_id = $this->create($values);
72
+ $frm_duplicate_ids[$field->id] = $new_id;
73
+ $frm_duplicate_ids[$field->field_key] = $new_id;
74
  unset($field);
75
  }
76
  }
77
 
78
+ function update( $id, $values ){
79
  global $wpdb;
80
+
81
+ if (isset($values['field_key']))
 
 
82
  $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
 
83
 
84
  if ( isset($values['required']) ) {
85
  $values['required'] = (int) $values['required'];
86
  }
87
+
88
+ if (isset($values['default_value']) and is_array($values['default_value']))
89
+ $values['default_value'] = serialize($values['default_value']);
90
+
91
+ if (isset($values['field_options']) and is_array($values['field_options']))
92
+ $values['field_options'] = serialize($values['field_options']);
93
+
94
+ if (isset($values['options']) and is_array($values['options']))
95
+ $values['options'] = serialize($values['options']);
96
+
97
  $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
98
+
99
+ if(isset($values['form_id'])){
100
+ $form_id = $values['form_id'];
101
+ }else{
102
+ $field = $this->getOne($id);
103
+ if($field)
 
104
  $form_id = $field->form_id;
 
105
  unset($field);
106
  }
107
  unset($values);
108
+
109
+ if($query_results){
110
  wp_cache_delete( $id, 'frm_field' );
111
+ delete_transient('frm_all_form_fields_'. $form_id);
 
 
112
  }
113
+
114
  return $query_results;
115
  }
116
 
117
+ function destroy( $id ){
118
+ global $wpdb;
119
+
120
+ do_action('frm_before_destroy_field', $id);
121
+ do_action('frm_before_destroy_field_'. $id);
122
+
123
+ wp_cache_delete( $id, 'frm_field' );
124
+ $field = $this->getOne($id);
125
+ if ( !$field ) {
126
+ return false;
127
+ }
128
+
129
+ delete_transient('frm_all_form_fields_'. $field->form_id);
130
+
131
+ $wpdb->query("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id='$id'");
132
+ return $wpdb->query("DELETE FROM {$wpdb->prefix}frm_fields WHERE id='$id'");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
 
135
+ function getOne( $id ){
 
 
 
 
136
  global $wpdb;
137
+ $results = wp_cache_get( $id, 'frm_field' );
138
+ if(!$results){
139
+
140
+ $where = (is_numeric($id)) ? 'id=%d' : 'field_key=%s';
141
+ $results = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_fields WHERE $where", $id));
142
+
143
+ if($results){
144
+ wp_cache_set( $results->id, $results, 'frm_field' );
145
+ wp_cache_set( $results->field_key, $results, 'frm_field' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  }
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
+
149
+ if($results){
150
+ $results->field_options = maybe_unserialize($results->field_options);
151
+ if(isset($results->field_options['format']) and !empty($results->field_options['format']))
152
+ $results->field_options['format'] = addslashes($results->field_options['format']);
153
+ $results->options = maybe_unserialize($results->options);
154
+ $results->default_value = maybe_unserialize($results->default_value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  }
156
+
157
+ return stripslashes_deep($results);
158
  }
159
 
160
+ function getAll($where=array(), $order_by = '', $limit = '', $blog_id=false){
 
 
 
 
 
 
 
 
 
161
  global $wpdb;
162
+
163
+ if ($blog_id and is_multisite()){
164
  global $wpmuBaseTablePrefix;
165
+ if($wpmuBaseTablePrefix)
166
+ $prefix = "{$wpmuBaseTablePrefix}{$blog_id}_";
167
+ else
168
  $prefix = $wpdb->get_blog_prefix( $blog_id );
169
+
170
+ $table_name = "{$prefix}frm_fields";
171
+ $form_table_name = "{$prefix}frm_forms";
 
172
  }else{
173
  $table_name = $wpdb->prefix .'frm_fields';
174
  $form_table_name = $wpdb->prefix .'frm_forms';
175
  }
176
+
177
+ if(!empty($order_by) and !preg_match("/ORDER BY/", $order_by))
178
+ $order_by = " ORDER BY {$order_by}";
179
 
180
+ if(is_numeric($limit))
181
+ $limit = " LIMIT {$limit}";
182
+
 
 
 
183
  $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
184
+ $old_where = $where;
185
+ if(is_array($where)){
186
+ global $frmdb;
187
+ extract($frmdb->get_where_clause_and_values( $where ));
 
 
 
 
 
188
 
189
+ $query .= "{$where}{$order_by}{$limit}";
190
+ $query = $wpdb->prepare($query, $values);
191
  }else{
 
192
  $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
 
 
 
193
  }
194
+
195
+ if ($limit == ' LIMIT 1' or $limit == 1){
196
+ $results = $wpdb->get_row($query);
197
+ }else{
198
+ $ak = is_array($old_where) ? array_keys($old_where) : $old_where;
199
+ if($order_by == ' ORDER BY field_order' and empty($limit) and empty($blog_id) and is_array($old_where) and count($old_where) == 1 and reset($ak) == 'fi.form_id'){
200
+ $save_cache = true;
201
+ $results = get_transient('frm_all_form_fields_'. reset($old_where));
202
+ if($results and (is_array($results) or is_object($results)))
203
+ $cached = true;
204
+ }
205
+ unset($ak);
206
+ if(!isset($cached))
207
+ $results = $wpdb->get_results($query);
208
  }
209
+
210
+ if($results and !isset($cached)){
211
+ if(is_array($results)){
212
+ foreach($results as $r_key => $result){
213
+ wp_cache_set($result->id, $result, 'frm_field');
214
+ wp_cache_set($result->field_key, $result, 'frm_field');
215
+ $results[$r_key]->field_options = maybe_unserialize($result->field_options);
216
+ if(isset($results[$r_key]->field_options['format']) and !empty($results[$r_key]->field_options['format']))
217
+ $results[$r_key]->field_options['format'] = addslashes($results[$r_key]->field_options['format']);
218
+ $results[$r_key]->options = maybe_unserialize($result->options);
219
+ $results[$r_key]->default_value = maybe_unserialize($result->default_value);
220
+ $form_id = $result->form_id;
221
+
222
+ unset($r_key, $result);
223
  }
224
+ if(isset($save_cache))
225
+ set_transient('frm_all_form_fields_'. $form_id, $results, 60*60*6);
226
+ unset($form_id);
227
+ }else{
228
+ wp_cache_set($results->id, $results, 'frm_field');
229
+ wp_cache_set($results->field_key, $results, 'frm_field');
230
+ $results->field_options = maybe_unserialize($results->field_options);
231
+ if(isset($results->field_options['format']) and !empty($results->field_options['format']))
232
+ $results->field_options['format'] = addslashes($results->field_options['format']);
233
+ $results->options = maybe_unserialize($results->options);
234
+ $results->default_value = maybe_unserialize($results->default_value);
235
  }
 
 
 
 
 
 
 
236
  }
237
+
 
 
238
  return stripslashes_deep($results);
239
  }
240
 
241
+ function getIds($where = '', $order_by = '', $limit = ''){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  global $wpdb;
243
+
244
+ if ( !empty($order_by) && !preg_match("/ORDER BY/", $order_by) ){
245
  $order_by = ' ORDER BY '. $order_by;
246
  }
247
+
248
+ $query = "SELECT fi.id FROM {$wpdb->prefix}frm_fields fi " .
249
+ "LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON fi.form_id=fr.id" .
250
  FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
251
+ if ($limit == ' LIMIT 1' or $limit == 1)
252
+ $results = $wpdb->get_var($query);
253
+ else
254
+ $results = $wpdb->get_col($query);
 
255
  return $results;
256
  }
 
257
  }
classes/models/FrmForm.php CHANGED
@@ -1,35 +1,32 @@
1
  <?php
2
- if ( ! defined('ABSPATH') ) {
3
- die('You are not allowed to call this page directly.');
4
- }
 
5
 
6
  class FrmForm{
7
 
8
- /**
9
- * @return int|boolean id on success or false on failure
10
- */
11
- public static function create( $values ) {
12
- global $wpdb;
13
 
14
  $new_values = array(
15
  'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
16
  'name' => $values['name'],
17
  'description' => $values['description'],
18
  'status' => isset($values['status']) ? $values['status'] : 'draft',
19
- 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
  'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21
- 'parent_form_id'=> isset($values['parent_form_id']) ? (int) $values['parent_form_id'] : 0,
22
  'editable' => isset($values['editable']) ? (int) $values['editable'] : 0,
23
  'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
  );
26
-
27
  $options = array();
28
 
29
  $defaults = FrmFormsHelper::get_default_opts();
30
- foreach ( $defaults as $var => $default ) {
31
- $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
32
- unset( $var, $default );
 
33
  }
34
 
35
  $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
@@ -42,30 +39,27 @@ class FrmForm{
42
  //if(isset($values['id']) && is_numeric($values['id']))
43
  // $new_values['id'] = $values['id'];
44
 
45
- $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
46
 
47
- $id = $wpdb->insert_id;
48
- return $id;
49
  }
50
-
51
- /**
52
- * @return int|boolean ID on success or false on failure
53
- */
54
- public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
55
  global $wpdb;
56
 
57
- $values = self::getOne( $id, $blog_id );
58
- if ( ! $values ) {
 
59
  return false;
60
  }
61
-
62
  $new_key = $copy_keys ? $values->form_key : '';
63
-
64
  $new_values = array(
65
  'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
66
  'name' => $values->name,
67
  'description' => $values->description,
68
- 'status' => $template ? 'published' : 'draft',
69
  'logged_in' => $values->logged_in ? $values->logged_in : 0,
70
  'editable' => $values->editable ? $values->editable : 0,
71
  'created_at' => current_time('mysql', 1),
@@ -87,39 +81,37 @@ class FrmForm{
87
  }
88
 
89
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
90
-
91
  if ( $query_results ) {
 
92
  $form_id = $wpdb->insert_id;
93
- FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
94
-
95
  // update form settings after fields are created
96
- do_action('frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id));
97
  return $form_id;
 
 
98
  }
99
-
100
- return false;
101
  }
102
-
103
- public static function after_duplicate($form_id, $values) {
104
  $new_opts = $values['options'] = maybe_unserialize($values['options']);
105
-
106
  if ( isset($new_opts['success_msg']) ) {
107
  $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
108
  }
109
-
110
  $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
111
-
112
  if ( $new_opts != $values['options'] ) {
113
  global $wpdb;
114
- $wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => maybe_serialize($new_opts)), array( 'id' => $form_id));
115
  }
116
  }
117
 
118
- /**
119
- * @return int|boolean
120
- */
121
- public static function update( $id, $values, $create_link = false ) {
122
- global $wpdb;
123
 
124
  if ( $create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']) ) {
125
  $values['status'] = 'published';
@@ -129,9 +121,30 @@ class FrmForm{
129
  $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
130
  }
131
 
132
- $form_fields = array( 'form_key', 'name', 'description', 'status' );
133
 
134
- $new_values = self::set_update_options( array(), $values);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  foreach ( $values as $value_key => $value ) {
137
  if ( in_array($value_key, $form_fields) ) {
@@ -139,11 +152,7 @@ class FrmForm{
139
  }
140
  }
141
 
142
- if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
143
- $new_values['status'] = $values['new_status'];
144
- }
145
-
146
- if ( ! empty( $new_values ) ) {
147
  $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
148
  if ( $query_results ) {
149
  wp_cache_delete( $id, 'frm_form');
@@ -151,283 +160,120 @@ class FrmForm{
151
  } else {
152
  $query_results = true;
153
  }
154
- unset($new_values);
155
-
156
- $values = self::update_fields($id, $values);
157
-
158
- do_action('frm_update_form', $id, $values);
159
- do_action('frm_update_form_'. $id, $values);
160
-
161
- return $query_results;
162
- }
163
-
164
- /**
165
- * @return array
166
- */
167
- public static function set_update_options($new_values, $values) {
168
- if ( ! isset($values['options']) ) {
169
- return $new_values;
170
- }
171
 
172
- $options = array();
173
-
174
- $defaults = FrmFormsHelper::get_default_opts();
175
- foreach ( $defaults as $var => $default ) {
176
- $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
177
- }
178
-
179
- $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
180
- $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
181
- $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
182
- $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
183
-
184
- $options = apply_filters('frm_form_options_before_update', $options, $values);
185
- $new_values['options'] = serialize($options);
186
-
187
- return $new_values;
188
- }
189
-
190
-
191
- /**
192
- * @return array
193
- */
194
- public static function update_fields($id, $values) {
195
-
196
- if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
197
- return $values;
198
- }
199
-
200
- $all_fields = FrmField::get_all_for_form($id);
201
- if ( empty($all_fields) ) {
202
- return $values;
203
- }
204
-
205
- if ( ! isset($values['item_meta']) ) {
206
- $values['item_meta'] = array();
207
- }
208
-
209
- $field_array = array();
210
- $existing_keys = array_keys($values['item_meta']);
211
- foreach ( $all_fields as $fid ) {
212
- if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
213
- $values['item_meta'][$fid->id] = '';
214
  }
215
- $field_array[$fid->id] = $fid;
216
- }
217
- unset($all_fields);
218
 
219
- foreach ( $values['item_meta'] as $field_id => $default_value ) {
220
- if ( isset($field_array[$field_id]) ) {
221
- $field = $field_array[$field_id];
222
- } else {
223
- $field = FrmField::getOne($field_id);
224
- }
225
-
226
- if ( ! $field ) {
227
- continue;
228
  }
229
-
230
- if ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) {
231
- //updating the settings page
232
- if ( isset($values['field_options']['custom_html_'. $field_id]) ) {
233
- $field->field_options['custom_html'] = isset($values['field_options']['custom_html_'.$field_id]) ? $values['field_options']['custom_html_'.$field_id] : ( isset($field->field_options['custom_html']) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type));
234
- $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
235
- FrmField::update($field_id, array( 'field_options' => $field->field_options));
236
- } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
- $prev_opts = $field->field_options;
238
- $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
- if ( $prev_opts != $field->field_options ) {
240
- FrmField::update($field_id, array( 'field_options' => $field->field_options));
 
 
 
 
 
 
241
  }
242
- unset($prev_opts);
243
  }
244
- }
245
-
246
- if ( ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) && ! defined('WP_IMPORTING') ) {
247
- continue;
248
- }
249
-
250
- //updating the form
251
- foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes') as $opt ) {
252
- $field->field_options[$opt] = isset($values['field_options'][$opt .'_'. $field_id]) ? trim($values['field_options'][$opt .'_'. $field_id]) : '';
253
- }
254
-
255
- $field->field_options['required_indicator'] = isset($values['field_options']['required_indicator_'. $field_id]) ? trim($values['field_options']['required_indicator_'. $field_id]) : '*';
256
- $field->field_options['separate_value'] = isset($values['field_options']['separate_value_'. $field_id]) ? trim($values['field_options']['separate_value_'. $field_id]) : 0;
257
-
258
- $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259
- $default_value = maybe_serialize($values['item_meta'][$field_id]);
260
- $field_key = isset($values['field_options']['field_key_'. $field_id]) ? $values['field_options']['field_key_'. $field_id] : $field->field_key;
261
- $required = isset($values['field_options']['required_'. $field_id]) ? $values['field_options']['required_'. $field_id] : false;
262
- $field_type = isset($values['field_options']['type_'. $field_id]) ? $values['field_options']['type_'. $field_id] : $field->type;
263
- $field_description = isset($values['field_options']['description_'. $field_id]) ? $values['field_options']['description_'. $field_id] : $field->description;
264
-
265
- FrmField::update($field_id, array(
266
- 'field_key' => $field_key, 'type' => $field_type,
267
- 'default_value' => $default_value, 'field_options' => $field->field_options,
268
- 'description' => $field_description, 'required' => $required,
269
- ) );
270
-
271
- FrmField::delete_form_transient($field->form_id);
272
- }
273
-
274
- return $values;
275
- }
276
-
277
- /**
278
- * @param string $status
279
- * @return int|boolean
280
- */
281
- public static function set_status($id, $status) {
282
- if ( 'trash' == $status ) {
283
- return self::trash($id);
284
- }
285
-
286
- $statuses = array( 'published', 'draft', 'trash');
287
- if ( ! in_array( $status, $statuses ) ) {
288
- return false;
289
- }
290
-
291
- global $wpdb;
292
 
293
- if ( is_array($id) ) {
294
- $where = array( 'id' => $id );
295
- FrmDb::get_where_clause_and_values( $where );
296
- array_unshift( $where['values'], $status );
297
 
298
- $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
299
- } else {
300
- $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', array( 'status' => $status), array( 'id' => $id));
301
- }
 
 
302
 
303
- if ( $query_results ) {
304
- foreach ( (array) $id as $i ) {
305
- wp_cache_delete( $i, 'frm_form');
306
  }
307
  }
 
 
 
308
 
309
  return $query_results;
310
  }
311
 
312
- /**
313
- * @return int|boolean
314
- */
315
- public static function trash($id) {
316
- if ( ! EMPTY_TRASH_DAYS ) {
317
- return self::destroy( $id );
318
- }
319
-
320
- $form = self::getOne($id);
321
- if ( ! $form ) {
322
- return false;
323
- }
324
-
325
- $options = $form->options;
326
- $options['trash_time'] = time();
327
-
328
- global $wpdb;
329
- $query_results = $wpdb->update(
330
- $wpdb->prefix .'frm_forms',
331
- array( 'status' => 'trash', 'options' => serialize($options)),
332
- array( 'id' => $id)
333
- );
334
-
335
- if ( $query_results ) {
336
- wp_cache_delete( $id, 'frm_form');
337
- }
338
-
339
- return $query_results;
340
- }
341
-
342
- /**
343
- * @return int|boolean
344
- */
345
- public static function destroy( $id ){
346
- global $wpdb;
347
 
348
- $form = self::getOne($id);
349
- if ( ! $form ) {
350
  return false;
351
  }
352
 
353
- // Disconnect the entries from this form
354
- $entries = FrmDb::get_col( $wpdb->prefix .'frm_items', array( 'form_id' => $id) );
355
- foreach ( $entries as $entry_id ) {
356
- FrmEntry::destroy($entry_id);
357
- unset($entry_id);
358
  }
359
-
360
  // Disconnect the fields from this form
361
- $wpdb->query($wpdb->prepare('DELETE fi FROM '. $wpdb->prefix .'frm_fields AS fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id));
362
 
363
- $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
364
  if ( $query_results ) {
365
- // Delete all form actions linked to this form
366
- $action_control = FrmFormActionsController::get_form_actions( 'email' );
367
- $action_control->destroy($id, 'all');
368
-
369
  do_action('frm_destroy_form', $id);
370
  do_action('frm_destroy_form_'. $id);
371
  }
372
-
373
  return $query_results;
374
  }
375
-
376
- /**
377
- * @return string form name
378
- */
379
- public static function &getName( $id ) {
380
  global $wpdb;
381
-
382
- $form = FrmAppHelper::check_cache($id, 'frm_form');
383
- if ( $form ) {
384
- $r = stripslashes($form->name);
385
- return $r;
386
- }
387
-
388
- $query_key = is_numeric( $id ) ? 'id' : 'form_key';
389
- $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
390
- $r = stripslashes($r);
391
-
392
- return $r;
393
- }
394
-
395
- /**
396
- * @param string $key
397
- * @return int form id
398
- */
399
- public static function &getIdByKey( $key ){
400
- $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
401
- return $id;
402
- }
403
-
404
- /**
405
- * @param int $id
406
- * @return string form key
407
- */
408
- public static function &getKeyById($id){
409
- $id = (int) $id;
410
- $cache = FrmAppHelper::check_cache($id, 'frm_form');
411
  if ( $cache ) {
412
- return $cache->form_key;
413
- }
414
-
415
- $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
416
-
417
- return $key;
 
 
418
  }
419
-
420
- /**
421
- * @return object form
422
- */
423
- public static function getOne( $id, $blog_id = false ) {
424
  global $wpdb;
 
 
 
425
 
 
 
 
426
  if ( $blog_id && is_multisite() ) {
427
  global $wpmuBaseTablePrefix;
428
- $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
429
-
430
- $table_name = $prefix .'frm_forms';
431
  } else {
432
  $table_name = $wpdb->prefix .'frm_forms';
433
  $cache = wp_cache_get($id, 'frm_form');
@@ -435,18 +281,15 @@ class FrmForm{
435
  if ( isset($cache->options) ) {
436
  $cache->options = maybe_unserialize($cache->options);
437
  }
438
-
439
  return stripslashes_deep($cache);
440
  }
441
  }
442
-
443
- if ( is_numeric($id) ) {
444
- $where = array( 'id' => $id );
445
- } else {
446
- $where = array( 'form_key' => $id );
447
- }
448
- $results = FrmDb::get_row( $table_name, $where );
449
-
450
  if ( isset($results->options) ) {
451
  wp_cache_set($results->id, $results, 'frm_form');
452
  $results->options = maybe_unserialize($results->options);
@@ -454,111 +297,52 @@ class FrmForm{
454
  return stripslashes_deep($results);
455
  }
456
 
457
- /**
458
- * @return array of objects
459
- */
460
- public static function getAll( $where = array(), $order_by = '', $limit = '' ){
461
- global $wpdb;
462
-
463
- if ( is_numeric($limit) ) {
464
- $limit = ' LIMIT '. $limit;
465
- }
466
-
467
- $query = 'SELECT * FROM ' . $wpdb->prefix .'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . FrmAppHelper::esc_order($order_by) . FrmAppHelper::esc_limit($limit);
468
-
469
- if ( $limit == ' LIMIT 1' || $limit == 1 ) {
470
- if ( is_array($where) && ! empty($where) ) {
471
- $results = FrmDb::get_row($wpdb->prefix .'frm_forms', $where, '*', array( 'order_by' => $order_by) );
472
- } else {
473
- // the query has already been prepared if this is not an array
474
  $results = $wpdb->get_row($query);
475
- }
476
-
477
- if ( $results ) {
478
  wp_cache_set($results->id, $results, 'frm_form');
479
  $results->options = maybe_unserialize($results->options);
480
  }
481
  }else{
482
- if ( is_array($where) && ! empty($where) ) {
483
- $results = FrmDb::get_results( $wpdb->prefix .'frm_forms', $where, '*', compact('order_by', 'limit') );
484
  } else {
485
  $results = $wpdb->get_results($query);
486
  }
487
-
488
- if ( $results ) {
489
- foreach ( $results as $result ) {
490
- wp_cache_set( $result->id, $result, 'frm_form' );
491
- $result->options = maybe_unserialize( $result->options );
492
- }
493
  }
494
  }
495
-
496
  return stripslashes_deep($results);
497
  }
498
 
499
- /**
500
- * Get all published forms
501
- * @since 2.0
502
- */
503
- public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) {
504
- $query['is_template'] = 0;
505
- $query['status'] = array( null, '', 'published' );
506
- if ( $inc_children == 'exclude' ) {
507
- $query['parent_form_id'] = array( null, 0 );
508
- }
509
-
510
- $forms = self::getAll( $query, 'name', $limit );
511
- return $forms;
512
- }
513
-
514
- /**
515
- * @return int count of forms
516
- */
517
- public static function &get_count( ) {
518
- global $wpdb;
519
-
520
- $cache_key = 'frm_form_counts';
521
-
522
- $counts = wp_cache_get( $cache_key, 'counts' );
523
- if ( false !== $counts ) {
524
- return $counts;
525
- }
526
-
527
- $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
528
-
529
- $statuses = array( 'published', 'draft', 'template', 'trash');
530
- $counts = array_fill_keys( $statuses, 0 );
531
-
532
- foreach ( $results as $row ) {
533
- if ( 'trash' != $row->status ) {
534
- if ( $row->is_template ) {
535
- $counts['template']++;
536
- } else {
537
- $counts['published']++;
538
- }
539
- } else {
540
- $counts['trash']++;
541
- }
542
-
543
- if ( 'draft' == $row->status ) {
544
- $counts['draft']++;
545
- }
546
-
547
- unset($row);
548
- }
549
-
550
- $counts = (object) $counts;
551
- wp_cache_set( $cache_key, $counts, 'counts' );
552
-
553
- return $counts;
554
- }
555
-
556
- /**
557
- * @return array of errors
558
- */
559
- public static function validate( $values ){
560
  $errors = array();
561
 
 
 
 
 
 
 
 
562
  return apply_filters('frm_validate_form', $errors, $values);
563
  }
564
 
1
  <?php
2
+ if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
+
4
+ if(class_exists('FrmForm'))
5
+ return;
6
 
7
  class FrmForm{
8
 
9
+ function create( $values ) {
10
+ global $wpdb, $frm_settings;
 
 
 
11
 
12
  $new_values = array(
13
  'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
14
  'name' => $values['name'],
15
  'description' => $values['description'],
16
  'status' => isset($values['status']) ? $values['status'] : 'draft',
 
17
  'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0,
 
18
  'editable' => isset($values['editable']) ? (int) $values['editable'] : 0,
19
  'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
20
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
21
  );
22
+
23
  $options = array();
24
 
25
  $defaults = FrmFormsHelper::get_default_opts();
26
+ foreach ($defaults as $var => $default) {
27
+ $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default;
28
+ unset($var);
29
+ unset($default);
30
  }
31
 
32
  $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
39
  //if(isset($values['id']) && is_numeric($values['id']))
40
  // $new_values['id'] = $values['id'];
41
 
42
+ $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
43
 
44
+ return $wpdb->insert_id;
 
45
  }
46
+
47
+ function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
 
 
 
48
  global $wpdb;
49
 
50
+ $frm_form = new FrmForm();
51
+ $values = $frm_form->getOne( $id, $blog_id );
52
+ if ( !$values ) {
53
  return false;
54
  }
55
+
56
  $new_key = $copy_keys ? $values->form_key : '';
57
+
58
  $new_values = array(
59
  'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
60
  'name' => $values->name,
61
  'description' => $values->description,
62
+ 'status' => $template ? '' : 'draft',
63
  'logged_in' => $values->logged_in ? $values->logged_in : 0,
64
  'editable' => $values->editable ? $values->editable : 0,
65
  'created_at' => current_time('mysql', 1),
81
  }
82
 
83
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
84
+
85
  if ( $query_results ) {
86
+ global $frm_field;
87
  $form_id = $wpdb->insert_id;
88
+ $frm_field->duplicate($id, $form_id, $copy_keys, $blog_id);
89
+
90
  // update form settings after fields are created
91
+ do_action('frm_after_duplicate_form', $form_id, $new_values);
92
  return $form_id;
93
+ } else {
94
+ return false;
95
  }
 
 
96
  }
97
+
98
+ function after_duplicate($form_id, $values) {
99
  $new_opts = $values['options'] = maybe_unserialize($values['options']);
100
+
101
  if ( isset($new_opts['success_msg']) ) {
102
  $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
103
  }
104
+
105
  $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
106
+
107
  if ( $new_opts != $values['options'] ) {
108
  global $wpdb;
109
+ $wpdb->update($wpdb->prefix .'frm_forms', array('options' => maybe_serialize($new_opts)), array('id' => $form_id));
110
  }
111
  }
112
 
113
+ function update( $id, $values, $create_link = false ) {
114
+ global $wpdb, $frm_field, $frm_settings;
 
 
 
115
 
116
  if ( $create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']) ) {
117
  $values['status'] = 'published';
121
  $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
122
  }
123
 
124
+ $form_fields = array( 'form_key', 'name', 'description', 'status', 'prli_link_id' );
125
 
126
+ $new_values = array();
127
+
128
+ if (isset($values['options'])){
129
+ $options = array();
130
+
131
+ $defaults = FrmFormsHelper::get_default_opts();
132
+ foreach ($defaults as $var => $default) {
133
+ if ( $var == 'notification' && !defined('WP_IMPORTING')) {
134
+ $options[$var] = isset($values[$var]) ? $values[$var] : $default;
135
+ } else {
136
+ $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default;
137
+ }
138
+ }
139
+
140
+ $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
141
+ $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
142
+ $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
143
+ $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
144
+
145
+ $options = apply_filters('frm_form_options_before_update', $options, $values);
146
+ $new_values['options'] = serialize($options);
147
+ }
148
 
149
  foreach ( $values as $value_key => $value ) {
150
  if ( in_array($value_key, $form_fields) ) {
152
  }
153
  }
154
 
155
+ if ( !empty($new_values) ) {
 
 
 
 
156
  $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
157
  if ( $query_results ) {
158
  wp_cache_delete( $id, 'frm_form');
160
  } else {
161
  $query_results = true;
162
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
+ $all_fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
165
+ if ( $all_fields && (isset($values['options']) || isset($values['item_meta']) || isset($values['field_options'])) ) {
166
+ if ( !isset($values['item_meta']) ) {
167
+ $values['item_meta'] = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
+ $existing_keys = array_keys($values['item_meta']);
 
 
170
 
171
+ foreach ( $all_fields as $fid ) {
172
+ if ( !in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
173
+ $values['item_meta'][$fid->id] = '';
174
+ }
 
 
 
 
 
175
  }
176
+
177
+ foreach ( $values['item_meta'] as $field_id => $default_value ) {
178
+ $field = $frm_field->getOne($field_id);
179
+ if (!$field) continue;
180
+ $field_options = maybe_unserialize($field->field_options);
181
+
182
+ if ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) {
183
+ //updating the settings page
184
+ if(isset($values['field_options']['custom_html_'.$field_id])){
185
+ $field_options['custom_html'] = isset($values['field_options']['custom_html_'.$field_id]) ? $values['field_options']['custom_html_'.$field_id] : (isset($field_options['custom_html']) ? $field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type));
186
+ $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values);
187
+ $frm_field->update($field_id, array('field_options' => $field_options));
188
+ }else if($field->type == 'hidden' || $field->type == 'user_id'){
189
+ $prev_opts = $field_options;
190
+ $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values);
191
+ if($prev_opts != $field_options)
192
+ $frm_field->update($field_id, array('field_options' => $field_options));
193
+ unset($prev_opts);
194
  }
 
195
  }
196
+
197
+ if ( (!isset($values['options']) && !isset($values['field_options']['custom_html_'. $field_id])) || defined('WP_IMPORTING') ) {
198
+ //updating the form
199
+ foreach ( array('size', 'max', 'label', 'invalid', 'blank', 'classes') as $opt ) {
200
+ $field_options[$opt] = isset($values['field_options'][$opt.'_'.$field_id]) ? trim($values['field_options'][$opt.'_'.$field_id]) : '';
201
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
+ $field_options['required_indicator'] = isset($values['field_options']['required_indicator_'. $field_id]) ? trim($values['field_options']['required_indicator_'. $field_id]) : '*';
204
+ $field_options['separate_value'] = isset($values['field_options']['separate_value_'.$field_id]) ? trim($values['field_options']['separate_value_'.$field_id]) : 0;
 
 
205
 
206
+ $field_options = apply_filters('frm_update_field_options', $field_options, $field, $values);
207
+ $default_value = maybe_serialize($values['item_meta'][$field_id]);
208
+ $field_key = (isset($values['field_options']['field_key_'.$field_id])) ? $values['field_options']['field_key_'.$field_id] : $field->field_key;
209
+ $required = (isset($values['field_options']['required_'.$field_id])) ? $values['field_options']['required_'.$field_id] : false;
210
+ $field_type = (isset($values['field_options']['type_'.$field_id])) ? $values['field_options']['type_'.$field_id] : $field->type;
211
+ $field_description = (isset($values['field_options']['description_'.$field_id])) ? $values['field_options']['description_'.$field_id] : $field->description;
212
 
213
+ $frm_field->update($field_id, array('field_key' => $field_key, 'type' => $field_type, 'default_value' => $default_value, 'field_options' => $field_options, 'description' => $field_description, 'required' => $required));
214
+ }
 
215
  }
216
  }
217
+
218
+ do_action('frm_update_form', $id, $values);
219
+ do_action('frm_update_form_'. $id, $values);
220
 
221
  return $query_results;
222
  }
223
 
224
+ function destroy( $id ){
225
+ global $wpdb, $frm_entry;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
+ $form = $this->getOne($id);
228
+ if ( !$form || $form->default_template ) {
229
  return false;
230
  }
231
 
232
+ // Disconnect the items from this form
233
+ $entries = $frm_entry->getAll(array('it.form_id' => $id));
234
+ foreach ( $entries as $item ) {
235
+ $frm_entry->destroy($item->id);
236
+ unset($item);
237
  }
 
238
  // Disconnect the fields from this form
239
+ $query_results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_fields WHERE form_id=%d", $id));
240
 
241
+ $query_results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_forms WHERE id=%d", $id));
242
  if ( $query_results ) {
 
 
 
 
243
  do_action('frm_destroy_form', $id);
244
  do_action('frm_destroy_form_'. $id);
245
  }
 
246
  return $query_results;
247
  }
248
+
249
+ function getName( $id ) {
 
 
 
250
  global $wpdb;
251
+ $cache = wp_cache_get($id, 'frm_form');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  if ( $cache ) {
253
+ return stripslashes($cache->name);
254
+ }
255
+ $query = "SELECT name FROM {$wpdb->prefix}frm_forms WHERE ";
256
+ $query .= (is_numeric($id)) ? "id=%d" : "form_key=%s";
257
+ $query = $wpdb->prepare($query, $id);
258
+
259
+ $r = $wpdb->get_var($query);
260
+ return stripslashes($r);
261
  }
262
+
263
+ function getIdByKey( $key ){
 
 
 
264
  global $wpdb;
265
+ $query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_forms WHERE form_key=%s LIMIT 1", $key);
266
+ return $wpdb->get_var($query);
267
+ }
268
 
269
+ function getOne( $id, $blog_id=false ){
270
+ global $wpdb, $frmdb;
271
+
272
  if ( $blog_id && is_multisite() ) {
273
  global $wpmuBaseTablePrefix;
274
+ $prefix = $wpmuBaseTablePrefix ? "{$wpmuBaseTablePrefix}{$blog_id}_" : $wpdb->get_blog_prefix( $blog_id );
275
+
276
+ $table_name = "{$prefix}frm_forms";
277
  } else {
278
  $table_name = $wpdb->prefix .'frm_forms';
279
  $cache = wp_cache_get($id, 'frm_form');
281
  if ( isset($cache->options) ) {
282
  $cache->options = maybe_unserialize($cache->options);
283
  }
284
+
285
  return stripslashes_deep($cache);
286
  }
287
  }
288
+
289
+ $where = $wpdb->prepare( is_numeric($id) ? 'id=%d' : 'form_key=%s', $id );
290
+
291
+ $results = $wpdb->get_row("SELECT * FROM $table_name WHERE $where");
292
+
 
 
 
293
  if ( isset($results->options) ) {
294
  wp_cache_set($results->id, $results, 'frm_form');
295
  $results->options = maybe_unserialize($results->options);
297
  return stripslashes_deep($results);
298
  }
299
 
300
+ function getAll( $where = array(), $order_by = '', $limit = '' ){
301
+ global $wpdb, $frmdb;
302
+
303
+ if(is_numeric($limit))
304
+ $limit = " LIMIT {$limit}";
305
+
306
+ $query = 'SELECT * FROM ' . $wpdb->prefix .'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
307
+
308
+ if ($limit == ' LIMIT 1' || $limit == 1){
309
+ if(is_array($where))
310
+ $results = $frmdb->get_one_record($wpdb->prefix .'frm_forms', $where, '*', $order_by);
311
+ else
 
 
 
 
 
312
  $results = $wpdb->get_row($query);
313
+
314
+ if($results){
 
315
  wp_cache_set($results->id, $results, 'frm_form');
316
  $results->options = maybe_unserialize($results->options);
317
  }
318
  }else{
319
+ if ( is_array($where) && !empty($where) ) {
320
+ $results = $frmdb->get_records($wpdb->prefix .'frm_forms', $where, $order_by, $limit);
321
  } else {
322
  $results = $wpdb->get_results($query);
323
  }
324
+
325
+ if($results){
326
+ foreach($results as $result){
327
+ wp_cache_set($result->id, $result, 'frm_form');
328
+ $result->options = maybe_unserialize($result->options);
329
+ }
330
  }
331
  }
332
+
333
  return stripslashes_deep($results);
334
  }
335
 
336
+ function validate( $values ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  $errors = array();
338
 
339
+ /*if( $values['form_key'] == null || $values['form_key'] == '' ){
340
+ if( $values['name'] == null || $values['name'] == '' )
341
+ $errors[] = "Key can't be blank";
342
+ else
343
+ $_POST['form_key'] = $values['name'];
344
+ }*/
345
+
346
  return apply_filters('frm_validate_form', $errors, $values);
347
  }
348
 
classes/models/FrmFormAction.php DELETED
@@ -1,529 +0,0 @@
1
- <?php
2
-
3
- class FrmFormAction {
4
-
5
- public $id_base; // Root id for all actions of this type.
6
- public $name; // Name for this action type.
7
- public $option_name;
8
- public $action_options; // Option array passed to wp_register_sidebar_widget()
9
- public $control_options; // Option array passed to wp_register_widget_control()
10
-
11
- public $form_id; // The ID of the form to evaluate
12
- public $number = false; // Unique ID number of the current instance.
13
- public $id = ''; // Unique ID string of the current instance (id_base-number)
14
- public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
15
-
16
- // Member functions that you must over-ride.
17
-
18
- /** Update a particular instance.
19
- *
20
- * This function should check that $new_instance is set correctly.
21
- * The newly calculated value of $instance should be returned.
22
- * If "false" is returned, the instance won't be saved/updated.
23
- *
24
- * @param array $new_instance New settings for this instance as input by the user via form()
25
- * @param array $old_instance Old settings for this instance
26
- * @return array Settings to save or bool false to cancel saving
27
- */
28
- public function update($new_instance, $old_instance) {
29
- return $new_instance;
30
- }
31
-
32
- /**
33
- * Echo the settings update form
34
- *
35
- * @param array $instance Current settings
36
- */
37
- public function form($instance, $args = array()) {
38
- echo '<p class="no-options-widget">' . __( 'There are no options for this action.', 'formidable' ) . '</p>';
39
- return 'noform';
40
- }
41
-
42
- /**
43
- * @return array of the default options
44
- */
45
- public function get_defaults() {
46
- return array();
47
- }
48
-
49
- public function get_switch_fields() {
50
- return array();
51
- }
52
-
53
- public function migrate_values($action, $form) {
54
- return $action;
55
- }
56
-
57
- // Functions you'll need to call.
58
-
59
- /**
60
- * PHP5 constructor
61
- *
62
- * @param string $id_base Optional Base ID for the widget, lower case,
63
- * if left empty a portion of the widget's class name will be used. Has to be unique.
64
- * @param string $name Name for the widget displayed on the configuration page.
65
- * @param array $action_options Optional Passed to wp_register_sidebar_widget()
66
- * - description: shown on the configuration page
67
- * - classname
68
- * @param array $control_options Optional Passed to wp_register_widget_control()
69
- * - width: required if more than 250px
70
- * - height: currently not used but may be needed in the future
71
- */
72
- public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
73
- if ( ! defined('ABSPATH') ) {
74
- die('You are not allowed to call this page directly.');
75
- }
76
-
77
- $this->id_base = strtolower($id_base);
78
- $this->name = $name;
79
- $this->option_name = 'frm_' . $this->id_base .'_action';
80
-
81
- $default_options = array(
82
- 'classes' => '',
83
- 'active' => true,
84
- 'event' => array( 'create'),
85
- 'limit' => 1,
86
- 'force_event' => false,
87
- 'priority' => 20,
88
- 'ajax_load' => true,
89
- 'tooltip' => $name,
90
- );
91
-
92
- $this->action_options = wp_parse_args( $action_options, $default_options );
93
- $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base) );
94
- }
95
-
96
- /**
97
- * @param string $id_base
98
- */
99
- public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
100
- FrmFormAction::__construct( $id_base, $name, $action_options, $control_options );
101
- }
102
-
103
- /**
104
- * Constructs name attributes for use in form() fields
105
- *
106
- * This function should be used in form() methods to create name attributes for fields to be saved by update()
107
- *
108
- * @param string $field_name Field name
109
- * @return string Name attribute for $field_name
110
- */
111
- public function get_field_name($field_name, $post_field = 'post_content') {
112
- return $this->option_name . '[' . $this->number . ']'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
113
- }
114
-
115
- /**
116
- * Constructs id attributes for use in form() fields
117
- *
118
- * This function should be used in form() methods to create id attributes for fields to be saved by update()
119
- *
120
- * @param string $field_name Field name
121
- * @return string ID attribute for $field_name
122
- */
123
- public function get_field_id($field_name) {
124
- return $field_name .'_'. $this->number;
125
- }
126
-
127
- // Private Function. Don't worry about this.
128
-
129
- public function _set($number) {
130
- $this->number = $number;
131
- $this->id = $this->id_base . '-' . $number;
132
- }
133
-
134
- public function prepare_new($form_id = false) {
135
- if ( $form_id ) {
136
- $this->form_id = $form_id;
137
- }
138
-
139
- $post_content = array();
140
- $default_values = $this->get_global_defaults();
141
-
142
- // fill default values
143
- $post_content = wp_parse_args( $post_content, $default_values);
144
-
145
- if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
146
- $post_content['event'] = array( reset($this->action_options['event']) );
147
- }
148
-
149
- $form_action = array(
150
- 'post_title' => $this->name,
151
- 'post_content' => $post_content,
152
- 'post_excerpt' => $this->id_base,
153
- 'ID' => '',
154
- 'post_status' => 'publish',
155
- 'post_type' => FrmFormActionsController::$action_post_type,
156
- 'post_name' => $this->form_id .'_'. $this->id_base .'_'. $this->number,
157
- 'menu_order' => $this->form_id,
158
- );
159
- unset($post_content);
160
-
161
- return (object) $form_action;
162
- }
163
-
164
- public function create($form_id) {
165
- $this->form_id = $form_id;
166
-
167
- $action = $this->prepare_new();
168
-
169
- return $this->save_settings($action);
170
- }
171
-
172
- public function duplicate_form_actions($form_id, $old_id) {
173
- if ( $form_id == $old_id ) {
174
- // don't duplicate the actions if this is a template getting updated
175
- return;
176
- }
177
-
178
- $this->form_id = $old_id;
179
- $actions = $this->get_all();
180
-
181
- $this->form_id = $form_id;
182
- foreach ( $actions as $action ) {
183
- $this->duplicate_one($action, $form_id);
184
- unset($action);
185
- }
186
- }
187
-
188
- /* Check if imported action should be created or updated
189
- *
190
- * Since 2.0
191
- *
192
- * @param array $action
193
- * @return integer $post_id
194
- */
195
- public function maybe_create_action( $action, $forms ) {
196
- if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) {
197
- // Update action only
198
- $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
199
- $post_id = $this->save_settings( $action );
200
- } else {
201
- // Create action
202
- $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
203
- $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
204
- }
205
- return $post_id;
206
- }
207
-
208
- public function duplicate_one($action, $form_id) {
209
- global $frm_duplicate_ids;
210
-
211
- $action->menu_order = $form_id;
212
- $switch = $this->get_global_switch_fields();
213
- foreach ( $action->post_content as $key => $val ) {
214
- if ( is_numeric($val) && isset($frm_duplicate_ids[$val]) ) {
215
- $action->post_content[$key] = $frm_duplicate_ids[$val];
216
- } else if ( ! is_array( $val ) ) {
217
- $action->post_content[$key] = FrmFieldsHelper::switch_field_ids($val);
218
- } else if ( isset($switch[$key]) && is_array($switch[$key]) ) {
219
- // loop through each value if empty
220
- if ( empty($switch[$key]) ) {
221
- $switch[$key] = array_keys($val);
222
- }
223
-
224
- foreach ( $switch[$key] as $subkey ) {
225
- $action->post_content[$key] = $this->duplicate_array_walk($action->post_content[$key], $subkey, $val);
226
- }
227
- }
228
-
229
- unset($key, $val);
230
- }
231
- unset($action->ID);
232
-
233
- return $this->save_settings($action);
234
- }
235
-
236
- private function duplicate_array_walk($action, $subkey, $val) {
237
- global $frm_duplicate_ids;
238
-
239
- if ( is_array($subkey) ) {
240
- foreach ( $subkey as $subkey2 ) {
241
- foreach ( (array) $val as $ck => $cv ) {
242
- if ( is_array($cv) ) {
243
- $action[$ck] = $this->duplicate_array_walk($action[$ck], $subkey2, $cv);
244
- } else if ( isset($cv[$subkey]) && is_numeric($cv[$subkey]) && isset($frm_duplicate_ids[$cv[$subkey]]) ) {
245
- $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]];
246
- }
247
- }
248
- }
249
- } else {
250
- foreach ( (array) $val as $ck => $cv ) {
251
- if ( is_array($cv) ) {
252
- $action[$ck] = $this->duplicate_array_walk($action[$ck], $subkey, $cv);
253
- } else if ( $ck == $subkey && isset($frm_duplicate_ids[$cv]) ) {
254
- $action[$ck] = $frm_duplicate_ids[$cv];
255
- }
256
- }
257
- }
258
-
259
- return $action;
260
- }
261
-
262
- /**
263
- * Deal with changed settings.
264
- *
265
- * Do NOT over-ride this function
266
- *
267
- */
268
- public function update_callback( $form_id ) {
269
- $this->form_id = $form_id;
270
-
271
- $all_instances = $this->get_settings();
272
-
273
- // We need to update the data
274
- if ( $this->updated ) {
275
- return;
276
- }
277
-
278
- if ( isset($_POST[$this->option_name]) && is_array($_POST[$this->option_name]) ) {
279
- $settings = $_POST[$this->option_name];
280
- } else {
281
- return;
282
- }
283
-
284
- $action_ids = array();
285
-
286
- foreach ( $settings as $number => $new_instance ) {
287
- $this->_set($number);
288
-
289
- if ( ! isset($new_instance['post_title']) ) {
290
- // settings were never opened, so don't update
291
- $action_ids[] = $new_instance['ID'];
292
- $this->updated = true;
293
- continue;
294
- }
295
-
296
- $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
297
-
298
- $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
299
- $new_instance['post_name'] = $this->form_id .'_'. $this->id_base .'_'. $this->number;
300
- $new_instance['menu_order'] = $this->form_id;
301
- $new_instance['post_status'] = 'publish';
302
- $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
303
-
304
- $instance = $this->update( $new_instance, $old_instance );
305
-
306
- /**
307
- * Filter an action's settings before saving.
308
- *
309
- * Returning false will effectively short-circuit the widget's ability
310
- * to update settings.
311
- *
312
- * @since 2.0
313
- *
314
- * @param array $instance The current widget instance's settings.
315
- * @param array $new_instance Array of new widget settings.
316
- * @param array $old_instance Array of old widget settings.
317
- * @param WP_Widget $this The current widget instance.
318
- */
319
- $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
320
-
321
- $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
322
- $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
323
-
324
- if ( false !== $instance ) {
325
- $all_instances[$number] = $instance;
326
- }
327
-
328
- $action_ids[] = $this->save_settings($instance);
329
-
330
- $this->updated = true;
331
- }
332
-
333
- return $action_ids;
334
- }
335
-
336
- public function save_settings($settings) {
337
- $settings = (array) $settings;
338
-
339
- $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
340
-
341
- if ( empty($settings['ID']) ) {
342
- unset($settings['ID']);
343
- }
344
-
345
- // delete all styling caches
346
- FrmAppHelper::cache_delete_group('frm_actions');
347
-
348
- // Remove the balanceTags filter in case WordPress is trying to validate the XHTML
349
- remove_filter( 'content_save_pre', 'balanceTags', 50 );
350
-
351
- return wp_insert_post($settings);
352
- }
353
-
354
- public function get_single_action( $id ) {
355
- $action = get_post($id);
356
- $action = $this->prepare_action($action);
357
- $this->_set($id);
358
- return $action;
359
- }
360
-
361
- public function get_one( $form_id ) {
362
- return $this->get_all($form_id, 1);
363
- }
364
-
365
- public function get_all( $form_id = false, $limit = 99 ) {
366
- if ( $form_id ) {
367
- $this->form_id = $form_id;
368
- }
369
-
370
- $type = $this->id_base;
371
-
372
- global $frm_vars;
373
- $frm_vars['action_type'] = $type;
374
-
375
- add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
376
- $query = array(
377
- 'post_type' => FrmFormActionsController::$action_post_type,
378
- 'post_status' => 'any',
379
- 'numberposts' => 99,
380
- 'order' => 'ASC',
381
- 'suppress_filters' => false,
382
- );
383
-
384
- if ( $form_id != 'all' ) {
385
- // allow actions for all forms
386
- $query['menu_order'] = $this->form_id;
387
- }
388
-
389
- $actions = get_posts( $query );
390
- unset($query);
391
-
392
- remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
393
-
394
- if ( empty($actions) ) {
395
- return array();
396
- }
397
-
398
- $settings = array();
399
- foreach ( $actions as $action ) {
400
- if ( count($settings) >= $limit ) {
401
- continue;
402
- }
403
-
404
- $action = $this->prepare_action($action);
405
-
406
- $settings[$action->ID] = $action;
407
- }
408
-
409
- if ( 1 === $limit ) {
410
- $settings = reset($settings);
411
- }
412
-
413
- return $settings;
414
- }
415
-
416
- public function prepare_action($action) {
417
- $action->post_content = FrmAppHelper::maybe_json_decode($action->post_content);
418
-
419
- $default_values = $this->get_global_defaults();
420
-
421
- // fill default values
422
- $action->post_content = wp_parse_args( $action->post_content, $default_values);
423
-
424
- foreach ( $default_values as $k => $vals ) {
425
- if ( is_array($vals) && ! empty($vals) ) {
426
- if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty($action->post_content[$k]) ) {
427
- continue;
428
- }
429
- $action->post_content[$k] = wp_parse_args($action->post_content[$k], $vals);
430
- }
431
- }
432
-
433
- if ( ! is_array($action->post_content['event']) ) {
434
- $action->post_content['event'] = explode(',', $action->post_content['event']);
435
- }
436
-
437
- return $action;
438
- }
439
-
440
- public function destroy($form_id = false, $type = 'default') {
441
- global $wpdb;
442
-
443
- $this->form_id = $form_id;
444
-
445
- $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
446
- if ( $form_id ) {
447
- $query['menu_order'] = $form_id;
448
- }
449
- if ( 'all' != $type ) {
450
- $query['post_excerpt'] = $this->id_base;
451
- }
452
-
453
- $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
454
-
455
- foreach ( $post_ids as $id ) {
456
- wp_delete_post($id);
457
- }
458
- }
459
-
460
- public function get_settings() {
461
- return FrmFormActionsHelper::get_action_for_form($this->form_id, $this->id_base);
462
- }
463
-
464
- public function get_global_defaults() {
465
- $defaults = $this->get_defaults();
466
-
467
- if ( ! isset($defaults['event']) ) {
468
- $defaults['event'] = array( 'create');
469
- }
470
-
471
- if ( ! isset($defaults['conditions']) ) {
472
- $defaults['conditions'] = array(
473
- 'send_stop' => '',
474
- 'any_all' => '',
475
- );
476
- }
477
-
478
- return $defaults;
479
- }
480
-
481
- public function get_global_switch_fields() {
482
- $switch = $this->get_switch_fields();
483
- $switch['conditions'] = array( 'hide_field');
484
- return $switch;
485
- }
486
-
487
- /**
488
- * Migrate settings from form->options into new action.
489
- */
490
- public function migrate_to_2($form, $update = 'update') {
491
- $action = $this->prepare_new($form->id);
492
- $form->options = maybe_unserialize($form->options);
493
-
494
- // fill with existing options
495
- foreach ( $action->post_content as $name => $val ) {
496
- if ( isset($form->options[$name]) ) {
497
- $action->post_content[$name] = $form->options[$name];
498
- unset($form->options[$name]);
499
- }
500
- }
501
-
502
- $action = $this->migrate_values($action, $form);
503
-
504
- // check if action already exists
505
- $post_id = get_posts( array(
506
- 'name' => $action->post_name,
507
- 'post_type' => FrmFormActionsController::$action_post_type,
508
- 'post_status' => $action->post_status,
509
- 'numberposts' => 1,
510
- ) );
511
-
512
- if ( empty($post_id) ) {
513
- // create action now
514
- $post_id = $this->save_settings($action);
515
- }
516
-
517
- if ( $post_id && 'update' == $update ) {
518
- global $wpdb;
519
- $form->options = maybe_serialize($form->options);
520
-
521
- // update form options
522
- $wpdb->update($wpdb->prefix .'frm_forms', array( 'options' => $form->options), array( 'id' => $form->id));
523
- wp_cache_delete( $form->id, 'frm_form');
524
- }
525
-
526
- return $post_id;
527
- }
528
-
529
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/models/FrmNotification.php CHANGED
@@ -1,368 +1,115 @@
1
  <?php
 
2
 
3
  class FrmNotification{
4
- public function __construct(){
5
- if ( ! defined('ABSPATH') ) {
6
- die('You are not allowed to call this page directly.');
7
- }
8
- add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
9
  }
10
-
11
- public static function trigger_email($action, $entry, $form) {
12
- if ( defined('WP_IMPORTING') ) {
13
- return;
14
- }
15
-
16
- global $wpdb;
17
-
18
- $notification = $action->post_content;
19
- $email_key = $action->ID;
20
-
21
- // Set the subject
22
- if ( empty($notification['email_subject']) ) {
23
- $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]');
24
- }
25
-
26
- $plain_text = $notification['plain_text'] ? true : false;
27
-
28
- //Filter these fields
29
- $filter_fields = array(
30
- 'email_to', 'cc', 'bcc',
31
- 'reply_to', 'from',
32
- 'email_subject', 'email_message',
33
- );
34
-
35
- add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
36
-
37
- //Get all values in entry in order to get User ID field ID
38
- $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' );
39
- $user_id_field = $user_id_key = '';
40
- foreach ( $values as $value ) {
41
- if ( $value->field_type == 'user_id' ) {
42
- $user_id_field = $value->field_id;
43
- $user_id_key = $value->field_key;
44
- break;
45
- }
46
- unset($value);
47
- }
48
-
49
- //Filter and prepare the email fields
50
- foreach ( $filter_fields as $f ) {
51
- //Don't allow empty From
52
- if ( $f == 'from' && empty($notification[$f]) ) {
53
- $notification[$f] = '[admin_email]';
54
- } else if ( in_array($f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from')) ) {
55
- //Remove brackets
56
- //Add a space in case there isn't one
57
- $notification[$f] = str_replace('<', ' ', $notification[$f]);
58
- $notification[$f] = str_replace( array( '"', '>'), '', $notification[$f]);
59
-
60
- //Switch userID shortcode to email address
61
- if ( strpos($notification[$f], '[' . $user_id_field . ']' ) !== false || strpos($notification[$f], '[' . $user_id_key . ']' ) !== false ) {
62
- $user_data = get_userdata($entry->metas[$user_id_field]);
63
- $user_email = $user_data->user_email;
64
- $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] );
65
- }
66
- }
67
-
68
- $notification[$f] = FrmFieldsHelper::basic_replace_shortcodes($notification[$f], $form, $entry);
69
- }
70
-
71
- //Put recipients, cc, and bcc into an array if they aren't empty
72
- $to_emails = ( ! empty( $notification['email_to'] ) ? preg_split( '/(,|;)/', $notification['email_to'] ) : '' );
73
- $cc = ( ! empty( $notification['cc'] ) ? preg_split( '/(,|;)/', $notification['cc'] ) : '' );
74
- $bcc = ( ! empty( $notification['bcc'] ) ? preg_split( '/(,|;)/', $notification['bcc'] ) : '' );
75
-
76
- $to_emails = apply_filters('frm_to_email', $to_emails, array(), $form->id, compact('email_key', 'entry', 'form'));
77
-
78
- // Stop now if there aren't any recipients
79
- if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
80
- return;
81
- }
82
-
83
- $to_emails = array_unique( (array) $to_emails );
84
-
85
- $prev_mail_body = $mail_body = $notification['email_message'];
86
  $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
87
  'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
88
  'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
89
  ) );
90
-
91
- // Add the user info if it isn't already included
92
- if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
93
- $data = maybe_unserialize($entry->description);
94
- $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n";
95
- $mail_body .= __( 'IP Address', 'formidable' ) . ': '. $entry->ip ."\r\n";
96
- $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': '. FrmEntriesHelper::get_browser($data['browser']) ."\r\n";
97
- $mail_body .= __( 'Referrer', 'formidable' ) . ': '. $data['referrer']."\r\n";
98
- }
99
- unset($prev_mail_body);
100
-
101
- // Add attachments
102
- $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
103
-
104
- if ( ! empty($notification['email_subject']) ) {
105
- $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
106
- }
107
-
108
- // check for a phone number
109
- foreach ( (array) $to_emails as $email_key => $e ) {
110
- $e = trim($e);
111
- if ( $e != '[admin_email]' && ! is_email($e) ) {
112
- $e = explode(' ', $e);
113
-
114
- //If to_email has name <test@mail.com> format
115
- if ( is_email(end($e)) ) {
116
- continue;
117
- }
118
-
119
- do_action('frm_send_to_not_email', array(
120
- 'e' => $e,
121
- 'subject' => $notification['email_subject'],
122
- 'mail_body' => $mail_body,
123
- 'reply_to' => $notification['reply_to'],
124
- 'from' => $notification['from'],
125
- 'plain_text' => $plain_text,
126
- 'attachments' => $attachments,
127
- 'form' => $form,
128
- 'email_key' => $email_key,
129
- ) );
130
-
131
- unset($to_emails[$email_key]);
132
- }
133
- }
134
-
135
- // Send the email now
136
- $sent_to = self::send_email( array(
137
- 'to_email' => $to_emails,
138
- 'subject' => $notification['email_subject'],
139
- 'message' => $mail_body,
140
- 'from' => $notification['from'],
141
- 'plain_text' => $plain_text,
142
- 'reply_to' => $notification['reply_to'],
143
- 'attachments' => $attachments,
144
- 'cc' => $cc,
145
- 'bcc' => $bcc,
146
- ) );
147
-
148
- return $sent_to;
149
- }
150
-
151
- public function entry_created($entry_id, $form_id) {
152
- _deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", '. $form_id .', '. $entry_id .', "email")');
153
- FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
154
- }
155
-
156
- public function send_notification_email($to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '') {
157
- _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
158
-
159
- return self::send_email(compact(
160
- 'to_email', 'subject', 'message',
161
- 'from', 'from_name', 'plain_text',
162
- 'attachments', 'reply_to'
163
- ));
164
- }
165
-
166
- /**
167
- * Put To, BCC, CC, Reply To, and From fields in Name <test@mail.com> format
168
- * Formats that should work: Name, "Name", test@mail.com, <test@mail.com>, Name <test@mail.com>,
169
- * "Name" <test@mail.com>, Name test@mail.com, "Name" test@mail.com, Name<test@mail.com>, "Name"<test@mail.com>
170
- * "First Last" <test@mail.com>
171
- *
172
- * Things that won't work: First Last (with no email entered)
173
- * @since 2.0
174
- * @param array $atts array of email fields, pass by reference
175
- * @param $admin_email
176
- */
177
- private static function format_email_fields( &$atts, $admin_email ) {
178
-
179
- // If from is empty or is set to admin_email, set it now
180
- $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
181
-
182
- // Filter values in these fields
183
- $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' );
184
-
185
- foreach ( $filter_fields as $f ) {
186
- // If empty, just skip it
187
- if ( empty($atts[$f]) ) {
188
- continue;
189
- }
190
-
191
- // to_email, cc, and bcc can be an array
192
- if ( is_array($atts[$f]) ) {
193
- foreach ( $atts[$f] as $key => $val ) {
194
- self::format_single_field( $atts, $f, $val, $key );
195
- unset( $key, $val );
196
- }
197
- unset($f);
198
- continue;
199
- }
200
-
201
- self::format_single_field( $atts, $f, $atts[$f] );
202
- }
203
-
204
- // If reply-to isn't set, make it match the from settings
205
- if ( empty( $atts['reply_to'] ) ) {
206
- $atts['reply_to'] = $atts['from'];
207
  }
208
-
209
- if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
210
- $atts['to_email'] = $admin_email;
 
211
  }
212
  }
213
-
214
- /**
215
- * Format individual email fields
216
- *
217
- * @since 2.0
218
- * @param array $atts pass by reference
219
- * @param string $f (to, from, reply_to, etc)
220
- * @param string $val value saved in field
221
- * @param int $key if in array, this will be set
222
- */
223
- private static function format_single_field( &$atts, $f, $val, $key = false ) {
224
- $val = trim($val);
225
-
226
- // If just a plain email is used
227
- if ( is_email($val) ) {
228
- // add sender's name if not included in $from
229
- if ( $f == 'from' ) {
230
- $part_2 = $atts[$f];
231
- $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
232
- } else {
233
- return;
234
- }
235
- } else {
236
- $parts = explode(' ', $val);
237
- $part_2 = end($parts);
238
-
239
- // If inputted correcly, $part_2 should be an email
240
- if ( is_email( $part_2 ) ) {
241
- $part_1 = trim( str_replace( $part_2, '', $val ) );
242
- } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) {
243
- // In case someone just puts a name in the From or Reply To field
244
- $part_1 = $part_2;
245
- $part_2 = get_option('admin_email');
246
- } else {
247
- // In case someone just puts a name in any other email field
248
- if ( false !== $key ) {
249
- unset( $atts[$f][$key] );
250
- return;
251
- }
252
- $atts[$f] = '';
253
- return;
254
- }
255
- }
256
-
257
- // Set up formatted value
258
- $final_val = $part_1 . ' <'. $part_2 .'>';
259
- $final_val = str_replace('"', '', $final_val);
260
-
261
- // If value is an array
262
- if ( false !== $key ) {
263
- $atts[$f][$key] = $final_val;
264
- return;
265
- }
266
- $atts[$f] = $final_val;
267
- }
268
-
269
- public static function send_email($atts) {
270
- $admin_email = get_option('admin_email');
271
- $defaults = array(
272
- 'to_email' => $admin_email,
273
- 'subject' => '',
274
- 'message' => '',
275
- 'from' => $admin_email,
276
- 'from_name' => '',
277
- 'cc' => '',
278
- 'bcc' => '',
279
- 'plain_text' => true,
280
- 'reply_to' => $admin_email,
281
- 'attachments' => array(),
282
- );
283
- $atts = wp_parse_args($atts, $defaults);
284
-
285
- // Put To, BCC, CC, Reply To, and From fields in the correct format
286
- self::format_email_fields( $atts, $admin_email );
287
-
288
- $recipient = $atts['to_email']; //recipient
289
- $header = array();
290
- $header[] = 'From: ' . $atts['from'];
291
-
292
- //Allow for cc and bcc arrays
293
- $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc']);
294
- foreach ( $array_fields as $key => $a_field ) {
295
- if ( empty($a_field) ) {
296
- continue;
297
- }
298
- if ( is_array($a_field ) ) {
299
- foreach ( $a_field as $email ) {
300
- $header[] = $key . ': ' . $email;
301
- }
302
- } else {
303
- $header[] = $key . ': ' . $a_field;
304
- }
305
- unset($key, $a_field);
306
- }
307
-
308
- $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html';
309
  $charset = get_option('blog_charset');
310
-
311
- $header[] = 'Reply-To: '. $atts['reply_to'];
 
 
312
  $header[] = 'Content-Type: '. $content_type .'; charset="'. $charset . '"';
313
- $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES );
314
-
315
- $message = do_shortcode($atts['message']);
316
-
317
- if ( $atts['plain_text'] ) {
318
- $message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars
319
  $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
320
- } else {
321
- // remove line breaks in HTML emails to prevent conflicts with Mandrill
322
- add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
323
- }
324
 
325
- $header = apply_filters('frm_email_header', $header, array(
326
- 'to_email' => $atts['to_email'], 'subject' => $atts['subject'],
327
- ) );
328
-
329
- if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) {
330
- $atts['subject'] = '=?'. $charset .'?B?'. base64_encode($atts['subject']) .'?=';
331
  }
332
-
333
  remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
334
  remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
335
-
336
- $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']);
337
- if ( ! $sent ) {
338
- $header = 'From: '. $atts['from'] ."\r\n";
339
- $recipient = implode(',', (array) $recipient);
340
- $sent = mail($recipient, $atts['subject'], $message, $header);
341
  }
342
 
343
- // remove the filter now so other emails can still use it
344
- remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
345
-
346
- do_action('frm_notification', $recipient, $atts['subject'], $message);
347
-
348
- if ( $sent ) {
349
- $sent_to = array_merge( (array)$atts['to_email'], (array) $atts['cc'], (array) $atts['bcc']);
350
- $sent_to = array_filter( $sent_to );
351
- if ( apply_filters('frm_echo_emails', false) ) {
352
- $temp = str_replace('<', '&lt;', $sent_to);
353
- echo implode(', ', (array) $temp);
354
- }
355
- return $sent_to;
356
- }
357
  }
358
 
359
- /**
360
- * This function should only be fired when Mandrill is sending an HTML email
361
- * This will make sure Mandrill doesn't mess with our HTML emails
362
- *
363
- * @since 2.0
364
- */
365
- public static function remove_mandrill_br() {
366
- return false;
367
- }
368
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
  class FrmNotification{
5
+ function __construct(){
6
+ add_action('frm_after_create_entry', array(&$this, 'entry_created'), 10, 2);
 
 
 
7
  }
8
+
9
+ function entry_created($entry_id, $form_id){
10
+ if (apply_filters('frm_stop_standard_email', false, $entry_id)) return;
11
+ global $frm_entry, $frm_entry_meta;
12
+
13
+ $entry = $frm_entry->getOne($entry_id, true);
14
+ $frm_form = new FrmForm();
15
+ $form = $frm_form->getOne($form_id);
16
+ $values = $frm_entry_meta->getAll("it.item_id = $entry_id", " ORDER BY fi.field_order");
17
+
18
+
19
+ if(isset($form->options['notification']))
20
+ $notification = reset($form->options['notification']);
21
+ else
22
+ $notification = $form->options;
23
+
24
+ // Set the from and to email names and addresses
25
+ $to_email = $notification['email_to'];
26
+ if ( empty($to_email) ) {
27
+ $to_email = '[admin_email]';
28
+ }
29
+
30
+ $to_emails = explode(',', $to_email);
31
+
32
+ $reply_to = $reply_to_name = '';
33
+
34
+ foreach ($values as $value) {
35
+ $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
36
+ if (is_array($val))
37
+ $val = implode(', ', $val);
38
+
39
+ if(isset($notification['reply_to']) and (int)$notification['reply_to'] == $value->field_id and is_email($val))
40
+ $reply_to = $val;
41
+
42
+ if(isset($notification['reply_to_name']) and (int)$notification['reply_to_name'] == $value->field_id)
43
+ $reply_to_name = $val;
44
+ }
45
+
46
+
47
+ if ( empty($reply_to) && $notification['reply_to'] == 'custom' ) {
48
+ $reply_to = $notification['cust_reply_to'];
49
+ }
50
+
51
+ if ( empty($reply_to_name) && $notification['reply_to_name'] == 'custom' ){
52
+ $reply_to_name = $notification['cust_reply_to_name'];
53
+ }
54
+
55
+ // Set the email message
56
+ $plain_text = (isset($notification['plain_text']) && $notification['plain_text']) ? true : false;
57
+ $mail_body = isset($notification['email_message']) ? $notification['email_message'] : '';
58
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
60
  'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
61
  'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
62
  ) );
63
+
64
+ // Set the subject
65
+ $subject = isset($notification['email_subject']) ? $notification['email_subject'] : '';
66
+ if ( empty($subject) ) {
67
+ $frm_blogname = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES );
68
+ $subject = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), $form->name, $frm_blogname);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
+
71
+ // Send the emails now
72
+ foreach ( (array) $to_emails as $to_email) {
73
+ $this->send_notification_email(trim($to_email), $subject, $mail_body, $reply_to, $reply_to_name, $plain_text);
74
  }
75
  }
76
+
77
+ function send_notification_email($to_email, $subject, $message, $reply_to='', $reply_to_name='', $plain_text=true, $attachments=array()){
78
+ $content_type = ($plain_text) ? 'text/plain' : 'text/html';
79
+ $reply_to_name = ($reply_to_name == '') ? wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ) : $reply_to_name; //senders name
80
+ $reply_to = ($reply_to == '' or $reply_to == '[admin_email]') ? get_option('admin_email') : $reply_to; //senders e-mail address
81
+
82
+ if($to_email == '[admin_email]')
83
+ $to_email = get_option('admin_email');
84
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  $charset = get_option('blog_charset');
86
+ $recipient = $to_email; //recipient
87
+ $header = array();
88
+ $header[] = 'From: "'. $reply_to_name .'" <'. $reply_to .'>';
89
+ $header[] = 'Reply-To: '. $reply_to;
90
  $header[] = 'Content-Type: '. $content_type .'; charset="'. $charset . '"';
91
+ $subject = wp_specialchars_decode(strip_tags(stripslashes($subject)), ENT_QUOTES );
92
+
93
+ $message = do_shortcode($message);
94
+ $message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars
95
+ if($plain_text)
 
96
  $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
 
 
 
 
97
 
98
+ $header = apply_filters('frm_email_header', $header, compact('to_email', 'subject'));
99
+
100
+ if ( apply_filters('frm_encode_subject', 1, $subject ) ) {
101
+ $subject = '=?'. $charset .'?B?'. base64_encode($subject) .'?=';
 
 
102
  }
103
+
104
  remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
105
  remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
106
+
107
+ if (!wp_mail($recipient, $subject, $message, $header, $attachments)){
108
+ $header = 'From: "'. $reply_to_name .'" <'. $reply_to .'>'. "\r\n";
109
+ mail($recipient, $subject, $message, $header);
 
 
110
  }
111
 
112
+ do_action('frm_notification', $recipient, $subject, $message);
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  }
114
 
 
 
 
 
 
 
 
 
 
115
  }
classes/models/FrmSettings.php CHANGED
@@ -1,250 +1,158 @@
1
  <?php
 
2
 
3
- class FrmSettings{
4
- public $option_name = 'frm_options';
5
- public $menu;
6
- public $mu_menu;
7
- public $preview_page_id;
8
- public $lock_keys;
9
- public $use_html;
10
- public $jquery_css;
11
- public $accordion_js;
12
-
13
- public $success_msg;
14
- public $blank_msg;
15
- public $unique_msg;
16
- public $invalid_msg;
17
- public $failed_msg;
18
- public $submit_value;
19
- public $login_msg;
20
- public $admin_permission;
21
-
22
- public $email_to;
23
- public $load_style;
24
- public $custom_style;
25
-
26
- public $pubkey;
27
- public $privkey;
28
- public $re_lang;
29
- public $re_msg;
30
-
31
- public function __construct() {
32
- if ( ! defined('ABSPATH') ) {
33
- die('You are not allowed to call this page directly.');
34
- }
35
-
36
- $settings = get_transient($this->option_name);
37
 
38
- if ( ! is_object($settings) ) {
39
- $settings = $this->translate_settings($settings);
40
- }
41
-
42
- foreach ( $settings as $setting_name => $setting ) {
43
- $this->{$setting_name} = $setting;
44
- unset($setting_name, $setting);
45
- }
46
 
 
47
  $this->set_default_options();
48
  }
49
-
50
- private function translate_settings($settings) {
51
- if ( $settings ) { //workaround for W3 total cache conflict
52
- return unserialize(serialize($settings));
53
- }
54
-
55
- $settings = get_option($this->option_name);
56
- if ( is_object($settings) ) {
57
- set_transient($this->option_name, $settings);
58
- return $settings;
59
- }
60
-
61
- // If unserializing didn't work
62
- if ( $settings ) { //workaround for W3 total cache conflict
63
- $settings = unserialize(serialize($settings));
64
- } else {
65
- $settings = $this;
66
- }
67
-
68
- update_option($this->option_name, $settings);
69
- set_transient($this->option_name, $settings);
70
-
71
- return $settings;
72
- }
73
-
74
- /**
75
- * @return array
76
- */
77
- public function default_options(){
78
  return array(
79
  'menu' => 'Formidable',
80
  'mu_menu' => 0,
81
  'preview_page_id' => 0,
82
  'lock_keys' => false,
 
83
  'use_html' => true,
84
  'jquery_css' => false,
85
  'accordion_js' => false,
86
-
87
- 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
88
- 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
89
- 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
90
- 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
91
- 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
92
- 'submit_value' => __( 'Submit', 'formidable' ),
93
- 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
94
- 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
95
-
96
  'email_to' => '[admin_email]',
97
  );
98
  }
99
 
100
- private function set_default_options(){
101
- $this->fill_recaptcha_settings();
102
-
103
- if ( ! isset($this->load_style) ) {
104
- if ( ! isset($this->custom_style) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  $this->custom_style = true;
106
- }
107
-
108
- $this->load_style = 'all';
 
109
  }
110
-
111
- $this->fill_with_defaults();
112
-
113
- if ( is_multisite() && is_admin() ) {
 
 
 
 
 
 
 
114
  $mu_menu = get_site_option('frm_admin_menu_name');
115
- if ( $mu_menu && ! empty($mu_menu) ) {
116
  $this->menu = $mu_menu;
117
  $this->mu_menu = 1;
118
  }
119
  }
120
-
121
  $frm_roles = FrmAppHelper::frm_capabilities('pro');
122
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
123
- if ( ! isset($this->$frm_role) ) {
124
  $this->$frm_role = 'administrator';
125
- }
126
- }
127
- }
128
-
129
- public function fill_with_defaults($params = array()) {
130
- $settings = $this->default_options();
131
-
132
- foreach ( $settings as $setting => $default ) {
133
- if ( isset($params['frm_'. $setting]) ) {
134
- $this->{$setting} = $params['frm_'. $setting];
135
- } else if ( ! isset($this->{$setting}) ) {
136
- $this->{$setting} = $default;
137
- }
138
- unset($setting, $default);
139
  }
140
  }
141
 
142
- private function fill_recaptcha_settings() {
143
- $privkey = '';
144
- $re_lang = 'en';
145
-
146
- if ( ! isset($this->pubkey) ) {
147
- // get the options from the database
148
- $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
149
- $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
150
- $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
151
- $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
152
- }
153
-
154
- if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
155
- $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
156
- }
157
-
158
- if ( ! isset($this->privkey) ) {
159
- $this->privkey = $privkey;
160
- }
161
-
162
- if ( ! isset($this->re_lang) ) {
163
- $this->re_lang = $re_lang;
164
- }
165
- }
166
-
167
- public function validate( $params, $errors ) {
168
  $errors = apply_filters( 'frm_validate_settings', $errors, $params );
169
  return $errors;
170
  }
171
 
172
- public function update($params){
173
- $this->fill_with_defaults($params);
174
- $this->update_settings($params);
175
-
176
  if ( $this->mu_menu ) {
177
  update_site_option('frm_admin_menu_name', $this->menu);
178
  } else if ( current_user_can('administrator') ) {
179
  update_site_option('frm_admin_menu_name', false);
180
  }
181
-
182
- $this->update_roles($params);
183
-
184
- do_action( 'frm_update_settings', $params );
185
- }
186
-
187
- private function update_settings($params) {
188
- $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
189
-
190
  $this->pubkey = trim($params['frm_pubkey']);
191
  $this->privkey = $params['frm_privkey'];
 
192
  $this->re_lang = $params['frm_re_lang'];
193
-
 
 
 
 
 
 
 
 
 
 
194
  $this->load_style = $params['frm_load_style'];
195
- $this->preview_page_id = (int) $params['frm-preview-page-id'];
196
  $this->lock_keys = isset($params['frm_lock_keys']) ? $params['frm_lock_keys'] : 0;
197
-
 
198
  $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
199
  //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
 
200
  $this->jquery_css = isset($params['frm_jquery_css']) ? $params['frm_jquery_css'] : 0;
201
  $this->accordion_js = isset($params['frm_accordion_js']) ? $params['frm_accordion_js'] : 0;
202
- }
203
-
204
- private function update_roles($params) {
205
  //update roles
206
- global $wp_roles;
207
-
208
  $frm_roles = FrmAppHelper::frm_capabilities();
209
  $roles = get_editable_roles();
210
- foreach ( $frm_roles as $frm_role => $frm_role_description ) {
211
- $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
212
-
213
- if ( count($this->$frm_role) === 1 ) {
214
- $set_role = reset($this->$frm_role);
215
- switch ( $set_role ) {
216
- case 'subscriber':
217
- array_push($this->$frm_role, 'contributor');
218
- case 'contributor':
219
- array_push($this->$frm_role, 'author');
220
- case 'author':
221
- array_push($this->$frm_role, 'editor');
222
- case 'editor':
223
- array_push($this->$frm_role, 'administrator');
224
- }
225
- unset($set_role);
226
- }
227
-
228
- foreach ( $roles as $role => $details ) {
229
- if ( in_array($role, $this->$frm_role) ) {
230
- $wp_roles->add_cap( $role, $frm_role );
231
- } else {
232
  $wp_roles->remove_cap( $role, $frm_role );
233
- }
234
- unset($role, $details);
235
- }
236
  }
 
 
237
  }
238
 
239
- public function store(){
240
  // Save the posted value in the database
241
 
242
  update_option('frm_options', $this);
243
-
244
  delete_transient('frm_options');
245
  set_transient('frm_options', $this);
246
 
247
  do_action( 'frm_store_settings' );
248
  }
249
-
250
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
 
4
+ if(class_exists('FrmSettings'))
5
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ class FrmSettings{
 
 
 
 
 
 
 
8
 
9
+ function __construct(){
10
  $this->set_default_options();
11
  }
12
+
13
+ function default_options(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  return array(
15
  'menu' => 'Formidable',
16
  'mu_menu' => 0,
17
  'preview_page_id' => 0,
18
  'lock_keys' => false,
19
+ 'track' => false,
20
  'use_html' => true,
21
  'jquery_css' => false,
22
  'accordion_js' => false,
23
+
24
+ 'success_msg' => __('Your responses were successfully submitted. Thank you!', 'formidable'),
25
+ 'blank_msg' => __('This field cannot be blank.', 'formidable'),
26
+ 'unique_msg' => __('This value must be unique.', 'formidable'),
27
+ 'invalid_msg' => __('There was a problem with your submission. Errors are marked below.', 'formidable'),
28
+ 'failed_msg' => __('We\'re sorry. It looks like you\'ve already submitted that.', 'formidable'),
29
+ 'submit_value' => __('Submit', 'formidable'),
30
+ 'login_msg' => __('You do not have permission to view this form.', 'formidable'),
31
+ 'admin_permission' => __('You do not have permission to do that', 'formidable'),
32
+
33
  'email_to' => '[admin_email]',
34
  );
35
  }
36
 
37
+ function set_default_options(){
38
+ if(!isset($this->pubkey)){
39
+ $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); // get the options from the database
40
+
41
+ $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
42
+ }
43
+
44
+ if(!isset($this->privkey))
45
+ $this->privkey = (isset($recaptcha_opt) and isset($recaptcha_opt['privkey'])) ? $recaptcha_opt['privkey'] : '';
46
+
47
+ if(!isset($this->re_theme))
48
+ $this->re_theme = (isset($recaptcha_opt) and isset($recaptcha_opt['re_theme'])) ? $recaptcha_opt['re_theme'] : 'red';
49
+
50
+ if(!isset($this->re_lang))
51
+ $this->re_lang = (isset($recaptcha_opt) and isset($recaptcha_opt['re_lang'])) ? $recaptcha_opt['re_lang'] : 'en';
52
+
53
+ if(!isset($this->re_msg) or empty($this->re_msg))
54
+ $this->re_msg = __('The reCAPTCHA was not entered correctly', 'formidable');
55
+
56
+ if(!isset($this->load_style)){
57
+ if(!isset($this->custom_style))
58
  $this->custom_style = true;
59
+ if(!isset($this->custom_stylesheet))
60
+ $this->custom_stylesheet = false;
61
+
62
+ $this->load_style = ($this->custom_stylesheet) ? 'none' : 'all';
63
  }
64
+
65
+ $settings = $this->default_options();
66
+
67
+ foreach($settings as $setting => $default){
68
+ if(!isset($this->{$setting}))
69
+ $this->{$setting} = $default;
70
+ unset($setting);
71
+ unset($default);
72
+ }
73
+
74
+ if(is_multisite() and is_admin()){
75
  $mu_menu = get_site_option('frm_admin_menu_name');
76
+ if($mu_menu and !empty($mu_menu)){
77
  $this->menu = $mu_menu;
78
  $this->mu_menu = 1;
79
  }
80
  }
81
+
82
  $frm_roles = FrmAppHelper::frm_capabilities('pro');
83
+ foreach($frm_roles as $frm_role => $frm_role_description){
84
+ if(!isset($this->$frm_role))
85
  $this->$frm_role = 'administrator';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
  }
88
 
89
+ function validate($params,$errors){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  $errors = apply_filters( 'frm_validate_settings', $errors, $params );
91
  return $errors;
92
  }
93
 
94
+ function update($params){
95
+ global $wp_roles;
96
+
97
+ $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
98
  if ( $this->mu_menu ) {
99
  update_site_option('frm_admin_menu_name', $this->menu);
100
  } else if ( current_user_can('administrator') ) {
101
  update_site_option('frm_admin_menu_name', false);
102
  }
103
+
 
 
 
 
 
 
 
 
104
  $this->pubkey = trim($params['frm_pubkey']);
105
  $this->privkey = $params['frm_privkey'];
106
+ $this->re_theme = $params['frm_re_theme'];
107
  $this->re_lang = $params['frm_re_lang'];
108
+
109
+ $settings = $this->default_options();
110
+
111
+ foreach($settings as $setting => $default){
112
+ if(isset($params['frm_'. $setting]))
113
+ $this->{$setting} = $params['frm_'. $setting];
114
+
115
+ unset($setting);
116
+ unset($default);
117
+ }
118
+
119
  $this->load_style = $params['frm_load_style'];
120
+ $this->preview_page_id = (int)$params['frm-preview-page-id'];
121
  $this->lock_keys = isset($params['frm_lock_keys']) ? $params['frm_lock_keys'] : 0;
122
+ $this->track = isset($params['frm_track']) ? $params['frm_track'] : 0;
123
+
124
  $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
125
  //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
126
+ //$this->custom_stylesheet = isset($params['frm_custom_stylesheet']) ? $params['frm_custom_stylesheet'] : 0;
127
  $this->jquery_css = isset($params['frm_jquery_css']) ? $params['frm_jquery_css'] : 0;
128
  $this->accordion_js = isset($params['frm_accordion_js']) ? $params['frm_accordion_js'] : 0;
129
+
 
 
130
  //update roles
 
 
131
  $frm_roles = FrmAppHelper::frm_capabilities();
132
  $roles = get_editable_roles();
133
+ foreach($frm_roles as $frm_role => $frm_role_description){
134
+ $this->$frm_role = isset($params[$frm_role]) ? $params[$frm_role] : 'administrator';
135
+
136
+ foreach ($roles as $role => $details){
137
+ if($this->$frm_role == $role or ($this->$frm_role == 'editor' and $role == 'administrator') or ($this->$frm_role == 'author' and in_array($role, array('administrator', 'editor'))) or ($this->$frm_role == 'contributor' and in_array($role, array('administrator', 'editor', 'author'))) or $this->$frm_role == 'subscriber')
138
+ $wp_roles->add_cap( $role, $frm_role );
139
+ else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  $wp_roles->remove_cap( $role, $frm_role );
141
+ }
 
 
142
  }
143
+
144
+ do_action( 'frm_update_settings', $params );
145
  }
146
 
147
+ function store(){
148
  // Save the posted value in the database
149
 
150
  update_option('frm_options', $this);
151
+
152
  delete_transient('frm_options');
153
  set_transient('frm_options', $this);
154
 
155
  do_action( 'frm_store_settings' );
156
  }
157
+
158
  }
classes/models/FrmStyle.php DELETED
@@ -1,437 +0,0 @@
1
- <?php
2
- class FrmStyle{
3
- public $number = false; // Unique ID number of the current instance.
4
- public $id = 0; // the id of the post
5
-
6
- /**
7
- * @param int|string $id The id of the stylsheet or 'default'
8
- */
9
- public function __construct( $id = 0 ) {
10
- $this->id = $id;
11
- }
12
-
13
- public function get_new() {
14
- $this->id = 0;
15
-
16
- $max_slug_value = pow(36, 6);
17
- $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
- $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
19
-
20
- $style = array(
21
- 'post_type' => FrmStylesController::$post_type,
22
- 'ID' => '',
23
- 'post_title' => __( 'New Style', 'formidable' ),
24
- 'post_name' => $key,
25
- 'post_content' => $this->get_defaults(),
26
- 'menu_order' => '',
27
- 'post_status' => 'publish',
28
- );
29
-
30
- return (object) $style;
31
- }
32
-
33
- public function save($settings) {
34
- $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
35
-
36
- if ( empty($settings['ID']) ) {
37
- unset($settings['ID']);
38
- }
39
-
40
- // delete all styling caches
41
- FrmAppHelper::cache_delete_group('frm_styles');
42
-
43
- return wp_insert_post($settings);
44
- }
45
-
46
- public function duplicate($id) {
47
- // duplicating is a pro feature
48
- }
49
-
50
- public function update( $id = 'default' ) {
51
- $all_instances = $this->get_all();
52
-
53
- if ( empty($id) ) {
54
- $new_style = (array) $this->get_new();
55
- $all_instances[] = $new_style;
56
- }
57
-
58
- $action_ids = array();
59
-
60
- foreach ( $all_instances as $number => $new_instance ) {
61
- $new_instance = stripslashes_deep( (array) $new_instance);
62
- $this->id = $new_instance['ID'];
63
- if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
64
- $all_instances[$number] = $new_instance;
65
-
66
- if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
67
- // this style was set to default, so remove default setting on previous default style
68
- $new_instance['menu_order'] = 0;
69
- $action_ids[] = $this->save($new_instance);
70
- }
71
-
72
- // don't continue if not saving this style
73
- continue;
74
- }
75
-
76
- $new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
77
- $new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
78
- $new_instance['post_type'] = FrmStylesController::$post_type;
79
- $new_instance['post_status'] = 'publish';
80
- $new_instance['menu_order'] = isset($_POST['frm_style_setting']['menu_order']) ? (int) $_POST['frm_style_setting']['menu_order'] : 0;
81
-
82
- if ( empty($id) ) {
83
- $new_instance['post_name'] = $new_instance['post_title'];
84
- }
85
-
86
- $default_settings = $this->get_defaults();
87
-
88
- foreach ( $default_settings as $setting => $default ) {
89
- if ( strpos($setting, 'color') !== false || in_array($setting, array( 'error_bg', 'error_border', 'error_text')) ) {
90
- //if is a color
91
- $new_instance['post_content'][$setting] = str_replace('#', '', $new_instance['post_content'][$setting]);
92
- } else if ( in_array($setting, array( 'submit_style', 'important_style', 'auto_width')) && ! isset($new_instance['post_content'][$setting]) ) {
93
- $new_instance['post_content'][$setting] = 0;
94
- }
95
- }
96
-
97
- $all_instances[$number] = $new_instance;
98
-
99
- $action_ids[] = $this->save($new_instance);
100
-
101
- }
102
-
103
- $this->save_settings($all_instances);
104
-
105
- return $action_ids;
106
- }
107
-
108
- /**
109
- * Create static css file
110
- */
111
- public function save_settings($styles) {
112
- $filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php';
113
-
114
- if ( ! is_file($filename) ) {
115
- return;
116
- }
117
-
118
- $defaults = $this->get_defaults();
119
- $uploads = wp_upload_dir();
120
- $target_path = $uploads['basedir'] .'/formidable';
121
- $needed_dirs = array( $target_path, $target_path .'/css' );
122
- $dirs_exist = true;
123
-
124
- $saving = true;
125
- $css = '/* '. __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) .' */'. "\n";
126
-
127
- ob_start();
128
- $frm_style = $this;
129
- include($filename);
130
- $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) );
131
- ob_end_clean();
132
-
133
- $access_type = get_filesystem_method();
134
- if ( $access_type === 'direct' ) {
135
- $creds = request_filesystem_credentials( site_url() .'/wp-admin/', '', false, false, array() );
136
-
137
- // initialize the API
138
- if ( ! WP_Filesystem($creds) ) {
139
- // any problems and we exit
140
- $dirs_exist = false;
141
- }
142
-
143
- global $wp_filesystem;
144
-
145
- if ( $dirs_exist ) {
146
- $chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
147
- $chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
148
-
149
- // Create the directories if need be:
150
- foreach ( $needed_dirs as $_dir ) {
151
- // Only check to see if the Dir exists upon creation failure. Less I/O this way.
152
- if ( ! $wp_filesystem->mkdir( $_dir, $chmod_dir ) && ! $wp_filesystem->is_dir( $_dir ) ) {
153
- $dirs_exist = false;
154
- }
155
- }
156
-
157
- $index_path = $target_path .'/index.php';
158
- $wp_filesystem->put_contents( $index_path, "<?php\n// Silence is golden.\n?>", $chmod_file );
159
-
160
- // only write the file if the folders exist
161
- if ( $dirs_exist ) {
162
- $css_file = $target_path .'/css/formidablepro.css';
163
- $wp_filesystem->put_contents( $css_file, $css, $chmod_file );
164
- }
165
- }
166
- }
167
-
168
- update_option('frmpro_css', $css);
169
-
170
- delete_transient('frmpro_css');
171
- set_transient('frmpro_css', $css);
172
- }
173
-
174
- public function destroy($id) {
175
- return wp_delete_post($id);
176
- }
177
-
178
- public function get_one() {
179
- if ( 'default' == $this->id ) {
180
- $style = $this->get_default_style();
181
- if ( $style ) {
182
- $this->id = $style->ID;
183
- } else {
184
- $this->id = 0;
185
- }
186
- return $style;
187
- }
188
-
189
- $style = get_post($this->id);
190
-
191
- if ( ! $style ) {
192
- return $style;
193
- }
194
-
195
- $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
196
-
197
- $default_values = $this->get_defaults();
198
-
199
- // fill default values
200
- $style->post_content = $this->override_defaults($style->post_content);
201
- $style->post_content = wp_parse_args( $style->post_content, $default_values);
202
-
203
- return $style;
204
- }
205
-
206
- public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
207
- $post_atts = array(
208
- 'post_type' => FrmStylesController::$post_type,
209
- 'post_status' => 'publish',
210
- 'numberposts' => $limit,
211
- 'orderby' => $orderby,
212
- 'order' => $order,
213
- );
214
-
215
- $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts');
216
-
217
- if ( empty($temp_styles) ) {
218
- global $wpdb;
219
- // make sure there wasn't a conflict with the query
220
- $query = $wpdb->prepare('SELECT * FROM '. $wpdb->posts .' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish');
221
- $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
222
-
223
- if ( empty($temp_styles) ) {
224
- // create a new style if there are none
225
- $new = $this->get_new();
226
- $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' );
227
- $new->menu_order = 1;
228
- $new = $this->save( (array) $new);
229
- $this->update('default');
230
-
231
- $post_atts['include'] = $new;
232
-
233
- $temp_styles = get_posts( $post_atts );
234
- }
235
- }
236
-
237
- $default_values = $this->get_defaults();
238
- $default_style = false;
239
-
240
- $styles = array();
241
- foreach ( $temp_styles as $style ) {
242
- $this->id = $style->ID;
243
- if ( $style->menu_order ) {
244
- if ( $default_style ) {
245
- // only return one default
246
- $style->menu_order = 0;
247
- } else {
248
- // check for a default style
249
- $default_style = $style->ID;
250
- }
251
- }
252
-
253
- $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
254
-
255
- // fill default values
256
- $style->post_content = $this->override_defaults($style->post_content);
257
- $style->post_content = wp_parse_args( $style->post_content, $default_values);
258
-
259
- $styles[$style->ID] = $style;
260
- }
261
-
262
- if ( ! $default_style ) {
263
- $default_style = reset($styles);
264
- $styles[$default_style->ID]->menu_order = 1;
265
- }
266
-
267
- return $styles;
268
- }
269
-
270
- public function get_default_style($styles = null) {
271
- if ( ! isset($styles) ) {
272
- $styles = $this->get_all( 'menu_order', 'DESC', 1 );
273
- }
274
-
275
- foreach ( $styles as $style ) {
276
- if ( $style->menu_order ) {
277
- return $style;
278
- }
279
- }
280
- }
281
-
282
- public function override_defaults($settings) {
283
- if ( ! is_array($settings) ) {
284
- return $settings;
285
- }
286
-
287
- $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
288
-
289
- if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
290
- $settings['form_desc_size'] = $settings['description_font_size'];
291
- $settings['form_desc_color'] = $settings['description_color'];
292
- $settings['title_color'] = $settings['label_color'];
293
- }
294
-
295
- if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
296
- $settings['section_color'] = $settings['label_color'];
297
- $settings['section_border_color'] = $settings['border_color'];
298
- }
299
-
300
- if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
301
- $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
302
- $settings['submit_hover_color'] = $settings['submit_text_color'];
303
- $settings['submit_hover_border_color'] = $settings['submit_border_color'];
304
-
305
- $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
306
- $settings['submit_active_color'] = $settings['submit_text_color'];
307
- $settings['submit_active_border_color'] = $settings['submit_border_color'];
308
- }
309
-
310
- return $settings;
311
- }
312
-
313
- public function get_defaults(){
314
- return array(
315
- 'theme_css' => 'ui-lightness',
316
- 'theme_name' => 'UI Lightness',
317
-
318
- 'form_width' => '100%',
319
- 'form_align' => 'left',
320
- 'direction' => is_rtl() ? 'rtl' : 'ltr',
321
- 'fieldset' => '0px',
322
- 'fieldset_color' => '000000',
323
- 'fieldset_padding' => '0 0 15px 0',
324
- 'fieldset_bg_color' => '',
325
-
326
- 'title_size' => '20px',
327
- 'title_color' => '444444',
328
- 'form_desc_size' => '14px',
329
- 'form_desc_color' => '666666',
330
-
331
- 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
332
- 'font_size' => '14px',
333
- 'label_color' => '444444',
334
- 'weight' => 'bold',
335
- 'position' => 'none',
336
- 'align' => 'left',
337
- 'width' => '150px',
338
- 'required_color' => 'B94A48',
339
- 'required_weight' => 'bold',
340
- 'label_padding' => '0 0 3px 0',
341
-
342
- 'description_font_size' => '12px',
343
- 'description_color' => '666666',
344
- 'description_weight' => 'normal',
345
- 'description_style' => 'normal',
346
- 'description_align' => 'left',
347
-
348
- 'field_font_size' => '14px',
349
- 'field_height' => '32px',
350
- 'line_height' => 'normal',
351
- 'field_width' => '100%',
352
- 'auto_width' => false,
353
- 'field_pad' => '6px 10px',
354
- 'field_margin' => '20px',
355
- 'text_color' => '555555',
356
- //'border_color_hv' => 'cccccc',
357
- 'border_color' => 'cccccc',
358
- 'field_border_width' => '1px',
359
- 'field_border_style' => 'solid',
360
-
361
- 'bg_color' => 'ffffff',
362
- //'bg_color_hv' => 'ffffff',
363
- 'bg_color_active' => 'ffffff',
364
- 'border_color_active'=> '66afe9',
365
- 'text_color_error' => '444444',
366
- 'bg_color_error' => 'ffffff',
367
- 'border_color_error'=> 'B94A48',
368
- 'border_width_error'=> '1px',
369
- 'border_style_error'=> 'solid',
370
- 'bg_color_disabled' => 'ffffff',
371
- 'border_color_disabled' => 'E5E5E5',
372
- 'text_color_disabled' => 'A1A1A1',
373
-
374
- 'radio_align' => 'block',
375
- 'check_align' => 'block',
376
- 'check_font_size' => '13px',
377
- 'check_label_color' => '444444',
378
- 'check_weight' => 'normal',
379
-
380
- 'section_font_size' => '18px',
381
- 'section_color' => '444444',
382
- 'section_weight' => 'bold',
383
- 'section_pad' => '15px 0 3px 0',
384
- 'section_mar_top' => '15px',
385
- 'section_mar_bottom'=> '12px',
386
- 'section_bg_color' => '',
387
- 'section_border_color' => 'e8e8e8',
388
- 'section_border_width' => '2px',
389
- 'section_border_style' => 'solid',
390
- 'section_border_loc' => '-top',
391
- 'collapse_icon' => '6',
392
- 'collapse_pos' => 'after',
393
- 'repeat_icon' => '1',
394
-
395
- 'submit_style' => false,
396
- 'submit_font_size' => '14px',
397
- 'submit_width' => 'auto',
398
- 'submit_height' => 'auto',
399
- 'submit_bg_color' => 'ffffff',
400
- 'submit_border_color' => 'cccccc',
401
- 'submit_border_width' => '1px',
402
- 'submit_text_color' => '444444',
403
- 'submit_weight' => 'normal',
404
- 'submit_border_radius' => '4px',
405
- 'submit_bg_img' => '',
406
- 'submit_margin' => '10px',
407
- 'submit_padding' => '6px 11px',
408
- 'submit_shadow_color' => 'eeeeee',
409
- 'submit_hover_bg_color' => 'efefef',
410
- 'submit_hover_color' => '444444',
411
- 'submit_hover_border_color' => 'cccccc',
412
- 'submit_active_bg_color' => 'efefef',
413
- 'submit_active_color' => '444444',
414
- 'submit_active_border_color' => 'cccccc',
415
-
416
- 'border_radius' => '4px',
417
- 'error_bg' => 'F2DEDE',
418
- 'error_border' => 'EBCCD1',
419
- 'error_text' => 'B94A48',
420
- 'error_font_size' => '14px',
421
-
422
- 'success_bg_color' => 'DFF0D8',
423
- 'success_border_color' => 'D6E9C6',
424
- 'success_text_color' => '468847',
425
- 'success_font_size' => '14px',
426
-
427
- 'important_style' => false,
428
-
429
- 'custom_css' => '',
430
- );
431
- }
432
-
433
- public function get_field_name($field_name, $post_field = 'post_content') {
434
- return 'frm_style_setting'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
435
- }
436
-
437
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/recaptchalib.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * This is a PHP library that handles calling reCAPTCHA.
4
+ * - Documentation and latest version
5
+ * http://recaptcha.net/plugins/php/
6
+ * - Get a reCAPTCHA API Key
7
+ * https://www.google.com/recaptcha/admin/create
8
+ * - Discussion group
9
+ * http://groups.google.com/group/recaptcha
10
+ *
11
+ * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
12
+ * AUTHORS:
13
+ * Mike Crawford
14
+ * Ben Maurer
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ * of this software and associated documentation files (the "Software"), to deal
18
+ * in the Software without restriction, including without limitation the rights
19
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ * copies of the Software, and to permit persons to whom the Software is
21
+ * furnished to do so, subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in
24
+ * all copies or substantial portions of the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
+ * THE SOFTWARE.
33
+ */
34
+
35
+ /**
36
+ * The reCAPTCHA server URL's
37
+ */
38
+ define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
39
+ define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
40
+ define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
41
+
42
+ /**
43
+ * Encodes the given data into a query string format
44
+ * @param $data - array of string elements to be encoded
45
+ * @return string - encoded request
46
+ */
47
+ function _recaptcha_qsencode ($data) {
48
+ $req = "";
49
+ foreach ( $data as $key => $value )
50
+ $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
51
+
52
+ // Cut the last '&'
53
+ $req=substr($req,0,strlen($req)-1);
54
+ return $req;
55
+ }
56
+
57
+
58
+
59
+ /**
60
+ * Submits an HTTP POST to a reCAPTCHA server
61
+ * @param string $host
62
+ * @param string $path
63
+ * @param array $data
64
+ * @param int port
65
+ * @return array response
66
+ */
67
+ function _recaptcha_http_post($host, $path, $data, $port = 80) {
68
+
69
+ $req = _recaptcha_qsencode ($data);
70
+
71
+ $http_request = "POST $path HTTP/1.0\r\n";
72
+ $http_request .= "Host: $host\r\n";
73
+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
74
+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
75
+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
76
+ $http_request .= "\r\n";
77
+ $http_request .= $req;
78
+
79
+ $response = '';
80
+ if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
81
+ die ('Could not open socket');
82
+ }
83
+
84
+ fwrite($fs, $http_request);
85
+
86
+ while ( !feof($fs) )
87
+ $response .= fgets($fs, 1160); // One TCP-IP packet
88
+ fclose($fs);
89
+ $response = explode("\r\n\r\n", $response, 2);
90
+
91
+ return $response;
92
+ }
93
+
94
+
95
+
96
+ /**
97
+ * Gets the challenge HTML (javascript and non-javascript version).
98
+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
99
+ * is embedded within the HTML form it was called from.
100
+ * @param string $pubkey A public key for reCAPTCHA
101
+ * @param string $error The error given by reCAPTCHA (optional, default is null)
102
+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
103
+
104
+ * @return string - The HTML to be embedded in the user's form.
105
+ */
106
+ function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
107
+ {
108
+ if ($pubkey == null || $pubkey == '') {
109
+ die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
110
+ }
111
+
112
+ if ($use_ssl) {
113
+ $server = RECAPTCHA_API_SECURE_SERVER;
114
+ } else {
115
+ $server = RECAPTCHA_API_SERVER;
116
+ }
117
+
118
+ $errorpart = "";
119
+ if ($error) {
120
+ $errorpart = "&amp;error=" . $error;
121
+ }
122
+ return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
123
+
124
+ <noscript>
125
+ <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
126
+ <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
127
+ <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
128
+ </noscript>';
129
+ }
130
+
131
+
132
+
133
+
134
+ /**
135
+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
136
+ */
137
+ class ReCaptchaResponse {
138
+ var $is_valid;
139
+ var $error;
140
+ }
141
+
142
+
143
+ /**
144
+ * Calls an HTTP POST function to verify if the user's guess was correct
145
+ * @param string $privkey
146
+ * @param string $remoteip
147
+ * @param string $challenge
148
+ * @param string $response
149
+ * @param array $extra_params an array of extra variables to post to the server
150
+ * @return ReCaptchaResponse
151
+ */
152
+ function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
153
+ {
154
+ if ($privkey == null || $privkey == '') {
155
+ die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
156
+ }
157
+
158
+ if ($remoteip == null || $remoteip == '') {
159
+ die ("For security reasons, you must pass the remote ip to reCAPTCHA");
160
+ }
161
+
162
+
163
+
164
+ //discard spam submissions
165
+ if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
166
+ $recaptcha_response = new ReCaptchaResponse();
167
+ $recaptcha_response->is_valid = false;
168
+ $recaptcha_response->error = 'incorrect-captcha-sol';
169
+ return $recaptcha_response;
170
+ }
171
+
172
+ $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
173
+ array (
174
+ 'privatekey' => $privkey,
175
+ 'remoteip' => $remoteip,
176
+ 'challenge' => $challenge,
177
+ 'response' => $response
178
+ ) + $extra_params
179
+ );
180
+
181
+ $answers = explode ("\n", $response [1]);
182
+ $recaptcha_response = new ReCaptchaResponse();
183
+
184
+ if (trim ($answers [0]) == 'true') {
185
+ $recaptcha_response->is_valid = true;
186
+ }
187
+ else {
188
+ $recaptcha_response->is_valid = false;
189
+ $recaptcha_response->error = $answers [1];
190
+ }
191
+ return $recaptcha_response;
192
+
193
+ }
194
+
195
+ /**
196
+ * gets a URL where the user can sign up for reCAPTCHA. If your application
197
+ * has a configuration page where you enter a key, you should provide a link
198
+ * using this function.
199
+ * @param string $domain The domain where the page is hosted
200
+ * @param string $appname The name of your application
201
+ */
202
+ function recaptcha_get_signup_url ($domain = null, $appname = null) {
203
+ return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
204
+ }
205
+
206
+ function _recaptcha_aes_pad($val) {
207
+ $block_size = 16;
208
+ $numpad = $block_size - (strlen ($val) % $block_size);
209
+ return str_pad($val, strlen ($val) + $numpad, chr($numpad));
210
+ }
211
+
212
+ /* Mailhide related code */
213
+
214
+ function _recaptcha_aes_encrypt($val,$ky) {
215
+ if (! function_exists ("mcrypt_encrypt")) {
216
+ die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
217
+ }
218
+ $mode=MCRYPT_MODE_CBC;
219
+ $enc=MCRYPT_RIJNDAEL_128;
220
+ $val=_recaptcha_aes_pad($val);
221
+ return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
222
+ }
223
+
224
+
225
+ function _recaptcha_mailhide_urlbase64 ($x) {
226
+ return strtr(base64_encode ($x), '+/', '-_');
227
+ }
228
+
229
+ /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
230
+ function recaptcha_mailhide_url($pubkey, $privkey, $email) {
231
+ if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
232
+ die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
233
+ "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
234
+ }
235
+
236
+
237
+ $ky = pack('H*', $privkey);
238
+ $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
239
+
240
+ return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
241
+ }
242
+
243
+ /**
244
+ * gets the parts of the email to expose to the user.
245
+ * eg, given johndoe@example,com return ["john", "example.com"].
246
+ * the email is then displayed as john...@example.com
247
+ */
248
+ function _recaptcha_mailhide_email_parts ($email) {
249
+ $arr = preg_split("/@/", $email );
250
+
251
+ if (strlen ($arr[0]) <= 4) {
252
+ $arr[0] = substr ($arr[0], 0, 1);
253
+ } else if (strlen ($arr[0]) <= 6) {
254
+ $arr[0] = substr ($arr[0], 0, 3);
255
+ } else {
256
+ $arr[0] = substr ($arr[0], 0, 4);
257
+ }
258
+ return $arr;
259
+ }
260
+
261
+ /**
262
+ * Gets html to display an email address given a public an private key.
263
+ * to get a key, go to:
264
+ *
265
+ * http://www.google.com/recaptcha/mailhide/apikey
266
+ */
267
+ function recaptcha_mailhide_html($pubkey, $privkey, $email) {
268
+ $emailparts = _recaptcha_mailhide_email_parts ($email);
269
+ $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
270
+
271
+ return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
272
+ "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
273
+
274
+ }
classes/views/frm-entries/_sidebar-shared-pub.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
- if ( ! isset( $entry) ) {
3
- $entry = $record;
4
- } ?>
5
-
6
- <div class="misc-pub-section curtime misc-pub-curtime">
7
- <span id="timestamp">
8
- <?php
9
- $datef = __( 'M j, Y @ G:i' );
10
- printf(__( 'Published on: <b>%1$s</b>'), date_i18n( $datef, strtotime( $entry->created_at ) )); ?>
11
- </span>
12
- </div>
13
- <?php if ( $entry->updated_at && $entry->updated_at != $entry->created_at ) { ?>
14
- <div class="misc-pub-section curtime misc-pub-curtime">
15
- <span id="timestamp">
16
- <?php printf(__( 'Updated on: <b>%1$s</b>', 'formidable' ), date_i18n( $datef, strtotime( $entry->updated_at ) )); ?>
17
- </span>
18
- </div>
19
- <?php } ?>
20
-
21
- <?php do_action('frm_entry_shared_sidebar', $entry); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-entries/direct.php CHANGED
@@ -1,13 +1,17 @@
1
  <!DOCTYPE html>
2
  <html <?php language_attributes(); ?>>
3
  <head>
4
- <title><?php bloginfo( 'name' ); ?> | <?php echo esc_html( $form->name ) ?></title>
5
- <meta charset="<?php bloginfo( 'charset' ); ?>" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7
- <?php wp_head(); ?>
 
 
8
  </head>
9
- <body class="frm_preview_page">
10
- <?php echo FrmFormsController::show_form( $form->id, '', true, true ); ?>
11
- <?php wp_footer(); ?>
 
 
12
  </body>
13
  </html>
1
  <!DOCTYPE html>
2
  <html <?php language_attributes(); ?>>
3
  <head>
4
+ <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
+ <title><?php bloginfo('name'); ?></title>
6
+ <?php wp_head();
7
+ if(!$frm_vars['pro_is_installed']){ ?>
8
+ <style type="text/css">.frm_forms.with_frm_style{max-width:750px;}</style>
9
+ <?php } ?>
10
  </head>
11
+ <body>
12
+ <div style="padding:25px;">
13
+ <?php echo FrmFormsController::show_form($form->id, '', true, true) ?>
14
+ </div>
15
+ <?php wp_footer(); ?>
16
  </body>
17
  </html>
classes/views/frm-entries/errors.php CHANGED
@@ -1,39 +1,35 @@
1
- <?php
2
- if ( isset($include_extra_container) ) { ?>
3
- <div class="<?php echo esc_attr( $include_extra_container ) ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
4
- <?php
5
- }
6
- if (isset($message) && $message != ''){
7
- if ( FrmAppHelper::is_admin() ) {
8
- ?><div id="message" class="frm_message updated frm_msg_padding"><?php echo $message ?></div><?php
9
- }else{
10
- FrmFormsHelper::get_scroll_js($form->id);
11
- echo $message;
12
  }
13
- }
14
 
15
- if ( isset($errors) && is_array( $errors ) && ! empty( $errors ) ) {
 
16
 
17
- if ( isset( $form ) && is_object( $form ) ) {
18
- FrmFormsHelper::get_scroll_js( $form->id );
19
- } ?>
20
- <div class="frm_error_style">
21
  <?php
22
  $img = '';
23
- if ( ! FrmAppHelper::is_admin() ) {
24
  $img = apply_filters('frm_error_icon', $img);
25
- if ( $img && ! empty($img) ) {
26
- ?><img src="<?php echo esc_attr( $img ) ?>" alt="" />
27
- <?php
28
  }
29
- }
30
-
31
- $frm_settings = FrmAppHelper::get_settings();
32
- if ( empty( $frm_settings->invalid_msg ) ) {
33
  $show_img = false;
34
- foreach ( $errors as $error ) {
35
- if ( $show_img && ! empty($img) ) {
36
- ?><img src="<?php echo esc_attr( $img ) ?>" alt="" /><?php
37
  }else{
38
  $show_img = true;
39
  }
@@ -43,14 +39,13 @@ if ( empty( $frm_settings->invalid_msg ) ) {
43
  echo $frm_settings->invalid_msg;
44
 
45
  $show_img = true;
46
- foreach ( $errors as $err_key => $error ) {
47
- if ( ! is_numeric($err_key) && ( $err_key == 'cptch_number' || strpos($err_key, 'field') === 0 ) ) {
48
  continue;
49
- }
50
-
51
- echo '<br/>';
52
- if ( $show_img && ! empty($img) ) {
53
- ?><img src="<?php echo esc_attr( $img ) ?>" alt="" /><?php
54
  }else{
55
  $show_img = true;
56
  }
@@ -58,10 +53,4 @@ if ( empty( $frm_settings->invalid_msg ) ) {
58
  }
59
  } ?>
60
  </div>
61
- <?php
62
- }
63
-
64
- if ( isset($include_extra_container) ) { ?>
65
- </div>
66
- <?php
67
- }
1
+ <?php global $frm_settings;
2
+ if (isset($message) && $message != ''){
3
+ if(is_admin() and !defined('DOING_AJAX')){
4
+ ?><div id="message" class="frm_message updated" style="padding:5px;"><?php echo $message ?></div><?php
5
+ }else{
6
+ ?><script type="text/javascript">jQuery(document).ready(function($){frmScrollMsg(<?php echo $form->id ?>);})</script><?php
7
+ echo $message;
 
 
 
 
8
  }
9
+ }
10
 
11
+ if( isset($errors) && is_array($errors) && !empty($errors) ){
12
+ global $frm_settings;
13
 
14
+ if ( isset($form) && is_object($form) ) { ?>
15
+ <script type="text/javascript">jQuery(document).ready(function($){frmScrollMsg(<?php echo $form->id ?>);})</script>
16
+ <?php } ?>
17
+ <div class="frm_error_style">
18
  <?php
19
  $img = '';
20
+ if(!is_admin() or defined('DOING_AJAX')){
21
  $img = apply_filters('frm_error_icon', $img);
22
+ if($img and !empty($img)){
23
+ ?><img src="<?php echo $img ?>" alt="" />
24
+ <?php
25
  }
26
+ }
27
+
28
+ if(empty($frm_settings->invalid_msg)){
 
29
  $show_img = false;
30
+ foreach( $errors as $error ){
31
+ if($show_img and !empty($img)){
32
+ ?><img src="<?php echo $img ?>" alt="" /><?php
33
  }else{
34
  $show_img = true;
35
  }
39
  echo $frm_settings->invalid_msg;
40
 
41
  $show_img = true;
42
+ foreach( $errors as $err_key => $error ){
43
+ if(!is_numeric($err_key) and ($err_key == 'cptch_number' or strpos($err_key, 'field') === 0 or strpos($err_key, 'captcha') === 0 ))
44
  continue;
45
+
46
+ echo '<br/>';
47
+ if($show_img and !empty($img)){
48
+ ?><img src="<?php echo $img ?>" alt="" /><?php
 
49
  }else{
50
  $show_img = true;
51
  }
53
  }
54
  } ?>
55
  </div>
56
+ <?php } ?>
 
 
 
 
 
 
classes/views/frm-entries/form.php CHANGED
@@ -1,11 +1,17 @@
1
- <?php
2
- global $frm_vars;
3
- FrmFormsHelper::form_loaded($form, $values['custom_style'], $frm_vars['load_css']);
 
 
 
 
 
 
4
 
5
  echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $description); ?>
6
  <div class="frm_form_fields <?php echo apply_filters('frm_form_fields_class', '', $values); ?>">
7
  <fieldset>
8
- <legend class="frm_hidden"><?php echo wp_kses($form->name, array()); ?></legend>
9
  <input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" />
10
  <input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" />
11
  <input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" />
@@ -17,22 +23,21 @@ echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $
17
  <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin); ?>" />
18
  <?php }
19
 
20
- if ( $values['fields'] ) {
21
- foreach ( $values['fields'] as $field ) {
22
- if ( apply_filters( 'frm_show_normal_field_type', true, $field['type'] ) ) {
23
- echo FrmFieldsHelper::replace_shortcodes( $field['custom_html'], $field, $errors, $form );
24
- } else {
25
- do_action( 'frm_show_other_field_type', $field, $form, array( 'action' => $form_action ) );
26
- }
27
-
28
- do_action('frm_get_field_scripts', $field, $form);
29
- }
30
  }
31
 
32
- $frm_settings = FrmAppHelper::get_settings();
33
- if ( FrmAppHelper::is_admin() && ! $frm_settings->lock_keys ) { ?>
34
  <div class="frm_form_field form-field">
35
- <label class="frm_primary_label"><?php _e( 'Entry Key', 'formidable' ) ?></label>
36
  <input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" />
37
  </div>
38
  <?php }else{ ?>
@@ -42,24 +47,22 @@ if ( FrmAppHelper::is_admin() && ! $frm_settings->lock_keys ) { ?>
42
  do_action('frm_entry_form', $form, $form_action, $errors);
43
 
44
  global $frm_vars;
45
- if ( isset($frm_vars['div']) && $frm_vars['div'] ) {
46
  echo "</div>\n";
47
- unset($frm_vars['div']);
48
- }
49
-
50
- echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form);
51
-
 
52
 
53
- if ( has_action('frm_entries_footer_scripts') ) { ?>
 
54
  <script type="text/javascript">
55
  <?php do_action('frm_entries_footer_scripts', $values['fields'], $form); ?>
56
- </script><?php
57
- }
58
 
59
- if ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ) {
60
  unset($values['fields']);
61
  FrmFormsHelper::get_custom_submit($values['submit_html'], $form, $submit, $form_action, $values);
62
  }
63
- ?>
64
- </fieldset>
65
- </div>
1
+ <?php
2
+ global $frm_vars, $frm_settings;
3
+ FrmFormsHelper::form_loaded($form);
4
+ if($values['custom_style']) $frm_vars['load_css'] = true;
5
+
6
+ if((!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css']){
7
+ echo FrmAppController::footer_js('header');
8
+ $frm_vars['css_loaded'] = true;
9
+ }
10
 
11
  echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $description); ?>
12
  <div class="frm_form_fields <?php echo apply_filters('frm_form_fields_class', '', $values); ?>">
13
  <fieldset>
14
+ <div>
15
  <input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" />
16
  <input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" />
17
  <input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" />
23
  <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin); ?>" />
24
  <?php }
25
 
26
+ if($values['fields']){
27
+ foreach($values['fields'] as $field){
28
+ $field_name = 'item_meta['. $field['id'] .']';
29
+ if (apply_filters('frm_show_normal_field_type', true, $field['type']))
30
+ echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form);
31
+ else
32
+ do_action('frm_show_other_field_type', $field, $form, array('action' => $form_action));
33
+
34
+ do_action('frm_get_field_scripts', $field, $form);
35
+ }
36
  }
37
 
38
+ if ((is_admin() and !defined('DOING_AJAX')) and !$frm_settings->lock_keys){ ?>
 
39
  <div class="frm_form_field form-field">
40
+ <label class="frm_primary_label"><?php _e('Entry Key', 'formidable') ?></label>
41
  <input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" />
42
  </div>
43
  <?php }else{ ?>
47
  do_action('frm_entry_form', $form, $form_action, $errors);
48
 
49
  global $frm_vars;
50
+ if(isset($frm_vars['div']) and $frm_vars['div']){
51
  echo "</div>\n";
52
+ $frm_vars['div'] = false;
53
+ } ?>
54
+ </div>
55
+ </fieldset>
56
+ </div>
57
+ <?php echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form);
58
 
59
+ global $wp_filter;
60
+ if(isset($wp_filter['frm_entries_footer_scripts']) and !empty($wp_filter['frm_entries_footer_scripts'])){ ?>
61
  <script type="text/javascript">
62
  <?php do_action('frm_entries_footer_scripts', $values['fields'], $form); ?>
63
+ </script><?php }
 
64
 
65
+ if ( !$form->is_template && $form->status == 'published' && (!is_admin() || defined('DOING_AJAX')) ) {
66
  unset($values['fields']);
67
  FrmFormsHelper::get_custom_submit($values['submit_html'], $form, $submit, $form_action, $values);
68
  }
 
 
 
classes/views/frm-entries/frm-entry.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST ) {
4
+
5
+ if ( !empty($errors) ) {
6
+ $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
7
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
8
+ return;
9
+ }
10
+
11
+ do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
12
+ if ( !apply_filters('frm_continue_to_create', true, $form->id) ) {
13
+ return;
14
+ }
15
+
16
+ $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
17
+ $created = (isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id])) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
18
+ $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
19
+
20
+ if ( !$created || !is_numeric($created) || $conf_method == 'message' ) {
21
+ $saved_message = apply_filters('frm_content', $saved_message, $form, $created);
22
+ $message = ($created && is_numeric($created)) ? '<div class="frm_message" id="message">'. wpautop(do_shortcode($saved_message)) .'</div>' : '<div class="frm_error_style">'. $frm_settings->failed_msg .'</div>';
23
+
24
+ if ( !isset($form->options['show_form']) || $form->options['show_form'] ) {
25
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
26
+ } else {
27
+ global $frm_vars;
28
+ FrmFormsHelper::form_loaded($form);
29
+ if ( $values['custom_style'] ) {
30
+ $frm_vars['load_css'] = true;
31
+ }
32
+
33
+ if ( (!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css'] ) {
34
+ echo FrmAppController::footer_js('header');
35
+ $frm_vars['css_loaded'] = true;
36
+ }
37
+ ?>
38
+ <div class="frm_forms<?php echo ($values['custom_style']) ? ' with_frm_style' : ''; ?>" id="frm_form_<?php echo $form->id ?>_container"><?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php') ?></div>
39
+ <?php
40
+ }
41
+ } else {
42
+ do_action('frm_success_action', $conf_method, $form, $form->options, $created);
43
+ }
44
+
45
+ do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
46
+ }else{
47
+ do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
48
+ if (apply_filters('frm_continue_to_new', true, $form->id, $params['action'])){
49
+ $values = FrmEntriesHelper::setup_new_vars($fields, $form);
50
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
51
+ }
52
+ }
classes/views/frm-entries/list.php CHANGED
@@ -1,34 +1,31 @@
1
  <div id="form_entries_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2><?php _e( 'Entries', 'formidable' ); ?>
4
- <?php do_action('frm_entry_inside_h2', $form); ?>
5
- </h2>
 
6
 
7
- <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
8
-
9
- <form id="posts-filter" method="get">
10
- <div id="poststuff">
11
- <div id="post-body" class="metabox-holder columns-2">
12
- <div id="post-body-content">
13
- <?php FrmAppController::get_form_nav($form, true, 'hide'); ?>
14
- </div>
15
- <div id="postbox-container-1" class="postbox-container">
16
- <input type="hidden" name="page" value="formidable-entries" />
17
- <input type="hidden" name="form" value="<?php echo ($form) ? $form->id : ''; ?>" />
18
- <input type="hidden" name="frm_action" value="list" />
19
- <?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' ); ?>
20
- </div>
21
- <div class="clear"></div>
22
- </div>
23
- <?php if ( $form ) { ?>
24
- <div id="titlediv">
25
- <input id="title" type="text" value="<?php echo esc_attr($form->name == '' ? __( '(no title)') : $form->name) ?>" readonly="readonly" disabled="disabled" />
26
- </div>
27
- <?php } ?>
28
-
29
- <?php $wp_list_table->display(); ?>
30
-
31
- </div>
32
- </form>
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  </div>
 
1
  <div id="form_entries_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2>
4
+ <?php _e('Entries', 'formidable'); ?>
5
+ <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
+ </h2>
7
 
8
+ <?php if($form) FrmAppController::get_form_nav($form->id, true); ?>
9
+
10
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
11
+ <?php FrmAppController::update_message('view, search, export, and bulk delete your saved entries'); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ <?php if(!$form or $entry_count){ ?>
14
+ <img src="<?php echo FrmAppHelper::plugin_url() ?>/screenshot-5.png" alt="Entries List" style="max-width:100%"/>
15
+ <?php }else{ ?>
16
+ <table class="wp-list-table widefat post fixed" cellspacing="0">
17
+ <thead>
18
+ <tr><th class="manage-column" scope="col"> </th></tr>
19
+ </thead>
20
+ <tbody>
21
+ <tr><td>
22
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php'); ?>
23
+ </td></tr>
24
+ </tbody>
25
+ <tfoot>
26
+ <tr><th class="manage-column" scope="col"> </th></tr>
27
+ </tfoot>
28
+ </table>
29
+ <?php } ?>
30
  </div>
31
+
classes/views/frm-entries/new.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
- if ( empty($values) || ! isset($values['fields']) || empty($values['fields']) ) { ?>
3
- <div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($form); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
4
- <div class="frm_error_style"><strong><?php _e( 'Oops!', 'formidable' ) ?></strong> <?php printf( __( 'You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable' ), '<a href="'. admin_url('?page=formidable&frm_action=edit&id='. $form->id) .'">', '</a>' ) ?>
5
  </div>
6
- </div>
7
  <?php
8
  return;
9
  } ?>
10
- <div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($values); ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container">
11
- <form enctype="<?php echo apply_filters('frm_form_enctype', 'multipart/form-data', $form) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo esc_attr( $form->form_key ) ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?>>
12
- <?php
13
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
14
  $form_action = 'create';
15
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/form.php');
16
  ?>
17
  </form>
18
  </div>
1
  <?php
2
+ if(empty($values) or !isset($values['fields']) or empty($values['fields'])){ ?>
3
+ <div class="frm_forms with_frm_style" id="frm_form_<?php echo $form->id ?>_container">
4
+ <div class="frm_error_style"><strong><?php _e('Oops!', 'formidable') ?></strong> <?php printf(__('You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable'), '<a href="'. admin_url('?page=formidable&frm_action=edit&id='. $form->id) .'">', '</a>') ?>
5
  </div>
6
+ </div>
7
  <?php
8
  return;
9
  } ?>
10
+ <div class="frm_forms<?php echo ($values['custom_style']) ? ' with_frm_style' : ''; ?>" id="frm_form_<?php echo $form->id ?>_container">
11
+ <form enctype="<?php echo apply_filters('frm_form_enctype', 'multipart/form-data', $form) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo $form->form_key ?>" <?php echo ($frm_settings->use_html) ? '' : 'action=""'; ?>>
12
+ <?php
13
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
14
  $form_action = 'create';
15
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/form.php');
16
  ?>
17
  </form>
18
  </div>
classes/views/frm-entries/no_entries.php CHANGED
@@ -1,18 +1,48 @@
1
- <div class="frmcenter frm_no_entries_form">
2
- <?php
3
- if ( $form && isset($form->options['no_save']) && $form->options['no_save'] ) { ?>
4
- <h3><?php _e( 'This form is not set to save any entries.', 'formidable' ) ?></h3>
5
- <p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=settings&id='. $form->id) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p>
6
- <?php
7
- } else if ( $form ) {
 
 
 
 
8
  ?>
9
- <div class="frm_no_entries_header"><?php printf(__( 'No Entries for form: %s', 'formidable' ), $form->name); ?></div>
10
- <p class="frm_no_entries_text"><?php printf( __( 'For instructions on publishing your form see %1$sthis page%2$s <br/> or click "%3$sAdd New%4$s" above to add an entry from here (Requires License)', 'formidable' ), '<a href="https://formidablepro.com/knowledgebase/publish-your-forms/" target="_blank">', '</a>', '<a href="'. admin_url('admin.php?page=formidable-entries&frm_action=new&form='. $form->id) .'">', '</a>'); ?></p>
11
- <?php
12
- } else {
13
- ?>
14
- <div class="frm_no_entries_header"><?php _e( 'You have not created any forms yet.', 'formidable' ); ?></div>
15
- <p class="frm_no_entries_text"><?php printf( __( 'To view entries, you must first %1$sbuild a form%2$s', 'formidable' ), '<a href="'. esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) . '">', '</a>' ); ?></p>
16
- <?php
17
- } ?>
18
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if(!isset($colspan))
3
+ $colspan = (isset($form_cols)) ? count($form_cols)+1 : '';
4
+
5
+ $form->options = maybe_unserialize($form->options);
6
+
7
+ if(isset($form->options['no_save']) and $form->options['no_save']){ ?>
8
+ <h3><?php _e('This form is not set to save any entries.', 'formidable') ?></h3>
9
+ <p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=settings&id='. $form->id) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p>
10
+ <?php
11
+ }else{
12
  ?>
13
+ <h3><?php _e("You don't have any entries in this form.", 'formidable') ?><br/> <?php _e('How to publish', 'formidable') ?>:</h3>
14
+ </td></tr>
15
+ <tr class="alternate"><td colspan="<?php echo $colspan ?>">
16
+ <h3><?php _e('Option 1: Generate your shortcode', 'formidable') ?></h3>
17
+ <ol>
18
+ <li><?php _e('Go to your WordPress page or post.', 'formidable') ?></li>
19
+ <li>
20
+ <?php _e('Click on the "Add Form" button above the content box.', 'formidable') ?><br/>
21
+ <img alt="" src="http://static.strategy11.com.s3.amazonaws.com/insert-shortcode-icon.png">
22
+ </li>
23
+ <li><?php _e('Select your form from the dropdown and check the boxes to show the title and description if desired.', 'formidable') ?></li>
24
+ <li><?php _e('Click the "Insert Form" button.', 'formidable') ?></li>
25
+ </ol>
26
+ </td></tr>
27
+ <tr><td colspan="<?php echo $colspan ?>">
28
+ <h3><?php _e('Option 2: Add a Widget', 'formidable') ?></h3>
29
+ <ol class="alignleft" style="margin-right:30px;">
30
+ <li><?php _e('Drag a "Formidable Form" widget into your sidebar.', 'formidable') ?></li>
31
+ <li><?php _e('Select a form from the "Form" drop-down.', 'formidable') ?></li>
32
+ <li><?php _e('Click the "Save" button', 'formidable') ?></li>
33
+ </ol>
34
+ <img src="<?php echo FrmAppHelper::plugin_url() ?>/screenshot-6.png" alt="<?php esc_attr_e('Formidable Form Widget', 'formidable') ?>" title="<?php esc_attr_e('Formidable Form Widget', 'formidable') ?>" height="261" width="252" />
35
+ </td></tr>
36
+ <tr class="alternate"><td colspan="<?php echo $colspan ?>">
37
+ <h3><?php _e('Option 3: Insert the shortcode or PHP', 'formidable') ?></h3>
38
+ <p><?php _e('Insert the following shortcode in your page, post, or text widget. This will be replaced with your form:', 'formidable') ?><br/>
39
+ <input type="text" readonly="true" class="frm_select_box frm_no_items" value="[formidable id=<?php echo $form->id; ?>]" />
40
+ </p>
41
+ <p><?php _e('Show the form with the title and description:', 'formidable') ?><br/>
42
+ <input type="text" readonly="true" class="frm_select_box frm_no_items" value="[formidable id=<?php echo $form->id; ?> title=true description=true]" />
43
+ </p>
44
+
45
+ <p><?php _e('Insert into a theme template file:', 'formidable') ?><br/>
46
+ <input type="text" readonly="true" class="frm_select_box frm_no_items" value="echo FrmFormsController::show_form(<?php echo $form->id; ?>, $key='', $title=true, $description=true);" />
47
+ </p>
48
+ <?php } ?>
classes/views/frm-entries/show.php DELETED
@@ -1,74 +0,0 @@
1
- <div id="form_show_entry_page" class="wrap">
2
- <div class="frmicon icon32"><br/></div>
3
- <h2><?php _e( 'View Entry', 'formidable' ) ?>
4
- <?php do_action('frm_entry_inside_h2', $entry->form_id); ?>
5
- </h2>
6
-
7
- <div class="frm_forms">
8
-
9
- <div id="poststuff">
10
- <div id="post-body" class="metabox-holder columns-2">
11
- <div id="post-body-content">
12
- <?php FrmAppController::get_form_nav($entry->form_id, true); ?>
13
- <div class="postbox">
14
- <h3 class="hndle"><span><?php _e( 'Entry', 'formidable' ) ?></span></h3>
15
- <div class="inside">
16
- <table class="form-table"><tbody>
17
- <?php
18
- $first_h3 = 'frm_first_h3';
19
- foreach ( $fields as $field ) {
20
- if ( in_array( $field->type, array( 'captcha', 'html', 'end_divider', 'form' ) ) ) {
21
- continue;
22
- }
23
-
24
- if ( in_array($field->type, array( 'break', 'divider' ) ) ) {
25
- ?>
26
- </tbody></table>
27
- <br/><h3 class="<?php echo esc_attr( $first_h3 ) ?>"><?php echo esc_html( $field->name ) ?></h3>
28
- <table class="form-table"><tbody>
29
- <?php
30
- $first_h3 = '';
31
- } else {
32
- ?>
33
- <tr>
34
- <th scope="row"><?php echo esc_html( $field->name ) ?>:</th>
35
- <td>
36
- <?php
37
- $embedded_field_id = ( $entry->form_id != $field->form_id ) ? 'form' . $field->form_id : 0;
38
- $atts = array(
39
- 'type' => $field->type, 'post_id' => $entry->post_id,
40
- 'show_filename' => true, 'show_icon' => true, 'entry_id' => $entry->id,
41
- 'embedded_field_id' => $embedded_field_id,
42
- );
43
- echo $display_value = FrmEntriesHelper::prepare_display_value($entry, $field, $atts);
44
-
45
- if ( is_email($display_value) && ! in_array($display_value, $to_emails) ) {
46
- $to_emails[] = $display_value;
47
- }
48
- ?>
49
- </td>
50
- </tr>
51
- <?php }
52
- }
53
-
54
- ?>
55
-
56
- <?php if ( $entry->parent_item_id ) { ?>
57
- <tr><th><?php _e( 'Parent Entry ID', 'formidable' ) ?>:</th>
58
- <td><?php echo (int) $entry->parent_item_id ?>
59
- </td></tr>
60
- <?php } ?>
61
- </tbody></table>
62
- <?php do_action('frm_show_entry', $entry); ?>
63
- </div>
64
- </div>
65
-
66
- <?php do_action('frm_after_show_entry', $entry); ?>
67
-
68
- </div>
69
- <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-show.php'); ?>
70
- </div>
71
- </div>
72
- </div>
73
- </div>
74
- <br/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-entries/sidebar-shared.php DELETED
@@ -1,84 +0,0 @@
1
-
2
- <div class="postbox frm_with_icons" >
3
- <h3 class="hndle"><span><?php _e( 'Entry Details', 'formidable' ) ?></span></h3>
4
- <div class="inside">
5
- <?php if ( $entry->post_id ) { ?>
6
- <div class="misc-pub-section">
7
- <span class="dashicons dashicons-admin-post wp-media-buttons-icon"></span>
8
- <?php _e( 'Post', 'formidable' ) ?>:
9
- <b><?php echo get_the_title($entry->post_id) ?></b>
10
- <span><a href="<?php echo esc_url( admin_url('post.php?post='. $entry->post_id .'&action=edit') ) ?>"><?php _e( 'Edit', 'formidable' ) ?></a>
11
- <a href="<?php echo esc_url( get_permalink( $entry->post_id ) ) ?>"><?php _e( 'View', 'formidable' ) ?></a></span>
12
- </div>
13
- <?php } ?>
14
-
15
- <div class="misc-pub-section">
16
- <span class="dashicons dashicons-id wp-media-buttons-icon"></span>
17
- <?php _e( 'Entry ID', 'formidable' ) ?>: <b><?php echo (int) $entry->id ?></b>
18
- </div>
19
-
20
- <div class="misc-pub-section">
21
- <span class="dashicons dashicons-post-status wp-media-buttons-icon"></span>
22
- <?php _e( 'Entry Key', 'formidable' ) ?>:
23
- <b><?php echo $entry->item_key ?></b>
24
- </div>
25
-
26
- <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
27
- <?php if ( $entry->user_id ) { ?>
28
- <div class="misc-pub-section">
29
- <span class="dashicons dashicons-admin-users wp-media-buttons-icon"></span>
30
- <?php printf(__( 'Created by: %1$s', 'formidable' ), FrmProFieldsHelper::get_display_name($entry->user_id, 'display_name', array( 'link' => true))); ?>
31
- </div>
32
- <?php } ?>
33
-
34
- <?php if ( $entry->updated_by && $entry->updated_by != $entry->user_id ) { ?>
35
- <div class="misc-pub-section">
36
- <span class="dashicons dashicons-admin-users wp-media-buttons-icon"></span>
37
- <?php printf(__( 'Updated by: %1$s', 'formidable' ), FrmProFieldsHelper::get_display_name($entry->updated_by, 'display_name', array( 'link' => true)) ); ?>
38
- </div>
39
- <?php } ?>
40
- <?php } ?>
41
-
42
- </div>
43
- </div>
44
-
45
-
46
-
47
- <div class="postbox">
48
- <h3 class="hndle"><span><?php _e( 'User Information', 'formidable' ) ?></span></h3>
49
- <div class="inside">
50
- <div class="misc-pub-section">
51
- <?php _e( 'IP Address', 'formidable' ) ?>:
52
- <b><?php echo $entry->ip; ?></b>
53
- </div>
54
-
55
- <?php if ( isset($data['browser']) ) { ?>
56
- <div class="misc-pub-section">
57
- <b><?php _e( 'Browser/OS', 'formidable' ) ?></b>:<br/>
58
- <?php echo FrmEntriesHelper::get_browser($data['browser']); ?>
59
- </div>
60
- <?php } ?>
61
-
62
- <?php if ( isset($data['referrer']) ) { ?>
63
- <div class="misc-pub-section">
64
- <b><?php _e( 'Referrer', 'formidable' ) ?></b>:<br/>
65
- <?php echo str_replace("\r\n", '<br/>', $data['referrer']); ?>
66
- </div>
67
- <?php } ?>
68
-
69
- <?php
70
- foreach ( (array) $data as $k => $d ) {
71
- if ( in_array($k, array( 'browser', 'referrer')) ) {
72
- continue;
73
- }
74
- ?>
75
- <div class="misc-pub-section">
76
- <b><?php echo ucfirst(str_replace('-', ' ', $k)); ?></b>:
77
- <?php echo implode(', ', (array) $d); ?>
78
- </div>
79
- <?php
80
- unset($k, $d);
81
- }
82
- ?>
83
- </div>
84
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-entries/sidebar-show.php DELETED
@@ -1,38 +0,0 @@
1
- <div id="postbox-container-1" class="postbox-container">
2
- <div id="submitdiv" class="postbox">
3
- <h3 class="hndle"><span><?php _e( 'Entry Actions', 'formidable' ) ?></span></h3>
4
- <div class="inside">
5
- <div class="submitbox">
6
- <div id="minor-publishing" class="frm_remove_border">
7
- <div class="misc-pub-section">
8
- <?php do_action('frm_show_entry_publish_box', $entry); ?>
9
- <div class="clear"></div>
10
- </div>
11
- <div id="misc-publishing-actions">
12
- <?php include(dirname(__FILE__) .'/_sidebar-shared-pub.php'); ?>
13
- <div class="misc-pub-section">
14
- <span class="dashicons dashicons-format-aside wp-media-buttons-icon"></span>
15
- <a href="#" onclick="window.print();return false;"><?php _e( 'Print', 'formidable' ) ?></a>
16
- </div>
17
- </div>
18
- </div>
19
- <div id="major-publishing-actions">
20
- <?php if ( current_user_can('frm_delete_entries') ) { ?>
21
- <div id="delete-action">
22
- <a href="<?php echo esc_url( admin_url('admin.php?page=formidable-entries&frm_action=destroy&id='. $id .'&form='. $entry->form_id) ) ?>" class="submitdelete deletion" onclick="return confirm('<?php _e( 'Are you sure you want to delete that entry?', 'formidable' ) ?>');" title="<?php esc_attr_e( 'Delete' ) ?>"><?php _e( 'Delete' ) ?></a>
23
- <?php if ( ! empty($entry->post_id) ) { ?>
24
- <a href="<?php echo esc_url( admin_url('admin.php?page=formidable-entries&frm_action=destroy&id='. $id .'&form='. $entry->form_id .'&keep_post=1') ) ?>" class="submitdelete deletion frm_delete_wo_post" onclick="return confirm('<?php esc_attr_e( 'Are you sure you want to delete this entry?', 'formidable' ) ?>);" title="<?php esc_attr_e( 'Delete entry but leave the post', 'formidable' ) ?>"><?php _e( 'Delete without Post', 'formidable' ) ?></a>
25
- <?php } ?>
26
- </div>
27
- <?php } ?>
28
-
29
- <?php do_action('frm_entry_major_pub', $entry); ?>
30
- <div class="clear"></div>
31
- </div>
32
- </div>
33
- </div>
34
- </div>
35
- <?php do_action('frm_show_entry_sidebar', $entry);
36
- FrmEntriesController::entry_sidebar($entry);
37
- ?>
38
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/import_choices.php CHANGED
@@ -3,54 +3,82 @@
3
  <head>
4
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
  <title><?php bloginfo('name'); ?></title>
6
- <?php
7
  wp_admin_css( 'global' );
8
  wp_admin_css();
9
  wp_admin_css( 'colors' );
10
  wp_admin_css( 'ie' );
11
- if ( is_multisite() ) {
12
  wp_admin_css( 'ms' );
13
- }
14
 
15
  do_action('admin_print_styles');
16
  do_action('admin_print_scripts');
17
-
18
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </head>
20
- <body class="wp-admin no-js wp-core-ui frm_field_opts_popup <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>">
21
- <div class="frm_med_padding">
22
- <p class="howto"><?php _e( 'Edit or add field options (one per line)', 'formidable' ) ?></p>
23
- <ul class="frm_prepop">
24
- <?php foreach ( $prepop as $label => $pop ) { ?>
25
- <li><a href="javascript:void(0)" onclick='frmPrePop(<?php echo str_replace("'", '&#145;', json_encode($pop)) ?>); return false;'><?php echo esc_html( $label ) ?></a></li>
26
  <?php } ?>
27
  </ul>
28
- <textarea name="frm_bulk_options" id="frm_bulk_options">
29
- <?php
30
- $other_array = array();
31
- foreach ( $field->options as $fkey => $fopt ) {
32
- //If it is an other option, don't include it
33
- if ( $fkey && strpos( $fkey, 'other') !== false ) {
34
- continue;
35
- }
36
- if ( is_array( $fopt ) ) {
37
- $label = (isset($fopt['label'])) ? $fopt['label'] : reset($fopt);
38
- $value = (isset($fopt['value'])) ? $fopt['value'] : $label;
39
- if ( $label != $value && isset($field->field_options['separate_value']) && $field->field_options['separate_value'] ) {
40
- echo "$label|$value\n";
41
- } else{
42
- echo $label ."\n";
43
- }
44
- }else{
45
- echo $fopt ."\n";
46
- }
47
  } ?>
48
  </textarea>
49
 
50
  <p class="submit clear">
51
- <input type="button" onclick="frmUpdateBulkOpts(<?php echo (int) $field->id ?>)" class="button-primary" value="<?php esc_attr_e( 'Update Field Choices', 'formidable' ) ?>" />
52
  </p>
53
  </div>
54
 
 
 
 
 
 
 
55
  </body>
56
  </html>
3
  <head>
4
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
  <title><?php bloginfo('name'); ?></title>
6
+ <?php
7
  wp_admin_css( 'global' );
8
  wp_admin_css();
9
  wp_admin_css( 'colors' );
10
  wp_admin_css( 'ie' );
11
+ if ( is_multisite() )
12
  wp_admin_css( 'ms' );
13
+ wp_enqueue_script('utils');
14
 
15
  do_action('admin_print_styles');
16
  do_action('admin_print_scripts');
17
+
18
  ?>
19
+ <style type="text/css">
20
+ #wpadminbar{display:none;}
21
+ .prepop{
22
+ float:left;
23
+ width:235px;
24
+ list-style:none;
25
+ overflow:auto;
26
+ border-right: 2px solid #DEDEDE;
27
+ padding-right:10px;
28
+ margin:0;
29
+ }
30
+ .prepop li{
31
+ margin: 0 0 3px;
32
+ }
33
+
34
+ .prepop li a{
35
+ background:#F5F5F5;
36
+ border:1px solid #EEEEEE;
37
+ border-color:#EEEEEE #DEDEDE #DEDEDE #EEEEEE;
38
+ display: block;
39
+ font-weight: bold;
40
+ height: 30px;
41
+ line-height: 30px;
42
+ margin: 0 10px 0 0;
43
+ text-align: center;
44
+ text-decoration: none;
45
+ cursor:pointer;
46
+ }
47
+ </style>
48
  </head>
49
+ <body class="wp-admin no-js wp-core-ui <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>" style="min-width:300px;background-color:#fff;">
50
+ <div style="padding:10px;">
51
+ <p class="howto"><?php _e('Edit or add field options (one per line)', 'formidable') ?></p>
52
+ <ul class="prepop">
53
+ <?php foreach($prepop as $label => $pop){ ?>
54
+ <li><a onclick='frmPrePop(<?php echo str_replace("'", '&#145;', json_encode($pop)) ?>); return false;'><?php echo $label ?></a></li>
55
  <?php } ?>
56
  </ul>
57
+ <textarea name="frm_bulk_options" id="frm_bulk_options" style="height:240px;width:335px;float:right;">
58
+ <?php foreach($field->options as $fopt){
59
+ if(is_array($fopt)){
60
+ $label = (isset($fopt['label'])) ? $fopt['label'] : reset($fopt);
61
+ $value = (isset($fopt['value'])) ? $fopt['value'] : $label;
62
+ if($label != $value and isset($field->field_options['separate_value']) and $field->field_options['separate_value'])
63
+ echo "$label|$value\n";
64
+ else
65
+ echo $label ."\n";
66
+ }else{
67
+ echo $fopt ."\n";
68
+ }
 
 
 
 
 
 
 
69
  } ?>
70
  </textarea>
71
 
72
  <p class="submit clear">
73
+ <input type="button" onclick="window.top.frmUpdateOpts(<?php echo $field->id ?>,jQuery('#frm_bulk_options').val()); window.top.tb_remove();" class="button-primary" value="<?php _e('Update Field Choices', 'formidable') ?>" />
74
  </p>
75
  </div>
76
 
77
+ <script type="text/javascript">
78
+ function frmPrePop(opts){
79
+ jQuery('#frm_bulk_options').val(opts.join("\n"));
80
+ return false;
81
+ }
82
+ </script>
83
  </body>
84
  </html>
classes/views/frm-fields/input.php CHANGED
@@ -1,154 +1,105 @@
1
- <?php if ( in_array($field['type'], array( 'email', 'url', 'text')) ) { ?>
2
- <input type="<?php echo ( $frm_settings->use_html || $field['type'] == 'password' ) ? $field['type'] : 'text'; ?>" id="<?php echo esc_attr( $html_id ) ?>" name="<?php echo esc_attr( $field_name ) ?>" value="<?php echo esc_attr( $field['value'] ) ?>" <?php do_action('frm_field_input_html', $field) ?>/>
3
  <?php }else if ($field['type'] == 'textarea'){ ?>
4
- <textarea name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php
5
- if ( $field['max'] ) {
6
- echo 'rows="'. esc_attr( $field['max'] ) .'" ';
7
- }
8
- do_action('frm_field_input_html', $field);
9
- ?>><?php echo FrmAppHelper::esc_textarea($field['value']) ?></textarea>
10
- <?php
11
-
12
- } else if ( $field['type'] == 'radio' ) {
13
- $read_only = false;
14
- if ( isset($field['read_only']) && $field['read_only'] && ( ! isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) {
15
- $read_only = true; ?>
16
- <input type="hidden" value="<?php echo esc_attr( $field['value'] ) ?>" name="<?php echo esc_attr( $field_name ) ?>" />
17
- <?php
18
- }
19
 
 
20
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
21
- do_action('frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
22
  } else if ( is_array($field['options']) ) {
23
  foreach ( $field['options'] as $opt_key => $opt ) {
24
- if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key)) {
25
  continue;
26
  }
27
-
28
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
29
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?>
30
- <div class="<?php echo apply_filters('frm_radio_class', 'frm_radio', $field, $field_val)?>"><?php
31
-
32
- if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
33
- ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
34
- }
35
- $checked = FrmAppHelper::check_selected($field['value'], $field_val) ? 'checked="checked" ' : ' ';
36
-
37
- $other_opt = false;
38
- $other_args = FrmAppHelper::prepare_other_input( $field, $other_opt, $checked, array( 'field_name' => $field_name, 'opt_key' => $opt_key ) );
39
  ?>
40
- <input type="radio" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php
41
- echo $checked;
42
- do_action('frm_field_input_html', $field);
43
- ?>/><?php
44
 
45
- if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
46
- echo ' '. $opt .'</label>';
47
  }
 
 
48
 
49
- if ( $other_opt ) { ?>
50
- <input type="text" <?php echo ( $read_only ? ' readonly="readonly" disabled="disabled"' : '' ); ?> class="frm_other_input <?php echo ( $checked != ' ' ? '' : ' frm_pos_none' ); ?>" name="<?php echo esc_attr( $other_args['name'] ) ?>" value="<?php echo esc_attr( $other_args['value'] ); ?>"><?php
51
- }
52
- unset( $other_opt, $other_args );
53
  ?></div>
54
  <?php
55
  }
56
  }
57
- }else if ($field['type'] == 'select'){
58
- $read_only = false;
59
- if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
60
- echo FrmFieldsHelper::dropdown_categories( array( 'name' => $field_name, 'field' => $field) );
61
- }else{
62
- if ( isset( $field['read_only'] ) && $field['read_only'] && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) && ! FrmAppHelper::is_admin() ) {
63
- $read_only = true; ?>
64
- <input type="hidden" value="<?php echo esc_attr($field['value']) ?>" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" />
65
- <select disabled="disabled" <?php do_action('frm_field_input_html', $field) ?>>
66
- <?php }else{ ?>
67
- <select name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" <?php do_action('frm_field_input_html', $field) ?>>
68
- <?php }
69
 
70
- $other_opt = $other_checked = false;
71
- foreach ( $field['options'] as $opt_key => $opt ) {
72
- $field_val = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
73
- $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
74
- $selected = FrmAppHelper::check_selected( $field['value'], $field_val );
75
- if ( $other_opt === false ) {
76
- $other_args = FrmAppHelper::prepare_other_input( $field, $other_opt, $selected, array( 'field_name' => $field_name, 'opt_key' => $opt_key ) );
77
- if ( FrmAppHelper::is_other_opt( $opt_key ) && $selected ) {
78
- $other_checked = true;
79
- }
80
- }
81
- ?>
82
- <option value="<?php echo esc_attr($field_val) ?>" <?php echo $selected ? ' selected="selected"' : ''; ?><?php echo ( FrmAppHelper::is_other_opt( $opt_key ) ) ? ' class="frm_other_trigger"' : '';?>><?php echo ($opt == '') ? ' ' : $opt; ?></option>
83
- <?php
84
- } ?>
 
85
  </select>
86
- <?php
87
- if ( $other_opt ) { ?>
88
- <input type="text" <?php echo ( $read_only ? 'readonly="readonly" disabled="disabled"' : '' );?> class="frm_other_input<?php echo ( $other_checked ? '' : ' frm_pos_none' ); echo ( $field['multiple'] ? ' frm_other_full' : '' ); ?>" name="<?php echo esc_attr( $other_args['name'] ) ?>" value="<?php echo esc_attr($other_args['value']);?>"><?php
89
- }
90
- }
91
  }else if ($field['type'] == 'checkbox'){
92
  $checked_values = $field['value'];
93
- $read_only = false;
94
-
95
- if ( isset($field['read_only']) && $field['read_only'] && ( ! isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) {
96
- $read_only = true;
97
- if ( $checked_values ) {
98
- foreach ( (array) $checked_values as $checked_value ) { ?>
99
- <input type="hidden" value="<?php echo esc_attr( $checked_value ) ?>" name="<?php echo esc_attr( $field_name ) ?>[]" />
100
- <?php
101
- }
102
- } else { ?>
103
- <input type="hidden" value="<?php echo esc_attr( $checked_values ) ?>" name="<?php echo esc_attr( $field_name ) ?>[]" />
104
- <?php
105
- }
106
- }
107
-
108
- if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
109
- do_action('frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
110
  } else if ( $field['options'] ) {
111
  foreach ( $field['options'] as $opt_key => $opt ) {
112
  if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
113
  continue;
114
  }
115
-
116
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
117
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
118
  $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
119
-
120
- // Check if other opt, and get values for other field if needed
121
- $other_opt = false;
122
- $other_args = FrmAppHelper::prepare_other_input( $field, $other_opt, $checked, array( 'field_name' => $field_name, 'opt_key' => $opt_key ) );
123
-
124
  ?>
125
- <div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ) ?>" id="frm_checkbox_<?php echo esc_attr( $field['id'] ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
126
 
127
- if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
128
- ?><label for="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php
129
  }
130
-
131
- ?><input type="checkbox" name="<?php echo esc_attr( $field_name ) ?>[<?php echo ( $other_opt ? esc_attr( $opt_key ) : '' ) ?>]" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>" value="<?php echo esc_attr( $field_val ) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php
132
-
133
- if ( ! isset( $atts ) || ! isset( $atts['label'] ) || $atts['label'] ) {
134
  echo ' '. $opt .'</label>';
135
  }
136
-
137
- if ( $other_opt ) { ?>
138
- <input type="text" <?php echo ( $read_only ? ' readonly="readonly" disabled="disabled"' : '' );?> class="frm_other_input <?php echo ( $checked ? '' : 'frm_pos_none' ); ?>" name="<?php echo esc_attr( $other_args['name'] ) ?>" value="<?php echo esc_attr( $other_args['value'] );?>"><?php
139
- }
140
-
141
- unset( $other_opt, $other_args, $checked );
142
-
143
  ?></div>
144
  <?php
145
  }
146
  }
147
- } else if ( $field['type'] == 'captcha' && ! FrmAppHelper::is_admin() ) {
148
- $frm_settings = FrmAppHelper::get_settings();
149
- if ( ! empty($frm_settings->pubkey) ) {
150
- FrmFieldsHelper::display_recaptcha($field);
 
 
 
 
 
 
 
 
 
 
 
 
151
  }
152
  } else {
153
- do_action('frm_form_fields', $field, $field_name, compact('errors', 'html_id'));
154
  }
1
+ <?php if ($field['type'] == 'text'){ ?>
2
+ <input type="text" id="field_<?php echo $field['field_key'] ?>" name="<?php echo $field_name ?>" value="<?php echo esc_attr($field['value']) ?>" <?php do_action('frm_field_input_html', $field) ?>/>
3
  <?php }else if ($field['type'] == 'textarea'){ ?>
4
+ <textarea name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>"<?php if($field['size']) echo ' cols="'. $field['size'].'"'; if($field['max']) echo ' rows="'. $field['max'] .'"'; ?> <?php do_action('frm_field_input_html', $field) ?>><?php echo FrmAppHelper::esc_textarea($field['value']) ?></textarea>
5
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ }else if ($field['type'] == 'radio'){
8
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
9
+ do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
10
  } else if ( is_array($field['options']) ) {
11
  foreach ( $field['options'] as $opt_key => $opt ) {
12
+ if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
13
  continue;
14
  }
15
+
16
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
17
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
 
 
 
 
 
 
 
 
 
18
  ?>
19
+ <div class="<?php echo apply_filters('frm_radio_class', 'frm_radio', $field, $field_val)?>"><?php
 
 
 
20
 
21
+ if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
22
+ ?><label for="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>"><?php
23
  }
24
+
25
+ ?><input type="radio" name="<?php echo $field_name ?>" id="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php echo (FrmAppHelper::check_selected($field['value'], $field_val)) ? 'checked="checked"' : ''; ?> <?php do_action('frm_field_input_html', $field) ?>/><?php
26
 
27
+ if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
28
+ echo ' '. $opt .'</label>';
29
+ }
 
30
  ?></div>
31
  <?php
32
  }
33
  }
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ }else if ($field['type'] == 'select'){
36
+ if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
37
+ echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
38
+ }else{
39
+ if ( isset($field['read_only']) && $field['read_only'] && (!isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && (!is_admin() || defined('DOING_AJAX')) ) { ?>
40
+ <input type="hidden" value="<?php echo esc_attr($field['value']) ?>" name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" />
41
+ <select disabled="disabled" <?php do_action('frm_field_input_html', $field) ?>>
42
+ <?php }else{ ?>
43
+ <select name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" <?php do_action('frm_field_input_html', $field) ?>>
44
+ <?php }
45
+ foreach ($field['options'] as $opt_key => $opt){
46
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
47
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?>
48
+ <option value="<?php echo esc_attr($field_val) ?>" <?php
49
+ if (FrmAppHelper::check_selected($field['value'], $field_val)) echo ' selected="selected"'; ?>><?php echo ($opt == '') ? ' ' : $opt; ?></option>
50
+ <?php } ?>
51
  </select>
52
+ <?php }
53
+
 
 
 
54
  }else if ($field['type'] == 'checkbox'){
55
  $checked_values = $field['value'];
56
+
57
+ if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
58
+ do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  } else if ( $field['options'] ) {
60
  foreach ( $field['options'] as $opt_key => $opt ) {
61
  if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
62
  continue;
63
  }
64
+
65
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
66
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
67
  $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
68
+
 
 
 
 
69
  ?>
70
+ <div class="<?php echo apply_filters('frm_checkbox_class', 'frm_checkbox', $field, $field_val) ?>" id="frm_checkbox_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php
71
 
72
+ if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
73
+ ?><label for="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>"><?php
74
  }
75
+
76
+ ?><input type="checkbox" name="<?php echo $field_name ?>[]" id="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php
77
+
78
+ if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
79
  echo ' '. $opt .'</label>';
80
  }
81
+
 
 
 
 
 
 
82
  ?></div>
83
  <?php
84
  }
85
  }
86
+
87
+ } else if ( $field['type'] == 'captcha' && (!is_admin() || defined('DOING_AJAX')) ) {
88
+ global $frm_settings;
89
+ $error_msg = null;
90
+
91
+ if ( !empty($errors) ) {
92
+ foreach ( $errors as $error_key => $error ) {
93
+ if ( strpos($error_key, 'captcha-') === 0 ) {
94
+ $error_msg = preg_replace('/^captcha-/', '', $error_key);
95
+ }
96
+ unset($error);
97
+ }
98
+ }
99
+
100
+ if ( !empty($frm_settings->pubkey) ) {
101
+ FrmFieldsHelper::display_recaptcha($field, $error_msg);
102
  }
103
  } else {
104
+ do_action('frm_form_fields', $field, $field_name);
105
  }
classes/views/frm-fields/radio.php CHANGED
@@ -1,22 +1,12 @@
1
  <?php
2
- if ( ! is_array($field['options']) ) {
3
- return;
4
- }
5
-
6
- foreach ( $field['options'] as $opt_key => $opt ) {
7
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
8
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
9
-
10
- // Get string for Other text field, if needed
11
- $other_val = FrmAppHelper::get_other_val( $opt_key, $field );
12
-
13
- $checked = ( $other_val || isset($field['value']) && (( ! is_array($field['value']) && $field['value'] == $field_val ) || (is_array($field['value']) && in_array($field_val, $field['value']) ) ) ) ? ' checked="checked"':'';
14
-
15
- if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
16
- include(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
17
- } else {
18
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
19
- }
20
-
21
- unset($checked, $other_val);
22
  }
 
1
  <?php
2
+ if (is_array($field['options'])){
3
+ foreach($field['options'] as $opt_key => $opt){
4
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
5
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
6
+ $checked = (isset($field['value']) and ((!is_array($field['value']) && $field['value'] == $field_val ) || (is_array($field['value']) && in_array($field_val, $field['value'])))) ? ' checked="true"':'';
 
 
 
 
 
 
 
 
 
 
 
7
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
8
+
9
+ unset($checked);
10
+ }
11
  }
12
+ ?>
classes/views/frm-fields/show-build.php DELETED
@@ -1,64 +0,0 @@
1
- <?php if ( in_array($display['type'], array( 'text', 'website', 'email', 'url') ) ) { ?>
2
- <input type="text" name="<?php echo esc_attr( $field_name ) ?>" id="<?php echo esc_attr( $html_id ) ?>" value="<?php echo esc_attr( $field['default_value'] ); ?>" <?php echo ( isset($field['size']) && $field['size'] ) ? esc_attr( 'style="width:'. $field['size'] . ( is_numeric($field['size']) ? 'px' : '') .';"' ) : ''; ?> class="dyn_default_value" />
3
- <?php }else if ($field['type'] == 'textarea'){ ?>
4
- <textarea name="<?php echo esc_attr( $field_name ) ?>" <?php
5
- echo ( isset($field['size']) && $field['size'] ) ? esc_attr( 'style="width:'. $field['size'] . ( is_numeric($field['size']) ? 'px' : '') .';"' ) : '';
6
- ?> rows="<?php echo esc_attr( $field['max'] ); ?>" id="<?php echo esc_attr( $html_id ) ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea>
7
-
8
- <?php
9
-
10
- } else if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
11
- $field['default_value'] = maybe_unserialize($field['default_value']);
12
- if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
13
- do_action('frm_after_checkbox', array( 'field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
14
- } else {
15
- do_action('frm_add_multiple_opts_labels', $field); ?>
16
- <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>">
17
- <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php'); ?>
18
- </ul>
19
- <?php
20
- }
21
- } else if ( $field['type'] == 'select' ) {
22
- if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
23
- echo FrmFieldsHelper::dropdown_categories( array( 'name' => $field_name, 'field' => $field) );
24
- } else { ?>
25
- <select name="<?php echo esc_attr( $field_name ) . ( ( isset($field['multiple']) && $field['multiple']) ? '[]' : '' ); ?>" <?php
26
- echo ( isset($field['size']) && $field['size'] ) ? 'class="auto_width"' : '';
27
- echo ( isset($field['multiple']) && $field['multiple'] ) ? ' multiple="multiple"' : ''; ?> >
28
- <?php foreach ( $field['options'] as $opt_key => $opt ) {
29
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
30
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
31
- $selected = ($field['default_value'] == $field_val || FrmAppHelper::get_other_val( $opt_key, $field ) )?(' selected="selected"'):(''); ?>
32
- <option value="<?php echo esc_attr( $field_val ) ?>"<?php echo $selected ?>><?php echo esc_html( $opt ) ?> </option>
33
- <?php } ?>
34
- </select>
35
- <?php }
36
-
37
- if ( $display['default_blank'] ) { ?>
38
- <span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm_clear_on_focus frm-show-click">
39
- <?php FrmFieldsHelper::show_default_blank_js($field['default_blank']); ?>
40
- </span>
41
- <?php } ?>
42
- <div class="clear"></div>
43
- <div class="frm-show-click frm_small_top_margin">
44
- <?php
45
-
46
- if ( ! isset($field['post_field']) || ! in_array($field['post_field'], array( 'post_status', 'post_category')) ) { ?>
47
- <?php do_action('frm_add_multiple_opts_labels', $field); ?>
48
- <ul id="frm_field_<?php echo esc_attr( $field['id'] ) ?>_opts" class="frm_sortable_field_opts<?php echo ( count($field['options']) > 10 ) ? ' frm_field_opts_list' : ''; ?>">
49
- <?php FrmFieldsHelper::show_single_option($field); ?>
50
- </ul>
51
- <?php
52
- } ?>
53
- </div>
54
- <?php
55
- } else if ($field['type'] == 'captcha' ) {
56
- ?>
57
- <?php if ( empty($frm_settings->pubkey) ) { ?>
58
- <div class="howto frm_no_captcha_text"><?php printf(__( 'Your captcha will not appear on your form until you %1$sset up%2$s the Site and Private Keys', 'formidable' ), '<a href="?page=formidable-settings">', '</a>') ?></div>
59
- <?php } ?>
60
- <input type="hidden" name="<?php echo esc_attr( $field_name ) ?>" value="1" />
61
- <?php
62
- } else {
63
- do_action( 'frm_display_added_fields', $field );
64
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-fields/show.php CHANGED
@@ -1,4 +1 @@
1
- <?php
2
- _deprecated_file( basename(__FILE__), '1.07.11', 'FrmFieldsHelper::replace_shortcodes' );
3
-
4
- echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form);
1
+ <?php echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form); ?>
 
 
 
classes/views/frm-fields/single-option.php CHANGED
@@ -1,12 +1,16 @@
1
- <li id="frm_delete_field_<?php echo esc_attr( $field['id'] ); ?>-<?php echo esc_attr( $opt_key ) ?>_container" class="frm_single_option">
2
- <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon" data-fid="<?php echo esc_attr( $field['id'] ); ?>"> </a>
3
- <?php if ( $field['type'] != 'select' ) { ?>
4
- <input type="<?php echo esc_attr( $field['type'] ) ?>" name="<?php echo esc_attr( $field_name ) ?><?php echo ( $field['type'] == 'checkbox' ) ? '[]' : ''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset( $checked ) ? $checked : ''; ?>/>
5
- <?php } ?>
6
- <label class="frm_ipe_field_option field_<?php echo esc_attr( $field['id'] ) ?>_option <?php echo $field['separate_value'] ? 'frm_with_key' : ''; ?>" id="<?php echo esc_attr( $html_id ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php echo ($opt == '') ? __( '(Blank)', 'formidable' ) : $opt ?></label>
7
- <span class="frm_option_key field_<?php echo esc_attr( $field['id'] ) ?>_option_key<?php echo $field['separate_value'] ? '' : ' frm_hidden'; ?>">
8
- <label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo esc_attr( $field['id'] ) ?>-<?php echo esc_attr( $opt_key ) ?>"><?php echo ( $field_val == '' ) ? __( '(Blank)', 'formidable' ) : $field_val ?></label>
9
- </span>
10
- </li>
 
11
  <?php
12
- unset($field_val, $opt, $opt_key);
 
 
 
1
+ <div id="frm_delete_field_<?php echo $field['id']; ?>-<?php echo $opt_key ?>_container" class="frm_single_option">
2
+ <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon"> </a>
3
+ <?php if ($field['type'] != 'select'){ ?>
4
+ <input type="<?php echo $field['type'] ?>" name="<?php echo $field_name ?><?php echo ($field['type'] == 'checkbox')?'[]':''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset($checked)? $checked : ''; ?>/>
5
+ <?php } ?>
6
+ <label class="frm_ipe_field_option field_<?php echo $field['id']?>_option <?php echo $field['separate_value'] ? 'frm_with_key' : ''; ?>" id="field_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php echo ($opt == '') ? __('(Blank)', 'formidable') : $opt ?></label>
7
+ <span class="frm_option_key field_<?php echo $field['id']?>_option_key" <?php echo $field['separate_value'] ? '' : "style='display:none;'"; ?>>
8
+ <label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php echo ($field_val == '') ? __('(Blank)', 'formidable') : $field_val ?></label>
9
+ </span>
10
+ </div>
11
+ <div class="clear"></div>
12
  <?php
13
+ unset($field_val);
14
+ unset($opt);
15
+ unset($opt_key);
16
+ ?>
classes/views/frm-form-actions/_action_inside.php DELETED
@@ -1,57 +0,0 @@
1
- <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
2
- <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
3
-
4
- <table class="form-table">
5
- <tr>
6
- <th>
7
- <label <?php FrmAppHelper::maybe_add_tooltip('action_title') ?>><?php _e( 'Label', 'formidable' ) ?></label>
8
- </th>
9
- <td><input type="text" name="<?php echo esc_attr( $action_control->get_field_name('post_title', '') ) ?>" value="<?php echo esc_attr($form_action->post_title); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip('action_title', 'open') ?>" id="<?php echo esc_attr( $action_control->get_field_id('action_post_title') ) ?>" />
10
- </td>
11
- </tr>
12
- </table>
13
- <?php $action_control->form($form_action, compact('form', 'action_key', 'values')); ?>
14
-
15
- <table class="form-table frm-no-margin">
16
- <tr><td>
17
- <?php
18
- if ( ! isset( $action_control->action_options['event'] ) ) {
19
- $events = 'create';
20
- }
21
-
22
- if ( ! is_array( $action_control->action_options['event'] ) ) {
23
- $action_control->action_options['event'] = explode( ',', $action_control->action_options['event'] );
24
- }
25
-
26
- if ( count( $action_control->action_options['event'] ) == 1 || $action_control->action_options['force_event'] ) {
27
- foreach ( $action_control->action_options['event'] as $e ) { ?>
28
- <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('event') ) ?>[]" value="<?php echo esc_attr( $e ) ?>" />
29
- <?php
30
- }
31
- } else {
32
- ?>
33
- <p><label><?php _e( 'Trigger this action after', 'formidable' ) ?></label>
34
- <?php
35
- $event_labels = array(
36
- 'create' => __( 'Create', 'formidable' ),
37
- 'update' => __( 'Update', 'formidable' ),
38
- 'delete' => __( 'Delete', 'formidable' ),
39
- );
40
-
41
- foreach ( $action_control->action_options['event'] as $event ) { ?>
42
- <label for="frm_action_event_<?php echo esc_attr( $event ) ?>" class="frm_action_events">
43
- <input type="checkbox" name="<?php echo esc_attr( $action_control->get_field_name('event') ) ?>[]" value="<?php echo esc_attr( $event ) ?>" id="<?php echo esc_attr( $action_control->get_field_id('frm_action_event_'. $event) ) ?>" <?php FrmAppHelper::checked($form_action->post_content['event'], $event) ?> />
44
- <?php echo isset( $event_labels[ $event ] ) ? $event_labels[ $event ] : $event; ?>
45
- </label>
46
- <?php
47
- }
48
- ?> </p>
49
- <?php
50
- }
51
-
52
- do_action( 'frm_additional_action_settings', $form_action, compact( 'form', 'action_control', 'action_key', 'values' ) );
53
-
54
- ?>
55
- <span class="alignright frm_action_id <?php echo empty( $form_action->ID ) ? 'frm_hidden' : ''; ?>"><?php printf( __( 'Action ID: %1$s', 'formidable' ), $form_action->ID); ?></span>
56
- </td></tr>
57
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-form-actions/_email_settings.php DELETED
@@ -1,64 +0,0 @@
1
- <table class="form-table frm-no-margin">
2
- <tr>
3
- <th><label <?php FrmAppHelper::maybe_add_tooltip('email_to') ?>><?php _e( 'To', 'formidable' ) ?></label>
4
- </th>
5
- <td><input type="text" name="<?php echo esc_attr( $this->get_field_name('email_to') ) ?>" value="<?php echo esc_attr( $form_action->post_content['email_to'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip('email_to', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('email_to') ) ?>" />
6
- </td>
7
- <td class="frm_bcc_cc_container">
8
- <a href="javascript:void(0)" class="button frm_email_buttons frm_bcc_button <?php
9
- echo ( ! empty($form_action->post_content['bcc']) ? 'frm_hidden' : '' );
10
- ?>" data-emailrow="bcc"><?php _e( 'BCC', 'formidable' ) ?></a>
11
- <a href="javascript:void(0)" class="button frm_email_buttons frm_cc_button <?php
12
- echo ( ! empty($form_action->post_content['cc']) ? 'frm_hidden' : '' );
13
- ?>" data-emailrow="cc"><?php _e( 'CC', 'formidable' ) ?></a>
14
- </td>
15
- </tr>
16
- <tr id="frm_cc_row" class="<?php echo ( empty($form_action->post_content['cc']) ? 'frm_hidden' : '' )?>" >
17
- <th><label <?php FrmAppHelper::maybe_add_tooltip('cc') ?>><?php _e( 'CC', 'formidable' ) ?></label>
18
- </th>
19
- <td class="frm_right_addon">
20
- <input type="text" name="<?php echo esc_attr( $this->get_field_name('cc') ) ?>" value="<?php echo esc_attr( $form_action->post_content['cc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('cc', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('cc') ) ?>" />
21
- <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="cc"></a>
22
- </td>
23
- <td></td>
24
- </tr>
25
- <tr id="frm_bcc_row" class="<?php echo ( empty($form_action->post_content['bcc']) ? 'frm_hidden' : '' )?>" >
26
- <th><label <?php FrmAppHelper::maybe_add_tooltip('bcc') ?>><?php _e( 'BCC', 'formidable' ) ?></label>
27
- </th>
28
- <td class="frm_right_addon">
29
- <input type="text" name="<?php echo esc_attr( $this->get_field_name('bcc') ) ?>" value="<?php echo esc_attr( $form_action->post_content['bcc'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('bcc', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('bcc') ) ?>" />
30
- <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="bcc"></a>
31
- </td>
32
- <td></td>
33
- </tr>
34
- <tr id="frm_reply_to_row" class="<?php echo ( empty($form_action->post_content['reply_to']) ? 'frm_hidden' : '' )?>">
35
- <th><label <?php FrmAppHelper::maybe_add_tooltip('reply_to') ?>><?php _e( 'Reply to', 'formidable' ) ?></label>
36
- </th>
37
- <td class="frm_right_addon">
38
- <input type="text" name="<?php echo esc_attr( $this->get_field_name('reply_to') ) ?>" value="<?php echo esc_attr( $form_action->post_content['reply_to'] ); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('reply_to', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('reply_to') ) ?>" />
39
- <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="reply_to"></a>
40
- </td>
41
- <td></td>
42
- </tr>
43
- <tr>
44
- <th><label <?php FrmAppHelper::maybe_add_tooltip('from') ?>><?php _e( 'From', 'formidable' ) ?></label></th>
45
- <td><input type="text" name="<?php echo esc_attr( $this->get_field_name('from') ) ?>" value="<?php echo esc_attr( $form_action->post_content['from'] ); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip('from', 'open') ?>" id="<?php echo esc_attr( $this->get_field_id('from') ) ?>" />
46
- </td>
47
- <td><a href="javascript:void(0)" class="button frm_email_buttons frm_reply_to_button <?php echo ( ! empty( $form_action->post_content['reply_to'] ) ? 'frm_hidden' : '' ) ?>" data-emailrow="reply_to"><?php _e( 'Reply To', 'formidable' ) ?></a></td>
48
- </tr>
49
- <tr>
50
- <td colspan="3" class="frm_no_top_padding">
51
- <p><label <?php FrmAppHelper::maybe_add_tooltip('email_subject', '', $form->name) ?>><?php _e( 'Subject', 'formidable' ) ?></label><br/>
52
- <input type="text" name="<?php echo esc_attr( $this->get_field_name('email_subject') ) ?>" class="frm_not_email_subject large-text <?php FrmAppHelper::maybe_add_tooltip('email_subject', 'open', $form->name) ?>" id="<?php echo esc_attr( $this->get_field_id('email_subject') ) ?>" size="55" value="<?php echo esc_attr( $form_action->post_content['email_subject'] ); ?>" /></p>
53
-
54
- <p><label><?php _e( 'Message', 'formidable' ) ?> </label><br/>
55
- <textarea name="<?php echo esc_attr( $this->get_field_name('email_message') ) ?>" class="frm_not_email_message large-text" id="<?php echo esc_attr( $this->get_field_id('email_message') ) ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea($form_action->post_content['email_message']) ?></textarea></p>
56
-
57
- <h4><?php _e( 'Options', 'formidable' ) ?> </h4>
58
- <label for="<?php echo esc_attr( $this->get_field_id('inc_user_info') ) ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name('inc_user_info') ) ?>" class="frm_not_inc_user_info" id="<?php echo esc_attr( $this->get_field_id('inc_user_info') ) ?>" value="1" <?php checked( $form_action->post_content['inc_user_info'], 1 ); ?> /> <?php _e( 'Append IP Address, Browser, and Referring URL to message', 'formidable' ) ?></label>
59
-
60
- <p><label for="<?php echo esc_attr( $this->get_field_id('plain_text') ) ?>"><input type="checkbox" name="<?php echo esc_attr( $this->get_field_name('plain_text') ) ?>" id="<?php echo esc_attr( $this->get_field_id('plain_text') ) ?>" value="1" <?php checked( $form_action->post_content['plain_text'], 1 ); ?> /> <?php _e( 'Send Emails in Plain Text', 'formidable' ) ?></label></p>
61
- <?php FrmAppHelper::update_message('conditionally send email notifications'); ?>
62
- </td>
63
- </tr>
64
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-form-actions/default_actions.php DELETED
@@ -1,65 +0,0 @@
1
- <?php
2
- // add post action
3
- class FrmDefPostAction extends FrmFormAction {
4
- public function __construct() {
5
- $action_ops = FrmFormActionsHelper::default_action_opts();
6
- $action_ops['classes'] = 'ab-icon frm_dashicon_font dashicons-before';
7
-
8
- $this->FrmFormAction('wppost', __( 'Create Post', 'formidable' ), $action_ops);
9
- }
10
- }
11
-
12
-
13
- // add register action
14
- class FrmDefRegAction extends FrmFormAction {
15
- public function __construct() {
16
- $action_ops = FrmFormActionsHelper::default_action_opts('frm_register_icon');
17
-
18
- $this->FrmFormAction('register', __( 'Register User', 'formidable' ), $action_ops);
19
- }
20
- }
21
-
22
- // add paypal action
23
- class FrmDefPayPalAction extends FrmFormAction {
24
- public function __construct() {
25
- $action_ops = FrmFormActionsHelper::default_action_opts('frm_paypal_icon');
26
-
27
- $this->FrmFormAction('paypal', __( 'Collect Payment', 'formidable' ), $action_ops);
28
- }
29
- }
30
-
31
- // add aweber action
32
- class FrmDefAweberAction extends FrmFormAction {
33
- public function __construct() {
34
- $action_ops = FrmFormActionsHelper::default_action_opts('frm_aweber_icon');
35
-
36
- $this->FrmFormAction('aweber', __( 'Aweber', 'formidable' ), $action_ops);
37
- }
38
- }
39
-
40
- // add mailchimp action
41
- class FrmDefMlcmpAction extends FrmFormAction {
42
- public function __construct() {
43
- $action_ops = FrmFormActionsHelper::default_action_opts('frm_mailchimp_icon');
44
-
45
- $this->FrmFormAction('mailchimp', __( 'MailChimp', 'formidable' ), $action_ops);
46
- }
47
- }
48
-
49
- // add twilio action
50
- class FrmDefTwilioAction extends FrmFormAction {
51
- public function __construct() {
52
- $action_ops = FrmFormActionsHelper::default_action_opts('frm_sms_icon');
53
-
54
- $this->FrmFormAction('twilio', __( 'Twilio', 'formidable' ), $action_ops);
55
- }
56
- }
57
-
58
- // add highrise action
59
- class FrmDefHrsAction extends FrmFormAction {
60
- public function __construct() {
61
- $action_ops = FrmFormActionsHelper::default_action_opts('frm_highrise_icon');
62
-
63
- $this->FrmFormAction('highrise', __( 'Highrise', 'formidable' ), $action_ops);
64
- }
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-form-actions/email_action.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
-
3
- class FrmEmailAction extends FrmFormAction {
4
-
5
- public function __construct() {
6
- $action_ops = array(
7
- 'classes' => 'frm_email_icon frm_icon_font',
8
- 'active' => true,
9
- 'event' => array( 'create'),
10
- 'limit' => 99,
11
- 'priority' => 10,
12
- 'ajax_load' => false,
13
- );
14
- $action_ops = apply_filters('frm_email_control_settings', $action_ops);
15
-
16
- $this->FrmFormAction('email', __( 'Email Notification', 'formidable' ), $action_ops);
17
- }
18
-
19
- public function form( $form_action, $args = array() ) {
20
- extract($args);
21
-
22
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_email_settings.php');
23
- }
24
-
25
- public function get_defaults() {
26
- return array(
27
- 'email_to' => '[admin_email]',
28
- 'cc' => '',
29
- 'bcc' => '',
30
- 'from' => '[sitename] <[admin_email]>',
31
- 'reply_to' => '',
32
- 'email_subject' => '',
33
- 'email_message' => '[default-message]',
34
- 'inc_user_info' => 0,
35
- 'plain_text' => 0,
36
- 'event' => array( 'create'),
37
- );
38
- }
39
-
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-form-actions/form_action.php DELETED
@@ -1,40 +0,0 @@
1
- <?php
2
- $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings';
3
-
4
- $form_action = apply_filters('frm_form_action_settings', $form_action, $form_action->post_excerpt);
5
- $form_action = apply_filters('frm_form_'. $form_action->post_excerpt .'_action_settings', $form_action);
6
-
7
- ?>
8
- <div id="frm_form_action_<?php echo esc_attr( $action_key ) ?>" class="widget frm_form_action_settings frm_single_<?php echo esc_attr( $form_action->post_excerpt ) ?>_settings" data-actionkey="<?php echo esc_attr( $action_key ) ?>">
9
- <div class="widget-top">
10
- <div class="widget-title-action">
11
- <a href="javascript:void(0)" class="widget-action hide-if-no-js"></a>
12
- </div>
13
- <div class="widget-title">
14
- <h3><span class="frm_form_action_icon <?php echo esc_attr( $action_control->action_options['classes'] ) ?>"></span>
15
- <?php echo esc_html( $form_action->post_title ); ?>
16
- </h3>
17
- <span class="frm_email_icons alignright">
18
- <a href="javascript:void(0)" data-removeid="frm_form_action_<?php echo esc_attr( $action_key ) ?>" class="frm_icon_font frm_delete_icon frm_remove_form_action"> </a>
19
- </span>
20
- </div>
21
- </div>
22
- <div class="widget-inside frm_hidden">
23
- <?php
24
- if ( defined('DOING_AJAX') || ! $action_control->action_options['ajax_load'] ) {
25
- // only load settings if they are just added or are open
26
- include(dirname(__FILE__) .'/_action_inside.php');
27
- } else {
28
- // include hidden settings so action won't get lost on update ?>
29
- <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" />
30
- <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" />
31
- <?php
32
- } ?>
33
- </div>
34
- <style type="text/css">
35
- .frm_no_actions{
36
- opacity:0;
37
- *visibility:hidden;
38
- }
39
- </style>
40
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-forms/_publish_box.php DELETED
@@ -1,110 +0,0 @@
1
- <div id="submitdiv" class="postbox">
2
- <div class="inside">
3
- <div class="submitbox" id="submitpost">
4
-
5
- <div id="minor-publishing">
6
- <div id="minor-publishing-actions">
7
- <?php if ( 'draft' == $values['status'] ) { ?>
8
- <div id="save-action">
9
- <input type="button" value="<?php esc_html_e( 'Save Draft', 'formidable' ); ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-secondary button-large" id="save-post" />
10
- <span class="spinner"></span>
11
- </div>
12
- <?php } ?>
13
- <div id="preview-action">
14
- <?php
15
- if ( ! isset($hide_preview) || ! $hide_preview ) {
16
-
17
- if ( isset($values['form_key']) ) {
18
- $frm_settings = FrmAppHelper::get_settings();
19
- if ( empty($frm_settings->preview_page_id) ) { ?>
20
- <a href="<?php echo esc_url( FrmFormsHelper::get_direct_link($values['form_key']) ); ?>" class="preview button" target="wp-frm-preview-<?php echo esc_attr( $id ) ?>"><?php _e( 'Preview', 'formidable' ) ?></a>
21
- <?php
22
- } else {
23
- ?>
24
- <div class="preview dropdown">
25
- <a href="#" id="frm-previewDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php _e( 'Preview', 'formidable' ) ?> <b class="caret"></b></a>
26
-
27
- <ul class="frm-dropdown-menu pull-right" role="menu" aria-labelledby="frm-previewDrop">
28
- <li><a href="<?php echo esc_url( FrmFormsHelper::get_direct_link($values['form_key']) ); ?>" target="_blank"><?php _e( 'On Blank Page', 'formidable' ) ?></a></li>
29
- <li><a href="<?php echo esc_url( add_query_arg('form', $values['form_key'], get_permalink( $frm_settings->preview_page_id )) ) ?>" target="_blank"><?php _e( 'In Theme', 'formidable' ) ?></a></li>
30
- </ul>
31
- </div>
32
- <?php }
33
- }
34
- } ?>
35
- </div>
36
- <?php if ( 'draft' == $values['status'] ) { ?>
37
- <div class="clear"></div>
38
- <?php } ?>
39
- </div><!-- #minor-publishing-actions -->
40
-
41
- <div id="misc-publishing-actions">
42
- <div class="misc-pub-section">
43
-
44
- <?php if ( $values['is_template'] ) { ?>
45
- <br/>
46
- <?php } else { ?>
47
- <span id="frm_shortcode"><span class="frm-buttons-icon wp-media-buttons-icon"></span> <?php _e( 'Form', 'formidable' ) ?> <strong><?php _e( 'Shortcodes', 'formidable' ) ?></strong></span>
48
- <a href="#edit_frm_shortcode" class="edit-frm_shortcode hide-if-no-js" tabindex='4'><?php _e( 'Show', 'formidable' ) ?></a>
49
- <div id="frm_shortcodediv" class="hide-if-js">
50
- <p class="howto"><?php _e( 'Insert on a page, post, or text widget', 'formidable' ) ?>:</p>
51
- <p><input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo esc_attr( $id ); ?>]" />
52
- <input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo esc_attr( $id ); ?> title=true description=true]" />
53
- </p>
54
-
55
- <p class="howto"><?php _e( 'Insert in a template', 'formidable' ) ?>:</p>
56
- <p><input type="text" readonly="true" class="frm_select_box frm_insert_in_template" value="&lt;?php echo FrmFormsController::get_form_shortcode( array( 'id' => $id, 'title' => false, 'description' => false)); ?&gt;" /></p>
57
-
58
- <p><a href="#edit_frm_shortcode" class="cancel-frm_shortcode hide-if-no-js"><?php _e( 'Hide', 'formidable' ); ?></a></p>
59
- </div>
60
- <?php } ?>
61
- </div>
62
-
63
-
64
- <div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e( 'Status', 'formidable' ) ?>:</label>
65
- <span id="form-status-display"><?php echo FrmFormsHelper::status_nice_name($values['status']); ?></span>
66
- <?php if ( 'draft' != $values['status'] && ( ! isset($_GET['frm_action']) || 'settings' != $_GET['frm_action'] ) ) { ?>
67
- <a href="#post_status" class="edit-form-status hide-if-no-js" data-slidedown="form-status-select"><span aria-hidden="true"><?php _e( 'Edit') ?></span> <span class="screen-reader-text"><?php _e( 'Edit status') ?></span></a>
68
-
69
- <div id="form-status-select" class="frm_hidden">
70
- <select name="frm_change_status" id="form_change_status">
71
- <option value="published" <?php selected($values['status'], 'published') ?>><?php _e( 'Published' ) ?></option>
72
- <option value="draft" <?php selected($values['status'], 'draft') ?>><?php _e( 'Draft' ) ?></option>
73
- </select>
74
- <a href="#post_status" class="save-form-status hide-if-no-js button"><?php _e( 'OK') ?></a>
75
- <a href="#post_status" class="cancel-form-status hide-if-no-js button-cancel" data-slideup="form-status-select"><?php _e( 'Cancel') ?></a>
76
- </div>
77
- <?php } ?>
78
- </div><!-- .misc-pub-section -->
79
-
80
- <?php if ( has_action('frm_settings_buttons') ) { ?>
81
- <div class="misc-pub-section">
82
- <?php do_action('frm_settings_buttons', $values); ?>
83
- <div class="clear"></div>
84
- </div>
85
- <?php } ?>
86
-
87
- </div><!-- #misc-publishing-actions -->
88
- <div class="clear"></div>
89
- </div><!-- #minor-publishing -->
90
-
91
- <div id="major-publishing-actions">
92
- <div id="delete-action">
93
- <?php echo FrmFormsHelper::delete_trash_link($id, $values['status']); ?>
94
- </div>
95
-
96
- <div id="publishing-action">
97
- <span class="spinner"></span>
98
- <?php if ( isset($_GET['frm_action']) && 'settings' == $_GET['frm_action'] ) { ?>
99
- <input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" class="frm_submit_form frm_submit_settings_btn button-primary button-large" id="frm_submit_side_top" />
100
- <?php } else { ?>
101
- <input type="button" value="<?php echo isset($button) ? esc_attr($button) : __( 'Update', 'formidable' ); ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary button-large" id="frm_submit_side_top" />
102
- <?php } ?>
103
- </div>
104
-
105
- <div class="clear"></div>
106
- </div><!-- #major-publishing-actions -->
107
-
108
- </div><!-- .submitbox -->
109
- </div><!-- .inside -->
110
- </div><!-- .submitdiv -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-forms/add_field.php CHANGED
@@ -1,322 +1,303 @@
1
  <?php
2
-
3
- $display = apply_filters('frm_display_field_options', array(
4
- 'type' => $field['type'], 'field_data' => $field,
5
- 'required' => true, 'unique' => false, 'read_only' => false,
6
- 'description' => true, 'options' => true, 'label_position' => true,
7
- 'invalid' => false, 'size' => false, 'clear_on_focus' => false,
8
- 'default_blank' => true, 'css' => true, 'conf_field' => false,
9
- ));
10
-
11
- $li_classes = 'form-field edit_form_item frm_field_box frm_top_container frm_not_divider edit_field_type_'. $display['type'];
12
- $li_classes = apply_filters('frm_build_field_class', $li_classes, $field );
13
-
14
- if ( isset($values) && isset($values['ajax_load']) && $values['ajax_load'] && isset($count) && $count > 10 && ! in_array($field['type'], array( 'divider', 'end_divider')) ) {
15
- ?>
16
- <li id="frm_field_id_<?php echo esc_attr( $field['id'] ); ?>" class="<?php echo esc_attr( $li_classes ) ?> frm_field_loading" data-fid="<?php echo esc_attr( $field['id'] ) ?>" data-formid="<?php echo esc_attr( 'divider' == $field['type'] ? $field['form_select'] : $field['form_id'] ); ?>" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
17
- <img src="<?php echo FrmAppHelper::plugin_url() ?>/images/ajax_loader.gif" alt="<?php esc_attr_e( 'Loading', 'formidable' ) ?>" />
18
  <span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars(json_encode($field)) ?></span>
19
  </li>
20
  <?php
21
  return;
22
  }
23
 
24
- $frm_settings = FrmAppHelper::get_settings();
25
-
26
- if ( ! isset( $frm_all_field_selection ) ) {
27
- if ( isset($frm_field_selection) && isset($pro_field_selection) ) {
28
- $frm_all_field_selection = array_merge($frm_field_selection, $pro_field_selection);
29
- } else {
30
- $pro_field_selection = FrmFieldsHelper::pro_field_selection();
31
- $frm_all_field_selection = array_merge(FrmFieldsHelper::field_selection(), $pro_field_selection);
32
  }
33
  }
34
 
35
- $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
 
 
 
36
 
37
-
38
- if ( ! isset( $ajax ) ) {
39
- $li_classes .= ' ui-state-default widgets-holder-wrap'; ?>
40
- <li id="frm_field_id_<?php echo esc_attr( $field['id'] ); ?>" class="<?php echo esc_attr( $li_classes ) ?>" data-fid="<?php echo esc_attr( $field['id'] ) ?>" data-formid="<?php echo ( 'divider' == $field['type'] ) ? esc_attr( $field['form_select'] ) : esc_attr( $field['form_id'] ); ?>">
41
- <?php
42
- }
43
-
44
- if ( $field['type'] == 'divider' ) { ?>
45
- <div class="divider_section_only">
46
- <?php
47
- }
48
- ?>
49
-
50
- <a href="javascript:void(0);" class="frm_bstooltip alignright frm-show-hover frm-move frm-hover-icon frm_icon_font frm_move_icon" title="<?php esc_attr_e( 'Move Field', 'formidable' ) ?>"> </a>
51
- <a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_delete_icon frm_delete_field" title="<?php esc_attr_e( 'Delete Field', 'formidable' ) ?>"> </a>
52
- <a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_duplicate_icon" title="<?php ( $field['type'] == 'divider' ) ? esc_attr_e( 'Duplicate Section', 'formidable' ) : esc_attr_e( 'Duplicate Field', 'formidable' ) ?>"> </a>
53
  <input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr($field['id']) ?>" />
54
  <?php do_action('frm_extra_field_actions', $field['id']); ?>
55
- <?php if ( $display['required'] ) { ?>
56
- <span id="require_field_<?php echo esc_attr( $field['id'] ); ?>">
57
- <a href="javascript:void(0);" class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int) $field['required'] ?>" id="req_field_<?php echo esc_attr( $field['id'] ); ?>" title="Click to Mark as <?php echo ($field['required'] == '0') ? '' : 'not '; ?>Required"></a>
58
  </span>
59
- <?php }
60
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  ?>
62
- <label class="<?php echo ( $field['type'] == 'end_divider' ) ? '' : 'frm_ipe_field_label'; ?> frm_primary_label <?php echo ($field['type'] == 'break') ? 'button': ''; ?>" id="field_label_<?php echo esc_attr( $field['id'] ); ?>"><?php echo ($field['name'] == '') ? __( '(no label)') : force_balance_tags($field['name']); ?></label>
63
 
64
-
65
- <div id="field_<?php echo esc_attr( $field['id'] ) ?>_inner_container" class="frm_inner_field_container">
66
- <div class="frm_form_fields" data-ftype="<?php echo esc_attr( $display['type'] ) ?>">
67
  <?php
68
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/show-build.php');
69
-
70
- if ($display['clear_on_focus']){ ?>
71
- <span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm-show-click"><?php
72
-
73
- if ( $display['default_blank'] ) {
74
- FrmFieldsHelper::show_default_blank_js($field['default_blank']);
75
- }
76
 
77
- FrmFieldsHelper::show_onfocus_js($field['clear_on_focus']);
 
 
78
  ?>
79
- </span>
 
 
 
 
 
80
  <?php
81
-
82
- do_action('frm_extra_field_display_options', $field);
83
- }
84
  ?>
85
- <div class="clear"></div>
86
- </div>
87
  <?php
88
- if ($display['description']){ ?>
89
- <div class="frm_ipe_field_desc description <?php echo ($field['description'] == '') ? 'frm-show-click' : '' ?>" id="field_description_<?php echo esc_attr( $field['id'] ); ?>"><?php echo ($field['description'] == '') ? __( '(Click to add description)', 'formidable' ) : force_balance_tags( $field['description'] ); ?></div>
90
- <input type="hidden" name="field_options[description_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['description'] ); ?>" />
91
-
92
- <?php } ?>
93
- </div> <?php //End field_x_inner_container div
94
-
95
- if ( $display['conf_field'] ) { ?>
96
- <div id="frm_conf_field_<?php echo esc_attr( $field['id'] ) ?>_container" class="frm_conf_field_container frm_form_fields frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
97
- <div id="frm_conf_field_<?php echo esc_attr( $field['id'] ) ?>_inner_container" class="frm_inner_conf_container">
98
- <input type="text" id="conf_field_<?php echo esc_attr( $field['field_key'] ) ?>" name="field_options[conf_input_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_input'] ); ?>" <?php do_action('frm_field_input_html', $field) ?> />
99
- <div class="frm_ipe_field_conf_desc description <?php echo ($field['conf_desc'] == '') ? 'frm-show-click' : '' ?>"><?php echo ($field['conf_desc'] == '') ? __( '(Click to add description)', 'formidable' ) : force_balance_tags($field['conf_desc']); ?></div>
100
- <input type="hidden" name="field_options[conf_desc_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_desc'] ); ?>" />
101
- </div>
102
- <?php if ($display['clear_on_focus']){ ?>
103
- <div class="alignleft">
104
- <span id="frm_clear_on_focus_<?php echo esc_attr( $field['id'] ) ?>" class="frm-show-click">
105
- <?php
106
- if ( $display['default_blank'] ) {
107
- FrmFieldsHelper::show_default_blank_js($field['default_blank']);
108
- }
109
-
110
- FrmFieldsHelper::show_onfocus_js($field['clear_on_focus']);
111
- ?>
112
- </span>
113
- </div>
114
- <?php } ?>
115
- </div>
116
- <div class="clear"></div>
117
  <?php }
118
-
119
- if ( in_array($field['type'], array( 'select', 'radio', 'checkbox')) ) { ?>
120
- <div class="frm-show-click frm_small_top_margin"><?php
121
-
 
 
 
 
 
122
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
123
  echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
124
- } else if ( ! isset( $field['post_field'] ) || ! in_array( $field['post_field'], array( 'post_category', 'post_status') ) ) {
125
- ?>
126
- <div id="frm_add_field_<?php echo esc_attr( $field['id'] ); ?>">
127
- <a href="javascript:void(0);" data-opttype="single" class="button frm_cb_button frm_add_opt"><?php _e( 'Add Option', 'formidable' ) ?></a>
128
-
129
- <?php
130
- if ( FrmAppHelper::pro_is_installed() ) { ?>
131
- <a href="javascript:void(0);" id="other_button_<?php echo esc_attr( $field['id'] ); ?>" data-opttype="other" data-ftype="<?php echo esc_attr( $field['type'] ) ?>" class="button frm_cb_button frm_add_opt<?php echo ( in_array( $field['type'], array( 'radio', 'select') ) && $field['other'] == true ? ' frm_hidden' : '' ); ?>"><?php _e( 'Add "Other"', 'formidable' ) ?></a>
132
- <input type="hidden" value="<?php echo esc_attr( $field['other'] ); ?>" id="other_input_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[other_<?php echo esc_attr( $field['id'] ); ?>]">
133
- <?php
134
- }
135
-
136
- if ( ! isset($field['post_field']) || $field['post_field'] != 'post_category' ) { ?>
137
- <a href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '&quot;', $field['name']))), 20) . ' '. __( 'Field Choices', 'formidable' ); ?>" class="thickbox frm_orange"><?php _e( 'Bulk Edit Options', 'formidable' ) ?></a>
 
 
 
 
138
  <?php } ?>
139
  </div>
 
 
 
140
  <?php
141
- }
142
  ?>
143
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  <?php
145
- }
 
146
 
147
- do_action('frm_before_field_options', $field);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  if ($display['options']){ ?>
150
  <div class="widget">
151
  <div class="widget-top">
152
- <div class="widget-title-action"><a href="javascript:void(0);" class="widget-action"></a></div>
153
- <div class="widget-title"><h4><?php _e( 'Field Options', 'formidable' ) ?> (ID <?php echo (int) $field['id'] ?>)</h4></div>
154
  </div>
155
  <div class="widget-inside">
156
- <table class="form-table frm_clear_none">
157
  <?php $field_types = FrmFieldsHelper::get_field_types($field['type']); ?>
158
- <tr><td class="frm_150_width"><label><?php _e( 'Field Type', 'formidable' ) ?></label></td>
159
  <td>
160
- <div class="hide-if-no-js edit-slug-box frm_help" title="<?php esc_attr_e( 'The field key can be used as an alternative to the field ID in many cases.', 'formidable' ) ?>">
161
- <?php _e( 'Field Key:', 'formidable' ) ?>
162
- <div class="<?php echo ($frm_settings->lock_keys) ? 'frm_field_key' : 'frm_ipe_field_key" title="'. __( 'Click to edit.', 'formidable' ); ?>" ><?php echo esc_html( $field['field_key'] ); ?></div>
163
- <?php if ( ! $frm_settings->lock_keys ) { ?>
164
- <input type="hidden" name="field_options[field_key_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['field_key'] ); ?>" />
165
  <?php } ?>
166
  </div>
167
-
168
- <select <?php if ( count($field_types) == 1 ) { ?>disabled="disabled"<?php } else { ?>name="field_options[type_<?php echo esc_attr( $field['id'] ) ?>]"<?php } ?>>
 
 
 
169
  <?php
170
- foreach ( $field_types as $fkey => $ftype ) { ?>
171
- <option value="<?php echo esc_attr( $fkey ) ?>" <?php echo ( $fkey == $field['type'] ) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists($fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>><?php echo is_array($ftype) ? $ftype['name'] : $ftype ?> </option>
172
- <?php
173
- unset( $fkey, $ftype );
174
- } ?>
175
- </select>
176
-
177
- <?php
178
- if ( $display['required'] ) { ?>
179
- <label for="frm_req_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label"><input type="checkbox" id="frm_req_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_req_field" name="field_options[required_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php echo $field['required'] ? 'checked="checked"': ''; ?> /> <?php _e( 'Required', 'formidable' ) ?></label>
180
- <?php
181
- }
182
-
183
- if ( $display['unique'] ) {
184
- if ( ! isset( $field['unique'] ) ) {
185
  $field['unique'] = false;
186
- }
187
  ?>
188
- <label for="frm_uniq_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\' then no one else will be allowed to enter the same name.', 'formidable' ) ?>"><input type="checkbox" name="field_options[unique_<?php echo esc_attr( $field['id'] ) ?>]" id="frm_uniq_field_<?php echo esc_attr( $field['id'] ) ?>" value="1" <?php checked( $field['unique'], 1 ); ?> class="frm_mark_unique" /> <?php _e( 'Unique', 'formidable' ) ?></label>
189
- <?php
190
- }
191
-
192
- if ( $display['read_only'] ) {
193
- if ( ! isset( $field['read_only'] ) ) {
194
  $field['read_only'] = false;
195
- }
196
  ?>
197
- <label for="frm_read_only_field_<?php echo esc_attr( $field['id'] ) ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ) ?>" ><input type="checkbox" id="frm_read_only_field_<?php echo esc_attr( $field['id'] ) ?>" name="field_options[read_only_<?php echo esc_attr( $field['id'] ) ?>]" value="1" <?php echo $field['read_only'] ? ' checked="checked"' : ''; ?>/> <?php _e( 'Read Only', 'formidable' ) ?></label>
198
- <?php }
199
-
200
- do_action('frm_field_options_form_top', $field, $display, $values);
201
-
202
- ?>
203
- <?php
204
- if ( $display['required'] ) { ?>
205
- <div class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>">
206
- <span class="howto"><?php _e( 'Indicate required field with', 'formidable' ) ?></span>
207
- <input type="text" name="field_options[required_indicator_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['required_indicator'] ); ?>" />
208
  </div>
209
  <?php } ?>
210
  </td>
211
  </tr>
212
-
213
- <?php
214
- if ( $display['css'] ) { ?>
215
- <tr><td><label><?php _e( 'CSS layout classes', 'formidable' ) ?></label>
216
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable' ) ?>" ></span>
217
- </td>
218
- <td><input type="text" name="field_options[classes_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['classes'] ) ?>" id="frm_classes_<?php echo esc_attr( $field['id'] ) ?>" class="frm_classes frm_long_input" />
219
  </td>
 
 
220
  </tr>
221
- <?php
222
- }
223
-
224
- if ( $display['label_position'] ) { ?>
225
- <tr><td class="frm_150_width"><label><?php _e( 'Label Position', 'formidable' ) ?></label></td>
226
- <td><select name="field_options[label_<?php echo esc_attr( $field['id'] ) ?>]">
227
- <option value=""<?php selected($field['label'], ''); ?>><?php _e( 'Default', 'formidable' ) ?></option>
228
- <option value="top"<?php selected($field['label'], 'top'); ?>><?php _e( 'Top', 'formidable' ) ?></option>
229
- <option value="left"<?php selected($field['label'], 'left'); ?>><?php _e( 'Left', 'formidable' ) ?></option>
230
- <option value="right"<?php selected($field['label'], 'right'); ?>><?php _e( 'Right', 'formidable' ) ?></option>
231
- <option value="inline"<?php selected($field['label'], 'inline'); ?>><?php _e( 'Inline (left without a set width)', 'formidable' ) ?></option>
232
- <option value="none"<?php selected($field['label'], 'none'); ?>><?php _e( 'None', 'formidable' ) ?></option>
233
- <option value="hidden"<?php selected($field['label'], 'hidden'); ?>><?php _e( 'Hidden (but leave the space)', 'formidable' ) ?></option>
234
  </select>
235
- </td>
236
  </tr>
237
  <?php } ?>
238
  <?php if ($display['size']){ ?>
239
- <tr><td class="frm_150_width"><label><?php _e( 'Field Size', 'formidable' ) ?></label></td>
240
  <td>
241
- <?php
242
- if ( in_array( $field['type'], array( 'select', 'time', 'data' ) ) ) {
243
- if ( ! isset( $values['custom_style'] ) || $values['custom_style'] ) { ?>
244
- <label for="size_<?php echo esc_attr( $field['id'] ) ?>"><input type="checkbox" name="field_options[size_<?php echo esc_attr( $field['id'] ) ?>]" id="size_<?php echo esc_attr( $field['id'] ) ?>" value="1" <?php echo ( isset($field['size']) && $field['size'] ) ? 'checked="checked"' : ''; ?> /> <?php _e( 'automatic width', 'formidable' ) ?></label>
245
- <?php
246
- }
247
- } else { ?>
248
- <input type="text" name="field_options[size_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['size'] ); ?>" size="5" /> <span class="howto"><?php _e( 'pixels wide', 'formidable' ) ?></span>
249
-
250
- <input type="text" name="field_options[max_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['max'] ); ?>" size="5" /> <span class="howto"><?php echo ( $field['type'] == 'textarea' || $field['type'] == 'rte' ) ? __( 'rows high', 'formidable' ) : __( 'characters maximum', 'formidable' ) ?></span>
251
- <?php
252
- } ?>
253
  </td>
254
  </tr>
255
  <?php } ?>
256
- <?php do_action('frm_field_options_form', $field, $display, $values);
257
-
258
- if ( $display['required'] || $display['invalid'] || $display['unique'] || $display['conf_field'] ) { ?>
259
- <tr class="frm_validation_msg <?php echo ($display['invalid'] || $field['required'] || (isset($field['unique']) && $field['unique']) || ( isset($field['conf_field']) && $field['conf_field'] ) ) ? '' : 'frm_hidden'; ?>"><td colspan="2">
260
- <div class="menu-settings">
261
- <h3 class="frm_no_bg"><?php _e( 'Validation', 'formidable' ) ?></h3>
262
-
263
- <div class="frm_validation_box">
264
- <?php
265
- if ( $display['required'] ) { ?>
266
- <p class="frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>"><label><?php _e( 'Required', 'formidable' ) ?></label>
267
- <input type="text" name="field_options[blank_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['blank'] ); ?>" />
268
  </p>
269
- <?php
270
- }
271
-
272
- if ( $display['invalid'] ) { ?>
273
- <p><label><?php _e( 'Invalid Format', 'formidable' ) ?></label>
274
- <input type="text" name="field_options[invalid_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['invalid'] ); ?>" />
275
  </p>
276
- <?php
277
- }
278
-
279
- if ( $display['unique'] ) { ?>
280
- <p class="frm_unique_details<?php echo esc_attr( $field['id'] . ( $field['unique'] ? '' : ' frm_hidden' ) ); ?>">
281
- <label><?php _e( 'Unique', 'formidable' ) ?></label>
282
- <input type="text" name="field_options[unique_msg_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['unique_msg'] ); ?>" />
283
  </p>
284
- <?php
285
- }
286
-
287
- if ( $display['conf_field'] ) { ?>
288
- <p class="frm_conf_details<?php echo esc_attr( $field['id'] . ( $field['conf_field'] ? '' : ' frm_hidden' ) ); ?>">
289
- <label><?php _e( 'Confirmation', 'formidable' ) ?></label>
290
- <input type="text" name="field_options[conf_msg_<?php echo esc_attr( $field['id'] ) ?>]" value="<?php echo esc_attr( $field['conf_msg'] ); ?>" />
291
- </p>
292
- <?php
293
- } ?>
294
- </div>
295
- </div>
296
  </td>
297
  </tr>
298
  <?php } ?>
299
-
300
  </table>
301
  </div>
302
  </div>
303
- <?php }
304
-
305
- if ( $field['type'] == 'divider' ) { ?>
306
- </div>
307
- <div class="frm_no_section_fields">
308
- <p class="howto"><?php _e( 'Drag fields from your form or the sidebar into this section', 'formidable' ) ?></p>
309
- </div>
310
- <ul class="start_divider frm_sorting">
311
- <?php
312
- } else if ( $field['type'] == 'end_divider' ) { ?>
313
- </ul>
314
- <?php
315
- }
316
-
317
- if ( ! isset( $ajax ) ) { ?>
318
  </li>
319
- <?php
320
- }
321
-
322
- unset($display);
1
  <?php
2
+ if(isset($values) and isset($values['ajax_load']) and $values['ajax_load'] and isset($count) and $count > 10){ ?>
3
+ <li id="frm_field_id_<?php echo $field['id']; ?>" class="form-field frm_field_box frm_field_loading edit_form_item frm_top_container" data-triggered="0">
4
+ <img src="<?php echo FrmAppHelper::plugin_url() ?>/images/ajax_loader.gif" alt="<?php _e('Loading', 'formidable') ?>" />
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  <span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars(json_encode($field)) ?></span>
6
  </li>
7
  <?php
8
  return;
9
  }
10
 
11
+ global $frm_settings;
12
+ if(!isset($frm_all_field_selection)){
13
+ if(isset($frm_field_selection) and isset($frm_pro_field_selection)){
14
+ $frm_all_field_selection = array_merge($frm_field_selection, $frm_pro_field_selection);
15
+ }else{
16
+ $frm_pro_field_selection = FrmFieldsHelper::pro_field_selection();
17
+ $frm_all_field_selection = array_merge(FrmFieldsHelper::field_selection(), $frm_pro_field_selection);
 
18
  }
19
  }
20
 
21
+ if(!isset($frm_vars))
22
+ global $frm_vars;
23
+
24
+ $disabled_fields = ($frm_vars['pro_is_installed']) ? array() : $frm_pro_field_selection;
25
 
26
+
27
+ $display = apply_filters('frm_display_field_options', array(
28
+ 'type' => $field['type'], 'field_data' => $field,
29
+ 'required' => true, 'unique' => false, 'read_only' => false,
30
+ 'description' => true, 'options' => true, 'label_position' => true,
31
+ 'invalid' => false, 'size' => false, 'clear_on_focus' => false,
32
+ 'default_blank' => true, 'css' => true
33
+ )); ?>
34
+ <?php if(!isset($ajax)){ ?>
35
+ <li id="frm_field_id_<?php echo $field['id']; ?>" class="form-field edit_form_item frm_field_box ui-state-default edit_field_type_<?php echo $display['type'] ?> frm_top_container">
36
+ <?php } ?>
37
+ <a href="javascript:void(0);" class="frm_bstooltip alignright frm-show-hover frm-move frm-hover-icon frm_icon_font frm_move_field" title="<?php esc_attr_e('Move Field', 'formidable') ?>"> </a>
38
+ <a href="javascript:frm_delete_field(<?php echo $field['id']; ?>)" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_delete_icon" id="frm_delete_field<?php echo $field['id']; ?>" title="<?php esc_attr_e('Delete Field', 'formidable') ?>"> </a>
39
+ <a href="javascript:frm_duplicate_field(<?php echo $field['id']; ?>)" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_duplicate_form" title="<?php esc_attr_e('Duplicate Field', 'formidable') ?>"> </a>
 
 
40
  <input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr($field['id']) ?>" />
41
  <?php do_action('frm_extra_field_actions', $field['id']); ?>
42
+ <?php if ($display['required']){ ?>
43
+ <span id="require_field_<?php echo $field['id']; ?>">
44
+ <a class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int)$field['required'] ?>" id="req_field_<?php echo $field['id']; ?>" title="Click to Mark as <?php echo ($field['required'] == '0') ? '' : 'not '; ?>Required"></a>
45
  </span>
46
+ <?php } ?>
47
+ <label class="frm_ipe_field_label frm_primary_label <?php echo ($field['type'] == 'break') ? 'button': ''; ?>" id="field_label_<?php echo $field['id']; ?>"><?php echo force_balance_tags($field['name']) ?></label>
48
+
49
+ <div class="frm_form_fields" data-ftype="<?php echo $display['type'] ?>">
50
+ <?php if ($display['type'] == 'text'){ ?>
51
+ <input type="text" name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" value="<?php echo esc_attr($field['default_value']); ?>" <?php echo (isset($field['size']) && $field['size']) ? 'style="width:auto" size="'. $field['size'] .'"' : ''; ?> class="dyn_default_value" />
52
+ <?php }else if ($field['type'] == 'textarea'){ ?>
53
+ <textarea name="<?php echo $field_name ?>"<?php if ($field['size']) echo ' style="width:auto" cols="'. $field['size'] .'"' ?> rows="<?php echo $field['max']; ?>" id="field_<?php echo $field['field_key'] ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea>
54
+
55
+ <?php
56
+
57
+ }else if ($field['type'] == 'radio' or $field['type'] == 'checkbox'){
58
+ $field['default_value'] = maybe_unserialize($field['default_value']);
59
+ if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
60
+ do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
61
+ }else{ ?>
62
+ <div id="frm_field_<?php echo $field['id'] ?>_opts" class="clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>">
63
+ <?php do_action('frm_add_multiple_opts_labels', $field); ?>
64
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php'); ?>
65
+ </div>
66
+ <?php
67
+ }
68
  ?>
 
69
 
70
+ <div class="frm-show-click" style="margin-top:5px;">
 
 
71
  <?php
 
 
 
 
 
 
 
 
72
 
73
+ if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
74
+ echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
75
+ } else if ( !isset($field['post_field']) || $field['post_field'] != 'post_status' ) {
76
  ?>
77
+ <div id="frm_add_field_<?php echo $field['id']; ?>">
78
+ <a href="javascript:frm_add_field_option(<?php echo $field['id']; ?>)" class="frm_orange frm_add_opt">+ <?php _e('Add an Option', 'formidable') ?></a>
79
+
80
+ <?php _e('or', 'formidable'); ?>
81
+ <a title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '&quot;', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Field Choices', 'formidable') ?></a>
82
+ </div>
83
  <?php
84
+ }
 
 
85
  ?>
86
+ </div>
 
87
  <?php
88
+ }else if ($field['type'] == 'select'){
89
+ if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
90
+ echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
91
+ }else{ ?>
92
+ <select name="<?php echo $field_name; echo (isset($field['multiple']) and $field['multiple']) ? '[]' : ''; ?>" <?php
93
+ echo (isset($field['size']) && $field['size']) ? 'style="width:auto"' : '';
94
+ echo (isset($field['multiple']) and $field['multiple']) ? ' multiple="multiple"' : ''; ?> >
95
+ <?php foreach ($field['options'] as $opt_key => $opt){
96
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
97
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
98
+ $selected = ($field['default_value'] == $field_val)?(' selected="selected"'):(''); ?>
99
+ <option value="<?php echo $field_val ?>"<?php echo $selected ?>><?php echo $opt ?></option>
100
+ <?php } ?>
101
+ </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  <?php }
103
+ if ($display['default_blank']){ ?>
104
+ <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm-show-click">
105
+ <?php FrmFieldsHelper::show_default_blank_js($field['id'], $field['default_blank']); ?>
106
+ </span>
107
+ <?php } ?>
108
+ <div class="clear"></div>
109
+ <div class="frm-show-click" style="margin-top:5px;">
110
+ <?php
111
+
112
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
113
  echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
114
+ } else if ( !isset($field['post_field']) || $field['post_field'] != 'post_status' ) { ?>
115
+ <div id="frm_field_<?php echo $field['id'] ?>_opts"<?php echo (count($field['options']) > 10) ? ' class="frm_field_opts_list"' : ''; ?>>
116
+ <?php do_action('frm_add_multiple_opts_labels', $field); ?>
117
+ <?php
118
+
119
+ foreach ( $field['options'] as $opt_key => $opt ) {
120
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
121
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
122
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
123
+ }
124
+ ?>
125
+ </div>
126
+ <div id="frm_add_field_<?php echo $field['id']; ?>">
127
+ <a href="javascript:frm_add_field_option(<?php echo $field['id']; ?>)" class="frm_orange frm_add_opt">+ <?php _e('Add an Option', 'formidable') ?></a>
128
+
129
+ <?php if (!isset($field['post_field']) or $field['post_field'] != 'post_category'){ ?>
130
+ <?php _e('or', 'formidable'); ?>
131
+ <a title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '&quot;', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Field Choices', 'formidable') ?></a>
132
  <?php } ?>
133
  </div>
134
+ <?php
135
+ } ?>
136
+ </div>
137
  <?php
138
+ }else if ($field['type'] == 'captcha'){
139
  ?>
140
+ <img src="<?php echo FrmAppHelper::plugin_url() ?>/images/<?php echo $frm_settings->re_theme ?>-captcha.png" alt="captcha" />
141
+ <p class="howto" style="margin-top:0;"><?php printf(__('Hint: Change colors in the %1$sFormidable settings', 'formidable'), '<a href="?page=formidable-settings">') ?></a></p>
142
+ <div class="clear"></div>
143
+ <?php if (empty($frm_settings->pubkey)){ ?>
144
+ <div class="howto" style="font-weight:bold;color:red;"><?php printf(__('Your captcha will not appear on your form until you %1$sset up%2$s the Public and Private Keys', 'formidable'), '<a href="?page=formidable-settings">', '</a>') ?></div>
145
+ <?php } ?>
146
+ <input type="hidden" name="<?php echo $field_name ?>" value="1"/>
147
+ <?php
148
+ }else{
149
+ do_action('frm_display_added_fields',$field);
150
+ }
151
+
152
+ if ($display['clear_on_focus']){ ?>
153
+ <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm-show-click">
154
  <?php
155
+ if ($display['default_blank'])
156
+ FrmFieldsHelper::show_default_blank_js($field['id'], $field['default_blank']);
157
 
158
+ FrmFieldsHelper::show_onfocus_js($field['id'], $field['clear_on_focus']);
159
+ ?>
160
+ </span>
161
+ <?php
162
+
163
+ do_action('frm_extra_field_display_options', $field);
164
+ }
165
+ ?>
166
+ <div class="clear"></div>
167
+ </div>
168
+ <?php
169
+ if ($display['description']){ ?>
170
+ <div class="frm_ipe_field_desc description frm-show-click" id="field_description_<?php echo $field['id']; ?>"><?php echo ($field['description'] == '') ? __('(Click here to add a description or instructions)', 'formidable') : force_balance_tags($field['description']); ?></div>
171
+ <?php
172
+ }
173
 
174
  if ($display['options']){ ?>
175
  <div class="widget">
176
  <div class="widget-top">
177
+ <div class="widget-title-action"><a class="widget-action"></a></div>
178
+ <div class="widget-title"><h4><?php _e('Field Options', 'formidable') ?> (ID <?php echo $field['id'] ?>)</h4></div>
179
  </div>
180
  <div class="widget-inside">
181
+ <table class="form-table" style="clear:none;">
182
  <?php $field_types = FrmFieldsHelper::get_field_types($field['type']); ?>
183
+ <tr><td width="150px"><label><?php _e('Field Type', 'formidable') ?></label></td>
184
  <td>
185
+ <div class="hide-if-no-js edit-slug-box frm_help" title="<?php _e('The field key can be used as an alternative to the field ID in many cases.', 'formidable') ?>">
186
+ <?php _e('Field Key:', 'formidable') ?>
187
+ <div class="<?php echo ($frm_settings->lock_keys) ? 'frm_field_key' : 'frm_ipe_field_key" title="'. __('Click to edit.', 'formidable'); ?>" ><?php echo $field['field_key']; ?></div>
188
+ <?php if(!$frm_settings->lock_keys){ ?>
189
+ <input type="hidden" name="field_options[field_key_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['field_key']); ?>" />
190
  <?php } ?>
191
  </div>
192
+
193
+ <?php if (!empty($field_types)){ ?>
194
+ <select name="field_options[type_<?php echo $field['id'] ?>]">
195
+ <?php foreach ($field_types as $fkey => $ftype){ ?>
196
+ <option value="<?php echo $fkey ?>" <?php echo ($fkey == $field['type']) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists($fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>><?php echo $ftype ?></option>
197
  <?php
198
+ unset($fkey);
199
+ unset($ftype);
200
+ } ?>
201
+ </select>
202
+ <?php }else if(isset($frm_all_field_selection[$field['type']])){ ?>
203
+ <select disabled="disabled">
204
+ <option value=""><?php echo $frm_all_field_selection[$field['type']] ?></option>
205
+ </select>
206
+ <?php } ?>
207
+ <?php if ($display['required']){ ?>
208
+ <label for="frm_req_field_<?php echo $field['id'] ?>" class="frm_inline_label"><input type="checkbox" id="frm_req_field_<?php echo $field['id'] ?>" class="frm_req_field" name="field_options[required_<?php echo $field['id'] ?>]" value="1" <?php echo ($field['required']) ? 'checked="checked"': ''; ?> /> <?php _e('Required', 'formidable') ?></label>
209
+ <?php } ?>
210
+ <?php if($display['unique']){
211
+ if(!isset($field['unique']))
 
212
  $field['unique'] = false;
 
213
  ?>
214
+ <label for="frm_uniq_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php _e('Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\' then no one else will be allowed to enter the same name.', 'formidable') ?>"><input type="checkbox" name="field_options[unique_<?php echo $field['id'] ?>]" id="frm_uniq_field_<?php echo $field['id'] ?>" value="1" <?php echo $field['unique'] ? ' checked="checked"' : ''; ?> onclick="frmMarkUnique(<?php echo $field['id'] ?>,<?php echo ($field['unique']) ? 1 : 0; ?>)"/> <?php _e('Unique', 'formidable') ?></label>
215
+ <?php } ?>
216
+ <?php if($display['read_only']){
217
+ if(!isset($field['read_only']))
 
 
218
  $field['read_only'] = false;
 
219
  ?>
220
+ <label for="frm_read_only_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php _e('Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable') ?>" ><input type="checkbox" id="frm_read_only_field_<?php echo $field['id'] ?>" name="field_options[read_only_<?php echo $field['id'] ?>]" value="1" <?php echo $field['read_only'] ? ' checked="checked"' : ''; ?>/> <?php _e('Read Only', 'formidable') ?></label>
221
+ <?php } ?>
222
+
223
+ <?php if ($display['required']){ ?>
224
+ <div class="frm_required_details<?php echo $field['id'] . ( $field['required'] ? '' : ' frm_hidden'); ?>">
225
+ <span class="howto"><?php _e('Indicate required field with', 'formidable') ?></span>
226
+ <input type="text" name="field_options[required_indicator_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['required_indicator']); ?>" />
 
 
 
 
227
  </div>
228
  <?php } ?>
229
  </td>
230
  </tr>
231
+
232
+ <?php if ($display['css']){ ?>
233
+ <tr><td><label><?php _e('CSS layout classes', 'formidable') ?></label>
234
+ <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable') ?>" ></span>
 
 
 
235
  </td>
236
+ <td><input type="text" name="field_options[classes_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['classes']) ?>" id="frm_classes_<?php echo $field['id'] ?>" class="frm_classes frm_long_input" />
237
+ </td>
238
  </tr>
239
+ <?php } ?>
240
+ <?php if ($display['label_position']){ ?>
241
+ <tr><td width="150px"><label><?php _e('Label Position', 'formidable') ?></label></td>
242
+ <td><select name="field_options[label_<?php echo $field['id'] ?>]">
243
+ <option value=""<?php selected($field['label'], ''); ?>><?php _e('Default', 'formidable') ?></option>
244
+ <option value="top"<?php selected($field['label'], 'top'); ?>><?php _e('Top', 'formidable') ?></option>
245
+ <option value="left"<?php selected($field['label'], 'left'); ?>><?php _e('Left', 'formidable') ?></option>
246
+ <option value="right"<?php selected($field['label'], 'right'); ?>><?php _e('Right', 'formidable') ?></option>
247
+ <option value="inline"<?php selected($field['label'], 'inline'); ?>><?php _e('Inline (left without a set width)', 'formidable') ?></option>
248
+ <option value="none"<?php selected($field['label'], 'none'); ?>><?php _e('None', 'formidable') ?></option>
249
+ <option value="hidden"<?php selected($field['label'], 'hidden'); ?>><?php _e('Hidden (but leave the space)', 'formidable') ?></option>
 
 
250
  </select>
251
+ </td>
252
  </tr>
253
  <?php } ?>
254
  <?php if ($display['size']){ ?>
255
+ <tr><td width="150px"><label><?php _e('Field Size', 'formidable') ?></label></td>
256
  <td>
257
+ <?php if(in_array($field['type'], array('select', 'time', 'data'))){ ?>
258
+ <?php if(!isset($values['custom_style']) or $values['custom_style']){ ?>
259
+ <label for="size_<?php echo $field['id'] ?>"><input type="checkbox" name="field_options[size_<?php echo $field['id'] ?>]" id="size_<?php echo $field['id'] ?>" value="1" <?php echo (isset($field['size']) and $field['size'])? 'checked="checked"':''; ?> /> <?php _e('automatic width', 'formidable') ?>
260
+ <?php }
261
+ }else{ ?>
262
+ <input type="text" name="field_options[size_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['size']); ?>" size="5" /> <span class="howto"><?php echo ($field['type'] == 'textarea' || $field['type'] == 'rte')? __('columns wide', 'formidable') : __('characters wide', 'formidable') ?></span>
263
+
264
+ <input type="text" name="field_options[max_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['max']); ?>" size="5" /> <span class="howto"><?php echo ($field['type'] == 'textarea' || $field['type'] == 'rte')? __('rows high', 'formidable') : __('characters maximum', 'formidable') ?></span>
265
+ <?php } ?>
 
 
 
266
  </td>
267
  </tr>
268
  <?php } ?>
269
+ <?php do_action('frm_field_options_form', $field, $display, $values); ?>
270
+
271
+ <?php if ($display['required'] or $display['invalid'] or $display['unique']){ ?>
272
+ <tr class="frm_validation_msg <?php echo ($display['invalid'] || $field['required'] || (isset($field['unique']) && $field['unique'])) ? '' : 'frm_hidden'; ?>"><td><?php _e('Validation', 'formidable') ?></td>
273
+ <td class="frm_validation_box">
274
+ <?php if ($display['required']){ ?>
275
+ <p class="frm_required_details<?php echo $field['id'] . ($field['required'] ? '' : ' frm_hidden'); ?>"><label><?php _e('Required', 'formidable') ?></label>
276
+ <input type="text" name="field_options[blank_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['blank']); ?>" />
 
 
 
 
277
  </p>
278
+ <?php } ?>
279
+ <?php if ($display['invalid']){ ?>
280
+ <p><label><?php _e('Invalid Format', 'formidable') ?></label>
281
+ <input type="text" name="field_options[invalid_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['invalid']); ?>" />
 
 
282
  </p>
283
+ <?php } ?>
284
+ <?php if($display['unique']){ ?>
285
+ <p class="frm_unique_details<?php echo $field['id'] . ($field['unique'] ? '' : ' frm_hidden'); ?>">
286
+ <label><?php _e('Unique', 'formidable') ?></label>
287
+ <input type="text" name="field_options[unique_msg_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['unique_msg']); ?>" />
 
 
288
  </p>
289
+ <?php } ?>
290
+ <?php if ($display['default_blank']){ //TODO ?>
291
+ <?php } ?>
 
 
 
 
 
 
 
 
 
292
  </td>
293
  </tr>
294
  <?php } ?>
295
+
296
  </table>
297
  </div>
298
  </div>
299
+ <?php } ?>
300
+ <?php if(!isset($ajax)){ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  </li>
302
+ <?php } ?>
303
+ <?php unset($display); ?>
 
 
classes/views/frm-forms/add_field_links.php CHANGED
@@ -1,171 +1,125 @@
1
- <div id="postbox-container-1" class="postbox-container">
2
-
3
- <?php
4
- $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
5
- $action = sanitize_title( FrmAppHelper::get_param( $action ) );
6
- $button = ( $action == 'new' || $action == 'duplicate' ) ? __( 'Create', 'formidable' ) : __( 'Update', 'formidable' );
7
-
8
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/_publish_box.php');
9
- ?>
10
-
 
 
 
 
 
 
 
11
  <div id="frm_position_ele"></div>
12
-
13
-
14
  <div class="postbox frm_field_list">
15
  <div class="inside">
16
  <div id="taxonomy-linkcategory" class="categorydiv">
17
  <ul id="category-tabs" class="category-tabs frm-category-tabs">
18
  <li class="tabs" ><a href="#frm-insert-fields" id="frm_insert_fields_tab"><?php _e( 'Fields', 'formidable' ); ?></a></li>
19
- <li class="hide-if-no-js"><a href="#frm-layout-classes" id="frm_layout_classes_tab" class="frm_help" title="<?php esc_attr_e( 'Open the Field Options and click on the CSS Layout Classes option to enable this tab') ?>"><?php _e( 'Layout', 'formidable' ); ?></a></li>
20
- <?php do_action('frm_extra_form_instruction_tabs'); ?>
21
  </ul>
22
 
23
- <div id="frm-insert-fields" class="tabs-panel">
24
- <ul class="field_type_list">
25
- <?php
26
- $col_class = 'frm_col_one';
27
- foreach ( $frm_field_selection as $field_key => $field_type ) { ?>
28
- <li class="frmbutton button <?php echo esc_attr( $col_class .' frm_t'. $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>"><a href="#" class="frm_add_field"><?php echo esc_html( $field_type ) ?></a></li>
29
- <?php
30
- $col_class = empty( $col_class ) ? 'frm_col_one' : '';
31
- unset( $field_key, $field_type );
32
- } ?>
33
- </ul>
34
- <div class="clear"></div>
35
- <hr/>
36
- <ul<?php echo apply_filters('frm_drag_field_class', '') ?> style="margin-top:2px;">
37
- <?php
38
- $col_class = 'frm_col_one';
39
- $no_allow_class = apply_filters( 'frm_noallow_class', 'frm_noallow' );
40
- foreach ( FrmFieldsHelper::pro_field_selection() as $field_key => $field_type ) {
41
-
42
- if ( is_array( $field_type ) ) {
43
- $field_label = $field_type['name'];
44
-
45
- if ( isset( $field_type['switch_from'] ) ) { ?>
46
- <li class="frmbutton button <?php echo esc_attr( $col_class .' '. $no_allow_class .' frm_t'. $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>" data-switchto="<?php echo esc_attr( $field_type['switch_from'] ) ?>" style="display:none !important;"><?php echo apply_filters( 'frmpro_field_links', $field_label, $id, $field_key ) ?></li>
47
- <?php
48
- continue;
49
- }
50
-
51
- ?>
52
- <li class="frmbutton button <?php echo esc_attr( $col_class .' '. $no_allow_class .' frm_t'. $field_key ) ?> dropdown" id="<?php echo esc_attr( $field_key ) ?>" <?php echo ( isset( $field_type['switch_to'] ) ) ? 'data-switchto="'. esc_attr( $field_type['switch_to'] ) .'"' : ''; ?>>
53
- <a href="#" id="frm-<?php echo esc_attr( $field_key ) ?>Drop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php echo esc_html( $field_label ) ?> <b class="caret"></b></a>
54
-
55
- <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-<?php echo esc_attr( $field_key ) ?>Drop">
56
- <?php
57
- foreach ( $field_type['types'] as $k => $type ) { ?>
58
- <li class="frm_t<?php echo esc_attr( $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>|<?php echo esc_attr( $k ) ?>"><?php echo apply_filters( 'frmpro_field_links', $type, $id, $field_key .'|'. $k ) ?></li>
59
- <?php
60
- unset( $k, $type );
61
- } ?>
62
- </ul>
63
- </li>
64
- <?php
65
- } else {
66
- $field_label = $field_type;
67
- ?>
68
- <li class="frmbutton button <?php echo esc_attr( $col_class .' '. $no_allow_class .' frm_t'. $field_key ) ?>" id="<?php echo esc_attr( $field_key ) ?>"><?php echo apply_filters( 'frmpro_field_links', $field_label, $id, $field_key ) ?></li>
69
- <?php
70
- }
71
-
72
- $col_class = empty($col_class) ? 'frm_col_one' : '';
73
- unset($field_key, $field_type, $field_label);
74
  } ?>
75
- </ul>
76
- <div class="clear"></div>
77
  </div>
78
  <?php do_action('frm_extra_form_instructions'); ?>
79
-
80
- <div id="frm-layout-classes" class="tabs-panel">
81
- <p class="howto"><?php _e( 'Add classes in the "CSS layout classes" field option', 'formidable' ) ?></p>
82
  <ul class="frm_code_list">
83
  <?php $classes = array(
84
- 'frm_first' => array(
85
- 'label' => __( 'First', 'formidable' ),
86
- 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm_third', 'formidable' ),
87
- ),
88
- 'frm_last' => array(
89
- 'label' => __( 'Last', 'formidable' ),
90
- 'title' => __( 'Add this to the last field in each row along with a width. ie frm_last frm_third', 'formidable' ),
91
- ),
92
- 'frm_half' => __( '1/2', 'formidable' ),
93
- 'frm_third' => __( '1/3', 'formidable' ),
94
- 'frm_two_thirds' => __( '2/3', 'formidable' ),
95
- 'frm_fourth' => __( '1/4', 'formidable' ),
96
- 'frm_fifth' => __( '1/5', 'formidable' ),
97
- 'frm_sixth' => __( '1/6', 'formidable' ),
98
- 'frm_seventh' => __( '1/7', 'formidable' ),
99
- 'frm_eigth' => __( '1/8', 'formidable' ),
100
- 'frm_inline' => array(
101
- 'label' => __( 'Inline', 'formidable' ),
102
- 'title' => __( 'Align fields in a row without a specific width.', 'formidable' )
103
- ),
104
-
105
- 'frm_full' => array(
106
- 'label' => __( '100% width', 'formidable' ),
107
- 'title' => __( 'Force the field to fill the full space with 100% width.', 'formidable' )
108
- ),
109
- 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
110
- 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
111
- 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
112
- 'frm_two_col' => array( 'label' => __( '2 Col Options', 'formidable' ), 'title' => __( 'Put your radio button or checkbox options into two columns.', 'formidable' )),
113
- 'frm_three_col' => array( 'label' => __( '3 Col Options', 'formidable' ), 'title' => __( 'Put your radio button or checkbox options into three columns.', 'formidable' )),
114
- 'frm_four_col' => array( 'label' => __( '4 Col Options', 'formidable' ), 'title' => __( 'Put your radio button or checkbox options into four columns.', 'formidable' )),
115
- 'frm_total' => array( 'label' => __( 'Total', 'formidable' ), 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' )),
116
- 'frm_scroll_box' => array( 'label' => __( 'Scroll Box', 'formidable' ), 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options.', 'formidable' ))
117
  );
118
-
119
- $classes = apply_filters( 'frm_layout_classes', $classes );
120
- $col = 'one';
121
- foreach ( $classes as $c => $d ) {
122
- $title = ( ! empty( $d ) && is_array( $d ) && isset( $d['title'] ) ) ? $d['title'] : '';
123
- ?>
124
- <li class="frm_col_<?php echo esc_attr( $col ) ?>">
125
- <a href="javascript:void(0);" class="frmbutton frm_insert_code button show_frm_classes<?php
126
- if ( ! empty( $title ) ) {
127
- echo ' frm_help';
128
- } ?>" data-code="<?php echo esc_attr($c) ?>" <?php
129
- if ( ! empty( $title ) ) {
130
- ?>title="<?php echo esc_attr($title); ?>"<?php
131
- } ?>>
132
- <?php
133
- if ( empty( $d ) ) {
134
- echo $c;
135
- } else if ( ! is_array( $d ) ) {
136
- echo $d;
137
- } else if ( isset( $d['label'] ) ) {
138
- echo $d['label'];
139
- }
140
- ?>
141
  </a>
142
  </li>
143
- <?php
144
- $col = ( $col == 'one' ) ? 'two' : 'one';
145
- unset( $c, $d );
146
- }
147
- ?>
 
148
  </ul>
149
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
150
  </div>
151
  </div>
152
-
153
- <div class="submitbox" id="major-publishing-actions">
154
- <div id="delete-action">
155
- <?php echo FrmFormsHelper::delete_trash_link($id, $values['status']); ?>
156
- </div>
157
-
158
- <div id="publishing-action">
159
- <form method="post" id="frm_js_build_form">
160
- <span class="spinner"></span>
161
- <input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
162
- <input type="button" value="<?php echo esc_attr($button) ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary button-large" id="frm_submit_side" />
163
- </form>
164
- </div>
165
- <div class="clear"></div>
166
- </div><!-- #major-publishing-actions -->
167
-
168
-
169
-
170
  </div>
171
- </div>
1
+ <div id="postbox-container-1" class="<?php echo FrmAppController::get_postbox_class(); ?>">
2
+ <?php if(!isset($hide_preview) or !$hide_preview){
3
+ if (!$values['is_template']){ ?>
4
+ <p class="howto" style="margin-top:0;"><?php _e('Insert into a post, page, display or text widget', 'formidable') ?>:
5
+ <input type="text" readonly="true" class="frm_select_box" value='[formidable id=<?php echo $id; ?>]' /></p>
6
+ <?php } ?>
7
+
8
+ <?php if(isset($values['form_key'])){ ?>
9
+ <p class="frm_orange"><a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" target="_blank"><?php _e('Preview Form', 'formidable') ?></a>
10
+ <?php global $frm_settings;
11
+ if (!empty($frm_settings->preview_page_id)){ ?>
12
+ <?php _e('or', 'formidable') ?>
13
+ <a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('Preview in Current Theme', 'formidable') ?></a>
14
+ <?php } ?>
15
+ </p>
16
+ <?php }
17
+ } ?>
18
  <div id="frm_position_ele"></div>
19
+
 
20
  <div class="postbox frm_field_list">
21
  <div class="inside">
22
  <div id="taxonomy-linkcategory" class="categorydiv">
23
  <ul id="category-tabs" class="category-tabs frm-category-tabs">
24
  <li class="tabs" ><a href="#frm-insert-fields" id="frm_insert_fields_tab"><?php _e( 'Fields', 'formidable' ); ?></a></li>
25
+ <li class="hide-if-no-js"><a href="#frm-layout-classes" id="frm_layout_classes_tab"><?php _e( 'Layout', 'formidable' ); ?></a></li>
26
+ <?php do_action('frm_extra_form_instruction_tabs'); ?>
27
  </ul>
28
 
29
+ <div id="frm-insert-fields" class="tabs-panel" style="max-height:none;overflow:visible;">
30
+ <ul class="field_type_list">
31
+ <?php
32
+ $col_class = 'frm_col_one';
33
+ foreach ($frm_field_selection as $field_key => $field_type){ ?>
34
+ <li class="frmbutton button <?php echo $col_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>"><a href="javascript:add_frm_field_link(<?php echo $id ?>,'<?php echo $field_key ?>');"><?php echo $field_type ?></a></li>
35
+ <?php
36
+ $col_class = (empty($col_class)) ? 'frm_col_one' : '';
37
+ } ?>
38
+ </ul>
39
+ <div class="clear"></div>
40
+
41
+ <h4 class="title" style="margin-bottom:0;margin-top:4px;"><?php _e('Pro Fields', 'formidable') ?></h4>
42
+ <ul<?php echo apply_filters('frm_drag_field_class', '') ?> style="margin-top:2px;">
43
+ <?php $col_class = 'frm_col_one';
44
+ foreach (FrmFieldsHelper::pro_field_selection() as $field_key => $field_type){ ?>
45
+ <li class="frmbutton button <?php echo $col_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>"><?php echo apply_filters('frmpro_field_links', $field_type, $id, $field_key) ?></li>
46
+ <?php
47
+ $col_class = (empty($col_class)) ? 'frm_col_one' : '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  } ?>
49
+ </ul>
50
+ <div class="clear"></div>
51
  </div>
52
  <?php do_action('frm_extra_form_instructions'); ?>
53
+
54
+ <div id="frm-layout-classes" class="tabs-panel" style="display:none;max-height:none;">
55
+ <p class="howto"><?php _e('Add classes in the "CSS layout classes" field option', 'formidable') ?></p>
56
  <ul class="frm_code_list">
57
  <?php $classes = array(
58
+ 'frm_first_half' => __('First 1/2', 'formidable'),
59
+ 'frm_last_half' => __('Last 1/2', 'formidable'),
60
+ 'frm_first_third' => __('First 1/3', 'formidable'),
61
+ 'frm_last_third' => __('Last 1/3', 'formidable'),
62
+ 'frm_first_two_thirds' => __('First 2/3', 'formidable'),
63
+ 'frm_last_two_thirds' => __('Last 2/3', 'formidable'),
64
+ 'frm_third' => __('1/3', 'formidable'),
65
+ 'frm_fourth' => __('1/4', 'formidable'),
66
+ 'frm_first_fourth' => array('label' => __('First 1/4', 'formidable')),
67
+ 'frm_last_fourth' => __('Last 1/4', 'formidable'),
68
+ 'frm_first_fifth' => __('First 1/5', 'formidable'),
69
+ 'frm_last_fifth' => __('Last 1/5', 'formidable'),
70
+ 'frm_fifth' => __('1/5', 'formidable'),
71
+ 'frm_inline' => array('label' => __('Inline', 'formidable'), 'title' => __('Align fields in a row without a specific width.', 'formidable')),
72
+ 'frm_first_inline' => array('label' => __('First Inline', 'formidable'), 'title' => __('Align fields at the beginning of a row without a specific width.', 'formidable')),
73
+ 'frm_last_inline' => array('label' => __('Last Inline', 'formidable'), 'title' => __('Align fields at the end of a row without a specific width.', 'formidable')),
74
+
75
+ 'frm_full' => array('label' => __('100% width', 'formidable'), 'title' => __('Force the field to fill the full space with 100% width.', 'formidable')),
76
+ 'frm_grid_first' => __('First Grid Row', 'formidable'),
77
+ 'frm_grid' => __('Even Grid Row', 'formidable'),
78
+ 'frm_grid_odd' => __('Odd Grid Row', 'formidable'),
79
+ 'frm_two_col' => array('label' => __('2 Col Options', 'formidable'), 'title' => __('Put your radio button or checkbox options into two columns.', 'formidable')),
80
+ 'frm_three_col' => array('label' => __('3 Col Options', 'formidable'), 'title' => __('Put your radio button or checkbox options into three columns.', 'formidable')),
81
+ 'frm_four_col' => array('label' => __('4 Col Options', 'formidable'), 'title' => __('Put your radio button or checkbox options into four columns.', 'formidable')),
82
+ 'frm_total' => array('label' => __('Total', 'formidable'), 'title' => __('Add this to a read-only field to display the text in bold without a border or background.', 'formidable')),
83
+ 'frm_scroll_box' => array('label' => __('Scroll Box', 'formidable'), 'title' => __('If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options.', 'formidable'))
 
 
 
 
 
 
 
84
  );
85
+ $classes = apply_filters('frm_layout_classes', $classes);
86
+ $col = 'one';
87
+ foreach($classes as $c => $d){
88
+ $title = (!empty($d) and is_array($d) and isset($d['title'])) ? $d['title'] : '';
89
+ ?>
90
+ <li class="frm_col_<?php echo $col ?>">
91
+ <a class="frmbutton frm_insert_code button show_frm_classes<?php if(!empty($title)) echo ' frm_help'; ?>" data-code="<?php echo esc_attr($c) ?>" href="javascript:void(0)" <?php if(!empty($title)){ ?>title="<?php echo esc_attr($title); ?>"<?php } ?>>
92
+ <?php
93
+ if(empty($d))
94
+ echo $c;
95
+ else if(!is_array($d))
96
+ echo $d;
97
+ else if(isset($d['label']))
98
+ echo $d['label'];
99
+ ?>
 
 
 
 
 
 
 
 
100
  </a>
101
  </li>
102
+ <?php
103
+ $col = ($col == 'one') ? 'two' : 'one';
104
+ unset($c);
105
+ unset($d);
106
+ }
107
+ ?>
108
  </ul>
109
  </div>
110
+
111
+ <?php
112
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
113
+ $action = FrmAppHelper::get_param($action);
114
+ $button = ($action == 'new' or $action == 'duplicate') ? __('Create', 'formidable') : __('Update', 'formidable');
115
+ ?>
116
+ <form method="post" id="frm_js_build_form">
117
+ <input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
118
+ <p><input type="button" onclick="frmSubmit<?php echo (isset($values['ajax_load']) and $values['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php echo esc_attr($button) ?>" class="frm_submit_form button-primary" id="frm_submit_side" />
119
+ <span class="frm-loading-img"></span>
120
+ </p>
121
+ </form>
122
  </div>
123
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  </div>
125
+ </div>
classes/views/frm-forms/default-templates.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php FrmFormsHelper::get_template_dropdown($all_templates); ?>
2
+
3
+ <h3><?php _e('Default Templates', 'formidable') ?></h3>
4
+ <table class="widefat post fixed" id="posts-filter" cellspacing="0">
5
+ <thead>
6
+ <tr>
7
+ <th class="manage-column" width="30%"><?php _e('Name') ?></th>
8
+ <th class="manage-column"><?php _e('Description') ?></th>
9
+ </tr>
10
+ </thead>
11
+ <?php if(empty($default_templates)){ ?>
12
+ <tr><td colspan="2"><?php _e('No Templates Found', 'formidable') ?></td></tr>
13
+ <?php
14
+ }else{
15
+ $alternate = false;
16
+ foreach($default_templates as $form){
17
+ $alternate = (!$alternate) ? 'alternate' : false;
18
+ ?>
19
+ <tr class="<?php echo $alternate ?>">
20
+ <td class="post-title">
21
+ <a class="row-title" href="<?php echo $url = FrmFormsHelper::get_direct_link($form->form_key, $form); ?>" title="<?php _e('View', 'formidable')?> <?php echo esc_attr($form->name) ?>" target="blank"><?php echo $form->name; ?></a><br/>
22
+ <div class="row-actions">
23
+ <?php if(current_user_can('frm_edit_forms')){ ?>
24
+ <span><a href="?page=formidable&amp;frm_action=duplicate&amp;id=<?php echo $form->id; ?>"><?php _e('Create Form from Template', 'formidable') ?></a></span> |
25
+ <?php } ?>
26
+ <?php global $frm_settings;
27
+ if ($frm_settings->preview_page_id > 0)
28
+ $url = add_query_arg('form', $form->form_key, get_permalink($frm_settings->preview_page_id));
29
+ ?>
30
+ <span><a href="<?php echo $url ?>" target="blank"><?php _e('View', 'formidable') ?></a></span>
31
+ </div>
32
+ </td>
33
+ <td><?php echo $form->description ?></td>
34
+ </tr>
35
+ <?php
36
+ }
37
+ }
38
+ ?>
39
+ <tfoot>
40
+ <tr>
41
+ <th class="manage-column"><?php _e('Name') ?></th>
42
+ <th class="manage-column"><?php _e('Description') ?></th>
43
+ </tr>
44
+ </tfoot>
45
+ </table>
46
+
47
+ <br/><br/><h3><?php _e('Custom Templates', 'formidable') ?></h3>
classes/views/frm-forms/edit.php CHANGED
@@ -1,48 +1,53 @@
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2><?php echo ( $form->is_template ? __( 'Templates', 'formidable' ) : __( 'Build', 'formidable' )); ?>
4
- <a href="?page=formidable&amp;frm_action=new" class="add-new-h2"><?php _e( 'Add New', 'formidable' ); ?></a>
5
  </h2>
6
-
7
- <?php
8
- // Add form messages
9
- require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
10
- ?>
11
-
12
- <div id="poststuff">
 
 
 
 
 
 
13
 
14
  <div id="post-body" class="metabox-holder columns-2">
15
  <div id="post-body-content">
16
- <?php
17
-
18
- // Add form nav
19
- if ( ! $values['is_template'] ) {
20
- FrmAppController::get_form_nav( $id, true, 'hide' );
21
- }
22
-
23
- ?>
24
- <div class="frm_form_builder<?php echo FrmFormsHelper::get_form_style_class($form); ?>">
25
-
26
- <p class="frm_hidden frm-no-margin">
27
- <input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
28
  <span class="frm-loading-img"></span>
29
  </p>
30
-
31
  <form method="post" id="frm_build_form">
32
  <input type="hidden" name="frm_action" value="update" />
33
  <input type="hidden" name="action" value="update" />
34
- <input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
35
 
36
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
37
 
38
- <p>
39
- <input type="button" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
 
 
40
  <span class="frm-loading-img"></span>
41
  </p>
42
  </form>
43
  </div>
44
  </div>
45
- <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php'); ?>
 
 
 
46
  </div>
47
  </div>
48
  </div>
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2><?php echo ( $form->is_template ? __('Templates', 'formidable') : __('Build', 'formidable')); ?>
4
+ <a href="?page=formidable&amp;frm_action=new-selection" class="add-new-h2"><?php _e('Add New', 'formidable'); ?></a>
5
  </h2>
6
+ <?php
7
+ if ( ! $form->is_template ) {
8
+ FrmAppController::get_form_nav($id, true);
9
+ }
10
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
+
12
+ if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
13
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
14
+ <?php
15
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
16
+ }else{ ?>
17
+ <div id="poststuff">
18
+ <?php } ?>
19
 
20
  <div id="post-body" class="metabox-holder columns-2">
21
  <div id="post-body-content">
22
+ <div class="frm_form_builder<?php echo (isset($form->options['custom_style']) && $form->options['custom_style']) ? ' with_frm_style' : ''; ?>">
23
+
24
+ <p style="margin-top:0;">
25
+ <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
26
+ <?php _e('or', 'formidable') ?>
27
+ <a class="button-secondary cancel" href="?page=formidable<?php echo ($form->is_template) ? '-templates' : ''; ?>"><?php _e('Cancel', 'formidable') ?></a>
 
 
 
 
 
 
28
  <span class="frm-loading-img"></span>
29
  </p>
30
+
31
  <form method="post" id="frm_build_form">
32
  <input type="hidden" name="frm_action" value="update" />
33
  <input type="hidden" name="action" value="update" />
34
+ <input type="hidden" name="id" value="<?php echo $id; ?>" />
35
 
36
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
37
 
38
+ <p>
39
+ <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
40
+ <?php _e('or', 'formidable') ?>
41
+ <a class="button-secondary cancel" href="?page=formidable<?php echo $form->is_template ? '-templates' : ''; ?>"><?php _e('Cancel', 'formidable') ?></a>
42
  <span class="frm-loading-img"></span>
43
  </p>
44
  </form>
45
  </div>
46
  </div>
47
+ <?php
48
+ if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
49
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
50
+ ?>
51
  </div>
52
  </div>
53
  </div>
classes/views/frm-forms/form.php CHANGED
@@ -1,61 +1,33 @@
1
  <?php wp_nonce_field('frm_save_form_nonce', 'frm_save_form'); ?>
2
- <input type="hidden" name="status" value="<?php echo esc_attr( $values['status'] ); ?>" />
3
- <input type="hidden" name="new_status" value="" />
4
 
5
  <div id="frm_form_editor_container">
6
  <div id="titlediv">
7
- <input type="text" name="name" value="<?php echo esc_attr($form->name); ?>" id="title" placeholder="<?php esc_attr_e( 'Enter title here') ?>" />
8
  <div id="edit-slug-box" class="hide-if-no-js">
9
- <div id="frm_form_key_box" class="alignright">
10
- <strong><?php _e( 'Form Key:', 'formidable' ) ?></strong>
11
- <div id="editable-post-name" class="frm_ipe_form_key" title="<?php esc_attr_e( 'Click to edit.', 'formidable' ) ?>"><?php echo esc_html( $form->form_key ); ?></div>
12
  </div>
13
- <div id="frm_form_desc" class="frm_ipe_form_desc alignleft"><?php echo ($form->description == '') ? __( '(Click to add description)', 'formidable' ) : force_balance_tags($form->description); ?></div>
14
- <div class="frm_clear"></div>
15
  </div>
16
  </div>
17
 
18
  <div <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'class="postbox"' : ''; ?>>
19
- <div class="frm_no_fields <?php echo ( isset($values['fields']) && ! empty($values['fields']) ) ? 'frm_hidden' : ''; ?>">
20
- <div class="alignleft sketch1">
21
- <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow1.png'; ?>" alt="" />
22
- </div>
23
- <div class="alignleft sketch1_text">
24
- <?php _e( '1. Name your form', 'formidable' ) ?>
25
- </div>
26
-
27
- <div class="alignright sketch2">
28
- <?php _e( '2. Click or drag a field to<br/>add it to your form', 'formidable' ) ?>
29
- <div class="clear"></div>
30
- <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow2.png'; ?>" alt="" />
31
- </div>
32
- <div class="clear"></div>
33
-
34
- <div class="frm_drag_inst"><?php _e( 'Add Fields Here', 'formidable' ) ?></div>
35
- <p id="frm_create_template_form">
36
- <?php _e( 'Or load fields from a template', 'formidable' ); ?>
37
- <select id="frm_create_template_dropdown">
38
- <?php foreach ( $all_templates as $temp ) { ?>
39
- <option value="<?php echo esc_attr( $temp->id ) ?>"><?php echo FrmAppHelper::truncate( $temp->name, 40 ) ?></option>
40
- <?php } ?>
41
- </select>
42
- <input type="button" id="frm_create_template_button" class="button-secondary" value="<?php esc_attr_e( 'Load Template', 'formidable' ) ?>" />
43
- </p>
44
-
45
- <div class="alignleft sketch3">
46
- <div class="alignright"><?php _e( '3. Save your form', 'formidable' ) ?></div>
47
- <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow3.png'; ?>" alt="" />
48
- </div>
49
- <div class="clear"></div>
50
- </div>
51
- <ul id="new_fields" class="frm_sorting <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'inside' : ''; ?>">
52
  <?php
53
  if ( isset($values['fields']) && ! empty($values['fields']) ) {
54
  $count = 0;
55
  foreach ( $values['fields'] as $field ) {
56
  $count++;
57
  $field_name = 'item_meta['. $field['id'] .']';
58
- $html_id = FrmFieldsHelper::get_html_id($field);
59
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
60
  unset($field, $field_name);
61
  }
1
  <?php wp_nonce_field('frm_save_form_nonce', 'frm_save_form'); ?>
 
 
2
 
3
  <div id="frm_form_editor_container">
4
  <div id="titlediv">
5
+ <input type="text" name="name" value="<?php echo esc_attr($form->name); ?>" id="title" placeholder="<?php esc_attr_e('Enter title here') ?>" />
6
  <div id="edit-slug-box" class="hide-if-no-js">
7
+ <div class="alignright" style="width:13em;max-width:30%">
8
+ <strong><?php _e('Form Key:', 'formidable') ?></strong>
9
+ <div id="editable-post-name" class="frm_ipe_form_key" title="<?php _e('Click to edit.', 'formidable') ?>"><?php echo $form->form_key; ?></div>
10
  </div>
11
+ <div class="frm_ipe_form_desc alignleft" style="width:70%"><?php echo ($form->description == '') ? __('(Click here to add a description or instructions)', 'formidable') : force_balance_tags($form->description); ?></div>
12
+ <div style="clear:both"></div>
13
  </div>
14
  </div>
15
 
16
  <div <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'class="postbox"' : ''; ?>>
17
+ <div class="frm_no_fields <?php echo ( isset($values['fields']) && ! empty($values['fields']) ) ? 'frm_hidden' : ''; ?>">
18
+ <div class="frm_brace">{</div>
19
+ <div class="alignright frm_nofields_text">
20
+ <div class="frm_all_field_inst"><?php _e('Add fields here', 'formidable') ?></div>
21
+ <div class="frm_drag_inst"><?php _e('(Just click or drag)', 'formidable') ?></div>
22
+ </div>
23
+ </div>
24
+ <ul id="new_fields" class="<?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'inside' : ''; ?>">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  <?php
26
  if ( isset($values['fields']) && ! empty($values['fields']) ) {
27
  $count = 0;
28
  foreach ( $values['fields'] as $field ) {
29
  $count++;
30
  $field_name = 'item_meta['. $field['id'] .']';
 
31
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
32
  unset($field, $field_name);
33
  }
classes/views/frm-forms/insert_form_popup.php CHANGED
@@ -1,50 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
- <div id="frm_insert_form" class="frm_hidden">
3
- <div id="frm_popup_content">
4
- <div class="media-modal wp-core-ui">
5
- <a href="#" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text"><?php _e( 'Close panel', 'formidable' ) ?></span></span></a>
 
6
 
7
- <div class="media-modal-content">
8
- <div class="media-frame mode-select wp-core-ui hide-router">
9
-
10
- <div id="frm_insert_form_content">
11
-
12
- <div class="media-frame-menu">
13
- <div class="media-menu">
14
- <?php foreach ( $shortcodes as $shortcode => $labels ) { ?>
15
- <a href="#" class="media-menu-item frm_switch_sc" id="sc-link-<?php echo esc_attr( $shortcode ) ?>">
16
- <?php echo esc_html( $labels['name'] ) ?>
17
- <span class="howto"><?php echo esc_html( $labels['label'] ) ?></span>
18
- </a>
 
 
 
19
  <?php } ?>
20
- <div class="clear"></div>
21
- </div>
22
- </div>
23
-
24
- <div class="media-frame-title"><h1><?php _e( 'Insert a Form', 'formidable' ) ?> <span class="spinner"></span><span class="dashicons dashicons-arrow-down"></span></h1></div>
25
-
26
- <div class="media-frame-content">
27
- <div class="attachments-browser">
28
- <div id="frm_shortcode_options" class="media-embed">
29
-
30
- </div>
31
- </div>
32
- </div>
33
-
34
- <div class="media-frame-toolbar">
35
- <div class="media-toolbar">
36
- <div class="media-toolbar-secondary">
37
- <input type="text" value="" id="frm_complete_shortcode" />
38
- </div>
39
- <div class="media-toolbar-primary search-form">
40
- <a href="javascript:void(0);" class="button-primary button button-large media-button-group" id="frm_insert_shortcode"><?php _e( 'Insert into Post', 'formidable' ) ?></a>
41
- </div>
42
- </div>
43
- </div>
44
- </div>
45
- </div>
46
-
47
- </div>
48
- </div>
49
  </div>
50
- </div>
1
+ <script type="text/javascript">
2
+ function frm_insert_form(){
3
+ var form_id=jQuery("#frm_add_form_id").val();
4
+ if(form_id==""){alert("<?php _e('Please select a form', 'formidable') ?>");return;}
5
+ var title_qs=jQuery("#frm_display_title").is(":checked") ? " title=true" : "";
6
+ var description_qs=jQuery("#frm_display_description").is(":checked") ? " description=true" : "";
7
+ var win = window.dialogArguments || opener || parent || top;
8
+ win.send_to_editor("[formidable id="+form_id+title_qs+description_qs+"]");
9
+ }
10
+
11
+ function frm_insert_display(){
12
+ var display_id = jQuery("#frm_add_display_id").val();
13
+ if(display_id==""){alert("<?php _e('Please select a view', 'formidable') ?>");return;}
14
+ var filter_qs=jQuery("#frm_filter_content").is(":checked") ? " filter=1" : "";
15
+ var win = window.dialogArguments || opener || parent || top;
16
+ win.send_to_editor("[display-frm-data id="+display_id+filter_qs+"]");
17
+ }
18
+
19
+ function frm_insert_search(){
20
+ var win = window.dialogArguments || opener || parent || top;
21
+ win.send_to_editor("[frm-search]");
22
+ }
23
+ </script>
24
+ <style type="text/css">
25
+ #frm_popup_content h3{
26
+ color:#5A5A5A;
27
+ font-family:Georgia,"Times New Roman",Times,serif;
28
+ font-weight:normal;
29
+ font-size:1.6em;
30
+ }
31
+ .frm_box_line{border-bottom:1px solid #DFDFDF;display:block;margin:20px 0;}
32
+ </style>
33
 
34
+ <div id="frm_insert_form" style="display:none;">
35
+ <div class="wrap" id="frm_popup_content">
36
+ <h3><?php _e("Select a form to insert", "formidable"); ?></h3>
37
+
38
+ <p><?php FrmFormsHelper::forms_dropdown( 'frm_add_form_id' )?></p>
39
 
40
+ <p><label for="frm_display_title"><input type="checkbox" id="frm_display_title" /> <?php _e("Display form title", "formidable"); ?></label> &nbsp; &nbsp;
41
+ <label for="frm_display_description"><input type="checkbox" id="frm_display_description" /> <?php _e("Display form description", "formidable"); ?></label>
42
+ </p>
43
+
44
+ <p><input type="button" class="button-primary" value="Insert Form" onclick="frm_insert_form();" /></p>
45
+
46
+ <?php if(isset($displays) and !empty($displays)){ ?>
47
+ <div class="frm_box_line"></div>
48
+ <h3><?php _e('Select a view to insert', 'formidable'); ?></h3>
49
+
50
+ <p>
51
+ <select name="frm_add_display_id" id="frm_add_display_id">
52
+ <option value=""></option>
53
+ <?php foreach ($displays as $display){ ?>
54
+ <option value="<?php echo $display->ID ?>"><?php echo $display->post_title ?></option>
55
  <?php } ?>
56
+ </select>
57
+ </p>
58
+
59
+ <p><label for="frm_filter_content"><input type="checkbox" id="frm_filter_content" /> <?php _e("Filter shortcodes within the view content", "formidable"); ?></label>
60
+ <span class="howto"><?php _e("Note: In some cases, this option can create an infinite loop", "formidable"); ?></span>
61
+ </p>
62
+
63
+ <p><input type="button" class="button-primary" value="Insert View" onclick="frm_insert_display();" /></p>
64
+
65
+ <div class="frm_box_line"></div>
66
+ <h3><?php _e("Insert a search box", "formidable"); ?></h3>
67
+ <p><input type="button" class="button-primary" value="Insert Search" onclick="frm_insert_search();" /></p>
68
+ <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  </div>
70
+ </div>
classes/views/frm-forms/list.php CHANGED
@@ -1,28 +1,21 @@
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2 id="frm_form_page_header">
4
- <?php
5
- echo $params['template'] ? __( 'Templates', 'formidable' ) : __( 'Forms', 'formidable' );
6
- if ( ! $params['template'] && current_user_can( 'frm_edit_forms' ) ) { ?>
7
- <a href="?page=formidable&amp;frm_action=new" class="add-new-h2"><?php _e( 'Add New', 'formidable' ); ?></a>
8
- <?php
9
- } ?>
10
  </h2>
11
-
12
- <?php
13
- require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
14
- $wp_list_table->views();
15
- ?>
16
 
17
  <form id="posts-filter" method="get">
18
- <input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ) ?>" />
19
  <input type="hidden" name="frm_action" value="list" />
20
- <?php
21
 
22
- $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' );
23
- $wp_list_table->display();
24
 
25
- ?>
26
  </form>
27
 
28
- </div>
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2 style="height:34px;"><?php echo ($params['template'])? __('Templates', 'formidable') : __('Forms', 'formidable');
4
+ if(!$params['template'] and current_user_can('frm_edit_forms')){ ?>
5
+ <a href="?page=formidable&amp;frm_action=new-selection" class="add-new-h2"><?php _e('Add New', 'formidable'); ?></a>
6
+ <?php } ?>
 
 
 
7
  </h2>
8
+
9
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
 
 
 
10
 
11
  <form id="posts-filter" method="get">
12
+ <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>" />
13
  <input type="hidden" name="frm_action" value="list" />
14
+ <?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' );
15
 
16
+ if ($params['template']) require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/default-templates.php');
 
17
 
18
+ $wp_list_table->display(); ?>
19
  </form>
20
 
21
+ </div>
classes/views/frm-forms/mb_html_tab.php CHANGED
@@ -1,53 +1,54 @@
1
- <div id="frm-html-tags" class="tabs-panel">
2
  <ul class="frm_code_list">
3
  <?php
4
  $col = 'one';
5
  $entry_shortcodes = array(
6
- 'id' => __( 'Field ID', 'formidable' ),
7
- 'key' => __( 'Field Key', 'formidable' ),
8
- 'field_name' => __( 'Field Name', 'formidable' ),
9
- 'description' => __( 'Field Description', 'formidable' ),
10
- 'label_position' => __( 'Label Position', 'formidable' ),
11
- 'required_label' => __( 'Required Label', 'formidable' ),
12
- 'input' => __( 'Input Field', 'formidable' ),
13
- 'input opt=1' => array( 'label' => __( 'Single Option', 'formidable' ), 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' )),
14
- 'input label=0' => __( 'Hide Option Label', 'formidable' ),
15
- 'required_class' => array( 'label' => __( 'Required Class', 'formidable' ), 'title' => __( 'Add class name if field is required', 'formidable' )),
16
- 'error_class' => array( 'label' => __( 'Error Class', 'formidable' ), 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ))
17
  );
18
 
19
- foreach ( $entry_shortcodes as $skey => $sname ) {
20
  ?>
21
- <li class="frm_col_<?php echo esc_attr( $col ) ?>">
22
- <a href="javascript:void(0)" class="show_field_custom_html frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="<?php echo esc_attr($skey) ?>" <?php echo is_array($sname) ? 'title="'. $sname['title'] .'"' : ''; ?>><?php echo is_array($sname) ? $sname['label'] : $sname; ?></a>
23
  </li>
24
  <?php
25
  $col = ($col == 'one') ? 'two' : 'one';
26
- unset($skey, $sname);
 
27
  }
28
  ?>
29
  </ul>
30
-
31
  <ul class="frm_code_list clear">
32
- <?php
33
  $col = 'one';
34
- foreach ( array(
35
- 'form_name' => __( 'Form Name', 'formidable' ), 'form_description' => __( 'Form Description', 'formidable' ),
36
- 'form_key' => __( 'Form Key', 'formidable' ), 'deletelink' => __( 'Delete Entry Link', 'formidable' ) ) as $skey => $sname ) { ?>
37
- <li class="frm_col_<?php echo esc_attr( $col ) ?>">
38
- <a href="javascript:void(0)" class="show_before_html show_after_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname; ?></a>
39
  </li>
40
  <?php
41
- $col = ($col == 'one') ? 'two' : 'one';
42
  }
43
-
44
- foreach ( array(
45
- 'button_label' => __( 'Button Label', 'formidable' ), 'button_action' => __( 'Button Hook', 'formidable' ) ) as $skey => $sname ) { ?>
46
- <li class="frm_col_<?php echo esc_attr( $col ) ?>">
47
- <a href="javascript:void(0)" class="show_submit_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname; ?></a>
48
  </li>
49
  <?php
50
- $col = ($col == 'one') ? 'two' : 'one';
51
  } ?>
52
  </ul>
53
  </div>
1
+ <div id="frm-html-tags" class="tabs-panel" style="display:none;max-height:none;padding-right:0;">
2
  <ul class="frm_code_list">
3
  <?php
4
  $col = 'one';
5
  $entry_shortcodes = array(
6
+ 'id' => __('Field ID', 'formidable'),
7
+ 'key' => __('Field Key', 'formidable'),
8
+ 'field_name' => __('Field Name', 'formidable'),
9
+ 'description' => __('Field Description', 'formidable'),
10
+ 'label_position' => __('Label Position', 'formidable'),
11
+ 'required_label' => __('Required Label', 'formidable'),
12
+ 'input' => __('Input Field', 'formidable'),
13
+ 'input opt=1' => array('label' => __('Single Option', 'formidable'), 'title' => __('Show a single radio or checkbox option by replacing "1" with the order of the option', 'formidable')),
14
+ 'input label=0' => __('Hide Option Label', 'formidable'),
15
+ 'required_class' => array('label' => __('Required Class', 'formidable'), 'title' => __('Add class name if field is required', 'formidable')),
16
+ 'error_class' => array('label' => __('Error Class', 'formidable'), 'title' => __('Add class name if field has an error on form submit', 'formidable'))
17
  );
18
 
19
+ foreach($entry_shortcodes as $skey => $sname){
20
  ?>
21
+ <li class="frm_col_<?php echo $col ?>">
22
+ <a class="show_field_custom_html frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="<?php echo esc_attr($skey) ?>" href="javascript:void(0)" <?php echo is_array($sname) ? 'title="'. $sname['title'] .'"' : ''; ?>><?php echo is_array($sname) ? $sname['label'] : $sname; ?></a>
23
  </li>
24
  <?php
25
  $col = ($col == 'one') ? 'two' : 'one';
26
+ unset($skey);
27
+ unset($sname);
28
  }
29
  ?>
30
  </ul>
31
+
32
  <ul class="frm_code_list clear">
33
+ <?php
34
  $col = 'one';
35
+ foreach(array(
36
+ 'form_name' => __('Form Name', 'formidable'), 'form_description' => __('Form Description', 'formidable'),
37
+ 'form_key' => __('Form Key', 'formidable'), 'deletelink' => __('Delete Entry Link', 'formidable')) as $skey => $sname){ ?>
38
+ <li class="frm_col_<?php echo $col ?>">
39
+ <a class="show_before_html show_after_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>" href="javascript:void(0)"><?php echo $sname; ?></a>
40
  </li>
41
  <?php
42
+ $col = ($col == 'one') ? 'two' : 'one';
43
  }
44
+
45
+ foreach(array(
46
+ 'button_label' => __('Button Label', 'formidable'), 'button_action' => __('Button Hook', 'formidable')) as $skey => $sname){ ?>
47
+ <li class="frm_col_<?php echo $col ?>">
48
+ <a class="show_submit_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>" href="javascript:void(0)"><?php echo $sname; ?></a>
49
  </li>
50
  <?php
51
+ $col = ($col == 'one') ? 'two' : 'one';
52
  } ?>
53
  </ul>
54
  </div>
classes/views/frm-forms/mb_insert_fields.php CHANGED
@@ -1,7 +1,23 @@
1
  <div id="frm_adv_info" class="postbox">
2
- <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ) ?>"><br/></div>
3
- <h3 class="hndle"><span><?php _e( 'Customization', 'formidable' ) ?></span></h3>
4
  <div class="inside">
5
- <?php FrmFormsController::mb_tags_box($id); ?>
6
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  </div>
1
  <div id="frm_adv_info" class="postbox">
2
+ <div class="handlediv" title="<?php _e('Click to toggle', 'formidable') ?>"><br/></div><h3 class="hndle"><span><?php _e('Customization', 'formidable') ?></span></h3>
 
3
  <div class="inside">
4
+ <?php if($frm_vars['pro_is_installed']){
5
+ FrmProDisplaysController::mb_tags_box($id);
6
+ }else{ ?>
7
+ <div id="taxonomy-linkcategory" class="categorydiv">
8
+ <ul id="category-tabs" class="category-tabs frm-category-tabs">
9
+ <li class="tabs" ><a href="#frm-insert-fields-box" id="frm_insert_fields_tab" ><?php _e( 'Insert Fields', 'formidable' ); ?></a></li>
10
+ <li class="hide-if-no-js"><a href="#frm-html-tags" id="frm_html_tags_tab" ><?php _e( 'HTML Tags', 'formidable' ); ?></a></li>
11
+ </ul>
12
+ <div id="frm-insert-fields-box" class="tabs-panel" style="max-height:none;padding-right:0;">
13
+ <br/><br/>
14
+ <?php FrmAppController::update_message('insert field values into your messages'); ?>
15
+ </div>
16
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_html_tab.php'); ?>
17
+ </div>
18
+ <?php
19
+ } ?>
20
+
21
+
22
+ </div>
23
  </div>
classes/views/frm-forms/new-field-js.php CHANGED
@@ -1 +1 @@
1
- <?php _deprecated_file( basename(__FILE__), '1.07.10', null, __( 'This file no longer needs to be included.' ) );
1
+ <?php _deprecated_file( basename(__FILE__), '1.07.10', null, __( 'This file no longer needs to be included.' ) ); ?>
classes/views/frm-forms/new-selection.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <div class="frmicon icon32"><br/></div>
3
+ <h2><?php _e('Build New Form', 'formidable') ?></h2>
4
+
5
+ <div class="clear"></div>
6
+ <div id="menu-management" class="nav-menus-php frm-menu-boxes">
7
+ <div class="menu-edit">
8
+ <div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
9
+ <div style="font-size:15px;background:transparent;" class="search"><?php _e('Pre-Built Form', 'formidable') ?></div>
10
+ </div></div>
11
+
12
+ <form method="get">
13
+ <div id="post-body">
14
+ <p><?php _e('Select a template to generate your form.', 'formidable'); ?></p>
15
+ <input type="hidden" name="frm_action" value="duplicate" />
16
+ <input type="hidden" name="page" value="formidable" />
17
+ <select name="id">
18
+ <?php foreach ($all_templates as $temp){ ?>
19
+ <option value="<?php echo $temp->id ?>"><?php echo FrmAppHelper::truncate($temp->name, 40) ?></option>
20
+ <?php } ?>
21
+ </select><br/>
22
+ </div>
23
+ <div id="nav-menu-footer">
24
+ <div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Create', 'formidable') ?>" /></div>
25
+
26
+ <div class="clear"></div>
27
+ </div>
28
+ </form>
29
+ </div>
30
+ </div>
31
+
32
+ <div id="menu-management" class="nav-menus-php frm-menu-boxes">
33
+ <div class="menu-edit">
34
+ <div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
35
+ <div style="font-size:15px;background:transparent;" class="search"><?php _e('Blank Form', 'formidable') ?></div>
36
+ </div></div>
37
+
38
+ <form method="get">
39
+ <div id="post-body">
40
+ <p style="padding-bottom:26px;"><?php _e('Start with a blank form and build anything.', 'formidable'); ?></p>
41
+ <input type="hidden" name="frm_action" value="new" />
42
+ <input type="hidden" name="page" value="formidable" />
43
+ </div>
44
+ <div id="nav-menu-footer">
45
+ <div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Create', 'formidable') ?>" /></div>
46
+
47
+ <div class="clear"></div>
48
+ </div>
49
+ </form>
50
+ </div>
51
+
52
+ <div class="clear"></div>
53
+ </div>
54
+
55
+ <div class="clear"></div>
56
+ </div>
classes/views/frm-forms/new.php CHANGED
@@ -1,38 +1,53 @@
1
  <div class="wrap">
2
- <div class="frmicon icon32"><br/></div>
3
- <h2><?php _e( 'Build New Form', 'formidable' ) ?>
4
- <a href="?page=formidable-new" class="add-new-h2 frm_invisible"><?php _e( 'Add New', 'formidable' ); ?></a>
5
  </h2>
6
-
 
 
 
 
 
 
 
 
 
 
7
  <div id="poststuff">
 
 
8
  <div id="post-body" class="metabox-holder columns-2">
9
  <div id="post-body-content">
10
- <?php
11
- if ( ! $values['is_template'] ) {
12
- FrmAppController::get_form_nav($id, true, 'hide');
13
- }
14
- require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
15
-
16
- ?>
17
-
18
- <div class="frm_form_builder<?php echo FrmFormsHelper::get_form_style_class($form); ?>">
19
-
20
  <form method="post" id="frm_build_form">
21
  <input type="hidden" name="frm_action" value="create" />
22
  <input type="hidden" name="action" value="create" />
23
- <input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
24
 
25
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
26
 
27
  <p>
28
- <input type="button" value="<?php esc_attr_e( 'Create', 'formidable' ) ?>" class="frm_submit_<?php echo ( isset( $values['ajax_load'] ) && $values['ajax_load'] ) ? '' : 'no_'; ?>ajax button-primary" />
 
 
29
  <span class="frm-loading-img"></span>
30
  </p>
31
  </form>
32
-
33
- </div>
34
  </div>
35
- <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php'); ?>
 
 
 
 
36
  </div>
37
  </div>
38
- </div>
1
  <div class="wrap">
2
+ <div class="frmicon icon32"><br/></div>
3
+ <h2><?php _e('Build New Form', 'formidable') ?>
4
+ <a href="?page=formidable-new" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
5
  </h2>
6
+ <?php
7
+ if ( !$form->is_template ) {
8
+ FrmAppController::get_form_nav($id, true);
9
+ }
10
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
+
12
+ if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
13
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
14
+ <?php
15
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
16
+ }else{ ?>
17
  <div id="poststuff">
18
+ <?php } ?>
19
+
20
  <div id="post-body" class="metabox-holder columns-2">
21
  <div id="post-body-content">
22
+ <div class="frm_form_builder<?php echo (isset($form->options['custom_style']) && $form->options['custom_style']) ? ' with_frm_style' : ''; ?>">
23
+
24
+ <p style="margin-top:0;">
25
+ <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Create', 'formidable') ?>" class="button-primary" />
26
+ <?php _e('or', 'formidable') ?>
27
+ <a class="button-secondary cancel" href="?page=formidable&amp;frm_action=destroy&amp;id=<?php echo $id; ?>"><?php _e('Cancel', 'formidable') ?></a>
28
+ <span class="frm-loading-img"></span>
29
+ </p>
30
+
 
31
  <form method="post" id="frm_build_form">
32
  <input type="hidden" name="frm_action" value="create" />
33
  <input type="hidden" name="action" value="create" />
34
+ <input type="hidden" name="id" value="<?php echo $id; ?>" />
35
 
36
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
37
 
38
  <p>
39
+ <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Create', 'formidable') ?>" class="button-primary" />
40
+ <?php _e('or', 'formidable') ?>
41
+ <a class="button-secondary cancel" href="?page=formidable&amp;frm_action=destroy&amp;id=<?php echo $id; ?>"><?php _e('Cancel', 'formidable') ?></a>
42
  <span class="frm-loading-img"></span>
43
  </p>
44
  </form>
 
 
45
  </div>
46
+ </div>
47
+ <?php
48
+ if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
49
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
50
+ ?>
51
  </div>
52
  </div>
53
+ </div>
classes/views/frm-forms/notification.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
2
+ <div id="frm_notification_<?php echo $email_key ?>" class="tabs-panel notification_settings <?php if(!$first_email) echo 'panel_secondary' ?>" style="display:<?php echo ($a == 'notification_settings') ? 'block' : 'none'; ?>;">
3
+ <table class="form-table <?php if(!$first_email) echo 'menu-settings'; ?>">
4
+ <tr>
5
+ <td><label><?php _e('From/Reply to', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Usually the name and email of the person filling out the form. Select from Text, Email, User ID, or hidden fields for the name. &lt;br/&gt;Defaults to your site name and admin email found on the WordPress General Settings page.', 'formidable') ?>"></span>
6
+ </td>
7
+ <td class="frm_email_reply_container">
8
+ <div class="alignright frm_email_actions feature-filter">
9
+ <?php echo $email_key; ?>
10
+ <?php if ( $email_key !== 0 ) { ?>
11
+ <span class="frm_email_icons">
12
+ <a data-removeid="frm_notification_<?php echo $email_key ?>" class="frm_icon_font frm_delete_icon frm_remove_email"> </a>
13
+ </span>
14
+ <?php } ?>
15
+ </div>
16
+ <span class="howto"><?php _e('Name') ?></span>
17
+
18
+ <select name="notification[<?php echo $email_key ?>][reply_to_name]" id="reply_to_name_<?php echo $email_key ?>" onchange="frmCheckCustomEmail(this.value,'reply_to_name',<?php echo $email_key ?>)">
19
+ <option value=""><?php echo FrmAppHelper::truncate(get_option('blogname'), 80); ?></option>
20
+ <option value="custom" <?php selected($notification['reply_to_name'], 'custom'); ?>><?php _e('Custom Name', 'formidable') ?></option>
21
+ <?php
22
+ if(!empty($values['fields'])){ ?>
23
+ <optgroup label="<?php _e('Fields', 'formidable') ?>">
24
+ <?php
25
+ $field_select = array('text', 'email', 'user_id', 'hidden', 'select', 'radio');
26
+ foreach($values['fields'] as $val_key => $fo){
27
+ if(in_array($fo['type'], $field_select)){ ?>
28
+ <option value="<?php echo $fo['id'] ?>" <?php selected($notification['reply_to_name'], $fo['id']); ?>><?php echo FrmAppHelper::truncate($fo['name'], 40) ?></option>
29
+ <?php }else if($fo['type'] == 'data' and isset($fo['data_type']) and $fo['data_type'] != 'data'){
30
+ if(isset($values['fields'][$val_key]['linked'])){
31
+ foreach($values['fields'][$val_key]['linked'] as $linked_field){
32
+ if(!in_array($linked_field->type, $field_select)) continue; ?>
33
+ <option value="<?php echo $fo['id'] ?>|<?php echo $linked_field->id ?>" <?php selected($notification['reply_to_name'], $fo['id'] .'|'. $linked_field->id); ?>><?php echo $fo['name'] .': '. FrmAppHelper::truncate($linked_field->name, 40) ?></option>
34
+ <?php }
35
+ }
36
+ }
37
+ }
38
+ } ?>
39
+ </select>
40
+
41
+ <span class="howto" ><?php _e('Email', 'formidable') ?></span>
42
+ <select name="notification[<?php echo $email_key ?>][reply_to]" id="reply_to_<?php echo $email_key ?>" onchange="frmCheckCustomEmail(this.value,'reply_to',<?php echo $email_key ?>)">
43
+ <option value=""><?php echo get_option('admin_email') ?></option>
44
+ <option value="custom" <?php selected($notification['reply_to'], 'custom'); ?>><?php _e('Custom Address', 'formidable') ?></option>
45
+ <?php
46
+ if(!empty($values['fields'])){ ?>
47
+ <optgroup label="<?php _e('Fields', 'formidable') ?>">
48
+ <?php
49
+ foreach($values['fields'] as $val_key => $fo){
50
+ if(in_array($fo['type'], $field_select)){ ?>
51
+ <option value="<?php echo $fo['id'] ?>" <?php selected($notification['reply_to'], $fo['id']); ?>><?php echo FrmAppHelper::truncate($fo['name'], 40) ?></option>
52
+ <?php }else if($fo['type'] == 'data' and isset($fo['data_type']) and $fo['data_type'] != 'data'){
53
+ if(isset($values['fields'][$val_key]['linked'])){ ?>
54
+ <?php foreach($values['fields'][$val_key]['linked'] as $linked_field){
55
+ if(!in_array($linked_field->type, $field_select)) continue; ?>
56
+ <option value="<?php echo $fo['id'] ?>|<?php echo $linked_field->id ?>" <?php selected($notification['reply_to'], $fo['id'] .'|'. $linked_field->id); ?>><?php echo $fo['name'] .': '. FrmAppHelper::truncate($linked_field->name, 40) ?></option>
57
+ <?php }
58
+ }
59
+ }
60
+ }
61
+ } ?>
62
+ </select>
63
+
64
+ <div id="frm_cust_reply_container_<?php echo $email_key ?>" <?php echo ($notification['reply_to_name'] == 'custom' or $notification['reply_to'] == 'custom') ? '' : 'style="display:none"'; ?>>
65
+ <span class="howto" style="visibility:hidden;"><?php _e('Name') ?></span>
66
+ <input type="text" name="notification[<?php echo $email_key ?>][cust_reply_to_name]" value="<?php echo esc_attr($notification['cust_reply_to_name']) ?>" id="cust_reply_to_name_<?php echo $email_key ?>" title="<?php _e('Name') ?>" <?php echo ($notification['reply_to_name'] == 'custom') ? '' : 'style="visibility:hidden;"'; ?> />
67
+ <span class="howto" style="visibility:hidden;"><?php _e('Email', 'formidable') ?></span>
68
+ <input type="text" name="notification[<?php echo $email_key ?>][cust_reply_to]" value="<?php echo esc_attr($notification['cust_reply_to']) ?>" id="cust_reply_to_<?php echo $email_key ?>" title="<?php _e('Email Address', 'formidable') ?>" <?php echo ($notification['reply_to'] == 'custom') ? '' : 'style="visibility:hidden;"'; ?> />
69
+ </div>
70
+ </td>
71
+ </tr>
72
+
73
+ <tr>
74
+ <td colspan="2"><label><?php _e('Email Recipients', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e('To send to multiple addresses, separate each address with a comma. You can use [admin_email] to dynamically use the address on your WordPress General Settings page. &lt;br/&gt;PRO only: Leave blank if you do not want email notifications for this form.', 'formidable') ?>"></span>
75
+ <input type="text" name="notification[<?php echo $email_key ?>][email_to]" value="<?php echo esc_attr($notification['email_to']); ?>" class="frm_not_email_to frm_long_input" id="email_to_<?php echo $email_key ?>" />
76
+
77
+ <p><label><?php _e('Subject', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php echo esc_attr(sprintf(__('If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable'), $form->name, get_option('blogname'))); ?>"></span><br/>
78
+ <input type="text" name="notification[<?php echo $email_key ?>][email_subject]" class="frm_not_email_subject frm_long_input" id="email_subject_<?php echo $email_key ?>" size="55" value="<?php echo esc_attr($notification['email_subject']); ?>" /></p>
79
+
80
+ <p><label><?php _e('Message', 'formidable') ?> </label><br/>
81
+ <textarea name="notification[<?php echo $email_key ?>][email_message]" class="frm_not_email_message frm_long_input" id="email_message_<?php echo $email_key ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea($notification['email_message']) ?></textarea></p>
82
+
83
+ <h4><?php _e('Options', 'formidable') ?> </h4>
84
+ <label for="inc_user_info_<?php echo $email_key ?>"><input type="checkbox" name="notification[<?php echo $email_key ?>][inc_user_info]" class="frm_not_inc_user_info" id="inc_user_info_<?php echo $email_key ?>" value="1" <?php checked($notification['inc_user_info'], 1); ?> /> <?php _e('Append IP Address, Browser, and Referring URL to message', 'formidable') ?></label>
85
+
86
+ <p><label for="plain_text_<?php echo $email_key ?>"><input type="checkbox" name="notification[<?php echo $email_key ?>][plain_text]" id="plain_text_<?php echo $email_key ?>" value="1" <?php checked($notification['plain_text'], 1); ?> /> <?php _e('Send Emails in Plain Text', 'formidable') ?></label></p>
87
+ <?php
88
+ if(!$frm_vars['pro_is_installed'])
89
+ FrmAppController::update_message('send autoresponders or conditionally send email notifications');
90
+
91
+ do_action('frm_additional_form_notification_options', $values, compact('notification', 'email_key')); ?>
92
+ </td></tr>
93
+ </table>
94
+ </div>
classes/views/frm-forms/settings.php CHANGED
@@ -1,254 +1,194 @@
1
  <div id="form_settings_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2><?php _e( 'Settings', 'formidable' ) ?>
4
- <a href="#" class="add-new-h2 frm_invisible"></a>
5
  </h2>
6
-
7
- <?php
8
- // Add form messages
9
  require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
10
- ?>
11
-
 
 
 
 
12
  <div id="poststuff">
 
 
13
  <div id="post-body" class="metabox-holder columns-2">
14
  <div id="post-body-content">
15
- <?php
16
- FrmAppController::get_form_nav($id, true);
17
- ?>
 
 
 
 
 
 
 
18
 
19
- <form method="post" class="frm_form_settings">
20
- <input type="hidden" name="id" id="form_id" value="<?php echo (int) $id; ?>" />
21
  <input type="hidden" name="frm_action" value="update_settings" />
22
-
 
23
  <div class="meta-box-sortables">
24
  <div class="categorydiv postbox">
25
- <h3 class="hndle"><span><?php echo __( 'Form Settings', 'formidable' ) ?></span></h3>
26
  <div class="inside frm-help-tabs">
27
  <div id="contextual-help-back"></div>
28
  <div id="contextual-help-columns">
29
  <div class="contextual-help-tabs">
30
  <ul class="frm-category-tabs frm-form-setting-tabs">
31
  <?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
32
- <li <?php echo ($a == 'advanced_settings') ? 'class="tabs active"' : '' ?>><a href="#advanced_settings"><?php _e( 'General', 'formidable' ) ?></a></li>
33
- <li <?php echo ($a == 'email_settings') ? 'class="tabs active"' : '' ?>><a href="#email_settings"><?php _e( 'Form Actions', 'formidable' ); ?></a></li>
34
- <li <?php echo ($a == 'html_settings') ? 'class="tabs active"' : '' ?>><a href="#html_settings"><?php _e( 'Customize HTML', 'formidable' ) ?></a></li>
35
- <?php foreach ( $sections as $sec_name => $section ) { ?>
36
- <li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo esc_attr( $sec_name ) ?>_settings"><?php echo ucfirst($sec_name) ?></a></li>
 
37
  <?php } ?>
38
  </ul>
39
  </div>
40
- <div class="advanced_settings tabs-panel <?php echo ($a == 'advanced_settings') ? 'frm_block' : 'frm_hidden' ?>">
41
- <h3 class="frm_first_h3"><?php _e( 'On Submit', 'formidable' ); ?>
42
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Choose what will happen after the user submits this form.', 'formidable' );
43
- if ( ! FrmAppHelper::pro_is_installed() ) {
44
- esc_attr_e( ' Upgrade to Formidable Forms to get access to all options in the dropdown.', 'formidable' );
45
- } ?>" ></span>
46
- </h3>
47
-
48
- <!--On Submit Section-->
49
- <table class="form-table">
50
- <tr>
51
- <td class="frm_175_width">
52
- <select name="options[success_action]" id="success_action">
53
- <option value="message" <?php selected($values['success_action'], 'message') ?>><?php _e( 'Show Message', 'formidable' )?></option>
54
- <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
55
- <option value="redirect" <?php selected($values['success_action'], 'redirect');
56
- ?>><?php _e( 'Redirect to URL', 'formidable' ) ?></option>
57
- <option value="page" <?php selected($values['success_action'], 'page');
58
- ?>><?php _e( 'Show Page Content', 'formidable' )?></option>
59
- <?php } else { ?>
60
- <option value="redirect" disabled="disabled" <?php selected($values['success_action'], 'redirect');
61
- ?>><?php _e( 'Redirect to URL', 'formidable' ); echo ' '. __( '(Pro feature)', 'formidable' ); ?></option>
62
- <option value="page" disabled="disabled" <?php selected($values['success_action'], 'page');
63
- ?>><?php _e( 'Show Page Content', 'formidable' ); echo ' '. __( '(Pro feature)', 'formidable' ); ?></option>
64
- <?php } ?>
65
- </select>
66
- </td>
67
- <td>
68
- <span class="success_action_redirect_box success_action_box<?php echo ($values['success_action'] == 'redirect') ? '' : ' frm_hidden'; ?>">
69
- <input type="text" name="options[success_url]" id="success_url" value="<?php
70
- if ( isset( $values['success_url'] ) ) {
71
- echo esc_attr( $values['success_url'] );
72
- } ?>" placeholder="http://example.com" />
73
- </span>
74
 
75
- <?php if ( FrmAppHelper::pro_is_installed() ){ ?>
76
- <span class="success_action_page_box success_action_box<?php echo ($values['success_action'] == 'page') ? '' : ' frm_hidden'; ?>">
77
- <label><?php _e( 'Use Content from Page', 'formidable' ) ?></label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  <?php FrmAppHelper::wp_pages_dropdown( 'options[success_page_id]', $values['success_page_id'] ) ?>
79
- </span>
80
  <?php } ?>
81
  </td>
82
  </tr>
83
- <tr class="frm_show_form_opt success_action_message_box success_action_box<?php echo ($values['success_action'] == 'message') ? '' : ' frm_hidden'; ?>">
84
- <td colspan="2">
85
- <label for="show_form"><input type="checkbox" name="options[show_form]" id="show_form" value="1" <?php checked($values['show_form'], 1) ?> /> <?php _e( 'Show the form with the confirmation message', 'formidable' )?></label>
86
- </td>
87
- </tr>
88
- <tr>
89
- <td colspan="2"><label for="no_save"><input type="checkbox" name="options[no_save]" id="no_save" value="1" <?php checked($values['no_save'], 1); ?> /> <?php _e( 'Do not store entries submitted from this form', 'formidable' ) ?></label>
90
- </td>
91
- </tr>
92
- <?php if ( function_exists( 'akismet_http_post') ) { ?>
93
- <tr>
94
- <td colspan="2"><?php _e( 'Use Akismet to check entries for spam for', 'formidable' ) ?>
95
  <select name="options[akismet]">
96
- <option value=""><?php _e( 'no one', 'formidable' ) ?></option>
97
- <option value="1" <?php selected($values['akismet'], 1)?>><?php _e( 'everyone', 'formidable' ) ?></option>
98
- <option value="logged" <?php selected($values['akismet'], 'logged')?>><?php _e( 'visitors who are not logged in', 'formidable' ) ?></option>
99
  </select>
100
  </td>
101
  </tr>
102
  <?php } ?>
103
- <?php do_action('frm_additional_form_options', $values); ?>
104
- </table>
105
-
106
- <!--AJAX Section-->
107
- <h3><?php _e( 'AJAX', 'formidable' ) ?>
108
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Make stuff happen in the background without a page refresh', 'formidable' ) ?>" ></span>
109
- </h3>
110
- <table class="form-table">
111
- <tr>
112
- <td>
113
- <label for="ajax_load">
114
- <input type="checkbox" name="options[ajax_load]" id="ajax_load" value="1"<?php echo ( $values['ajax_load'] ) ? ' checked="checked"' : ''; ?> /> <?php _e( 'Load and save form builder page with AJAX', 'formidable' ) ?>
115
- </label>
116
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Recommended for long forms.', 'formidable' ) ?>" ></span>
117
- </td>
118
- </tr>
119
- <?php do_action('frm_add_form_ajax_options', $values); ?>
120
- </table>
121
-
122
- <!--Permissions Section-->
123
- <table class="form-table">
124
- <?php do_action('frm_add_form_perm_options', $values); ?>
125
- </table>
126
-
127
- <!--Styling & Buttons Section-->
128
- <h3><?php _e( 'Styling & Buttons', 'formidable' ) ?>
129
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Select a style for this form and set the text for your buttons.', 'formidable' ) ?>" ></span>
130
- </h3>
131
- <table class="form-table">
132
- <tr>
133
- <td class="frm_left_label"><label for="custom_style"><?php _e( 'Style Template', 'formidable' ) ?></label></td>
134
- <td><select name="options[custom_style]" id="custom_style">
135
- <option value="1" <?php selected($values['custom_style'], 1) ?>><?php _e( 'Always use default', 'formidable' )?></option>
136
- <?php foreach ( $styles as $s ) { ?>
137
- <option value="<?php echo esc_attr( $s->ID ) ?>" <?php selected( $s->ID, $values['custom_style'] ) ?>><?php echo esc_html( $s->post_title . ( empty( $s->menu_order ) ? '' : ' ('. __( 'default', 'formidable' ) .')' ) ) ?></option>
138
- <?php } ?>
139
- <option value="0" <?php selected($values['custom_style'], 0); selected($values['custom_style'], '') ?>><?php _e( 'Do not use Formidable styling', 'formidable' )?></option>
140
- </select></td>
141
- </tr>
142
- <tr>
143
- <td><label><?php _e( 'Submit Button Text', 'formidable' ) ?></label></td>
144
- <td><input type="text" name="options[submit_value]" value="<?php echo esc_attr($values['submit_value']); ?>" /></td>
145
- </tr>
146
- <?php do_action( 'frm_add_form_button_options', $values ); ?>
147
- </table>
148
-
149
- <!--Message Section-->
150
- <h3 id="frm_messages_header" class="<?php echo ( ( isset( $values['edit_action'] ) && $values['edit_action'] == 'message' && isset( $values['editable'] ) && $values['editable'] == 1 ) || $values['success_action'] == 'message' || $values['save_draft'] == 1 ) ? '' : 'frm_hidden'; ?>"><?php _e( 'Messages', 'formidable' ); ?>
151
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Set up your confirmation messages.', 'formidable' ) ?>" ></span>
152
- </h3>
153
- <table class="form-table">
154
- <tr class="success_action_message_box success_action_box<?php echo ($values['success_action'] == 'message') ? '' : ' frm_hidden'; ?>">
155
- <td>
156
- <div><?php _e( 'On Submit', 'formidable' ) ?></div>
157
- <textarea id="success_msg" name="options[success_msg]" cols="50" rows="2" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['success_msg']); ?></textarea>
158
- </td>
159
- </tr>
160
- <?php do_action('frm_add_form_msg_options', $values); ?>
161
  </table>
162
  </div>
163
 
164
-
165
- <div id="frm_notification_settings" class="frm_email_settings email_settings tabs-panel widgets-holder-wrap <?php echo ($a == 'email_settings') ? ' frm_block' : ' frm_hidden'; ?>">
166
- <div id="frm_email_addon_menu" class="manage-menus">
167
- <h3><?php _e( 'Add New Action', 'formidable' ) ?></h3>
168
- <ul class="frm_actions_list">
169
- <?php
170
-
171
- //For each add-on, add an li, class, and javascript function. If active, add an additional class.
172
- foreach ( $action_controls as $action_control ) {
173
- ?>
174
- <li><a href="javascript:void(0)" class="frm_<?php echo esc_attr( $action_control->id_base ) ?>_action frm_bstooltip <?php
175
- echo ( isset($action_control->action_options['active']) && $action_control->action_options['active']) ? 'frm_active_action ' : 'frm_inactive_action ';
176
- echo esc_attr( $action_control->action_options['classes'] );
177
- ?>" title="<?php echo esc_attr($action_control->action_options['tooltip']) ?>" data-limit="<?php echo isset($action_control->action_options['limit']) ? esc_attr( $action_control->action_options['limit'] ) : '99' ?>" data-actiontype="<?php echo esc_attr($action_control->id_base) ?>"></a></li>
178
- <?php
179
- unset($actions_icon);
180
- }
181
- ?>
182
- </ul>
183
- </div>
184
- <div class="frm_no_actions">
185
- <div class="inner_actions">
186
- <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow1.png'; ?>" alt=""/>
187
- <div class="clear"></div>
188
- <?php _e( 'Click an action to add it to this form', 'formidable' ) ?>
189
- </div>
190
- </div>
191
- <?php FrmFormActionsController::list_actions($form, $values); ?>
192
  </div>
193
-
194
- <div id="html_settings" class="tabs-panel <?php echo ($a == 'html_settings') ? ' frm_block' : ' frm_hidden'; ?>">
195
-
196
- <div class="frm_field_html_box frm_top_container">
197
- <p><label><?php _e( 'Form Classes', 'formidable' ) ?></label>
198
- <input type="text" name="options[form_class]" value="<?php echo esc_attr($values['form_class']) ?>" />
199
- </p>
200
- <div class="clear"></div>
201
-
202
- <p><label><?php _e( 'Before Fields', 'formidable' ) ?></label>
203
  <textarea name="options[before_html]" rows="4" id="before_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['before_html']) ?></textarea></p>
204
 
205
  <div id="add_html_fields">
206
- <?php
207
- if ( isset( $values['fields'] ) ) {
208
- foreach ( $values['fields'] as $field ) {
209
- if ( apply_filters( 'frm_show_custom_html', true, $field['type'] ) ) { ?>
210
- <p><label><?php echo esc_html( $field['name'] ) ?></label>
211
- <textarea name="field_options[custom_html_<?php echo esc_attr( $field['id'] ) ?>]" rows="7" id="custom_html_<?php echo esc_attr( $field['id'] ) ?>" class="field_custom_html frm_long_input"><?php echo FrmAppHelper::esc_textarea($field['custom_html']) ?></textarea></p>
212
  <?php }
213
  unset($field);
214
  }
215
  } ?>
216
  </div>
217
 
218
- <p><label><?php _e( 'After Fields', 'formidable' ) ?></label>
219
- <textarea name="options[after_html]" rows="3" id="after_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['after_html']) ?></textarea></p>
220
-
221
- <p><label><?php _e( 'Submit Button', 'formidable' ) ?></label>
222
  <textarea name="options[submit_html]" rows="3" id="submit_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['submit_html']) ?></textarea></p>
223
  </div>
224
  </div>
225
-
226
- <?php foreach ( $sections as $sec_name => $section ) { ?>
227
- <div id="<?php echo esc_attr( $sec_name ) ?>_settings" class="tabs-panel <?php echo ($a == $sec_name .'_settings') ? ' frm_block' : ' frm_hidden'; ?>"><?php
228
- if ( isset( $section['class'] ) ) {
229
- call_user_func( array($section['class'], $section['function']), $values);
230
- } else {
231
- call_user_func((isset($section['function']) ? $section['function'] : $section), $values);
 
 
 
 
 
 
 
232
  } ?>
233
  </div>
234
  <?php } ?>
235
-
236
  <?php do_action('frm_add_form_option_section', $values); ?>
237
  <div class="clear"></div>
238
  </div>
239
  </div>
 
 
240
  </div>
241
 
242
  </div>
243
 
244
- <p>
245
- <input type="submit" value="<?php esc_attr_e( 'Update', 'formidable' ) ?>" class="button-primary" />
 
 
246
  </p>
247
  </form>
248
 
249
 
250
  </div>
251
- <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php'); ?>
 
 
 
252
  </div>
253
  </div>
254
  </div>
1
  <div id="form_settings_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2><?php _e('Settings', 'formidable') ?>
4
+ <a href="#" class="add-new-h2" style="visibility:hidden;"></a>
5
  </h2>
6
+ <?php FrmAppController::get_form_nav($id, true);
 
 
7
  require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
8
+
9
+ if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
10
+ <div id="poststuff" class="metabox-holder has-right-sidebar">
11
+ <?php
12
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php');
13
+ }else{ ?>
14
  <div id="poststuff">
15
+ <?php } ?>
16
+
17
  <div id="post-body" class="metabox-holder columns-2">
18
  <div id="post-body-content">
19
+
20
+ <form method="post" class="frm_form_settings">
21
+ <p style="clear:left; margin-top:0;">
22
+ <input type="submit" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
23
+ <?php _e('or', 'formidable') ?>
24
+ <a class="button-secondary cancel" href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=edit&id='. $id) ?>"><?php _e('Cancel', 'formidable') ?></a>
25
+ <?php do_action('frm_settings_buttons', $values); ?>
26
+ </p>
27
+
28
+ <div class="clear"></div>
29
 
30
+ <input type="hidden" name="id" value="<?php echo $id; ?>" />
 
31
  <input type="hidden" name="frm_action" value="update_settings" />
32
+ <div id="poststuff" class="metabox-holder">
33
+ <div id="post-body">
34
  <div class="meta-box-sortables">
35
  <div class="categorydiv postbox">
36
+ <h3 class="hndle"><span><?php echo FrmAppHelper::truncate($values['name'], 40) .' '. __('Settings', 'formidable') ?></span></h3>
37
  <div class="inside frm-help-tabs">
38
  <div id="contextual-help-back"></div>
39
  <div id="contextual-help-columns">
40
  <div class="contextual-help-tabs">
41
  <ul class="frm-category-tabs frm-form-setting-tabs">
42
  <?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
43
+ <li <?php echo ($a == 'advanced_settings') ? 'class="tabs active"' : '' ?>><a href="#advanced_settings"><?php _e('General', 'formidable') ?></a></li>
44
+ <li <?php echo ($a == 'notification_settings') ? 'class="tabs active"' : '' ?>><a href="#notification_settings"><?php _e('Emails', 'formidable') ?></a></li>
45
+ <li <?php echo ($a == 'html_settings') ? 'class="tabs active"' : '' ?>><a href="#html_settings"><?php _e('Customize HTML', 'formidable') ?></a></li>
46
+ <li <?php echo ($a == 'post_settings') ? 'class="tabs active"' : '' ?>><a href="#post_settings"><?php _e('Create Posts', 'formidable') ?></a></li>
47
+ <?php foreach($sections as $sec_name => $section){ ?>
48
+ <li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo $sec_name ?>_settings"><?php echo ucfirst($sec_name) ?></a></li>
49
  <?php } ?>
50
  </ul>
51
  </div>
52
+ <div style="display:<?php echo ($a == 'advanced_settings') ? 'block' : 'none'; ?>;" class="advanced_settings tabs-panel">
53
+ <table class="form-table">
54
+ <tr><td colspan="2"><label for="custom_style"><input type="checkbox" name="options[custom_style]" id="custom_style" <?php echo ($values['custom_style']) ? ' checked="checked"' : ''; ?> value="1" />
55
+ <?php _e('Use Formidable styling for this form', 'formidable') ?></label></td>
56
+ </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
+ <tr><td colspan="2"><label class="frm_left_label"><?php _e('Submit Button Text', 'formidable') ?></label>
59
+ <input type="text" name="options[submit_value]" value="<?php echo esc_attr($values['submit_value']); ?>" /></td>
60
+ </tr>
61
+
62
+ <tr><td colspan="2"><label><?php _e('Action After Form Submission', 'formidable') ?></label>
63
+ <?php if(!$frm_vars['pro_is_installed']){ ?>
64
+ <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('You must upgrade to Formidable Pro to get access to the second two options.', 'formidable') ?>" ></span>
65
+ <?php } ?><br/>
66
+
67
+ <label for="success_action_message"><input type="radio" name="options[success_action]" id="success_action_message" value="message" <?php checked($values['success_action'], 'message') ?> /> <?php _e('Display a Message', 'formidable') ?></label>
68
+ <label for="success_action_page" <?php echo $pro_feature ?>><input type="radio" name="options[success_action]" id="success_action_page" value="page" <?php checked($values['success_action'], 'page') ?> <?php if(!$frm_vars['pro_is_installed']) echo 'disabled="disabled" '; ?>/> <?php _e('Display content from another page', 'formidable') ?></label>
69
+ <label for="success_action_redirect" <?php echo $pro_feature ?>><input type="radio" name="options[success_action]" id="success_action_redirect" value="redirect" <?php checked($values['success_action'], 'redirect') ?> <?php if(!$frm_vars['pro_is_installed']) echo 'disabled="disabled" '; ?>/> <?php _e('Redirect to URL', 'formidable') ?></label>
70
+
71
+ <p class="frm_indent_opt success_action_redirect_box success_action_box" <?php echo ($values['success_action'] == 'redirect') ? '' : 'style="display:none;"'; ?>>
72
+ <input type="text" name="options[success_url]" id="success_url" value="<?php if(isset($values['success_url'])) echo esc_attr($values['success_url']); ?>" style="width:98%" placeholder="http://example.com" />
73
+ </p>
74
+
75
+ <div class="frm_indent_opt success_action_message_box success_action_box" <?php echo ($values['success_action'] == 'message') ? '' : 'style="display:none;"'; ?>>
76
+ <p><textarea id="success_msg" name="options[success_msg]" cols="50" rows="2" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['success_msg']); ?></textarea></p>
77
+ <p class="frm_show_form_opt">
78
+ <label for="show_form"><input type="checkbox" name="options[show_form]" id="show_form" value="1" <?php checked($values['show_form'], 1) ?> /> <?php _e('Show the form with the confirmation message', 'formidable')?></label>
79
+ </p>
80
+ </div>
81
+
82
+ <?php if($frm_vars['pro_is_installed']){ ?>
83
+ <p class="frm_indent_opt success_action_page_box success_action_box" <?php echo ($values['success_action'] == 'page') ? '' : 'style="display:none;"'; ?>>
84
+ <label><?php _e('Use Content from Page', 'formidable') ?></label>
85
  <?php FrmAppHelper::wp_pages_dropdown( 'options[success_page_id]', $values['success_page_id'] ) ?>
86
+ </p>
87
  <?php } ?>
88
  </td>
89
  </tr>
90
+
91
+ <tr><td colspan="2"><label for="ajax_load"><input type="checkbox" name="options[ajax_load]" id="ajax_load" value="1"<?php echo ($values['ajax_load']) ? ' checked="checked"' : ''; ?> /> <?php _e('Load and save form builder page with AJAX', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Recommended for long forms.', 'formidable') ?>" ></span></td></tr>
92
+
93
+
94
+ <?php do_action('frm_additional_form_options', $values); ?>
95
+
96
+ <tr><td colspan="2"><label for="no_save"><input type="checkbox" name="options[no_save]" id="no_save" value="1" <?php checked($values['no_save'], 1); ?> /> <?php _e('Do not store any entries submitted from this form.', 'formidable') ?> <span class="howto"><?php _e('Warning: There is no way to retrieve unsaved entries.', 'formidable') ?></span></label></td></tr>
97
+
98
+ <?php if (function_exists( 'akismet_http_post' )){ ?>
99
+ <tr><td colspan="2"><?php _e('Use Akismet to check entries for spam for', 'formidable') ?>
 
 
100
  <select name="options[akismet]">
101
+ <option value=""><?php _e('no one', 'formidable') ?></option>
102
+ <option value="1" <?php selected($values['akismet'], 1)?>><?php _e('everyone', 'formidable') ?></option>
103
+ <option value="logged" <?php selected($values['akismet'], 'logged')?>><?php _e('visitors who are not logged in', 'formidable') ?></option>
104
  </select>
105
  </td>
106
  </tr>
107
  <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  </table>
109
  </div>
110
 
111
+ <?php
112
+ $first_email = true;
113
+ foreach($values['notification'] as $email_key => $notification){
114
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/notification.php');
115
+ unset($email_key);
116
+ unset($notification);
117
+ $first_email = false;
118
+ }
119
+ if($frm_vars['pro_is_installed']){ ?>
120
+ <div id="frm_email_add_button" class="notification_settings hide_with_tabs submit" style="display:<?php echo ($a == 'notification_settings') ? 'block' : 'none'; ?>;">
121
+ <a href="javascript:frmAddEmailList(<?php echo $values['id'] ?>)" class="button-secondary">+ <?php _e('Add Notification', 'formidable') ?></a></td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  </div>
123
+ <?php } ?>
124
+
125
+ <div id="html_settings" class="tabs-panel" style="display:<?php echo ($a == 'html_settings') ? 'block' : 'none'; ?>;">
126
+
127
+ <div id="post-body-content" class="frm_top_container" style="margin-right:260px;">
128
+ <p><label class="frm_primary_label"><?php _e('Before Fields', 'formidable') ?></label>
 
 
 
 
129
  <textarea name="options[before_html]" rows="4" id="before_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['before_html']) ?></textarea></p>
130
 
131
  <div id="add_html_fields">
132
+ <?php
133
+ if (isset($values['fields'])){
134
+ foreach($values['fields'] as $field){
135
+ if (apply_filters('frm_show_custom_html', true, $field['type'])){ ?>
136
+ <p><label class="frm_primary_label"><?php echo $field['name'] ?></label>
137
+ <textarea name="field_options[custom_html_<?php echo $field['id'] ?>]" rows="7" id="custom_html_<?php echo $field['id'] ?>" class="field_custom_html frm_long_input"><?php echo FrmAppHelper::esc_textarea($field['custom_html']) ?></textarea></p>
138
  <?php }
139
  unset($field);
140
  }
141
  } ?>
142
  </div>
143
 
144
+ <p><label class="frm_primary_label"><?php _e('After Fields', 'formidable') ?></label>
145
+ <textarea name="options[after_html]" rows="3" id="after_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['after_html']) ?></textarea></p>
146
+
147
+ <p><label class="frm_primary_label"><?php _e('Submit Button', 'formidable') ?></label>
148
  <textarea name="options[submit_html]" rows="3" id="submit_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['submit_html']) ?></textarea></p>
149
  </div>
150
  </div>
151
+ <div id="post_settings" class="tabs-panel" style="display:<?php echo ($a == 'post_settings') ? 'block' : 'none'; ?>;">
152
+ <?php if($frm_vars['pro_is_installed'])
153
+ FrmProFormsController::post_options($values);
154
+ else
155
+ FrmAppController::update_message('create and edit posts, pages, and custom post types through your forms');
156
+ ?>
157
+ </div>
158
+
159
+ <?php foreach($sections as $sec_name => $section){ ?>
160
+ <div id="<?php echo $sec_name ?>_settings" class="tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
161
+ if(isset($section['class'])){
162
+ call_user_func(array($section['class'], $section['function']), $values);
163
+ }else{
164
+ call_user_func((isset($section['function']) ? $section['function'] : $section), $values);
165
  } ?>
166
  </div>
167
  <?php } ?>
168
+
169
  <?php do_action('frm_add_form_option_section', $values); ?>
170
  <div class="clear"></div>
171
  </div>
172
  </div>
173
+ </div>
174
+ </div>
175
  </div>
176
 
177
  </div>
178
 
179
+ <p>
180
+ <input type="submit" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
181
+ <?php _e('or', 'formidable') ?>
182
+ <a class="button-secondary cancel" href="<?php echo admin_url('admin.php?page=formidable') ?>&amp;frm_action=edit&amp;id=<?php echo $id ?>"><?php _e('Cancel', 'formidable') ?></a>
183
  </p>
184
  </form>
185
 
186
 
187
  </div>
188
+ <?php
189
+ if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
190
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php');
191
+ ?>
192
  </div>
193
  </div>
194
  </div>
classes/views/frm-forms/shortcode_opts.php DELETED
@@ -1,41 +0,0 @@
1
- <?php
2
- if ( ! empty($form_id) ) {
3
- ?>
4
- <h4 class="frm_left_label"><?php _e( 'Select a form:', 'formidable' ) ?></h4>
5
- <?php FrmFormsHelper::forms_dropdown( 'frmsc_'. $shortcode .'_'. $form_id ); ?>
6
- <div class="frm_box_line"></div>
7
- <?php
8
- }
9
-
10
- if ( ! empty($opts) ) { ?>
11
- <h4><?php _e( 'Options', 'formidable' ) ?></h4>
12
- <ul>
13
- <?php
14
- foreach ( $opts as $opt => $val ) {
15
- if ( isset( $val['type'] ) && 'text' == $val['type'] ) { ?>
16
- <li><label class="setting" for="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>">
17
- <span><?php echo esc_html( $val['label'] ) ?></span>
18
- <input type="text" id="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>" value="<?php echo esc_attr( $val['val'] ) ?>" />
19
- </label>
20
- </li>
21
- <?php
22
- } else if ( isset( $val['type'] ) && 'select' == $val['type'] ) { ?>
23
- <li><label class="setting" for="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>">
24
- <span><?php echo esc_html( $val['label'] ) ?></span>
25
- <select id="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>">
26
- <?php foreach ( $val['opts'] as $select_opt => $select_label ) { ?>
27
- <option value="<?php echo esc_attr( $select_opt ) ?>"><?php echo esc_html( $select_label ) ?></option>
28
- <?php } ?>
29
- </select>
30
- </label>
31
- </li>
32
- <?php
33
- } else { ?>
34
- <li><label class="setting" for="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>"><input type="checkbox" id="frmsc_<?php echo esc_attr( $shortcode .'_'. $opt ) ?>" value="<?php echo esc_attr( $val['val'] ) ?>" /> <?php echo esc_html( $val['label'] ) ?></label></li>
35
- <?php
36
- }
37
- }
38
- ?>
39
- </ul>
40
- <?php
41
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-forms/sidebar-settings.php CHANGED
@@ -1,11 +1,33 @@
1
- <div id="postbox-container-1" class="postbox-container">
2
- <?php
3
-
4
- if ( ! isset($hide_preview) || ! $hide_preview ) {
5
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/_publish_box.php');
6
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_insert_fields.php');
9
-
10
- ?>
 
 
 
 
 
 
 
 
11
  </div>
1
+ <div id="postbox-container-1" class="<?php echo FrmAppController::get_postbox_class(); ?>">
2
+ <?php if(!isset($hide_preview) or !$hide_preview){
3
+ if (!$values['is_template']){ ?>
4
+ <p class="howto" style="margin-top:0;"><?php _e('Add to a post, page or text widget', 'formidable') ?>
5
+ <a href="http://formidablepro.com/knowledgebase/publish-your-forms/" target="_blank" class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Key and id are generally synonymous. For more information on using this shortcode, click now.', 'formidable') ?>" ></a>
6
+ <a href="javascript:void(0)" data-toggle=".frm_ext_sc"><?php _e('Show more', 'formidable') ?></a>
7
+ <input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?>]" />
8
+ <span class="frm_ext_sc">
9
+ <input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?> title=true description=true]" />
10
+ <input type="text" readonly="true" class="frm_select_box" value="[formidable key=<?php echo $values['form_key']; ?>]" /><br/>
11
+
12
+ <?php _e('Insert in a template', 'formidable') ?>
13
+ <input type="text" readonly="true" class="frm_select_box" value="&lt;?php echo FrmFormsController::get_form_shortcode(array('id' => <?php echo $id; ?>, 'title' => false, 'description' => false)); ?&gt;" /><br/>
14
+
15
+ <?php _e('Direct Link', 'formidable') ?>
16
+ <input type="text" readonly="true" class="frm_select_box" value="<?php echo esc_attr(FrmFormsHelper::get_direct_link($values['form_key'])) ?>" />
17
+ </span>
18
+ </p>
19
+ </tr>
20
+ <?php } ?>
21
 
22
+ <p class="frm_orange"><a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" target="_blank"><?php _e('Preview Form', 'formidable') ?></a>
23
+ <?php global $frm_settings;
24
+ if ($frm_settings->preview_page_id > 0){ ?>
25
+ <?php _e('or', 'formidable') ?>
26
+ <a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('Preview in Current Theme', 'formidable') ?></a>
27
+ <?php } ?>
28
+ </p>
29
+ <?php
30
+ } ?>
31
+
32
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_insert_fields.php') ?>
33
  </div>
classes/views/frm-settings/form.php CHANGED
@@ -1,173 +1,164 @@
1
  <div id="form_global_settings" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2><?php _e( 'Global Settings', 'formidable' ); ?></h2>
4
 
5
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
6
-
7
  <div id="poststuff" class="metabox-holder">
8
  <div id="post-body">
9
  <div class="meta-box-sortables">
10
  <div class="categorydiv postbox">
11
- <h3 class="hndle"><span><?php _e( 'Global Settings', 'formidable' ) ?></span></h3>
12
  <div class="inside frm-help-tabs">
13
  <div id="contextual-help-back"></div>
14
  <div id="contextual-help-columns">
15
  <div class="contextual-help-tabs">
16
  <ul class="frm-category-tabs">
17
  <?php $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings'; ?>
18
- <li <?php echo ($a == 'general_settings') ? 'class="tabs active"' : '' ?>><a href="#general_settings" class="frm_cursor_pointer"><?php _e( 'General', 'formidable' ) ?></a></li>
19
- <?php foreach ( $sections as $sec_name => $section ) { ?>
20
- <li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo esc_attr( $sec_name ) ?>_settings"><?php echo isset($section['name']) ? $section['name'] : ucfirst($sec_name) ?></a></li>
21
  <?php } ?>
22
  </ul>
23
  </div>
24
 
25
  <?php do_action('frm_before_settings'); ?>
26
-
27
  <form name="frm_settings_form" method="post" class="frm_settings_form" action="?page=formidable-settings<?php echo (isset($_GET['t'])) ? '&amp;t='. $_GET['t'] : ''; ?>">
28
  <input type="hidden" name="frm_action" value="process-form" />
29
  <input type="hidden" name="action" value="process-form" />
30
  <?php wp_nonce_field('process_form_nonce', 'process_form'); ?>
31
-
32
- <div class="general_settings tabs-panel <?php echo ($a == 'general_settings') ? 'frm_block' : 'frm_hidden'; ?>">
33
- <p class="submit">
34
- <input class="button-primary" type="submit" value="<?php esc_attr_e( 'Update Options', 'formidable' ) ?>" />
35
  </p>
36
-
37
- <h3><?php _e( 'Styling & Scripts', 'formidable' ); ?></h3>
38
-
39
- <p><label class="frm_left_label"><?php _e( 'Load Formidable styling', 'formidable' ) ?></label>
 
 
40
  <select id="frm_load_style" name="frm_load_style">
41
- <option value="all" <?php selected($frm_settings->load_style, 'all') ?>><?php _e( 'on every page of your site', 'formidable' ) ?></option>
42
- <option value="dynamic" <?php selected($frm_settings->load_style, 'dynamic') ?>><?php _e( 'only on applicable pages', 'formidable' ) ?></option>
43
- <option value="none" <?php selected($frm_settings->load_style, 'none') ?>><?php _e( 'Don\'t use Formidable styling on any page', 'formidable' ) ?></option>
44
  </select>
45
  </p>
46
-
47
- <p><label for="frm_use_html"><input type="checkbox" id="frm_use_html" name="frm_use_html" value="1" <?php checked($frm_settings->use_html, 1) ?> > <?php _e( 'Use HTML5 in forms', 'formidable' ) ?></label>
48
  </p>
49
-
50
  <?php do_action('frm_style_general_settings', $frm_settings); ?>
51
-
52
- <h3><?php _e( 'User Permissions', 'formidable' ); ?>
53
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'Select users that are allowed access to Formidable. Without access to View Forms, users will be unable to see the Formidable menu.', 'formidable' ) ?>"></span>
54
- </h3>
55
- <table class="form-table">
56
- <?php foreach ( $frm_roles as $frm_role => $frm_role_description ) { ?>
57
- <tr>
58
- <td class="frm_left_label"><label><?php echo esc_html( $frm_role_description ) ?></label></td>
59
- <td><?php FrmAppHelper::wp_roles_dropdown( $frm_role, $frm_settings->$frm_role, 'multiple' ) ?></td>
60
- </tr>
61
- <?php } ?>
62
- </table>
63
-
64
- <h3><?php _e( 'reCAPTCHA', 'formidable' ); ?>
65
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog. reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot.', 'formidable' ) ?>" ></span>
66
- </h3>
67
-
68
- <p class="howto">reCAPTCHA requires an API key, consisting of a "site" and a "private" key. You can sign up for a <a href="https://www.google.com/recaptcha/" target="_blank">free reCAPTCHA key</a>.</p>
69
-
70
- <p><label class="frm_left_label"><?php _e( 'Site Key', 'formidable' ) ?></label>
71
  <input type="text" name="frm_pubkey" id="frm_pubkey" size="42" value="<?php echo esc_attr($frm_settings->pubkey) ?>" /></p>
72
-
73
- <p><label class="frm_left_label"><?php _e( 'Private Key', 'formidable' ) ?></label>
 
74
  <input type="text" name="frm_privkey" id="frm_privkey" size="42" value="<?php echo esc_attr($frm_settings->privkey) ?>" /></p>
75
 
76
- <p><label class="frm_left_label"><?php _e( 'reCAPTCHA Language', 'formidable' ) ?></label>
 
 
 
 
 
 
 
 
 
77
  <select name="frm_re_lang" id="frm_re_lang">
78
- <?php foreach ( $captcha_lang as $lang => $lang_name ) { ?>
79
- <option value="<?php echo esc_attr($lang) ?>" <?php selected($frm_settings->re_lang, $lang) ?>><?php echo esc_html( $lang_name ) ?></option>
80
  <?php } ?>
81
  </select></p>
82
-
83
- <h3><?php _e( 'Default Messages', 'formidable' ); ?>
84
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'You can override the success message and submit button settings on individual forms.', 'formidable' ) ?>"></span>
85
- </h3>
86
-
87
- <p>
88
- <label class="frm_left_label"><?php _e( 'Failed/Duplicate Entry', 'formidable' ); ?>
89
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a form is submitted and passes validation, but something goes wrong.', 'formidable' ) ?>" ></span>
90
- </label>
91
- <input type="text" id="frm_failed_msg" name="frm_failed_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->failed_msg ) ?>" />
92
- </p>
93
-
94
- <p>
95
- <label class="frm_left_label"><?php _e( 'Blank Field', 'formidable' ); ?>
96
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a required field is left blank.', 'formidable' ) ?>" ></span>
97
- </label>
98
- <input type="text" id="frm_blank_msg" name="frm_blank_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->blank_msg ) ?>" />
99
- </p>
100
-
101
- <p>
102
- <label class="frm_left_label"><?php _e( 'Incorrect Field', 'formidable' ); ?>
103
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a field response is either incorrect or missing.', 'formidable' ) ?>" ></span>
104
- </label>
105
- <input type="text" id="frm_invalid_msg" name="frm_invalid_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->invalid_msg ) ?>" />
106
- </p>
107
-
108
- <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
109
- <p>
110
- <label class="frm_left_label"><?php _e( 'Unique Value', 'formidable' ); ?>
111
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The message seen when a user selects a value in a unique field that has already been used.', 'formidable' ) ?>" ></span>
112
- </label>
113
- <input type="text" id="frm_unique_msg" name="frm_unique_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->unique_msg ) ?>" />
114
- </p>
115
- <?php } else { ?>
116
- <input type="hidden" id="frm_unique_msg" name="frm_unique_msg" value="<?php echo esc_attr( $frm_settings->unique_msg ) ?>" />
117
- <input type="hidden" id="frm_login_msg" name="frm_login_msg" class="frm_with_left_label" value="<?php echo esc_attr( $frm_settings->login_msg ) ?>" />
118
- <?php } ?>
119
-
120
- <p>
121
- <label class="frm_left_label"><?php _e( 'Success Message', 'formidable' ); ?>
122
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e( 'The default message seen after a form is submitted.', 'formidable' ) ?>" ></span>
123
- </label>
124
- <input type="text" id="frm_success_msg" name="frm_success_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->success_msg) ?>" />
125
- </p>
126
-
127
- <p>
128
- <label class="frm_left_label"><?php _e( 'Default Submit Button', 'formidable' ); ?></label>
129
- <input type="text" value="<?php echo esc_attr( $frm_settings->submit_value ) ?>" id="frm_submit_value" name="frm_submit_value" class="frm_with_left_label" />
130
- </p>
131
-
132
  <?php do_action('frm_settings_form', $frm_settings); ?>
133
-
134
- <?php if ( ! FrmAppHelper::pro_is_installed() ) { ?>
135
  <div class="clear"></div>
136
- <h3><?php _e( 'Miscellaneous', 'formidable' ) ?></h3>
 
 
137
  <?php } ?>
138
- <p><label class="frm_left_label"><?php _e( 'Admin menu label', 'formidable' ); ?></label>
139
  <input type="text" name="frm_menu" id="frm_menu" value="<?php echo esc_attr($frm_settings->menu) ?>" />
140
- <?php if ( is_multisite() && is_super_admin() ) { ?>
141
- <label for="frm_mu_menu"><input type="checkbox" name="frm_mu_menu" id="frm_mu_menu" value="1" <?php checked($frm_settings->mu_menu, 1) ?> /> <?php _e( 'Use this menu name site-wide', 'formidable' ); ?></label>
142
  <?php } ?>
143
  </p>
144
-
145
- <p><label class="frm_left_label"><?php _e( 'Preview Page', 'formidable' ); ?></label>
146
  <?php FrmAppHelper::wp_pages_dropdown('frm-preview-page-id', $frm_settings->preview_page_id ) ?>
147
  </p>
148
-
 
 
 
149
  </div>
150
-
151
- <?php
152
- foreach ( $sections as $sec_name => $section ) {
153
- if ( $a == $sec_name .'_settings' ) { ?>
154
- <style type="text/css">.<?php echo esc_attr( $sec_name ) ?>_settings{display:block;}</style><?php }?>
155
- <div id="<?php echo esc_attr( $sec_name ) ?>_settings" class="<?php echo esc_attr( $sec_name ) ?>_settings tabs-panel <?php echo ( $a == $sec_name .'_settings' ) ? 'frm_block' : 'frm_hidden'; ?>"><?php
156
- if ( isset( $section['class'] ) ) {
157
- call_user_func( array($section['class'], $section['function']));
158
- } else {
159
- call_user_func((isset($section['function']) ? $section['function'] : $section));
160
  } ?>
161
  </div>
162
- <?php
163
- } ?>
164
-
165
- <p class="alignright frm_uninstall">
166
- <a href="javascript:void(0)" id="frm_uninstall_now"><?php _e( 'Uninstall Formidable', 'formidable' ) ?></a>
167
  <span class="spinner frm_spinner"></span>
168
  </p>
169
  <p class="submit">
170
- <input class="button-primary" type="submit" value="<?php esc_attr_e( 'Update Options', 'formidable' ) ?>" />
171
  </p>
172
 
173
  </form>
1
  <div id="form_global_settings" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2><?php _e('Global Settings', 'formidable'); ?></h2>
4
 
5
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
6
+
7
  <div id="poststuff" class="metabox-holder">
8
  <div id="post-body">
9
  <div class="meta-box-sortables">
10
  <div class="categorydiv postbox">
11
+ <h3 class="hndle"><span><?php _e('Global Settings', 'formidable') ?></span></h3>
12
  <div class="inside frm-help-tabs">
13
  <div id="contextual-help-back"></div>
14
  <div id="contextual-help-columns">
15
  <div class="contextual-help-tabs">
16
  <ul class="frm-category-tabs">
17
  <?php $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings'; ?>
18
+ <li <?php echo ($a == 'general_settings') ? 'class="tabs active"' : '' ?>><a href="#general_settings" style="cursor:pointer"><?php _e('General', 'formidable') ?></a></li>
19
+ <?php foreach($sections as $sec_name => $section){ ?>
20
+ <li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo $sec_name ?>_settings"><?php echo isset($section['name']) ? $section['name'] : ucfirst($sec_name) ?></a></li>
21
  <?php } ?>
22
  </ul>
23
  </div>
24
 
25
  <?php do_action('frm_before_settings'); ?>
26
+
27
  <form name="frm_settings_form" method="post" class="frm_settings_form" action="?page=formidable-settings<?php echo (isset($_GET['t'])) ? '&amp;t='. $_GET['t'] : ''; ?>">
28
  <input type="hidden" name="frm_action" value="process-form" />
29
  <input type="hidden" name="action" value="process-form" />
30
  <?php wp_nonce_field('process_form_nonce', 'process_form'); ?>
31
+
32
+ <div class="general_settings tabs-panel" style="border-top:none;display:<?php echo ($a == 'general_settings') ? 'block' : 'none'; ?>;">
33
+ <p class="submit" style="padding:0;">
34
+ <input class="button-primary" type="submit" value="<?php _e('Update Options', 'formidable') ?>" />
35
  </p>
36
+
37
+
38
+ <div class="menu-settings">
39
+ <h3 class="frm_no_bg"><?php _e('Styling & Scripts', 'formidable'); ?></h3>
40
+
41
+ <p><?php _e('Load Formidable styling', 'formidable') ?>
42
  <select id="frm_load_style" name="frm_load_style">
43
+ <option value="all" <?php selected($frm_settings->load_style, 'all') ?>><?php _e('on every page of your site', 'formidable') ?></option>
44
+ <option value="dynamic" <?php selected($frm_settings->load_style, 'dynamic') ?>><?php _e('only on applicable pages', 'formidable') ?></option>
45
+ <option value="none" <?php selected($frm_settings->load_style, 'none') ?>><?php _e('Don\'t use Formidable styling on any page', 'formidable') ?></option>
46
  </select>
47
  </p>
48
+
49
+ <p><label for="frm_use_html"><input type="checkbox" id="frm_use_html" name="frm_use_html" value="1" <?php checked($frm_settings->use_html, 1) ?> > <?php _e('Use HTML5 in forms', 'formidable') ?></label>
50
  </p>
51
+
52
  <?php do_action('frm_style_general_settings', $frm_settings); ?>
53
+ </div>
54
+
55
+ <div class="menu-settings">
56
+ <h3 class="frm_no_bg"><?php _e('User Permissions', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Select users that are allowed access to Formidable. Without access to View Forms, users will be unable to see the Formidable menu.', 'formidable') ?>" ></span></h3>
57
+ <p><?php foreach($frm_roles as $frm_role => $frm_role_description){ ?>
58
+ <label class="frm_left_label"><?php echo $frm_role_description ?></label> <?php FrmAppHelper::wp_roles_dropdown( $frm_role, $frm_settings->$frm_role ) ?>
59
+ <span class="clear"></span>
60
+ <?php } ?></p>
61
+ </div>
62
+
63
+ <div class="menu-settings">
64
+ <h3 class="frm_no_bg"><?php _e('reCAPTCHA', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog. reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot.', 'formidable') ?>" ></span></h3>
65
+
66
+ <p class="howto">reCAPTCHA requires an API key, consisting of a "public" and a "private" key. You can sign up for a <a href="https://www.google.com/recaptcha/admin/create" target="_blank">free reCAPTCHA key</a>.</p>
67
+
68
+ <!-- reCAPTCHA public key -->
69
+ <p><label class="frm_left_label"><?php _e('Public Key', 'formidable') ?></label>
 
 
 
70
  <input type="text" name="frm_pubkey" id="frm_pubkey" size="42" value="<?php echo esc_attr($frm_settings->pubkey) ?>" /></p>
71
+
72
+ <!-- reCAPTCHA private key -->
73
+ <p><label class="frm_left_label"><?php _e('Private Key', 'formidable') ?></label>
74
  <input type="text" name="frm_privkey" id="frm_privkey" size="42" value="<?php echo esc_attr($frm_settings->privkey) ?>" /></p>
75
 
76
+ <p><label class="frm_left_label"><?php _e('reCAPTCHA Theme', 'formidable') ?></label>
77
+ <select name="frm_re_theme" id="frm_re_theme">
78
+ <?php foreach($recaptcha_themes as $theme_value => $theme_name){ ?>
79
+ <option value="<?php echo esc_attr($theme_value) ?>" <?php selected($frm_settings->re_theme, $theme_value) ?>><?php echo $theme_name ?></option>
80
+ <?php }
81
+ unset($recaptcha_themes, $theme_value, $theme_name);
82
+ ?>
83
+ </select></p>
84
+
85
+ <p><label class="frm_left_label"><?php _e('reCAPTCHA Language', 'formidable') ?></label>
86
  <select name="frm_re_lang" id="frm_re_lang">
87
+ <?php foreach(array('en' => __('English', 'formidable'), 'nl' => __('Dutch', 'formidable'), 'fr' => __('French', 'formidable'), 'de' => __('German', 'formidable'), 'pt' => __('Portuguese', 'formidable'), 'ru' => __('Russian', 'formidable'), 'es' => __('Spanish', 'formidable'), 'tr' => __('Turkish', 'formidable')) as $lang => $lang_name){ ?>
88
+ <option value="<?php echo esc_attr($lang) ?>" <?php selected($frm_settings->re_lang, $lang) ?>><?php echo $lang_name ?></option>
89
  <?php } ?>
90
  </select></p>
91
+ </div>
92
+
93
+ <div class="menu-settings">
94
+ <h3 class="frm_no_bg"><?php _e('Default Messages', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('You can override the success message and submit button settings on individual forms.', 'formidable') ?>" ></span></h3>
95
+
96
+ <p><label class="frm_left_label"><?php _e('Failed/Duplicate Entry', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a form is submitted and passes validation, but something goes wrong.', 'formidable') ?>" ></span></label>
97
+ <input type="text" id="frm_failed_msg" name="frm_failed_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->failed_msg) ?>" /></p>
98
+
99
+ <p><label class="frm_left_label"><?php _e('Blank Field', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a required field is left blank.', 'formidable') ?>" ></span></label>
100
+ <input type="text" id="frm_blank_msg" name="frm_blank_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->blank_msg) ?>" /></p>
101
+
102
+ <p><label class="frm_left_label"><?php _e('Incorrect Field', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a field response is either incorrect or missing.', 'formidable') ?>" ></span></label>
103
+ <input type="text" id="frm_invalid_msg" name="frm_invalid_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->invalid_msg) ?>" /></p>
104
+
105
+ <?php if($frm_vars['pro_is_installed']){ ?>
106
+ <p><label class="frm_left_label"><?php _e('Unique Value', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a user selects a value in a unique field that has already been used.', 'formidable') ?>" ></span></label>
107
+ <input type="text" id="frm_unique_msg" name="frm_unique_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->unique_msg) ?>" /></p>
108
+ <?php }else{ ?>
109
+ <input type="hidden" id="frm_unique_msg" name="frm_unique_msg" value="<?php echo esc_attr($frm_settings->unique_msg) ?>" />
110
+ <?php } ?>
111
+ <input type="hidden" id="frm_login_msg" name="frm_login_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->login_msg) ?>" />
112
+
113
+ <p><label class="frm_left_label"><?php _e('Success Message', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The default message seen after a form is submitted.', 'formidable') ?>" ></span></label>
114
+ <input type="text" id="frm_success_msg" name="frm_success_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->success_msg) ?>" /></p>
115
+
116
+ <p><label class="frm_left_label"><?php _e('Default Submit Button', 'formidable'); ?></label>
117
+ <input type="text" value="<?php echo esc_attr($frm_settings->submit_value) ?>" id="frm_submit_value" name="frm_submit_value" class="frm_with_left_label" /></p>
118
+ </div>
119
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  <?php do_action('frm_settings_form', $frm_settings); ?>
121
+
122
+ <?php if(!$frm_vars['pro_is_installed']){ ?>
123
  <div class="clear"></div>
124
+ <div class="menu-settings">
125
+ <h3 class="frm_no_bg"><?php _e('Miscellaneous', 'formidable') ?></h3>
126
+ </div>
127
  <?php } ?>
128
+ <p><label class="frm_left_label"><?php _e('Admin menu label', 'formidable'); ?></label>
129
  <input type="text" name="frm_menu" id="frm_menu" value="<?php echo esc_attr($frm_settings->menu) ?>" />
130
+ <?php if (is_multisite() and is_super_admin()){ ?>
131
+ <label for="frm_mu_menu"><input type="checkbox" name="frm_mu_menu" id="frm_mu_menu" value="1" <?php checked($frm_settings->mu_menu, 1) ?> /> <?php _e('Use this menu name site-wide', 'formidable'); ?></label>
132
  <?php } ?>
133
  </p>
134
+
135
+ <p><label class="frm_left_label"><?php _e('Preview Page', 'formidable'); ?></label>
136
  <?php FrmAppHelper::wp_pages_dropdown('frm-preview-page-id', $frm_settings->preview_page_id ) ?>
137
  </p>
138
+
139
+ <p><label class="frm_left_label"><?php _e('Tracking', 'formidable'); ?></label>
140
+ <label for="frm_track"><input type="checkbox" id="frm_track" name="frm_track" value="1" <?php checked($frm_settings->track, 1) ?>> <?php _e('Track referrer information and pages visited', 'formidable') ?></label>
141
+ </p>
142
  </div>
143
+
144
+ <?php foreach($sections as $sec_name => $section){
145
+ if($a == $sec_name .'_settings'){ ?>
146
+ <style type="text/css">.<?php echo $sec_name ?>_settings{display:block;}</style><?php }?>
147
+ <div id="<?php echo $sec_name ?>_settings" class="<?php echo $sec_name ?>_settings tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
148
+ if(isset($section['class'])){
149
+ call_user_func(array($section['class'], $section['function']));
150
+ }else{
151
+ call_user_func((isset($section['function']) ? $section['function'] : $section));
 
152
  } ?>
153
  </div>
154
+ <?php } ?>
155
+
156
+ <p class="alignright frm_uninstall" style="padding-top:1.25em;">
157
+ <a href="javascript:frm_uninstall_now()"><?php _e('Uninstall Formidable', 'formidable') ?></a>
 
158
  <span class="spinner frm_spinner"></span>
159
  </p>
160
  <p class="submit">
161
+ <input class="button-primary" type="submit" value="<?php _e('Update Options', 'formidable') ?>" />
162
  </p>
163
 
164
  </form>
classes/views/frm-settings/license_box.php CHANGED
@@ -1,11 +1,11 @@
1
- <div class="general_settings metabox-holder tabs-panel frm_license_box <?php echo ($a == 'general_settings') ? 'frm_block' : 'frm_hidden'; ?>">
2
- <?php if ( ! is_multisite() || is_super_admin() ) { ?>
3
  <div class="postbox">
4
  <div class="inside">
5
- <p class="alignright"><?php printf( __( '%1$sClick here%2$s to get it now', 'formidable' ), '<a href="http://formidablepro.com">', '</a>' ) ?> &#187;</p>
6
- <p><?php _e( 'Ready to take your forms to the next level?<br/>Formidable Forms will help you create views, manage data, and get reports.', 'formidable' ) ?></p>
7
-
8
- <p>Already signed up? <a href="http://formidablepro.com/knowledgebase/manually-install-formidable-pro/" target="_blank"><?php _e( 'Click here', 'formidable' ) ?></a> to get installation instructions and download the pro version.</p>
9
  </div>
10
  </div>
11
  <?php } ?>
1
+ <div class="general_settings metabox-holder tabs-panel" style="min-height:0px;border-bottom:none;display:<?php echo ($a == 'general_settings') ? 'block' : 'none'; ?>;">
2
+ <?php if (!is_multisite() or is_super_admin()){ ?>
3
  <div class="postbox">
4
  <div class="inside">
5
+ <p class="alignright"><?php printf(__('%1$sClick here%2$s to get it now', 'formidable'), '<a href="http://formidablepro.com">', '</a>') ?> &#187;</p>
6
+ <p><?php _e('Ready to take your forms to the next level?<br/>Formidable Pro will help you style forms, manage data, and get reports.', 'formidable') ?></p>
7
+
8
+ <p>Already signed up? <a href="http://formidablepro.com/knowledgebase/manually-install-formidable-pro/" target="_blank"><?php _e('Click here', 'formidable') ?></a> to get installation instructions and download the pro version.</p>
9
  </div>
10
  </div>
11
  <?php } ?>
classes/views/frm-settings/styling_tab.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div class="frm_update_msg">
2
+ This plugin version does not give you access to the visual form styler.<br/>
3
+ <a href="http://formidablepro.com/pricing/" target="_blank">Compare</a> our plans to find a solution that's right for you.
4
+ </div>
classes/views/frm-statistics/list.php CHANGED
@@ -1,19 +1,17 @@
1
  <div id="form_reports_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
  <h2>
4
- <?php _e( 'Reports', 'formidable' ) ?>
5
- <a href="#" class="add-new-h2 frm_invisible"><?php _e( 'Add New', 'formidable' ); ?></a>
6
  </h2>
7
 
8
- <?php
9
- if ( $form ) {
10
- FrmAppController::get_form_nav( $form, true );
11
- }
12
- require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
 
13
 
14
- FrmAppHelper::update_message( __( 'view reports and statistics on your saved entries', 'formidable' ) );
15
- ?>
16
-
17
- <img class="frm_no_reports" src="http://fp.strategy11.com/wp-content/themes/formidablepro/images/reports1.png" alt="Reports"/>
18
 
19
  </div>
1
  <div id="form_reports_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
  <h2>
4
+ <?php _e('Reports', 'formidable') ?>
5
+ <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
  </h2>
7
 
8
+ <?php
9
+ if($form) FrmAppController::get_form_nav($form, true);
10
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
+
12
+ FrmAppController::update_message('view reports and statistics on your saved entries');
13
+ ?>
14
 
15
+ <img src="http://fp.strategy11.com/wp-content/themes/formidablepro/images/reports1.png" alt="Reports" style="max-width:100%"/>
 
 
 
16
 
17
  </div>
classes/views/frm-statistics/list_displays.php CHANGED
@@ -1,18 +1,16 @@
1
  <div id="form_views_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
  <h2>
4
- <?php _e( 'Views', 'formidable' ); ?>
5
- <a href="#" class="add-new-h2 frm_invisible"><?php _e( 'Add New', 'formidable' ); ?></a>
6
  </h2>
7
 
8
- <?php
9
- if ( $form ) {
10
- FrmAppController::get_form_nav( $form );
11
- }
12
- require( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' );
13
- FrmAppHelper::update_message( __( 'display collected data in lists, calendars, and other formats', 'formidable' ) );
14
- ?>
15
 
16
- <img class="frm_no_views" src="http://fp.strategy11.com/images/custom-display-settings.png" alt="Display"/>
17
 
18
  </div>
1
  <div id="form_views_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
  <h2>
4
+ <?php _e('Views', 'formidable'); ?>
5
+ <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
  </h2>
7
 
8
+ <?php
9
+ if($form) FrmAppController::get_form_nav($form);
10
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
+ FrmAppController::update_message('display collected data in lists, calendars, and other formats');
12
+ ?>
 
 
13
 
14
+ <img src="http://fp.strategy11.com/images/custom-display-settings.png" alt="Display" style="max-width:100%"/>
15
 
16
  </div>
classes/views/shared/errors.php CHANGED
@@ -1,24 +1,12 @@
1
  <div class="clear"></div>
2
- <?php
3
- if ( isset($message) && $message != '' ) {
4
- if ( FrmAppHelper::is_admin() ) {
5
- ?><div id="message" class="updated frm_msg_padding"><?php
6
- echo $message;
7
- ?></div><?php
8
- } else {
9
- echo $message;
10
- }
11
- }
12
 
13
- if ( isset($errors) && is_array($errors) && count($errors) > 0 ) { ?>
14
  <div class="error">
15
  <ul id="frm_errors">
16
- <?php
17
- foreach ( $errors as $error ) {
18
  echo '<li>' . $error . '</li>';
19
- }
20
  ?>
21
  </ul>
22
  </div>
23
- <?php
24
- }
1
  <div class="clear"></div>
2
+ <?php if (isset($message) && $message != ''){ if(is_admin() and !defined('DOING_AJAX')){ ?><div id="message" class="updated" style="padding:5px;"><?php } echo $message; if(is_admin() and !defined('DOING_AJAX')){ ?></div><?php } } ?>
 
 
 
 
 
 
 
 
 
3
 
4
+ <?php if( isset($errors) && is_array($errors) && count($errors) > 0 ){ ?>
5
  <div class="error">
6
  <ul id="frm_errors">
7
+ <?php foreach( $errors as $error )
 
8
  echo '<li>' . $error . '</li>';
 
9
  ?>
10
  </ul>
11
  </div>
12
+ <?php } ?>
 
classes/views/shared/form-nav.php CHANGED
@@ -1,38 +1,9 @@
1
- <div id="titlediv">
2
  <ul class="frm_form_nav">
3
- <?php
4
- $class = ' class="first"';
5
- if ( current_user_can( 'frm_edit_forms' ) ) { ?>
6
- <li<?php echo $class ?>><a<?php FrmAppHelper::select_current_page( 'formidable', $current_page, array( 'edit', 'new', 'duplicate' ) ); ?> href="<?php echo esc_url( admin_url('admin.php?page=formidable&frm_action=edit&id='. $id) ) ?>"><?php _e( 'Build', 'formidable' ) ?></a> </li>
7
- <?php
8
- $class = '';
9
- }
10
-
11
- if ( current_user_can( 'frm_edit_forms' ) ) { ?>
12
- <li<?php echo $class ?>><a<?php FrmAppHelper::select_current_page( 'formidable', $current_page, array( 'settings' ) ); ?> href="<?php echo esc_url( admin_url('admin.php?page=formidable&frm_action=settings&id='. $id) ) ?>"><?php _e( 'Settings', 'formidable' ) ?></a> </li>
13
- <?php
14
- $class = '';
15
- } ?>
16
- <li<?php echo $class ?>> <a<?php FrmAppHelper::select_current_page( 'formidable-entries', $current_page ); ?> href="<?php echo esc_url( admin_
1
+ <?php if($form){ ?><p class="frm_title_head"><?php echo ($form->name == '') ? __('(no title)') : FrmAppHelper::truncate($form->name, 33) ?></p><?php } ?>
2
  <ul class="frm_form_nav">