Formidable Forms – Form Builder for WordPress - Version 2.0b7

Version Description

Download this release

Release Info

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

Code changes from version 2.0rc1 to 2.0b7

Files changed (79) hide show
  1. .gitignore +0 -1
  2. classes/controllers/FrmAppController.php +15 -15
  3. classes/controllers/FrmEntriesController.php +4 -14
  4. classes/controllers/FrmFieldsController.php +14 -16
  5. classes/controllers/FrmFormActionsController.php +2 -8
  6. classes/controllers/FrmFormsController.php +72 -58
  7. classes/controllers/FrmHooksController.php +17 -17
  8. classes/controllers/FrmSettingsController.php +5 -7
  9. classes/controllers/FrmStylesController.php +11 -37
  10. classes/controllers/FrmXMLController.php +23 -22
  11. classes/helpers/FrmAppHelper.php +67 -224
  12. classes/helpers/FrmEntriesHelper.php +84 -179
  13. classes/helpers/FrmEntriesListHelper.php +2 -6
  14. classes/helpers/FrmFieldsHelper.php +17 -44
  15. classes/helpers/FrmFormsHelper.php +12 -33
  16. classes/helpers/FrmFormsListHelper.php +6 -29
  17. classes/helpers/FrmListHelper.php +0 -1
  18. classes/helpers/FrmStylesHelper.php +5 -22
  19. classes/helpers/FrmXMLHelper.php +20 -29
  20. classes/models/FrmDb.php +21 -35
  21. classes/models/FrmEntry.php +26 -30
  22. classes/models/FrmEntryMeta.php +16 -20
  23. classes/models/FrmField.php +25 -42
  24. classes/models/FrmForm.php +1 -1
  25. classes/models/FrmFormAction.php +1 -1
  26. classes/models/FrmNotification.php +8 -9
  27. classes/models/FrmSettings.php +8 -9
  28. classes/models/FrmStyle.php +21 -28
  29. classes/views/frm-entries/direct.php +0 -0
  30. classes/views/frm-entries/errors.php +1 -1
  31. classes/views/frm-entries/form.php +0 -1
  32. classes/views/frm-entries/sidebar-shared.php +0 -84
  33. classes/views/frm-entries/sidebar-show.php +1 -3
  34. classes/views/frm-fields/input.php +53 -37
  35. classes/views/frm-fields/radio.php +8 -4
  36. classes/views/frm-fields/show-build.php +4 -2
  37. classes/views/frm-fields/show.php +0 -0
  38. classes/views/frm-fields/single-option.php +1 -0
  39. classes/views/frm-form-actions/default_actions.php +7 -7
  40. classes/views/frm-form-actions/email_action.php +3 -3
  41. classes/views/frm-forms/add_field.php +3 -3
  42. classes/views/frm-forms/add_field_links.php +1 -1
  43. classes/views/frm-forms/insert_form_popup.php +1 -3
  44. classes/views/frm-forms/shortcode_opts.php +0 -42
  45. classes/views/frm-settings/form.php +0 -0
  46. classes/views/shared/errors.php +1 -1
  47. classes/views/shared/head.php +19 -1
  48. classes/views/shared/mb_adv_info.php +2 -2
  49. classes/views/styles/show.php +1 -1
  50. classes/views/xml/forms_xml.php +1 -1
  51. classes/views/xml/posts_xml.php +1 -0
  52. css/_single_theme.css.php +2 -11
  53. css/custom_theme.css.php +6 -8
  54. css/frm_admin.css +0 -3
  55. css/frm_display.css +72 -0
  56. deprecated.php +19 -0
  57. formidable.php +2 -2
  58. images/ajax_loader.gif +0 -0
  59. images/form_16-2x.png +0 -0
  60. images/form_16.png +0 -0
  61. images/form_32_sprite-2x.png +0 -0
  62. images/form_32_sprite.png +0 -0
  63. images/tooltip.png +0 -0
  64. images/wpspin_light.gif +0 -0
  65. js/bootstrap.min.js +3 -3
  66. js/formidable.js +246 -368
  67. js/formidable.min.js +45 -45
  68. js/formidable_admin.js +12 -19
  69. js/jquery/jquery-ui-themepicker.js +0 -0
  70. js/jquery/jquery.editinplace.js +0 -0
  71. js/jquery/jquery.editinplace.packed.js +0 -0
  72. js/jquery/jquery.placeholder.js +0 -0
  73. languages/formidable-de_DE.mo +0 -0
  74. languages/formidable-de_DE.po +1169 -1286
  75. languages/formidable-en_US.po +1169 -1286
  76. languages/formidable-es_ES.mo +0 -0
  77. languages/formidable-es_ES.po +1169 -1286
  78. languages/formidable-fr_FR.mo +0 -0
  79. languages/formidable-fr_FR.po +974 -906
.gitignore DELETED
@@ -1 +0,0 @@
1
- .DS_Store
 
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.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,6 +162,7 @@ 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
 
166
  if ( FrmAppHelper::is_admin_page('formidable-settings') || FrmAppHelper::is_admin_page('formidable-styles') ) {
167
  // load multselect js
@@ -224,11 +225,6 @@ return false;
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,9 +246,11 @@ return false;
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,9 +268,6 @@ return false;
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,15 +347,20 @@ return false;
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']) ) {
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
  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
  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
 
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
  }
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
 
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
+ 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"));';
356
+ //wp_enqueue_style($css_key);
357
+ unset($css_key);
358
+ unset($file);
359
  }
360
+ unset($css);
361
+
362
+ echo '</script>'."\n";
363
  }
 
364
  }
365
 
366
  if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty($frm_vars['forms_loaded']) ) {
classes/controllers/FrmEntriesController.php CHANGED
@@ -244,11 +244,10 @@ class FrmEntriesController{
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,7 +263,8 @@ class FrmEntriesController{
264
  if($i > $max_columns)
265
  $result[] = $col_key; //remove some columns by default
266
  $i--;
267
- unset($col_key, $col);
 
268
  }
269
  }
270
 
@@ -512,8 +512,6 @@ class FrmEntriesController{
512
 
513
  if ( $atts['format'] == 'json' ) {
514
  return json_encode($values);
515
- } else if ( $atts['format'] == 'array' ) {
516
- return $values;
517
  }
518
 
519
  $content = array();
@@ -634,12 +632,4 @@ class FrmEntriesController{
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
  }
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
  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
 
512
 
513
  if ( $atts['format'] == 'json' ) {
514
  return json_encode($values);
 
 
515
  }
516
 
517
  $content = array();
632
  return $values;
633
  }
634
 
 
 
 
 
 
 
 
 
635
  }
classes/controllers/FrmFieldsController.php CHANGED
@@ -19,10 +19,6 @@ class FrmFieldsController{
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,20 +290,21 @@ class FrmFieldsController{
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,7 +424,8 @@ class FrmFieldsController{
427
  }
428
  unset($vals);
429
  }
430
- unset($opt_key, $opt);
 
431
  }
432
  }
433
 
@@ -438,9 +436,9 @@ class FrmFieldsController{
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
  }
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
  $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
  }
425
  unset($vals);
426
  }
427
+ unset($opt_key);
428
+ unset($opt);
429
  }
430
  }
431
 
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
  }
classes/controllers/FrmFormActionsController.php CHANGED
@@ -26,13 +26,10 @@ class FrmFormActionsController{
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,7 +189,7 @@ class FrmFormActionsController{
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,9 +217,6 @@ class FrmFormActionsController{
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,7 +291,7 @@ class FrmFormActionsController{
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']);
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
 
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
  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
  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']);
classes/controllers/FrmFormsController.php CHANGED
@@ -27,6 +27,7 @@ class FrmFormsController{
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,9 +43,7 @@ class FrmFormsController{
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,9 +84,7 @@ class FrmFormsController{
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,6 +106,8 @@ class FrmFormsController{
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,9 +121,8 @@ class FrmFormsController{
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,7 +145,7 @@ class FrmFormsController{
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,7 +157,7 @@ class FrmFormsController{
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,14 +173,13 @@ class FrmFormsController{
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');
@@ -222,6 +219,11 @@ class FrmFormsController{
222
  }
223
  }
224
 
 
 
 
 
 
225
  public static function page_preview(){
226
  $params = FrmFormsHelper::get_params();
227
  if (!$params['form']) return;
@@ -255,9 +257,7 @@ class FrmFormsController{
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,25 +330,8 @@ class FrmFormsController{
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,21 +340,17 @@ class FrmFormsController{
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,6 +384,9 @@ class FrmFormsController{
405
 
406
  $form_id = '';
407
  $opts = array();
 
 
 
408
  switch( $shortcode ) {
409
  case 'formidable':
410
  $form_id = 'id';
@@ -416,9 +398,48 @@ class FrmFormsController{
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,9 +685,9 @@ class FrmFormsController{
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,14 +738,12 @@ class FrmFormsController{
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,10 +781,6 @@ class FrmFormsController{
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,7 +797,6 @@ class FrmFormsController{
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);
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
  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
  }
85
 
86
  //Set radio button and checkbox meta equal to "other" value
87
+ $values = FrmEntriesHelper::set_other_vals( $values );
 
 
88
 
89
  $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
90
 
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
  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
  }
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
  }
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
  }
174
 
175
  //Set radio button and checkbox meta equal to "other" value
176
+ $values = FrmEntriesHelper::set_other_vals( $values );
 
 
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');
219
  }
220
  }
221
 
222
+
223
+ public static function after_duplicate($form_id, $values) {
224
+ FrmForm::after_duplicate($form_id, $values);
225
+ }
226
+
227
  public static function page_preview(){
228
  $params = FrmFormsHelper::get_params();
229
  if (!$params['form']) return;
257
  $controller = FrmAppHelper::get_param('controller');
258
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
259
  $form = FrmForm::getAll(array('form_key' => $key), '', 1);
260
+ if (!$form) $form = FrmForm::getAll('', '', 1);
 
 
261
 
262
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
263
  die();
330
  return $message;
331
  }
332
 
333
+ // Delete trashed forms
334
+ public static function scheduled_delete() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  global $wpdb;
336
 
337
  $trash_forms = $wpdb->get_results($wpdb->prepare("SELECT id, options FROM {$wpdb->prefix}frm_forms WHERE status = %s", 'trash'));
340
  return;
341
  }
342
 
343
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
 
 
344
 
 
345
  foreach ( $trash_forms as $form ) {
346
  $form->options = maybe_unserialize($form->options);
347
  if ( !isset($form->options['trash_time']) || $form->options['trash_time'] < $delete_timestamp ) {
348
  FrmForm::destroy($form->id);
 
349
  }
350
 
351
  unset($form);
352
  }
353
+
354
  }
355
 
356
  public static function insert_form_button($content){
384
 
385
  $form_id = '';
386
  $opts = array();
387
+
388
+ echo '<div id="sc-opts-'. $shortcode .'" class="frm_shortcode_option">';
389
+ echo '<input type="radio" name="frmsc" value="'. esc_attr($shortcode) .'" id="sc-'. esc_attr($shortcode) .'" style="display:none;" />';
390
  switch( $shortcode ) {
391
  case 'formidable':
392
  $form_id = 'id';
398
  );
399
  break;
400
  }
401
+
402
  $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
403
 
404
+ if ( ! empty($form_id) ) {
405
+ ?>
406
+ <h4 for="frmsc_<?php echo $shortcode .'_'. $form_id ?>" class="frm_left_label"><?php _e('Select a form:', 'formidable') ?></h4>
407
+ <?php FrmFormsHelper::forms_dropdown( 'frmsc_'. $shortcode .'_'. $form_id ); ?>
408
+ <div class="frm_box_line"></div>
409
+ <?php
410
+ }
411
+
412
+ if ( ! empty($opts) ) { ?>
413
+ <h4><?php _e('Options', 'formidable') ?></h4>
414
+ <ul>
415
+ <?php
416
+ foreach ( $opts as $opt => $val ) {
417
+ if ( isset($val['type']) && 'text' == $val['type'] ) { ?>
418
+ <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>">
419
+ <span><?php echo $val['label'] ?></span>
420
+ <input type="text" id="frmsc_<?php echo $shortcode .'_'. $opt ?>" value="<?php echo esc_attr($val['val']) ?>" />
421
+ </label>
422
+ <li>
423
+ <?php } else if ( isset($val['type']) && 'select' == $val['type'] ) { ?>
424
+ <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>">
425
+ <span><?php echo $val['label'] ?></span>
426
+ <select id="frmsc_<?php echo $shortcode .'_'. $opt ?>">
427
+ <?php foreach ( $val['opts'] as $select_opt => $select_label ) { ?>
428
+ <option value="<?php echo esc_attr($select_opt) ?>"><?php echo $select_label ?></option>
429
+ <?php } ?>
430
+ </select>
431
+ </label>
432
+ </li>
433
+ <?php } else { ?>
434
+ <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>
435
+ <?php
436
+ }
437
+ }
438
+ ?>
439
+ </ul>
440
+ <?php
441
+ }
442
+ echo '</div>';
443
 
444
  die();
445
  }
685
  return $errors;
686
  }
687
 
688
+ if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-toplevel_page_formidable' ) ) {
689
+ $frm_settings = FrmAppHelper::get_settings();
690
+ $errors[] = $frm_settings->admin_permission;
691
  return $errors;
692
  }
693
 
738
  $values['form_key'] = $filename;
739
  $values['is_template'] = $template;
740
  $values['status'] = 'published';
741
+ if($default) $values['default_template'] = 1;
 
 
742
 
743
  include($templates[$i]);
744
 
745
  //get updated form
746
+ if ( isset($form) && $form ) {
747
  $old_id = $form->id;
748
  $form = FrmForm::getOne($form->id);
749
  } else {
781
  }
782
  }else{
783
  $action = FrmAppHelper::get_param($action);
 
 
 
 
784
  }
785
 
786
  add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
797
  case 'trash':
798
  case 'untrash':
799
  case 'destroy':
 
800
  case 'settings':
801
  case 'update_settings':
802
  return self::$action($vars);
classes/controllers/FrmHooksController.php CHANGED
@@ -26,21 +26,19 @@ class FrmHooksController{
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
- $class = new $c;
34
  foreach ( $hooks as $hook ) {
35
- $class->$hook();
36
  unset($hook);
37
  }
38
- unset($c, $class);
39
  }
40
 
41
  }
42
 
43
- public function load_hooks(){
44
  if ( ! is_admin() ) {
45
  add_filter('the_content', 'FrmAppController::page_route', 10);
46
  }
@@ -48,12 +46,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_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,7 +62,9 @@ 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', 1);
 
 
68
  add_action('frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 2);
69
 
70
  // Forms Controller
@@ -85,7 +85,7 @@ class FrmHooksController{
85
  add_filter('frm_show_entry_styles', 'FrmStylesController::show_entry_styles');
86
  }
87
 
88
- public function load_admin_hooks() {
89
  add_action('admin_menu', 'FrmAppController::menu', 1);
90
  add_action('admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
91
  add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
@@ -113,13 +113,13 @@ class FrmHooksController{
113
  // Forms Controller
114
  add_action('admin_menu', 'FrmFormsController::menu', 10);
115
  add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
 
116
 
117
  add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
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
 
124
  // Settings Controller
125
  add_action('admin_menu', 'FrmSettingsController::menu', 45);
@@ -137,7 +137,7 @@ class FrmHooksController{
137
  add_action('admin_menu', 'FrmXMLController::menu', 41);
138
  }
139
 
140
- public function load_ajax_hooks() {
141
  add_action('wp_ajax_frm_install', 'FrmAppController::install' );
142
  add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
143
  add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
@@ -183,7 +183,7 @@ class FrmHooksController{
183
  add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
184
  }
185
 
186
- public function load_form_hooks() {
187
  // Fields Controller
188
  add_filter('frm_field_type', 'FrmFieldsController::change_type');
189
  add_action('frm_field_input_html', 'FrmFieldsController::input_html');
@@ -194,11 +194,11 @@ class FrmHooksController{
194
  add_filter('frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
195
  }
196
 
197
- public function load_view_hooks() {
198
  // Hooks go here when a view is loaded
199
  }
200
 
201
- public function load_multisite_hooks() {
202
  // drop tables when mu site is deleted
203
  add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
204
  }
26
  // Make sure the hooks are only triggered once
27
  add_filter('frm'. str_replace('load', '', $trigger_hooks) .'_loaded', '__return_true');
28
  }
 
29
 
30
  // Instansiate Controllers
31
  foreach ( $controllers as $c ) {
 
32
  foreach ( $hooks as $hook ) {
33
+ $c::$hook();
34
  unset($hook);
35
  }
36
+ unset($c);
37
  }
38
 
39
  }
40
 
41
+ public static function load_hooks(){
42
  if ( ! is_admin() ) {
43
  add_filter('the_content', 'FrmAppController::page_route', 10);
44
  }
46
  add_action('plugins_loaded', 'FrmAppController::load_lang' );
47
  add_action('init', 'FrmAppController::front_head' );
48
  add_filter('widget_text', 'FrmAppController::widget_text_filter', 8 );
49
+ add_filter('get_frm_stylesheet', 'FrmAppController::custom_stylesheet' );
50
+
51
  add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
52
 
53
+ // Update the session data
54
+ add_action('init', 'FrmAppController::referer_session', 1);
 
 
55
 
56
  // Entries controller
57
  add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
62
  add_filter('frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4);
63
 
64
  // Form Actions Controller
65
+ add_action('init', 'FrmFormActionsController::register_post_types', 0);
66
+ add_action('init', 'FrmFormActionsController::actions_init', 1);
67
+ add_action('frm_form_actions_init', 'FrmFormActionsController::register_actions');
68
  add_action('frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 2);
69
 
70
  // Forms Controller
85
  add_filter('frm_show_entry_styles', 'FrmStylesController::show_entry_styles');
86
  }
87
 
88
+ public static function load_admin_hooks() {
89
  add_action('admin_menu', 'FrmAppController::menu', 1);
90
  add_action('admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
91
  add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
113
  // Forms Controller
114
  add_action('admin_menu', 'FrmFormsController::menu', 10);
115
  add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
116
+ add_action('frm_after_duplicate_form', 'FrmFormsController::after_duplicate', 10, 2);
117
 
118
  add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
119
  add_action('admin_footer', 'FrmFormsController::insert_form_popup' );
120
  add_filter('media_buttons_context', 'FrmFormsController::insert_form_button' );
121
 
122
+ add_filter('frm_admin_list_form_action', 'FrmFormsController::process_bulk_form_actions' );
 
123
 
124
  // Settings Controller
125
  add_action('admin_menu', 'FrmSettingsController::menu', 45);
137
  add_action('admin_menu', 'FrmXMLController::menu', 41);
138
  }
139
 
140
+ public static function load_ajax_hooks() {
141
  add_action('wp_ajax_frm_install', 'FrmAppController::install' );
142
  add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
143
  add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
183
  add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
184
  }
185
 
186
+ public static function load_form_hooks() {
187
  // Fields Controller
188
  add_filter('frm_field_type', 'FrmFieldsController::change_type');
189
  add_action('frm_field_input_html', 'FrmFieldsController::input_html');
194
  add_filter('frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
195
  }
196
 
197
+ public static function load_view_hooks() {
198
  // Hooks go here when a view is loaded
199
  }
200
 
201
+ public static function load_multisite_hooks() {
202
  // drop tables when mu site is deleted
203
  add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
204
  }
classes/controllers/FrmSettingsController.php CHANGED
@@ -31,18 +31,17 @@ class FrmSettingsController{
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,10 +60,9 @@ class FrmSettingsController{
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
  }
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
  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
  }
classes/controllers/FrmStylesController.php CHANGED
@@ -42,17 +42,20 @@ class FrmStylesController{
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,8 +92,6 @@ class FrmStylesController{
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,26 +265,6 @@ class FrmStylesController{
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,10 +284,6 @@ class FrmStylesController{
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,9 +299,6 @@ class FrmStylesController{
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]) ) {
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
  // 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
  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
  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
  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]) ) {
classes/controllers/FrmXMLController.php CHANGED
@@ -73,9 +73,9 @@ class FrmXMLController{
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,16 +137,18 @@ class FrmXMLController{
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']) ) {
144
  $ids = $_POST['frm_export_forms'];
 
 
145
  }
146
 
147
- $type = false;
148
- if ( isset($_POST['type']) ) {
149
  $type = $_POST['type'];
 
 
150
  }
151
 
152
  $format = isset($_POST['format']) ? $_POST['format'] : 'xml';
@@ -210,28 +212,27 @@ class FrmXMLController{
210
  $where = $join = '';
211
  $table = $tables[$tb_type];
212
 
213
- $select = $table .'.id';
214
 
215
  switch ( $tb_type ) {
216
  case 'forms':
217
  //add forms
 
218
  if ( $args['ids'] ){
219
- $where = ' ('. $table .'.id IN ('. $args['ids'] .') OR '. $table .'.parent_form_id IN ('. $args['ids'] .'))';
220
- } else {
221
- $where = $wpdb->prepare( $table .'.status != %s', 'draft' );
222
  }
223
  break;
224
  case 'actions':
225
- $select = $table .'.ID';
226
  $where = $wpdb->prepare('post_type=%s', FrmFormActionsController::$action_post_type);
227
  if ( ! empty($args['ids']) ) {
228
- $where .= ' AND menu_order IN ('. $args['ids'] .')';
229
  }
230
  break;
231
  case 'items':
232
  //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
233
  if ( $args['ids'] ) {
234
- $where = $table .'.form_id IN ('. $args['ids'] .')';
235
  }
236
  break;
237
  case 'styles':
@@ -243,28 +244,28 @@ class FrmXMLController{
243
  $style_ids[] = $form_data->options['custom_style'];
244
  unset( $form_id, $form_data );
245
  }
246
- $select = $table .'.ID';
247
  $where = $wpdb->prepare('post_type=%s', 'frm_styles');
248
 
249
  // Only export selected styles
250
  if ( ! empty( $style_ids ) ) {
251
- $where .= ' AND ID IN ('. implode( ',', $style_ids ) .')';
252
  }
253
  break;
254
  default:
255
- $select = $table .'.ID';
256
  $join = "INNER JOIN $wpdb->postmeta pm ON (pm.post_id=$table.ID)";
257
  $where = "pm.meta_key='frm_form_id' AND pm.meta_value ";
258
  if ( empty($args['ids']) ) {
259
- $where .= '> 0';
260
  } else {
261
- $where .= 'IN ('. $args['ids'] .')';
262
  }
263
  break;
264
  }
265
 
266
  if ( ! empty($where) ) {
267
- $where = 'WHERE '. $where;
268
  }
269
 
270
  $records[$tb_type] = $wpdb->get_col( "SELECT $select FROM $table $join $where" );
@@ -275,7 +276,7 @@ class FrmXMLController{
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';
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
  }
138
 
139
  public static function export_xml() {
140
+ FrmAppHelper::ajax_permission_check('frm_edit_forms', 'show');
141
 
142
+ if (isset($_POST['frm_export_forms'])) {
 
143
  $ids = $_POST['frm_export_forms'];
144
+ } else {
145
+ $ids = array();
146
  }
147
 
148
+ if ( isset($_POST['type']) ){
 
149
  $type = $_POST['type'];
150
+ } else {
151
+ $type = false;
152
  }
153
 
154
  $format = isset($_POST['format']) ? $_POST['format'] : 'xml';
212
  $where = $join = '';
213
  $table = $tables[$tb_type];
214
 
215
+ $select = "$table.id";
216
 
217
  switch ( $tb_type ) {
218
  case 'forms':
219
  //add forms
220
+ $where = $wpdb->prepare( "$table.status != %s" , 'draft' );
221
  if ( $args['ids'] ){
222
+ $where .= " AND $table.id IN (". $args['ids'] .")";
 
 
223
  }
224
  break;
225
  case 'actions':
226
+ $select = "$table.ID";
227
  $where = $wpdb->prepare('post_type=%s', FrmFormActionsController::$action_post_type);
228
  if ( ! empty($args['ids']) ) {
229
+ $where .= " AND menu_order IN (". $args['ids'] .")";
230
  }
231
  break;
232
  case 'items':
233
  //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
234
  if ( $args['ids'] ) {
235
+ $where = "$table.form_id IN (". $args['ids'] .")";
236
  }
237
  break;
238
  case 'styles':
244
  $style_ids[] = $form_data->options['custom_style'];
245
  unset( $form_id, $form_data );
246
  }
247
+ $select = "$table.ID";
248
  $where = $wpdb->prepare('post_type=%s', 'frm_styles');
249
 
250
  // Only export selected styles
251
  if ( ! empty( $style_ids ) ) {
252
+ $where .= " AND ID IN (". implode( ',', $style_ids ) .")";
253
  }
254
  break;
255
  default:
256
+ $select = "$table.ID";
257
  $join = "INNER JOIN $wpdb->postmeta pm ON (pm.post_id=$table.ID)";
258
  $where = "pm.meta_key='frm_form_id' AND pm.meta_value ";
259
  if ( empty($args['ids']) ) {
260
+ $where .= "> 0";
261
  } else {
262
+ $where .= "IN (". $args['ids'] .")";
263
  }
264
  break;
265
  }
266
 
267
  if ( ! empty($where) ) {
268
+ $where = "WHERE ". $where;
269
  }
270
 
271
  $records[$tb_type] = $wpdb->get_col( "SELECT $select FROM $table $join $where" );
276
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
277
  }
278
 
279
+ function allow_mime($mimes) {
280
  if ( !isset($mimes['csv']) ) {
281
  // allow csv files
282
  $mimes['csv'] = 'text/csv';
classes/helpers/FrmAppHelper.php CHANGED
@@ -2,14 +2,9 @@
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
15
  *
@@ -17,7 +12,18 @@ class FrmAppHelper{
17
  * @return float The version of this plugin
18
  */
19
  public static function plugin_version() {
20
- return self::$plug_version;
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
 
23
  public static function plugin_folder() {
@@ -83,7 +89,7 @@ class FrmAppHelper{
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,10 +232,6 @@ class FrmAppHelper{
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,9 +277,6 @@ class FrmAppHelper{
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,10 +339,6 @@ class FrmAppHelper{
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,7 +420,7 @@ class FrmAppHelper{
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,10 +480,8 @@ class FrmAppHelper{
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,41 +517,31 @@ class FrmAppHelper{
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,143 +565,42 @@ class FrmAppHelper{
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) {
@@ -766,9 +648,6 @@ class FrmAppHelper{
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,10 +709,6 @@ class FrmAppHelper{
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,14 +724,13 @@ class FrmAppHelper{
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,10 +746,6 @@ class FrmAppHelper{
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,13 +767,8 @@ class FrmAppHelper{
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,9 +932,6 @@ class FrmAppHelper{
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,9 +1210,6 @@ class FrmAppHelper{
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,9 +1246,6 @@ class FrmAppHelper{
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,9 +1307,6 @@ class FrmAppHelper{
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,9 +1314,6 @@ class FrmAppHelper{
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,13 +1345,12 @@ class FrmAppHelper{
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,8 +1361,8 @@ class FrmAppHelper{
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,10 +1395,6 @@ class FrmAppHelper{
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,15 +1424,6 @@ class FrmAppHelper{
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);
@@ -1676,6 +1512,13 @@ class FrmAppHelper{
1676
  return $string;
1677
  }
1678
 
 
 
 
 
 
 
 
1679
  /*
1680
  * @since 1.07.10
1681
  *
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 1.07.02
10
  *
12
  * @return float The version of this plugin
13
  */
14
  public static function plugin_version() {
15
+ $cache_key = 'frm_plugin_version';
16
+
17
+ // check caching layer first
18
+ $version = self::check_cache_and_transient($cache_key);
19
+
20
+ if ( ! $version ) {
21
+ $plugin_data = get_file_data( self::plugin_path() .'/formidable.php', array('Version' => 'Version'), 'plugin' );
22
+ $version = $plugin_data['Version'];
23
+ set_transient($cache_key, $version);
24
+ }
25
+
26
+ return $version;
27
  }
28
 
29
  public static function plugin_folder() {
89
  */
90
  public static function update_message($features, $class = ''){
91
  if ( ! self::pro_is_installed() ) {
92
+ include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
93
  }
94
  }
95
 
232
  /*
233
  * @since 2.0
234
  */
 
 
 
 
235
  public static function simple_get($action) {
236
  if ( $_GET && isset($_GET[$action]) ) {
237
  return $_GET[$action];
277
  return $value;
278
  }
279
 
 
 
 
280
  public static function trigger_hook_load( $type, $object = null ) {
281
  // only load the form hooks once
282
  $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object);
339
  /*
340
  * @since 2.0
341
  */
 
 
 
 
342
  public static function delete_cache_and_transient($cache_key) {
343
  delete_transient($cache_key);
344
  wp_cache_delete($cache_key);
420
  public static function post_edit_link($post_id) {
421
  $post = get_post($post_id);
422
  if ( $post ) {
423
+ return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. FrmAppHelper::truncate($post->post_title, 50) .'</a>';
424
  }
425
  return '';
426
  }
480
  if($needed_role == '-1')
481
  return false;
482
 
483
+ if($needed_role == '' or current_user_can($needed_role))
 
484
  return true;
 
485
 
486
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
487
  foreach ($roles as $role){
517
  * Return permission message and stop the action if no permission
518
  * @since 2.0
519
  */
520
+ public static function permission_check($permission) {
521
+ if ( ! current_user_can($permission) ) {
522
+ $frm_settings = self::get_settings();
523
+ wp_die($frm_settings->admin_permission);
 
 
 
 
 
 
 
524
  }
525
  }
526
 
527
  /*
528
+ * Check if the user has permision for action.
529
+ * Return permission message and stop the action if no permission
530
  * @since 2.0
 
531
  */
532
+ public static function ajax_permission_check($permission, $show_message = 'hide') {
533
+ if ( current_user_can($permission) ) {
534
+ return;
 
 
 
 
 
535
  }
536
 
537
+ if ( 'hide' == $show_message ) {
538
+ $message = '';
539
+ } else {
540
  $frm_settings = self::get_settings();
541
+ $message = $frm_settings->admin_permission;
542
  }
543
 
544
+ die($message);
545
  }
546
 
547
  public static function checked($values, $current){
565
  $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
566
  */
567
 
568
+ if ( ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current ) ) {
569
+ return true;
570
+ } else {
571
+ return false;
572
+ }
 
 
 
 
 
 
 
 
573
  }
574
 
575
+ /*
576
+ * Check if value is equal to any of the field options. If not, set it as the other_val.
577
+ * @return string
 
 
 
 
 
578
  */
579
+ public static function check_other_selected( $value, $field_options, $field_type, $opt_key = '' ){
580
+ if ( !$value ) {
581
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
  }
583
 
584
+ $other_val = '';
585
+ if ( $field_type == 'radio' ) {
586
+ //Check if field value equals any of the options. If not, set it as the other value.
587
+ foreach ( $field_options as $opt_key => $opt_val ) {
588
+ if ( is_array( $opt_val ) ) {
589
+ if ( $opt_val['value'] == $value ) {
590
+ return '';
 
 
 
 
 
 
 
 
 
 
591
  }
592
+ } else if ( $opt_val == $value ) {
 
 
593
  return '';
594
  } else {
595
+ $other_val = $value;
596
  }
597
+ unset($opt_key, $opt_val);
 
 
 
 
598
  }
599
+ } else if ( array_key_exists ( $opt_key , (array) $value ) && $value[$opt_key] ) {
600
+ $other_val = $value[$opt_key];
601
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
 
603
+ return $other_val;
 
 
 
 
604
  }
605
 
606
  public static function recursive_trim(&$value) {
648
  return $url;
649
  }
650
 
 
 
 
651
  public static function script_version($handle) {
652
  global $wp_scripts;
653
  if ( ! $wp_scripts ) {
709
  return $contents;
710
  }
711
 
 
 
 
 
712
  public static function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
713
  global $wpdb;
714
 
724
  $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
725
  }
726
 
727
+ if (is_numeric($key) or in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
728
  $key = $key .'a';
 
729
 
730
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
731
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
732
 
733
+ if ($key_check or is_numeric($key_check)){
734
  $suffix = 2;
735
  do {
736
  $alt_post_name = substr($key, 0, 200-(strlen($suffix)+1)). "$suffix";
746
  * Editing a Form or Entry
747
  * @return bool|array
748
  */
 
 
 
 
749
  public static function setup_edit_vars($record, $table, $fields='', $default=false, $post_values=array()){
750
  if ( ! $record ) {
751
  return false;
767
 
768
  $values['description'] = self::use_wpautop($values['description']);
769
  $frm_settings = self::get_settings();
 
770
 
771
  foreach ( (array) $fields as $field ) {
 
 
 
 
772
  self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
773
  }
774
 
932
  }
933
  }
934
 
 
 
 
935
  public static function get_meta_value($field_id, $entry) {
936
  if ( isset($entry->metas) ) {
937
  return isset($entry->metas[$field_id]) ? $entry->metas[$field_id] : false;
1210
  return $term;
1211
  }
1212
 
 
 
 
1213
  public static function esc_order($order_query) {
1214
  if ( empty($order_query) ) {
1215
  return '';
1246
  return ' ORDER BY '. $order . ' '. $order_by;
1247
  }
1248
 
 
 
 
1249
  public static function esc_limit($limit) {
1250
  if ( empty($limit) ) {
1251
  return '';
1307
  return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
1308
  }
1309
 
 
 
 
1310
  public static function getFirstRecordNum($r_count,$current_p,$p_size){
1311
  if($current_p == 1)
1312
  return 1;
1314
  return (self::getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
1315
  }
1316
 
 
 
 
1317
  public static function &getRecordCount($where = '', $table_name) {
1318
  $cache_key = 'count_'. $table_name .'_'. maybe_serialize($where);
1319
  $query = 'SELECT COUNT(*) FROM ' . $table_name . self::prepend_and_or_where(' WHERE ', $where);
1345
  $referrerinfo = '';
1346
  $keywords = array();
1347
  $i = 1;
1348
+ if(isset($_SESSION) and isset($_SESSION['frm_http_referer']) and $_SESSION['frm_http_referer']){
1349
  foreach ($_SESSION['frm_http_referer'] as $referer) {
1350
  $referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
1351
  $keywords_used = self::get_referer_query($referer);
1352
+ if ($keywords_used)
1353
  $keywords[] = $keywords_used;
 
1354
 
1355
  $i++;
1356
  }
1361
  }
1362
 
1363
  $i = 1;
1364
+ if(isset($_SESSION) and isset($_SESSION['frm_http_pages']) and $_SESSION['frm_http_pages']){
1365
+ foreach ($_SESSION['frm_http_pages'] as $page) {
1366
  $referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
1367
  $i++;
1368
  }
1395
  $l2 = $name;
1396
  }
1397
 
 
 
 
 
1398
  $this_val = ( $p == $last ) ? $jv['value'] : array();
1399
 
1400
  switch ( $p ) {
1424
  $vars[$l1][$l2][$l3] = $this_val;
1425
  }
1426
  break;
 
 
 
 
 
 
 
 
 
1427
  }
1428
 
1429
  unset($this_val, $n);
1512
  return $string;
1513
  }
1514
 
1515
+ public static function check_mem_use($function='', $start_mem=0) {
1516
+ $mem = memory_get_usage(true) - $start_mem;
1517
+
1518
+ //error_log($mem .' '. $function);
1519
+ return $start_mem + $mem;
1520
+ }
1521
+
1522
  /*
1523
  * @since 1.07.10
1524
  *
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,7 +96,6 @@ 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
- unset($opt, $value);
100
  }
101
  }
102
 
@@ -113,6 +112,18 @@ class FrmEntriesHelper{
113
 
114
  $values = array_merge($form_defaults, $values);
115
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  return apply_filters('frm_setup_new_entry', $values);
117
  }
118
 
@@ -240,11 +251,7 @@ class FrmEntriesHelper{
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,15 +299,12 @@ class FrmEntriesHelper{
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,131 +523,93 @@ class FrmEntriesHelper{
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,65 +638,4 @@ class FrmEntriesHelper{
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
  }
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
  }
100
  }
101
 
112
 
113
  $values = array_merge($form_defaults, $values);
114
 
115
+ if ( ! isset($values['before_html']) ) {
116