Formidable Forms – Form Builder for WordPress - Version 2.0rc1

Version Description

Download this release

Release Info

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

Code changes from version 2.0b8 to 2.0rc1

Files changed (63) hide show
  1. classes/controllers/FrmAppController.php +13 -11
  2. classes/controllers/FrmEntriesController.php +12 -4
  3. classes/controllers/FrmFieldsController.php +16 -14
  4. classes/controllers/FrmFormActionsController.php +8 -2
  5. classes/controllers/FrmFormsController.php +58 -67
  6. classes/controllers/FrmHooksController.php +5 -9
  7. classes/controllers/FrmSettingsController.php +7 -5
  8. classes/controllers/FrmStylesController.php +37 -11
  9. classes/controllers/FrmXMLController.php +5 -5
  10. classes/helpers/FrmAppHelper.php +219 -51
  11. classes/helpers/FrmEntriesHelper.php +178 -97
  12. classes/helpers/FrmEntriesListHelper.php +6 -2
  13. classes/helpers/FrmFieldsHelper.php +42 -16
  14. classes/helpers/FrmFormsHelper.php +33 -12
  15. classes/helpers/FrmFormsListHelper.php +28 -6
  16. classes/helpers/FrmListHelper.php +1 -0
  17. classes/helpers/FrmStylesHelper.php +5 -5
  18. classes/helpers/FrmXMLHelper.php +4 -1
  19. classes/models/FrmDb.php +35 -21
  20. classes/models/FrmEntry.php +20 -23
  21. classes/models/FrmEntryMeta.php +16 -11
  22. classes/models/FrmField.php +42 -25
  23. classes/models/FrmForm.php +1 -1
  24. classes/models/FrmFormAction.php +1 -1
  25. classes/models/FrmNotification.php +9 -8
  26. classes/models/FrmSettings.php +9 -8
  27. classes/models/FrmStyle.php +28 -21
  28. classes/views/frm-entries/errors.php +1 -1
  29. classes/views/frm-entries/form.php +1 -0
  30. classes/views/frm-entries/sidebar-shared.php +84 -0
  31. classes/views/frm-entries/sidebar-show.php +3 -1
  32. classes/views/frm-fields/input.php +37 -53
  33. classes/views/frm-fields/radio.php +4 -8
  34. classes/views/frm-fields/show-build.php +2 -4
  35. classes/views/frm-fields/single-option.php +0 -1
  36. classes/views/frm-form-actions/default_actions.php +7 -7
  37. classes/views/frm-form-actions/email_action.php +3 -3
  38. classes/views/frm-forms/add_field.php +3 -3
  39. classes/views/frm-forms/add_field_links.php +1 -1
  40. classes/views/frm-forms/insert_form_popup.php +3 -1
  41. classes/views/frm-forms/shortcode_opts.php +42 -0
  42. classes/views/shared/errors.php +1 -1
  43. classes/views/shared/head.php +1 -19
  44. classes/views/shared/mb_adv_info.php +2 -2
  45. classes/views/styles/show.php +1 -1
  46. classes/views/xml/forms_xml.php +0 -1
  47. classes/views/xml/posts_xml.php +0 -1
  48. css/_single_theme.css.php +10 -1
  49. css/custom_theme.css.php +2 -6
  50. css/frm_admin.css +3 -0
  51. deprecated.php +0 -19
  52. formidable.php +2 -2
  53. js/bootstrap.min.js +3 -3
  54. js/formidable.js +367 -245
  55. js/formidable.min.js +45 -45
  56. js/formidable_admin.js +13 -11
  57. languages/formidable-de_DE.mo +0 -0
  58. languages/formidable-de_DE.po +1286 -1169
  59. languages/formidable-en_US.po +1286 -1169
  60. languages/formidable-es_ES.mo +0 -0
  61. languages/formidable-es_ES.po +1286 -1169
  62. languages/formidable-fr_FR.mo +0 -0
  63. languages/formidable-fr_FR.po +1073 -1140
classes/controllers/FrmAppController.php CHANGED
@@ -142,7 +142,7 @@ return false;
142
  return;
143
  }
144
 
145
- wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.2.0');
146
 
147
  if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
148
  ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
@@ -162,7 +162,6 @@ return false;
162
  add_thickbox();
163
 
164
  wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
165
- wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
166
 
167
  if ( FrmAppHelper::is_admin_page('formidable-settings') || FrmAppHelper::is_admin_page('formidable-styles') ) {
168
  // load multselect js
@@ -225,6 +224,11 @@ return false;
225
  return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
226
  }
227
 
 
 
 
 
 
228
  public static function front_head(){
229
  if (is_multisite()){
230
  $old_db_version = get_option('frm_db_version');
@@ -246,11 +250,9 @@ return false;
246
 
247
  self::localize_script('front');
248
 
249
- wp_enqueue_script('jquery');
250
-
251
  $frm_settings = FrmAppHelper::get_settings();
252
 
253
- $style = apply_filters('get_frm_stylesheet', array());
254
  if($style){
255
  foreach ( (array) $style as $k => $file ) {
256
  wp_register_style($k, $file, array(), $version);
@@ -268,6 +270,9 @@ return false;
268
  }
269
  }
270
 
 
 
 
271
  public static function localize_script($location){
272
  wp_localize_script('formidable', 'frm_js', array(
273
  'ajax_url' => admin_url( 'admin-ajax.php' ),
@@ -347,18 +352,15 @@ return false;
347
 
348
  $frm_settings = FrmAppHelper::get_settings();
349
  if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
350
- $css = apply_filters('get_frm_stylesheet', array());
351
 
352
- if(!empty($css)){
353
- echo "\n".'<script type="text/javascript">';
354
  foreach ( (array) $css as $css_key => $file ) {
355
  wp_enqueue_style($css_key);
356
  unset($css_key, $file);
357
  }
358
- unset($css);
359
-
360
- echo '</script>'."\n";
361
  }
 
362
  }
363
 
364
  if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty($frm_vars['forms_loaded']) ) {
142
  return;
143
  }
144
 
145
+ wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.3.2');
146
 
147
  if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
148
  ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
162
  add_thickbox();
163
 
164
  wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
 
165
 
166
  if ( FrmAppHelper::is_admin_page('formidable-settings') || FrmAppHelper::is_admin_page('formidable-styles') ) {
167
  // load multselect js
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');
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);
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' ),
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']) ) {
classes/controllers/FrmEntriesController.php CHANGED
@@ -244,10 +244,11 @@ class FrmEntriesController{
244
  return $result;
245
 
246
  global $frm_vars;
247
- if(isset($frm_vars['current_form']) and $frm_vars['current_form'])
248
  $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
 
249
 
250
- if(isset($frm_vars['current_form']) and $frm_vars['current_form'] and isset($frm_vars['current_form']->options['hidden_cols']) and !empty($frm_vars['current_form']->options['hidden_cols'])){
251
  $result = $frm_vars['current_form']->options['hidden_cols'];
252
  }else{
253
  $cols = $frm_vars['cols'];
@@ -263,8 +264,7 @@ class FrmEntriesController{
263
  if($i > $max_columns)
264
  $result[] = $col_key; //remove some columns by default
265
  $i--;
266
- unset($col_key);
267
- unset($col);
268
  }
269
  }
270
 
@@ -634,4 +634,12 @@ class FrmEntriesController{
634
  return $values;
635
  }
636
 
 
 
 
 
 
 
 
 
637
  }
244
  return $result;
245
 
246
  global $frm_vars;
247
+ if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
248
  $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
249
+ }
250
 
251
+ 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']) ) {
252
  $result = $frm_vars['current_form']->options['hidden_cols'];
253
  }else{
254
  $cols = $frm_vars['cols'];
264
  if($i > $max_columns)
265
  $result[] = $col_key; //remove some columns by default
266
  $i--;
267
+ unset($col_key, $col);
 
268
  }
269
  }
270
 
634
  return $values;
635
  }
636
 
637
+ public static function entry_sidebar($entry) {
638
+ $data = maybe_unserialize($entry->description);
639
+ $date_format = get_option('date_format');
640
+ $time_format = get_option('time_format');
641
+
642
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php');
643
+ }
644
+
645
  }
classes/controllers/FrmFieldsController.php CHANGED
@@ -19,6 +19,10 @@ class FrmFieldsController{
19
  foreach ( $fields as $field ) {
20
  $field = htmlspecialchars_decode(nl2br($field));
21
  $field = json_decode($field, true);
 
 
 
 
22
 
23
  $field_id = $field['id'];
24
 
@@ -290,21 +294,20 @@ class FrmFieldsController{
290
  $response = array( 'other' => true );
291
 
292
  //If the deleted option is an "other" option
293
- if ( strpos( $opt_key, 'other' ) !== false ) {
294
  //Assume all other options are gone, unless proven otherwise
295
  $other = false;
296
 
297
- //Check if all other options are really gone in CB field
298
- if ( $field->type == 'checkbox' ) {
299
- foreach ( $options as $o_key => $o_val ) {
300
- //If there is still an other option in the field, set other to true
301
- if ( $o_key && strpos( $o_key, 'other' ) !== false ) {
302
- $other = true;
303
- break;
304
- }
305
- unset( $o_key, $o_val );
306
  }
 
307
  }
 
308
  //If all other options are gone
309
  if ( false === $other ) {
310
  $field_options = maybe_unserialize( $field->field_options );
@@ -424,8 +427,7 @@ class FrmFieldsController{
424
  }
425
  unset($vals);
426
  }
427
- unset($opt_key);
428
- unset($opt);
429
  }
430
  }
431
 
@@ -436,9 +438,9 @@ class FrmFieldsController{
436
  if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
437
  $other_array[$opt_key] = $opt;
438
  }
439
- unset($opt_key,$opt);
440
  }
441
- if ( $other_array ) {
442
  $opts = array_merge( $opts, $other_array);
443
  }
444
  }
19
  foreach ( $fields as $field ) {
20
  $field = htmlspecialchars_decode(nl2br($field));
21
  $field = json_decode($field, true);
22
+ if ( ! isset($field['id']) ) {
23
+ // this field may have already been loaded
24
+ continue;
25
+ }
26
 
27
  $field_id = $field['id'];
28
 
294
  $response = array( 'other' => true );
295
 
296
  //If the deleted option is an "other" option
297
+ if ( FrmAppHelper::is_other_opt( $opt_key ) ) {
298
  //Assume all other options are gone, unless proven otherwise
299
  $other = false;
300
 
301
+ //Check if all other options are really gone
302
+ foreach ( $options as $o_key => $o_val ) {
303
+ //If there is still an other option in the field, set other to true
304
+ if ( FrmAppHelper::is_other_opt( $o_key ) ) {
305
+ $other = true;
306
+ break;
 
 
 
307
  }
308
+ unset( $o_key, $o_val );
309
  }
310
+
311
  //If all other options are gone
312
  if ( false === $other ) {
313
  $field_options = maybe_unserialize( $field->field_options );
427
  }
428
  unset($vals);
429
  }
430
+ unset($opt_key, $opt);
 
431
  }
432
  }
433
 
438
  if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
439
  $other_array[$opt_key] = $opt;
440
  }
441
+ unset($opt_key, $opt);
442
  }
443
+ if ( ! empty($other_array) ) {
444
  $opts = array_merge( $opts, $other_array);
445
  }
446
  }
classes/controllers/FrmFormActionsController.php CHANGED
@@ -26,10 +26,13 @@ class FrmFormActionsController{
26
  * menu_order: form id
27
  * post_excerpt: action type
28
  */
 
 
29
  }
30
 
31
  public static function actions_init() {
32
  self::$registered_actions = new Frm_Form_Action_Factory();
 
33
  do_action( 'frm_form_actions_init' );
34
  }
35
 
@@ -189,7 +192,7 @@ class FrmFormActionsController{
189
 
190
  $registered_actions = self::$registered_actions->actions;
191
 
192
- $old_actions = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE menu_order=%d", $form_id));
193
  $new_actions = array();
194
 
195
  foreach ( $registered_actions as $registered_action ) {
@@ -217,6 +220,9 @@ class FrmFormActionsController{
217
  self::trigger_actions('create', $form_id, $entry_id);
218
  }
219
 
 
 
 
220
  public static function trigger_actions($event, $form, $entry, $type = 'all') {
221
  $form_actions = FrmFormActionsHelper::get_action_for_form((is_object($form) ? $form->id : $form), $type);
222
 
@@ -291,7 +297,7 @@ class FrmFormActionsController{
291
  return;
292
  }
293
 
294
- $action_controls = FrmFormActionsController::get_form_actions( );
295
 
296
  foreach ( $action_controls as $action_control ) {
297
  $action_control->duplicate_form_actions($form_id, $args['old_id']);
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
 
192
 
193
  $registered_actions = self::$registered_actions->actions;
194
 
195
+ $old_actions = $wpdb->get_col($wpdb->prepare('SELECT ID FROM '. $wpdb->posts .' WHERE post_type=%s AND menu_order=%d', self::$action_post_type, $form_id));
196
  $new_actions = array();
197
 
198
  foreach ( $registered_actions as $registered_action ) {
220
  self::trigger_actions('create', $form_id, $entry_id);
221
  }
222
 
223
+ /**
224
+ * @param string $event
225
+ */
226
  public static function trigger_actions($event, $form, $entry, $type = 'all') {
227
  $form_actions = FrmFormActionsHelper::get_action_for_form((is_object($form) ? $form->id : $form), $type);
228
 
297
  return;
298
  }
299
 
300
+ $action_controls = self::get_form_actions( );
301
 
302
  foreach ( $action_controls as $action_control ) {
303
  $action_control->duplicate_form_actions($form_id, $args['old_id']);
classes/controllers/FrmFormsController.php CHANGED
@@ -27,7 +27,6 @@ class FrmFormsController{
27
 
28
  public static function head(){
29
  wp_enqueue_script('formidable-editinplace');
30
- wp_enqueue_script('jquery-frm-themepicker');
31
 
32
  if ( wp_is_mobile() ) {
33
  wp_enqueue_script( 'jquery-touch-punch' );
@@ -43,7 +42,9 @@ class FrmFormsController{
43
  FrmAppHelper::permission_check('frm_view_forms');
44
 
45
  $params = FrmFormsHelper::get_params();
46
- $errors = apply_filters('frm_admin_list_form_action', array());
 
 
47
  return self::display_forms_list($params, '', false, $errors);
48
  }
49
 
@@ -84,7 +85,9 @@ class FrmFormsController{
84
  }
85
 
86
  //Set radio button and checkbox meta equal to "other" value
87
- $values = FrmEntriesHelper::set_other_vals( $values, true );
 
 
88
 
89
  $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
90
 
@@ -106,8 +109,6 @@ class FrmFormsController{
106
  }else{
107
  FrmForm::update( $id, $values, true );
108
  die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
109
- //$message = __('Form was Successfully Created', 'formidable');
110
- //return self::settings($record, $message);
111
  }
112
  }
113
 
@@ -121,8 +122,9 @@ class FrmFormsController{
121
  public static function settings($id=false, $message=''){
122
  FrmAppHelper::permission_check('frm_edit_forms');
123
 
124
- if(!$id or !is_numeric($id))
125
- $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
 
126
  return self::get_settings_vars($id, '', $message);
127
  }
128
 
@@ -145,7 +147,7 @@ class FrmFormsController{
145
  }
146
 
147
  public static function edit_key(){
148
- FrmAppHelper::ajax_permission_check('frm_edit_forms');
149
 
150
  global $wpdb;
151
  $values = array('form_key' => trim($_POST['update_value']));
@@ -157,7 +159,7 @@ class FrmFormsController{
157
  }
158
 
159
  public static function edit_description(){
160
- FrmAppHelper::ajax_permission_check('frm_edit_forms');
161
 
162
  FrmForm::update($_POST['form_id'], array('description' => $_POST['update_value']));
163
  $description = FrmAppHelper::use_wpautop(stripslashes($_POST['update_value']));
@@ -173,13 +175,14 @@ class FrmFormsController{
173
  }
174
 
175
  //Set radio button and checkbox meta equal to "other" value
176
- $values = FrmEntriesHelper::set_other_vals( $values, true );
 
 
177
 
178
  $errors = FrmForm::validate($values);
179
-
180
- if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce')) ) ) {
181
- $frm_settings = FrmAppHelper::get_settings();
182
- $errors['form'] = $frm_settings->admin_permission;
183
  }
184
 
185
  $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
@@ -252,7 +255,9 @@ class FrmFormsController{
252
  $controller = FrmAppHelper::get_param('controller');
253
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
254
  $form = FrmForm::getAll(array('form_key' => $key), '', 1);
255
- if (!$form) $form = FrmForm::getAll('', '', 1);
 
 
256
 
257
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
258
  die();
@@ -325,8 +330,25 @@ class FrmFormsController{
325
  return $message;
326
  }
327
 
328
- // Delete trashed forms
329
- public static function scheduled_delete() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  global $wpdb;
331
 
332
  $trash_forms = $wpdb->get_results($wpdb->prepare("SELECT id, options FROM {$wpdb->prefix}frm_forms WHERE status = %s", 'trash'));
@@ -335,17 +357,21 @@ class FrmFormsController{
335
  return;
336
  }
337
 
338
- $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
 
 
339
 
 
340
  foreach ( $trash_forms as $form ) {
341
  $form->options = maybe_unserialize($form->options);
342
  if ( !isset($form->options['trash_time']) || $form->options['trash_time'] < $delete_timestamp ) {
343
  FrmForm::destroy($form->id);
 
344
  }
345
 
346
  unset($form);
347
  }
348
-
349
  }
350
 
351
  public static function insert_form_button($content){
@@ -379,9 +405,6 @@ class FrmFormsController{
379
 
380
  $form_id = '';
381
  $opts = array();
382
-
383
- echo '<div id="sc-opts-'. $shortcode .'" class="frm_shortcode_option">';
384
- echo '<input type="radio" name="frmsc" value="'. esc_attr($shortcode) .'" id="sc-'. esc_attr($shortcode) .'" style="display:none;" />';
385
  switch( $shortcode ) {
386
  case 'formidable':
387
  $form_id = 'id';
@@ -393,48 +416,9 @@ class FrmFormsController{
393
  );
394
  break;
395
  }
396
-
397
  $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
398
 
399
- if ( ! empty($form_id) ) {
400
- ?>
401
- <h4 for="frmsc_<?php echo $shortcode .'_'. $form_id ?>" class="frm_left_label"><?php _e('Select a form:', 'formidable') ?></h4>
402
- <?php FrmFormsHelper::forms_dropdown( 'frmsc_'. $shortcode .'_'. $form_id ); ?>
403
- <div class="frm_box_line"></div>
404
- <?php
405
- }
406
-
407
- if ( ! empty($opts) ) { ?>
408
- <h4><?php _e('Options', 'formidable') ?></h4>
409
- <ul>
410
- <?php
411
- foreach ( $opts as $opt => $val ) {
412
- if ( isset($val['type']) && 'text' == $val['type'] ) { ?>
413
- <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>">
414
- <span><?php echo $val['label'] ?></span>
415
- <input type="text" id="frmsc_<?php echo $shortcode .'_'. $opt ?>" value="<?php echo esc_attr($val['val']) ?>" />
416
- </label>
417
- <li>
418
- <?php } else if ( isset($val['type']) && 'select' == $val['type'] ) { ?>
419
- <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>">
420
- <span><?php echo $val['label'] ?></span>
421
- <select id="frmsc_<?php echo $shortcode .'_'. $opt ?>">
422
- <?php foreach ( $val['opts'] as $select_opt => $select_label ) { ?>
423
- <option value="<?php echo esc_attr($select_opt) ?>"><?php echo $select_label ?></option>
424
- <?php } ?>
425
- </select>
426
- </label>
427
- </li>
428
- <?php } else { ?>
429
- <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>"><input type="checkbox" id="frmsc_<?php echo $shortcode .'_'. $opt ?>" value="<?php echo esc_attr($val['val']) ?>" /> <?php echo $val['label'] ?></label><li>
430
- <?php
431
- }
432
- }
433
- ?>
434
- </ul>
435
- <?php
436
- }
437
- echo '</div>';
438
 
439
  die();
440
  }
@@ -680,9 +664,9 @@ class FrmFormsController{
680
  return $errors;
681
  }
682
 
683
- if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-toplevel_page_formidable' ) ) {
684
- $frm_settings = FrmAppHelper::get_settings();
685
- $errors[] = $frm_settings->admin_permission;
686
  return $errors;
687
  }
688
 
@@ -733,12 +717,14 @@ class FrmFormsController{
733
  $values['form_key'] = $filename;
734
  $values['is_template'] = $template;
735
  $values['status'] = 'published';
736
- if($default) $values['default_template'] = 1;
 
 
737
 
738
  include($templates[$i]);
739
 
740
  //get updated form
741
- if ( isset($form) && $form ) {
742
  $old_id = $form->id;
743
  $form = FrmForm::getOne($form->id);
744
  } else {
@@ -776,6 +762,10 @@ class FrmFormsController{
776
  }
777
  }else{
778
  $action = FrmAppHelper::get_param($action);
 
 
 
 
779
  }
780
 
781
  add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
@@ -792,6 +782,7 @@ class FrmFormsController{
792
  case 'trash':
793
  case 'untrash':
794
  case 'destroy':
 
795
  case 'settings':
796
  case 'update_settings':
797
  return self::$action($vars);
27
 
28
  public static function head(){
29
  wp_enqueue_script('formidable-editinplace');
 
30
 
31
  if ( wp_is_mobile() ) {
32
  wp_enqueue_script( 'jquery-touch-punch' );
42
  FrmAppHelper::permission_check('frm_view_forms');
43
 
44
  $params = FrmFormsHelper::get_params();
45
+ $errors = self::process_bulk_form_actions(array());
46
+ $errors = apply_filters('frm_admin_list_form_action', $errors);
47
+
48
  return self::display_forms_list($params, '', false, $errors);
49
  }
50
 
85
  }
86
 
87
  //Set radio button and checkbox meta equal to "other" value
88
+ if ( FrmAppHelper::pro_is_installed() ) {
89
+ $values = FrmProEntry::mod_other_vals( $values, 'back' );
90
+ }
91
 
92
  $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
93
 
109
  }else{
110
  FrmForm::update( $id, $values, true );
111
  die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
 
 
112
  }
113
  }
114
 
122
  public static function settings($id=false, $message=''){
123
  FrmAppHelper::permission_check('frm_edit_forms');
124
 
125
+ if ( ! $id || ! is_numeric($id) ) {
126
+ $id = (int) FrmAppHelper::get_param('id');
127
+ }
128
  return self::get_settings_vars($id, '', $message);
129
  }
130
 
147
  }
148
 
149
  public static function edit_key(){
150
+ FrmAppHelper::permission_check('frm_edit_forms', 'hide');
151
 
152
  global $wpdb;
153
  $values = array('form_key' => trim($_POST['update_value']));
159
  }
160
 
161
  public static function edit_description(){
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']));
175
  }
176
 
177
  //Set radio button and checkbox meta equal to "other" value
178
+ if ( FrmAppHelper::pro_is_installed() ) {
179
+ $values = FrmProEntry::mod_other_vals( $values, 'back' );
180
+ }
181
 
182
  $errors = FrmForm::validate($values);
183
+ $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce');
184
+ if ( $permission_error !== false ) {
185
+ $errors['form'] = $permission_error;
 
186
  }
187
 
188
  $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
255
  $controller = FrmAppHelper::get_param('controller');
256
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
257
  $form = FrmForm::getAll(array('form_key' => $key), '', 1);
258
+ if ( empty($form) ) {
259
+ $form = FrmForm::getAll('', '', 1);
260
+ }
261
 
262
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
263
  die();
330
  return $message;
331
  }
332
 
333
+ private static function delete_all() {
334
+ //check nonce url
335
+ $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
336
+ if ( $permission_error !== false ) {
337
+ self::display_forms_list('', '', 1, array($permission_error));
338
+ return;
339
+ }
340
+
341
+ $count = self::scheduled_delete(time());
342
+ $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
343
+
344
+ self::display_forms_list('', $message, 1);
345
+ }
346
+
347
+ /*
348
+ * Delete trashed forms based on how long they have been trashed
349
+ * @return int The number of forms deleted
350
+ */
351
+ public static function scheduled_delete($delete_timestamp = '') {
352
  global $wpdb;
353
 
354
  $trash_forms = $wpdb->get_results($wpdb->prepare("SELECT id, options FROM {$wpdb->prefix}frm_forms WHERE status = %s", 'trash'));
357
  return;
358
  }
359
 
360
+ if ( empty($delete_timestamp) ) {
361
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
362
+ }
363
 
364
+ $count = 0;
365
  foreach ( $trash_forms as $form ) {
366
  $form->options = maybe_unserialize($form->options);
367
  if ( !isset($form->options['trash_time']) || $form->options['trash_time'] < $delete_timestamp ) {
368
  FrmForm::destroy($form->id);
369
+ $count++;
370
  }
371
 
372
  unset($form);
373
  }
374
+ return $count;
375
  }
376
 
377
  public static function insert_form_button($content){
405
 
406
  $form_id = '';
407
  $opts = array();
 
 
 
408
  switch( $shortcode ) {
409
  case 'formidable':
410
  $form_id = 'id';
416
  );
417
  break;
418
  }
 
419
  $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
420
 
421
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/shortcode_opts.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
 
423
  die();
424
  }
664
  return $errors;
665
  }
666
 
667
+ $permission_error = FrmAppHelper::permission_nonce_error('', '_wpnonce', 'bulk-toplevel_page_formidable');
668
+ if ( $permission_error !== false ) {
669
+ $errors[] = $permission_error;
670
  return $errors;
671
  }
672
 
717
  $values['form_key'] = $filename;
718
  $values['is_template'] = $template;
719
  $values['status'] = 'published';
720
+ if ( $default ) {
721
+ $values['default_template'] = 1;
722
+ }
723
 
724
  include($templates[$i]);
725
 
726
  //get updated form
727
+ if ( isset($form) && ! empty($form) ) {
728
  $old_id = $form->id;
729
  $form = FrmForm::getOne($form->id);
730
  } else {
762
  }
763
  }else{
764
  $action = FrmAppHelper::get_param($action);
765
+ if ( isset( $_REQUEST['delete_all'] ) ) {
766
+ // override the action for this page
767
+ $action = 'delete_all';
768
+ }
769
  }
770
 
771
  add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
782
  case 'trash':
783
  case 'untrash':
784
  case 'destroy':
785
+ case 'delete_all':
786
  case 'settings':
787
  case 'update_settings':
788
  return self::$action($vars);
classes/controllers/FrmHooksController.php CHANGED
@@ -48,12 +48,12 @@ class FrmHooksController{
48
  add_action('plugins_loaded', 'FrmAppController::load_lang' );
49
  add_action('init', 'FrmAppController::front_head' );
50
  add_filter('widget_text', 'FrmAppController::widget_text_filter', 8 );
51
- add_filter('get_frm_stylesheet', 'FrmAppController::custom_stylesheet' );
52
-
53
  add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
54
 
55
- // Update the session data
56
- add_action('init', 'FrmAppController::referer_session', 1);
 
 
57
 
58
  // Entries controller
59
  add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
@@ -64,9 +64,7 @@ class FrmHooksController{
64
  add_filter('frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4);
65
 
66
  // Form Actions Controller
67
- add_action('init', 'FrmFormActionsController::register_post_types', 0);
68
- add_action('init', 'FrmFormActionsController::actions_init', 1);
69
- add_action('frm_form_actions_init', 'FrmFormActionsController::register_actions');
70
  add_action('frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 2);
71
 
72
  // Forms Controller
@@ -120,8 +118,6 @@ class FrmHooksController{
120
  add_action('admin_footer', 'FrmFormsController::insert_form_popup' );
121
  add_filter('media_buttons_context', 'FrmFormsController::insert_form_button' );
122
 
123
- add_filter('frm_admin_list_form_action', 'FrmFormsController::process_bulk_form_actions' );
124
-
125
  // Forms Model
126
  add_action('frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2);
127
 
48
  add_action('plugins_loaded', 'FrmAppController::load_lang' );
49
  add_action('init', 'FrmAppController::front_head' );
50
  add_filter('widget_text', 'FrmAppController::widget_text_filter', 8 );
 
 
51
  add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
52
 
53
+ if ( ! FrmAppHelper::is_admin() ) {
54
+ // Update the session data
55
+ add_action('init', 'FrmAppController::referer_session', 1);
56
+ }
57
 
58
  // Entries controller
59
  add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
64
  add_filter('frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4);
65
 
66
  // Form Actions Controller
67
+ add_action('init', 'FrmFormActionsController::register_post_types', 1);
 
 
68
  add_action('frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 2);
69
 
70
  // Forms Controller
118
  add_action('admin_footer', 'FrmFormsController::insert_form_popup' );
119
  add_filter('media_buttons_context', 'FrmFormsController::insert_form_button' );
120
 
 
 
121
  // Forms Model
122
  add_action('frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2);
123
 
classes/controllers/FrmSettingsController.php CHANGED
@@ -31,17 +31,18 @@ class FrmSettingsController{
31
 
32
  $frm_settings = FrmAppHelper::get_settings();
33
 
34
- if(!isset($_POST['process_form']) or !wp_verify_nonce($_POST['process_form'], 'process_form_nonce'))
35
  wp_die($frm_settings->admin_permission);
 
36
 
37
  $errors = array();
38
  $message = '';
39
 
40
- if(!isset($frm_vars['settings_routed']) or !$frm_vars['settings_routed']){
41
  //$errors = $frm_settings->validate($_POST,array());
42
  $frm_settings->update(stripslashes_deep($_POST));
43
 
44
- if( empty($errors) ){
45
  $frm_settings->store();
46
  $message = __('Settings Saved', 'formidable');
47
  }
@@ -60,9 +61,10 @@ class FrmSettingsController{
60
  public static function route($stop_load=false){
61
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
62
  $action = FrmAppHelper::get_param($action);
63
- if($action == 'process-form')
64
  return self::process_form($stop_load);
65
- else if($stop_load != 'stop_load')
66
  return self::display_form();
 
67
  }
68
  }
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
  }
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
  }
classes/controllers/FrmStylesController.php CHANGED
@@ -42,20 +42,17 @@ class FrmStylesController{
42
 
43
  self::load_pro_hooks();
44
  wp_enqueue_script('jquery-ui-datepicker');
45
- add_action('admin_head', 'FrmStylesController::head');
46
- }
47
 
48
- public static function head() {
49
- wp_enqueue_script('jquery-frm-themepicker');
 
 
 
50
 
51
  $style = apply_filters('frm_style_head', false);
52
- ?>
53
- <link type="text/css" rel="stylesheet" href="<?php echo FrmAppHelper::jquery_ui_base_url() ?>/themes/base/ui.all.css" />
54
- <link href="<?php echo admin_url('admin-ajax.php') ?>?action=frmpro_css" type="text/css" rel="Stylesheet" class="frm-custom-theme"/>
55
- <?php if ($style) { ?>
56
- <link href="<?php echo admin_url('admin-ajax.php') ?>?action=frmpro_load_css&flat=1&<?php echo http_build_query($style->post_content); ?>" type="text/css" rel="Stylesheet" class="frm-single-custom-theme"/>
57
- <?php }
58
- require(FrmAppHelper::plugin_path() .'/classes/views/shared/head.php');
59
  }
60
 
61
  public static function new_style($return = '') {
@@ -92,6 +89,8 @@ class FrmStylesController{
92
  // set the post id to the new style so it will be loaded for editing
93
  $post_id = reset($id);
94
  }
 
 
95
  $message = __('Your styling settings have been saved.', 'formidable');
96
  }
97
 
@@ -265,6 +264,26 @@ class FrmStylesController{
265
  die();
266
  }
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  // Get the stylesheets for the form settings page
269
  public static function get_style_opts() {
270
  $frm_style = new FrmStyle();
@@ -284,6 +303,10 @@ class FrmStylesController{
284
  return $frm_style->get_one();
285
  }
286
 
 
 
 
 
287
  public static function get_form_style_class($class, $style) {
288
  if ( 1 == $style ) {
289
  $style = 'default';
@@ -299,6 +322,9 @@ class FrmStylesController{
299
  return $class;
300
  }
301
 
 
 
 
302
  public static function get_style_val($val, $form = 'default') {
303
  $style = self::get_form_style($form);
304
  if ( $style && isset($style->post_content[$val]) ) {
42
 
43
  self::load_pro_hooks();
44
  wp_enqueue_script('jquery-ui-datepicker');
 
 
45
 
46
+ $version = FrmAppHelper::plugin_version();
47
+ wp_enqueue_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
48
+
49
+ wp_enqueue_style('jquery-ui-base', FrmAppHelper::jquery_ui_base_url() .'/themes/base/ui.all.css');
50
+ wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css');
51
 
52
  $style = apply_filters('frm_style_head', false);
53
+ if ( $style ) {
54
+ wp_enqueue_style('frm-single-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_load_css&flat=1&'. http_build_query($style->post_content));
55
+ }
 
 
 
 
56
  }
57
 
58
  public static function new_style($return = '') {
89
  // set the post id to the new style so it will be loaded for editing
90
  $post_id = reset($id);
91
  }
92
+ // include the CSS that includes this style
93
+ echo '<link href="'. admin_url('admin-ajax.php') .'?action=frmpro_css" type="text/css" rel="Stylesheet" class="frm-custom-theme" />';
94
  $message = __('Your styling settings have been saved.', 'formidable');
95
  }
96
 
264
  die();
265
  }
266
 
267
+ /*
268
+ * Check if the Formidable styling should be loaded,
269
+ * then enqueue it for the footer
270
+ * @since 2.0
271
+ */
272
+ public static function enqueue_style() {
273
+ global $frm_vars;
274
+
275
+ if ( isset($frm_vars['css_loaded']) && $frm_vars['css_loaded'] ) {
276
+ // the CSS has already been loaded
277
+ return;
278
+ }
279
+
280
+ $frm_settings = FrmAppHelper::get_settings();
281
+ if ( $frm_settings->load_style != 'none' ) {
282
+ wp_enqueue_style('formidable');
283
+ $frm_vars['css_loaded'] = true;
284
+ }
285
+ }
286
+
287
  // Get the stylesheets for the form settings page
288
  public static function get_style_opts() {
289
  $frm_style = new FrmStyle();
303
  return $frm_style->get_one();
304
  }
305
 
306
+ /**
307
+ * @param string $class
308
+ * @param string $style
309
+ */
310
  public static function get_form_style_class($class, $style) {
311
  if ( 1 == $style ) {
312
  $style = 'default';
322
  return $class;
323
  }
324
 
325
+ /**
326
+ * @param string $val
327
+ */
328
  public static function get_style_val($val, $form = 'default') {
329
  $style = self::get_form_style($form);
330
  if ( $style && isset($style->post_content[$val]) ) {
classes/controllers/FrmXMLController.php CHANGED
@@ -73,9 +73,9 @@ class FrmXMLController{
73
  $errors = array();
74
  $message = '';
75
 
76
- if ( !current_user_can('frm_edit_forms') || ! isset($_POST['import-xml']) || ! wp_verify_nonce($_POST['import-xml'], 'import-xml-nonce') ) {
77
- $frm_settings = FrmAppHelper::get_settings();
78
- $errors[] = $frm_settings->admin_permission;
79
  self::form($errors);
80
  return;
81
  }
@@ -137,7 +137,7 @@ class FrmXMLController{
137
  }
138
 
139
  public static function export_xml() {
140
- FrmAppHelper::ajax_permission_check('frm_edit_forms', 'show');
141
 
142
  $ids = array();
143
  if ( isset($_POST['frm_export_forms']) ) {
@@ -275,7 +275,7 @@ class FrmXMLController{
275
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
276
  }
277
 
278
- function allow_mime($mimes) {
279
  if ( !isset($mimes['csv']) ) {
280
  // allow csv files
281
  $mimes['csv'] = 'text/csv';
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
  }
137
  }
138
 
139
  public static function export_xml() {
140
+ FrmAppHelper::permission_check('frm_edit_forms', 'show');
141
 
142
  $ids = array();
143
  if ( isset($_POST['frm_export_forms']) ) {
275
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
276
  }
277
 
278
+ public static function allow_mime($mimes) {
279
  if ( !isset($mimes['csv']) ) {
280
  // allow csv files
281
  $mimes['csv'] = 'text/csv';
classes/helpers/FrmAppHelper.php CHANGED
@@ -2,13 +2,13 @@
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
  class FrmAppHelper{
5
- public static $db_version = 17; //version of the database we are moving to
6
  public static $pro_db_version = 27;
7
 
8
  /*
9
  * @since 2.0
10
  */
11
- public static $plug_version = '2.0b7';
12
 
13
  /*
14
  * @since 1.07.02
@@ -83,7 +83,7 @@ class FrmAppHelper{
83
  */
84
  public static function update_message($features, $class = ''){
85
  if ( ! self::pro_is_installed() ) {
86
- include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
87
  }
88
  }
89
 
@@ -226,6 +226,10 @@ class FrmAppHelper{
226
  /*
227
  * @since 2.0
228
  */
 
 
 
 
229
  public static function simple_get($action) {
230
  if ( $_GET && isset($_GET[$action]) ) {
231
  return $_GET[$action];
@@ -271,6 +275,9 @@ class FrmAppHelper{
271
  return $value;
272
  }
273
 
 
 
 
274
  public static function trigger_hook_load( $type, $object = null ) {
275
  // only load the form hooks once
276
  $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object);
@@ -333,6 +340,10 @@ class FrmAppHelper{
333
  /*
334
  * @since 2.0
335
  */
 
 
 
 
336
  public static function delete_cache_and_transient($cache_key) {
337
  delete_transient($cache_key);
338
  wp_cache_delete($cache_key);
@@ -414,7 +425,7 @@ class FrmAppHelper{
414
  public static function post_edit_link($post_id) {
415
  $post = get_post($post_id);
416
  if ( $post ) {
417
- return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. FrmAppHelper::truncate($post->post_title, 50) .'</a>';
418
  }
419
  return '';
420
  }
@@ -474,8 +485,10 @@ class FrmAppHelper{
474
  if($needed_role == '-1')
475
  return false;
476
 
477
- if($needed_role == '' or current_user_can($needed_role))
 
478
  return true;
 
479
 
480
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
481
  foreach ($roles as $role){
@@ -511,31 +524,41 @@ class FrmAppHelper{
511
  * Return permission message and stop the action if no permission
512
  * @since 2.0
513
  */
514
- public static function permission_check($permission) {
515
- if ( ! current_user_can($permission) ) {
516
- $frm_settings = self::get_settings();
517
- wp_die($frm_settings->admin_permission);
 
 
 
 
 
 
 
518
  }
519
  }
520
 
521
  /*
522
- * Check if the user has permision for action.
523
- * Return permission message and stop the action if no permission
524
  * @since 2.0
 
525
  */
526
- public static function ajax_permission_check($permission, $show_message = 'hide') {
527
- if ( current_user_can($permission) ) {
528
- return;
 
529
  }
530
 
531
- if ( 'hide' == $show_message ) {
532
- $message = '';
533
- } else {
 
 
534
  $frm_settings = self::get_settings();
535
- $message = $frm_settings->admin_permission;
536
  }
537
 
538
- die($message);
539
  }
540
 
541
  public static function checked($values, $current){
@@ -559,44 +582,145 @@ class FrmAppHelper{
559
  $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
560
  */
561
 
562
- if ( ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current ) ) {
563
- return true;
564
- } else {
565
- return false;
566
- }
567
  }
568
 
569
- /*
570
- * Check if value is equal to any of the field options. If not, set it as the other_val.
571
- * @return string
 
 
 
 
572
  */
573
- public static function check_other_selected( $value, $field_options, $field_type, $opt_key = '' ){
574
- if ( !$value ) {
575
- return;
576
- }
577
 
 
 
 
 
 
 
 
 
 
 
578
  $other_val = '';
579
- if ( $field_type == 'radio' ) {
580
- //Check if field value equals any of the options. If not, set it as the other value.
581
- foreach ( $field_options as $opt_key => $opt_val ) {
582
- if ( is_array( $opt_val ) ) {
583
- if ( $opt_val['value'] == $value ) {
584
- return '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
  }
586
- } else if ( $opt_val == $value ) {
 
 
587
  return '';
588
  } else {
589
- $other_val = $value;
590
  }
591
- unset($opt_key, $opt_val);
 
 
 
 
592
  }
593
- } else if ( array_key_exists ( $opt_key , (array) $value ) && $value[$opt_key] ) {
594
- $other_val = $value[$opt_key];
595
  }
596
-
597
  return $other_val;
598
  }
599
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  public static function recursive_trim(&$value) {
601
  if ( is_array($value) ) {
602
  $value = array_map(array('FrmAppHelper', 'recursive_trim'), $value);
@@ -642,6 +766,9 @@ class FrmAppHelper{
642
  return $url;
643
  }
644
 
 
 
 
645
  public static function script_version($handle) {
646
  global $wp_scripts;
647
  if ( ! $wp_scripts ) {
@@ -703,6 +830,10 @@ class FrmAppHelper{
703
  return $contents;
704
  }
705
 
 
 
 
 
706
  public static function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
707
  global $wpdb;
708
 
@@ -718,13 +849,14 @@ class FrmAppHelper{
718
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
719
  }
720
 
721
- if (is_numeric($key) or in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
722
  $key = $key .'a';
 
723
 
724
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
725
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
726
 
727
- if ($key_check or is_numeric($key_check)){
728
  $suffix = 2;
729
  do {
730
  $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
@@ -740,6 +872,10 @@ class FrmAppHelper{
740
  * Editing a Form or Entry
741
  * @return bool|array
742
  */
 
 
 
 
743
  public static function setup_edit_vars($record, $table, $fields='', $default=false, $post_values=array()){
744
  if ( ! $record ) {
745
  return false;
@@ -761,10 +897,13 @@ class FrmAppHelper{
761
 
762
  $values['description'] = self::use_wpautop($values['description']);
763
  $frm_settings = self::get_settings();
 
764
 
765
  foreach ( (array) $fields as $field ) {
766
- // Make sure to filter default values (for placeholder text)
767
- $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
 
 
768
  self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
769
  }
770
 
@@ -928,6 +1067,9 @@ class FrmAppHelper{
928
  }
929
  }
930
 
 
 
 
931
  public static function get_meta_value($field_id, $entry) {
932
  if ( isset($entry->metas) ) {
933
  return isset($entry->metas[$field_id]) ? $entry->metas[$field_id] : false;
@@ -1206,6 +1348,9 @@ class FrmAppHelper{
1206
  return $term;
1207
  }
1208
 
 
 
 
1209
  public static function esc_order($order_query) {
1210
  if ( empty($order_query) ) {
1211
  return '';
@@ -1242,6 +1387,9 @@ class FrmAppHelper{
1242
  return ' ORDER BY '. $order . ' '. $order_by;
1243
  }
1244
 
 
 
 
1245
  public static function esc_limit($limit) {
1246
  if ( empty($limit) ) {
1247
  return '';
@@ -1303,6 +1451,9 @@ class FrmAppHelper{
1303
  return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
1304
  }
1305
 
 
 
 
1306
  public static function getFirstRecordNum($r_count,$current_p,$p_size){
1307
  if($current_p == 1)
1308
  return 1;
@@ -1310,6 +1461,9 @@ class FrmAppHelper{
1310
  return (self::getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
1311
  }
1312
 
 
 
 
1313
  public static function &getRecordCount($where = '', $table_name) {
1314
  $cache_key = 'count_'. $table_name .'_'. maybe_serialize($where);
1315
  $query = 'SELECT COUNT(*) FROM ' . $table_name . self::prepend_and_or_where(' WHERE ', $where);
@@ -1341,12 +1495,13 @@ class FrmAppHelper{
1341
  $referrerinfo = '';
1342
  $keywords = array();
1343
  $i = 1;
1344
- if(isset($_SESSION) and isset($_SESSION['frm_http_referer']) and $_SESSION['frm_http_referer']){
1345
  foreach ($_SESSION['frm_http_referer'] as $referer) {
1346
  $referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
1347
  $keywords_used = self::get_referer_query($referer);
1348
- if ($keywords_used)
1349
  $keywords[] = $keywords_used;
 
1350
 
1351
  $i++;
1352
  }
@@ -1357,8 +1512,8 @@ class FrmAppHelper{
1357
  }
1358
 
1359
  $i = 1;
1360
- if(isset($_SESSION) and isset($_SESSION['frm_http_pages']) and $_SESSION['frm_http_pages']){
1361
- foreach ($_SESSION['frm_http_pages'] as $page) {
1362
  $referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
1363
  $i++;
1364
  }
@@ -1391,6 +1546,10 @@ class FrmAppHelper{
1391
  $l2 = $name;
1392
  }
1393
 
 
 
 
 
1394
  $this_val = ( $p == $last ) ? $jv['value'] : array();
1395
 
1396
  switch ( $p ) {
@@ -1420,6 +1579,15 @@ class FrmAppHelper{
1420
  $vars[$l1][$l2][$l3] = $this_val;
1421
  }
1422
  break;
 
 
 
 
 
 
 
 
 
1423
  }
1424
 
1425
  unset($this_val, $n);
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
  class FrmAppHelper{
5
+ public static $db_version = 18; //version of the database we are moving to
6
  public static $pro_db_version = 27;
7
 
8
  /*
9
  * @since 2.0
10
  */
11
+ public static $plug_version = '2.0rc1';
12
 
13
  /*
14
  * @since 1.07.02
83
  */
84
  public static function update_message($features, $class = ''){
85
  if ( ! self::pro_is_installed() ) {
86
+ include(self::plugin_path() .'/classes/views/shared/update_message.php');
87
  }
88
  }
89
 
226
  /*
227
  * @since 2.0
228
  */
229
+
230
+ /**
231
+ * @param string $action
232
+ */
233
  public static function simple_get($action) {
234
  if ( $_GET && isset($_GET[$action]) ) {
235
  return $_GET[$action];
275
  return $value;
276
  }
277
 
278
+ /**
279
+ * @param string $type
280
+ */
281
  public static function trigger_hook_load( $type, $object = null ) {
282
  // only load the form hooks once
283
  $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object);
340
  /*
341
  * @since 2.0
342
  */
343
+
344
+ /**
345
+ * @param string $cache_key
346
+ */
347
  public static function delete_cache_and_transient($cache_key) {
348
  delete_transient($cache_key);
349
  wp_cache_delete($cache_key);
425
  public static function post_edit_link($post_id) {
426
  $post = get_post($post_id);
427
  if ( $post ) {
428
+ return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. self::truncate($post->post_title, 50) .'</a>';
429
  }
430
  return '';
431
  }
485
  if($needed_role == '-1')
486
  return false;
487
 
488
+ // $needed_role will be equal to blank if "Logged-in users" is selected
489
+ if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
490
  return true;
491
+ }
492
 
493
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
494
  foreach ($roles as $role){
524
  * Return permission message and stop the action if no permission
525
  * @since 2.0
526
  */
527
+
528
+ /**
529
+ * @param string $permission
530
+ */
531
+ public static function permission_check($permission, $show_message = 'show') {
532
+ $permission_error = self::permission_nonce_error($permission);
533
+ if ( $permission_error !== false ) {
534
+ if ( 'hide' == $show_message ) {
535
+ $permission_error = '';
536
+ }
537
+ wp_die($permission_error);
538
  }
539
  }
540
 
541
  /*
542
+ * Check user permission and nonce
 
543
  * @since 2.0
544
+ * @return false|string The permission message or false if allowed
545
  */
546
+ public static function permission_nonce_error($permission, $nonce_name = '', $nonce = '') {
547
+ $error = false;
548
+ if ( ! empty($permission) && current_user_can($permission) ) {
549
+ return $error;
550
  }
551
 
552
+ if ( empty($nonce_name) ) {
553
+ return $error;
554
+ }
555
+
556
+ if ( $_REQUEST && ( ! isset($_REQUEST[$nonce_name]) || ! wp_verify_nonce($_REQUEST[$nonce_name], $nonce) ) ) {
557
  $frm_settings = self::get_settings();
558
+ $error = $frm_settings->admin_permission;
559
  }
560
 
561
+ return $error;
562
  }
563
 
564
  public static function checked($values, $current){
582
  $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
583
  */
584
 
585
+ return ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current );
 
 
 
 
586
  }
587
 
588
+ /**
589
+ * Check if current field option is an "other" option
590
+ *
591
+ * @since 2.0
592
+ *
593
+ * @param $opt_key string
594
+ * @return boolean true or false. Returns true if current field option is an "Other" option
595
  */
596
+ public static function is_other_opt( $opt_key ) {
597
+ return $opt_key && strpos( $opt_key, 'other' ) !== false;
598
+ }
 
599
 
600
+ /**
601
+ * Get value that belongs in "Other" text box
602
+ *
603
+ * @since 2.0
604
+ *
605
+ * @param $opt_key string
606
+ * @param $field array
607
+ * @return $other_val string
608
+ */
609
+ public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
610
  $other_val = '';
611
+
612
+ //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
613
+ if ( !self::is_other_opt( $opt_key ) || !isset( $field['value'] ) || !$field['value'] ) {
614
+ return $other_val;
615
+ }
616
+
617
+ // Check posted vals before checking saved values
618
+
619
+ // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
620
+ if ( $parent && isset( $_POST['item_meta'][$parent][$pointer]['other'][$field['id']] ) ) {
621
+ if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
622
+ $other_val = isset( $_POST['item_meta'][$parent][$pointer]['other'][$field['id']][$opt_key] ) ? $_POST['item_meta'][$parent][$pointer]['other'][$field['id']][$opt_key] : '';
623
+ } else {
624
+ $other_val = $_POST['item_meta'][$parent][$pointer]['other'][$field['id']];
625
+ }
626
+ return $other_val;
627
+
628
+ // For normal fields
629
+ } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][$field['id']] ) ) {
630
+ if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
631
+ $other_val = isset( $_POST['item_meta']['other'][$field['id']][$opt_key] ) ? $_POST['item_meta']['other'][$field['id']][$opt_key] : '';
632
+ } else {
633
+ $other_val = $_POST['item_meta']['other'][$field['id']];
634
+ }
635
+ return $other_val;
636
+ }
637
+
638
+ // For checkboxes
639
+ if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
640
+ // Check if there is an "other" val in saved value and make sure the "other" val is not equal to the Other checkbox option
641
+ if ( isset( $field['value'][$opt_key] ) && $field['options'][$opt_key] != $field['value'][$opt_key] ) {
642
+ $other_val = $field['value'][$opt_key];
643
+ }
644
+
645
+ // For radio buttons and dropdowns
646
+ } else {
647
+ //Check if saved value equals any of the options. If not, set it as the other value.
648
+ foreach ( $field['options'] as $opt_key => $opt_val ) {
649
+ $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
650
+ // Multi-select dropdowns - key is not preserved
651
+ if ( is_array( $field['value'] ) ) {
652
+ $o_key = array_search( $temp_val, $field['value'] );
653
+ if ( isset( $field['value'][$o_key] ) ) {
654
+ unset( $field['value'][$o_key], $o_key );
655
  }
656
+
657
+ // For radio and regular dropdowns
658
+ } else if ( $temp_val == $field['value'] ) {
659
  return '';
660
  } else {
661
+ $other_val = $field['value'];
662
  }
663
+ unset($opt_key, $opt_val, $temp_val);
664
+ }
665
+ // For multi-select dropdowns only
666
+ if ( is_array( $field['value'] ) && !empty( $field['value'] ) ) {
667
+ $other_val = reset( $field['value'] );
668
  }
 
 
669
  }
 
670
  return $other_val;
671
  }
672
 
673
+ /**
674
+ * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
675
+ * Intended for front-end use
676
+ *
677
+ * @since 2.0
678
+ *
679
+ * @param $field array
680
+ * @param $other_opt boolean
681
+ * @param $checked string
682
+ * @param $args array, should include opt_key and field name
683
+ * @return $other_val string
684
+ */
685
+ public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ){
686
+ //Check if this is an "Other" option
687
+ if ( !self::is_other_opt( $args['opt_key'] ) ) {
688
+ return;
689
+ }
690
+
691
+ $other_opt = true;
692
+ $other_args = array();
693
+ $parent = $pointer = '';
694
+
695
+ // Check for parent ID and pointer
696
+ $temp_array = explode( '[', $args['field_name'] );
697
+ // Count should only be greater than 3 if inside of a repeating section
698
+ if ( count( $temp_array ) > 3 ) {
699
+ $parent = str_replace( ']', '', $temp_array[1] );
700
+ $pointer = str_replace( ']', '', $temp_array[2]);
701
+ }
702
+ unset( $temp_array );
703
+
704
+ //Set up name for other field
705
+ $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
706
+ $other_args['name'] = preg_replace('/\[' . $field['id'] . '\]$/', '', $other_args['name']);
707
+ $other_args['name'] = $other_args['name'] . '[other]' . '[' . $field['id'] . ']';
708
+ //Converts item_meta[field_id] => item_meta[other][field_id] and
709
+ //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
710
+ if ( FrmFieldsHelper::is_field_with_multiple_values( $field ) ) {
711
+ $other_args['name'] .= '[' . $args['opt_key'] . ']';
712
+ }
713
+
714
+ // Get text for "other" text field
715
+ $other_args['value'] = self::get_other_val( $args['opt_key'], $field, $parent, $pointer );
716
+
717
+ if ( $other_args['value'] ) {
718
+ $checked = 'checked="checked" ';
719
+ }
720
+
721
+ return $other_args;
722
+ }
723
+
724
  public static function recursive_trim(&$value) {
725
  if ( is_array($value) ) {
726
  $value = array_map(array('FrmAppHelper', 'recursive_trim'), $value);
766
  return $url;
767
  }
768
 
769
+ /**
770
+ * @param string $handle
771
+ */
772
  public static function script_version($handle) {
773
  global $wp_scripts;
774
  if ( ! $wp_scripts ) {
830
  return $contents;
831
  }
832
 
833
+ /**
834
+ * @param string $table_name
835
+ * @param string $column
836
+ */
837
  public static function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
838
  global $wpdb;
839
 
849
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
850
  }
851
 
852
+ if ( is_numeric($key) || in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')) ) {
853
  $key = $key .'a';
854
+ }
855
 
856
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
857
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
858
 
859
+ if ( $key_check || is_numeric($key_check) ) {
860
  $suffix = 2;
861
  do {
862
  $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
872
  * Editing a Form or Entry
873
  * @return bool|array
874
  */
875
+
876
+ /**
877
+ * @param string $table
878
+ */
879
  public static function setup_edit_vars($record, $table, $fields='', $default=false, $post_values=array()){
880
  if ( ! $record ) {
881
  return false;
897
 
898
  $values['description'] = self::use_wpautop($values['description']);
899
  $frm_settings = self::get_settings();
900
+ $is_form_builder = self::is_admin_page('formidable');
901
 
902
  foreach ( (array) $fields as $field ) {
903
+ // Make sure to filter default values (for placeholder text), but not on the form builder page
904
+ if ( ! $is_form_builder ) {
905
+ $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
906
+ }
907
  self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
908
  }
909
 
1067
  }
1068
  }
1069
 
1070
+ /**
1071
+ * @return string
1072
+ */
1073
  public static function get_meta_value($field_id, $entry) {
1074
  if ( isset($entry->metas) ) {
1075
  return isset($entry->metas[$field_id]) ? $entry->metas[$field_id] : false;
1348
  return $term;
1349
  }
1350
 
1351
+ /**
1352
+ * @param string $order_query
1353
+ */
1354
  public static function esc_order($order_query) {
1355
  if ( empty($order_query) ) {
1356
  return '';
1387
  return ' ORDER BY '. $order . ' '. $order_by;
1388
  }
1389
 
1390
+ /**
1391
+ * @param string $limit
1392
+ */
1393
  public static function esc_limit($limit) {
1394
  if ( empty($limit) ) {
1395
  return '';
1451
  return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
1452
  }
1453
 
1454
+ /**
1455
+ * @param integer $current_p
1456
+ */
1457
  public static function getFirstRecordNum($r_count,$current_p,$p_size){
1458
  if($current_p == 1)
1459
  return 1;
1461
  return (self::getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
1462
  }
1463
 
1464
+ /**
1465
+ * @param string $table_name
1466
+ */
1467
  public static function &getRecordCount($where = '', $table_name) {
1468
  $cache_key = 'count_'. $table_name .'_'. maybe_serialize($where);
1469
  $query = 'SELECT COUNT(*) FROM ' . $table_name . self::prepend_and_or_where(' WHERE ', $where);
1495
  $referrerinfo = '';
1496
  $keywords = array();
1497
  $i = 1;
1498
+ if ( isset($_SESSION) && isset($_SESSION['frm_http_referer']) && $_SESSION['frm_http_referer'] ) {
1499
  foreach ($_SESSION['frm_http_referer'] as $referer) {
1500
  $referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
1501
  $keywords_used = self::get_referer_query($referer);
1502
+ if ( $keywords_used !== false ) {
1503
  $keywords[] = $keywords_used;
1504
+ }
1505
 
1506
  $i++;
1507
  }
1512
  }
1513
 
1514
  $i = 1;
1515
+ if ( isset($_SESSION) && isset($_SESSION['frm_http_pages']) && $_SESSION['frm_http_pages'] ) {
1516
+ foreach ( $_SESSION['frm_http_pages'] as $page ) {
1517
  $referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
1518
  $i++;
1519
  }
1546
  $l2 = $name;
1547
  }
1548
 
1549
+ if ( ! isset($l3) ) {
1550
+ $l3 = $name;
1551
+ }
1552
+
1553
  $this_val = ( $p == $last ) ? $jv['value'] : array();
1554
 
1555
  switch ( $p ) {
1579
  $vars[$l1][$l2][$l3] = $this_val;
1580
  }
1581
  break;
1582
+
1583
+ case 3:
1584
+ $l4 = $name;
1585
+ if ( $name == '' ) {
1586
+ $vars[$l1][$l2][$l3][] = $this_val;
1587
+ } else if ( ! isset($vars[$l1][$l2][$l3][$l4] ) ) {
1588
+ $vars[$l1][$l2][$l3][$l4] = $this_val;
1589
+ }
1590
+ break;
1591
  }
1592
 
1593
  unset($this_val, $n);
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -80,7 +80,7 @@ class FrmEntriesHelper{
80
 
81
  foreach ( (array) $field->field_options as $k => $v ) {
82
  if ( ! isset($field_array[$k]) ) {
83
- $field_array[$k] = $v;
84
  }
85
  unset($k, $v);
86
  }
@@ -96,6 +96,7 @@ class FrmEntriesHelper{
96
  if ( is_array($form->options) ) {
97
  foreach ( $form->options as $opt => $value ) {
98
  $values[$opt] = FrmAppHelper::get_post_param($opt, $value);
 
99
  }
100
  }
101
 
@@ -112,18 +113,6 @@ class FrmEntriesHelper{
112
 
113
  $values = array_merge($form_defaults, $values);
114
 
115
- if ( ! isset($values['before_html']) ) {
116
- $values['before_html'] = FrmFormsHelper::get_default_html('before');
117
- }
118
-
119
- if ( ! isset($values['after_html']) ) {
120
- $values['after_html'] = FrmFormsHelper::get_default_html('after');
121
- }
122
-
123
- if ( ! isset($values['submit_html']) ) {
124
- $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
125
- }
126
-
127
  return apply_filters('frm_setup_new_entry', $values);
128
  }
129
 
@@ -251,7 +240,11 @@ class FrmEntriesHelper{
251
  $meta = array('item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
252
 
253
  //This filter applies to the default-message shortcode and frm-show-entry shortcode only
254
- $val = apply_filters('frm_email_value', $prev_val, (object) $meta, $atts['entry']);
 
 
 
 
255
  }
256
 
257
  self::textarea_display_value( $val, $f->type, $atts['plain_text'] );
@@ -299,12 +292,15 @@ class FrmEntriesHelper{
299
 
300
  if ( $atts['format'] != 'text' ) {
301
  $values['ip'] = $atts['entry']->ip;
302
- $values['browser'] = $data['browser'];
303
  $values['referrer'] = $data['referrer'];
304
  } else {
305
  //$content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
306
  $values['ip'] = array('label' => __('IP Address', 'formidable'), 'val' => $atts['entry']->ip);
307
- $values['browser'] = array('label' => __('User-Agent (Browser/OS)', 'formidable'), 'val' => $data['browser']);
 
 
 
308
  $values['referrer'] = array('label' => __('Referrer', 'formidable'), 'val' => $data['referrer']);
309
  }
310
  }
@@ -523,107 +519,131 @@ class FrmEntriesHelper{
523
  return apply_filters('frm_display_value', $value, $field, $atts);
524
  }
525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  /**
527
- * Sets radio or checkbox value equal to "other" value if it is set
 
528
  * @since 2.0
529
  *
530
- * @param $values array of posted values
531
- * @param $clear_vals boolean. If Other vals are not cleared by JavaScript when selection is changed, this should be set to true. Other vals are not cleared with JavaScript on the back-end.
532
- * @return array of updated POST values
533
  */
534
- public static function set_other_vals( $values, $clear_vals = false ){
535
- if ( ! isset( $values['item_meta']['other'] ) ) {
536
- return $values;
537
- }
538
-
539
- $other_array = $values['item_meta']['other'];
540
- foreach ( $other_array as $f_id => $o_val ) {
541
- //For checkboxes
542
- if ( is_array( $o_val ) ) {
543
- foreach ( $o_val as $opt_key => $opt_val ) {
544
- $_POST['item_meta'][$f_id][$opt_key] = $values['item_meta'][$f_id][$opt_key] = $opt_val;
545
- unset( $opt_key, $opt_val );
546
- }
547
- //For radio buttons
548
- } else if ( $o_val ) {
549
- // If Other vals weren't cleared with JS (like on the back-end), check if they need to be cleared now
550
- if ( $clear_vals && isset( $values['item_meta'][$f_id] ) && !empty( $values['item_meta'][$f_id] ) ) {
551
- $field = FrmField::getOne( $f_id );
552
- $array = array_filter( $field->options, 'is_numeric', ARRAY_FILTER_USE_KEY );
553
- // Check if posted value is NOT equal to other value
554
- if ( !in_array( $values['item_meta'][$f_id], $array ) ) {
555
- $_POST['item_meta'][$f_id] = $values['item_meta'][$f_id] = $o_val;
556
- }
557
- unset( $array );
558
- } else {
559
- $_POST['item_meta'][$f_id] = $values['item_meta'][$f_id] = $o_val;
560
- }
561
- }
562
  }
563
- unset( $_POST['item_meta']['other'] );
564
 
565
- return $values;
 
 
 
 
 
 
 
 
 
 
 
 
 
566
  }
567
 
568
- /*
569
  * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
 
570
  * @since 2.0
571
- * @return array of updated POST values
 
 
 
572
  */
573
- public static function set_other_repeating_vals( $values, $field ){
574
- if ( ( $field->type == 'divider' && $field->field_options['repeat'] ) || $field->type == 'form' ) {
575
- // do nothing
576
- } else {
577
- return $values;
578
  }
579
 
580
- foreach ( $values['item_meta'][$field->id] as $k => $val ) {
581
- if ( ! isset( $val['other'] ) || ! is_array( $val['other'] ) ) {
582
- continue;
583
- }
584
-
585
- foreach ( $val['other'] as $sub_fid => $o_val ) {
586
-
587
- //For checkboxes
588
- if ( is_array( $o_val ) ) {
589
- foreach ( $o_val as $opt_key => $opt_val ) {
590
- $values['item_meta'][$field->id][$k][$sub_fid][$opt_key] = $opt_val;
591
- unset( $values['item_meta'][$field->id][$k]['other'][$sub_fid][$opt_key] );
592
- unset( $opt_key, $opt_val );
593
- }
594
 
595
- //For radio buttons
596
- } else if ( $o_val ) {
597
- $values['item_meta'][$field->id][$k][$sub_fid] = $o_val;
598
- unset( $values['item_meta'][$field->id][$k]['other'][$sub_fid] );
599
- }
600
- unset( $sub_fid, $o_val);
601
- }
602
 
603
- unset( $k, $val );
 
604
  }
605
-
606
- return $values;
607
  }
608
 
609
- public static function set_posted_value($field, $value, $args) {
610
- if ( empty($args['parent_field_id']) ) {
611
- $_POST['item_meta'][$field->id] = $value;
612
- } else {
613
- $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] = $value;
614
- }
615
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
 
617
- public static function get_posted_value($field, &$value, $args) {
618
- if ( is_object( $field ) ) {
619
- $field_id = $field->id;
620
- } else {
621
- $field_id = $field;
622
- }
623
- if ( empty($args['parent_field_id']) ) {
624
- $value = isset($_POST['item_meta'][$field_id]) ? $_POST['item_meta'][$field_id] : '';
625
  } else {
626
- $value = $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field_id];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
627
  }
628
  }
629
 
@@ -652,4 +672,65 @@ class FrmEntriesHelper{
652
 
653
  return $content;
654
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  }
80
 
81
  foreach ( (array) $field->field_options as $k => $v ) {
82
  if ( ! isset($field_array[$k]) ) {
83
+ $field_array[$k] = $v;
84
  }
85
  unset($k, $v);
86
  }
96
  if ( is_array($form->options) ) {
97
  foreach ( $form->options as $opt => $value ) {
98
  $values[$opt] = FrmAppHelper::get_post_param($opt, $value);
99
+ unset($opt, $value);
100
  }
101
  }
102
 
113
 
114
  $values = array_merge($form_defaults, $values);
115
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  return apply_filters('frm_setup_new_entry', $values);
117
  }
118
 
240
  $meta = array('item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
241
 
242
  //This filter applies to the default-message shortcode and frm-show-entry shortcode only
243
+ if ( isset($atts['filter']) && $atts['filter'] == false ) {
244
+ $val = $prev_val;
245
+ } else {
246
+ $val = apply_filters('frm_email_value', $prev_val, (object) $meta, $atts['entry']);
247
+ }
248
  }
249
 
250
  self::textarea_display_value( $val, $f->type, $atts['plain_text'] );
292
 
293
  if ( $atts['format'] != 'text' ) {
294
  $values['ip'] = $atts['entry']->ip;
295
+ $values['browser'] = self::get_browser($data['browser']);
296
  $values['referrer'] = $data['referrer'];
297
  } else {
298
  //$content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
299
  $values['ip'] = array('label' => __('IP Address', 'formidable'), 'val' => $atts['entry']->ip);
300
+ $values['browser'] = array(
301
+ 'label' => __('User-Agent (Browser/OS)', 'formidable'),
302
+ 'val' => self::get_browser($data['browser']),
303
+ );
304
  $values['referrer'] = array('label' => __('Referrer', 'formidable'), 'val' => $data['referrer']);
305
  }
306
  }
519
  return apply_filters('frm_display_value', $value, $field, $atts);
520
  }
521
 
522
+ public static function set_posted_value($field, $value, $args) {
523
+ // If validating a field with "other" opt, set back to prev value now
524
+ if ( isset( $args['other'] ) && $args['other'] ) {
525
+ $value = $args['temp_value'];
526
+ }
527
+ if ( empty($args['parent_field_id']) ) {
528
+ $_POST['item_meta'][$field->id] = $value;
529
+ } else {
530
+ $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] = $value;
531
+ }
532
+ }
533
+
534
+ public static function get_posted_value($field, &$value, $args) {
535
+ if ( is_object( $field ) ) {
536
+ $field_id = $field->id;
537
+ } else {
538
+ $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 = $_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 $field object
553
+ * @param $value string or array
554
+ * @param $args array
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 $field object
584
+ * @param $value string or array
585
+ * @param $args array
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 $value string or array
615
+ * @param $other_vals string or array (usually of posted values)
616
+ * @param $field object
617
+ * @param $args array
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
 
629
+ // Radio and dropdowns
 
 
 
 
 
 
 
630
  } else {
631
+ $other_key = array_filter( array_keys($field->options), 'is_string');
632
+ $other_key = reset( $other_key );
633
+
634
+ // Multi-select dropdown
635
+ if ( is_array( $value ) ) {
636
+ $o_key = array_search( $field->options[$other_key], $value );
637
+ if ( $o_key ) {
638
+ // Modify original value so key is preserved
639
+ $value[$other_key] = $value[$o_key];
640
+ unset( $value[$o_key] );
641
+ $args['temp_value'] = $value;
642
+ $value[$other_key] = reset( $other_vals );
643
+ }
644
+ } else if ( $field->options[$other_key] == $value ) {
645
+ $value = $other_vals;
646
+ }
647
  }
648
  }
649
 
672
 
673
  return $content;
674
  }
675
+
676
+ public static function get_browser($u_agent) {
677
+ $bname = __('Unknown', 'formidable');
678
+ $platform = __('Unknown', 'formidable');
679
+ $ub = '';
680
+
681
+ //First get the platform?
682
+ if ( preg_match('/linux/i', $u_agent) ) {
683
+ $platform = 'Linux';
684
+ } else if ( preg_match('/macintosh|mac os x/i', $u_agent) ) {
685
+ $platform = 'Mac';
686
+ } else if ( preg_match('/windows|win32/i', $u_agent) ) {
687
+ $platform = 'Windows';
688
+ }
689
+
690
+ // Next get the name of the useragent yes seperately and for good reason
691
+ if ( preg_match('/MSIE/i', $u_agent) && ! preg_match('/Opera/i', $u_agent) ) {
692
+ $bname = 'Internet Explorer';
693
+ $ub = 'MSIE';
694
+ } else if ( preg_match('/Firefox/i', $u_agent) ) {
695
+ $bname = 'Mozilla Firefox';
696
+ $ub = 'Firefox';
697
+ } else if ( preg_match('/Chrome/i', $u_agent) ) {
698
+ $bname = 'Google Chrome';
699
+ $ub = 'Chrome';
700
+ } else if ( preg_match('/Safari/i', $u_agent) ) {
701
+ $bname = 'Apple Safari';
702
+ $ub = 'Safari';
703
+ } else if ( preg_match('/Opera/i',$u_agent) ) {
704
+ $bname = $ub = 'Opera';
705
+ } else if ( preg_match('/Netscape/i', $u_agent) ) {
706
+ $bname = $ub = 'Netscape';
707
+ }
708
+
709
+ // finally get the correct version number
710
+ $known = array('Version', $ub, 'other');
711
+ $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
712
+ preg_match_all($pattern, $u_agent, $matches); // get the matching numbers
713
+
714
+ // see how many we have
715
+ $i = count($matches['browser']);
716
+ if ( $i != 1 ) {
717
+ //we will have two since we are not using 'other' argument yet
718
+ //see if version is before or after the name
719
+ if ( strripos($u_agent, 'Version') < strripos($u_agent,$ub) ) {
720
+ $version = $matches['version'][0];
721
+ } else {
722
+ $version = $matches['version'][1];
723
+ }
724
+ } else {
725
+ $version = $matches['version'][0];
726
+ }
727
+
728
+ // check if we have a number
729
+ if ( $version == '') {
730
+ $version = '?';
731
+ }
732
+
733
+ return $bname .' '. $version .' / '. $platform;
734
+ }
735
+
736
  }
classes/helpers/FrmEntriesListHelper.php CHANGED
@@ -149,10 +149,11 @@ class FrmEntriesListHelper extends FrmListHelper {
149
  $class = 'class="'. $column_name .' column-'. $column_name .'"';
150
 
151
  $style = '';
152
- if ( in_array( $column_name, $hidden ) )
153
  $style = ' style="display:none;"';
154
- else if(!$action_col and !in_array($column_name, array('cb', 'id', 'form_id', 'post_id')))
155
  $action_col = $column_name;
 
156
 
157
  $attributes = $class . $style;
158
 
@@ -241,6 +242,9 @@ class FrmEntriesListHelper extends FrmListHelper {
241
  return $r;
242
  }
243
 
 
 
 
244
  private function get_actions( &$actions, $item, $view_link ) {
245
  $actions['view'] = '<a href="' . esc_url( $view_link ) . '">'. __('View', 'formidable') .'</a>';
246
 
149
  $class = 'class="'. $column_name .' column-'. $column_name .'"';
150
 
151
  $style = '';
152
+ if ( in_array( $column_name, $hidden ) ) {
153
  $style = ' style="display:none;"';
154
+ } else if ( ! $action_col && ! in_array($column_name, array('cb', 'id', 'form_id', 'post_id')) ) {
155
  $action_col = $column_name;
156
+ }
157
 
158
  $attributes = $class . $style;
159
 
242
  return $r;
243
  }
244
 
245
+ /**
246
+ * @param string $view_link
247
+ */
248
  private function get_actions( &$actions, $item, $view_link ) {
249
  $actions['view'] = '<a href="' . esc_url( $view_link ) . '">'. __('View', 'formidable') .'</a>';
250
 
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -85,10 +85,12 @@ class FrmFieldsHelper{
85
  }
86
  }
87
 
88
- /*
89
  * Check if this field can hold an array of values
90
  *
91
  * @since 2.0
 
 
92
  * @return boolean
93
  */
94
  public static function is_field_with_multiple_values( $field ) {