Formidable Forms – Form Builder for WordPress - Version 1.04.07

Version Description

  • Minor bug fixes
  • PRO: Fixed bug preventing some hidden field values from being saved
  • PRO: Removed PHP warnings some users were seeing on the form entries page
Download this release

Release Info

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

Code changes from version 1.03.03 to 1.04.07

Files changed (69) hide show
  1. classes/controllers/FrmApiController.php +4 -1
  2. classes/controllers/FrmAppController.php +84 -24
  3. classes/controllers/FrmEntriesController.php +10 -6
  4. classes/controllers/FrmFieldsController.php +68 -16
  5. classes/controllers/FrmFormsController.php +53 -22
  6. classes/controllers/FrmSettingsController.php +13 -6
  7. classes/controllers/FrmStatisticsController.php +4 -1
  8. classes/helpers/FrmAppHelper.php +27 -32
  9. classes/helpers/FrmEntriesHelper.php +5 -5
  10. classes/helpers/FrmFieldsHelper.php +88 -39
  11. classes/helpers/FrmFormsHelper.php +11 -30
  12. classes/models/FrmDb.php +52 -19
  13. classes/models/FrmEntry.php +102 -39
  14. classes/models/FrmEntryMeta.php +38 -50
  15. classes/models/FrmField.php +21 -11
  16. classes/models/FrmForm.php +12 -11
  17. classes/models/FrmNotification.php +18 -11
  18. classes/models/FrmSettings.php +60 -10
  19. classes/models/FrmUpdate.php +21 -21
  20. classes/recaptchalib.php +277 -0
  21. classes/templates/contact.php +16 -16
  22. classes/views/frm-entries/direct.php +2 -2
  23. classes/views/frm-entries/form.php +54 -43
  24. classes/views/frm-entries/frm-entry.php +21 -5
  25. classes/views/frm-entries/list.php +2 -2
  26. classes/views/frm-entries/new.php +11 -11
  27. classes/views/frm-fields/input.php +36 -20
  28. classes/views/frm-fields/show.php +1 -1
  29. classes/views/frm-fields/single-option.php +6 -6
  30. classes/views/frm-forms/add_field.php +39 -36
  31. classes/views/frm-forms/add_field_links.php +34 -35
  32. classes/views/frm-forms/default-templates.php +3 -3
  33. classes/views/frm-forms/edit.php +23 -15
  34. classes/views/frm-forms/footer.php +14 -110
  35. classes/views/frm-forms/form.php +36 -29
  36. classes/views/frm-forms/insert_form_popup.php +69 -0
  37. classes/views/frm-forms/list.php +44 -36
  38. classes/views/frm-forms/new-option-js.php +1 -1
  39. classes/views/frm-forms/new-selection.php +3 -3
  40. classes/views/frm-forms/new.php +17 -15
  41. classes/views/frm-settings/form.php +74 -21
  42. classes/views/frm-statistics/list.php +2 -2
  43. classes/views/shared/errors.php +1 -1
  44. classes/views/shared/item-table-nav.php +1 -1
  45. css/frm_admin.css +93 -24
  46. css/frm_display.css +20 -10
  47. css/ui-lightness/{jquery-ui-1.7.2.custom.css → jquery-ui.css} +1 -43
  48. formidable.php +30 -13
  49. images/blackglass-captcha.png +0 -0
  50. images/clean-captcha.png +0 -0
  51. images/icon_16_bw.png +0 -0
  52. images/icon_color_arrow.gif +0 -0
  53. images/marker.png +0 -0
  54. images/mask.png +0 -0
  55. images/menu-bits-vs.gif +0 -0
  56. images/menuhoverbg.png +0 -0
  57. images/red-captcha.png +0 -0
  58. images/tr_icons_white.png +0 -0
  59. images/wheel.png +0 -0
  60. images/white-captcha.png +0 -0
  61. js/formidable.js +141 -73
  62. js/jquery/jquery-ui-themepicker.js +11 -85
  63. js/jquery/jquery.editinplace.js +6 -2
  64. js/jquery/jquery.editinplace.packed.js +1 -1
  65. languages/formidable-en_US.po +3758 -0
  66. languages/formidable-pt_BR.mo +0 -0
  67. languages/formidable-pt_BR.po +3758 -0
  68. languages/formidable-xx_XX.pot +1 -0
  69. readme.txt +113 -15
classes/controllers/FrmApiController.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
-
 
 
 
3
  class FrmApiController{
4
  function FrmApiController(){
5
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmApiController{
7
  function FrmApiController(){
8
  }
classes/controllers/FrmAppController.php CHANGED
@@ -1,14 +1,19 @@
1
  <?php
2
-
 
 
 
3
  class FrmAppController{
4
  function FrmAppController(){
5
  add_action('admin_menu', array( &$this, 'menu' ), 1);
 
6
  add_filter('frm_nav_array', array( &$this, 'frm_nav'), 1);
7
  add_filter('plugin_action_links_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( &$this, 'settings_link'), 10, 2 );
8
- add_action('after_plugin_row_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( &$this,'frmpro_action_needed'));
9
- add_action('admin_notices', array( &$this,'frmpro_get_started_headline'));
10
  add_filter('the_content', array( &$this, 'page_route' ), 1);
11
  add_action('init', array(&$this, 'front_head'));
 
12
  add_action('admin_init', array( &$this, 'admin_js'));
13
  register_activation_hook(FRM_PATH."/formidable.php", array( &$this, 'install' ));
14
  add_action('wp_ajax_frm_uninstall', array(&$this, 'uninstall') );
@@ -23,43 +28,51 @@ class FrmAppController{
23
 
24
  function menu(){
25
  if(current_user_can('administrator') and !current_user_can('frm_view_forms')){
26
- global $wp_roles;
27
  $frm_roles = FrmAppHelper::frm_capabilities();
28
  foreach($frm_roles as $frm_role => $frm_role_description)
29
- $wp_roles->add_cap( 'administrator', $frm_role );
30
  }
31
  global $frmpro_is_installed;
32
  if(current_user_can('frm_view_forms')){
33
  global $frm_forms_controller;
34
- add_menu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_forms', FRM_PLUGIN_NAME, array($frm_forms_controller,'route'), FRM_URL . '/images/icon_16.png');
35
  }elseif(current_user_can('frm_view_entries') and $frmpro_is_installed){
36
  global $frmpro_entries_controller;
37
- add_menu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_entries', FRM_PLUGIN_NAME, array($frmpro_entries_controller,'route'), FRM_URL . '/images/icon_16.png');
38
  }
39
  }
40
 
 
 
 
 
 
 
 
 
41
  function frm_nav(){
42
  $nav = array();
43
  if(current_user_can('frm_view_forms'))
44
- $nav[FRM_PLUGIN_NAME] = __('Forms', FRM_PLUGIN_NAME);
45
 
46
  if(current_user_can('frm_edit_forms'))
47
- $nav[FRM_PLUGIN_NAME . '-new'] = __('Create a Form', FRM_PLUGIN_NAME);
48
 
49
  if(current_user_can('frm_view_forms'))
50
- $nav[FRM_PLUGIN_NAME . '-templates'] = __('Templates', FRM_PLUGIN_NAME);
51
  return $nav;
52
  }
53
 
54
  // Adds a settings link to the plugins page
55
  function settings_link($links, $file){
56
- $settings = '<a href="'.admin_url('admin.php?page='.FRM_PLUGIN_NAME).'">' . __('Settings', FRM_PLUGIN_NAME) . '</a>';
57
  array_unshift($links, $settings);
58
 
59
  return $links;
60
  }
61
 
62
- function frmpro_action_needed( $plugin ){
63
  global $frm_update;
64
 
65
  if( $frm_update->pro_is_authorized() and !$frm_update->pro_is_installed() ){
@@ -68,12 +81,12 @@ class FrmAppController{
68
  $frm_update->queue_update(true);
69
  $inst_install_url = wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $plugin, 'upgrade-plugin_' . $plugin);
70
  ?>
71
- <td colspan="3" class="plugin-update"><div class="update-message" style="-moz-border-radius:5px; border:1px solid #CC0000;; margin:5px; background-color:#FFEBE8; padding:3px 5px;"><?php printf(__('Your Formidable Pro installation isn\'t quite complete yet.<br/>%1$sAutomatically Upgrade to Enable Formidable Pro%2$s', FRM_PLUGIN_NAME), '<a href="'.$inst_install_url.'">', '</a>'); ?></div></td>
72
  <?php
73
  }
74
  }
75
 
76
- function frmpro_get_started_headline(){
77
  global $frm_update;
78
 
79
  // Don't display this error as we're upgrading the thing... cmon
@@ -82,12 +95,23 @@ class FrmAppController{
82
 
83
  if (IS_WPMU and $frm_update->pro_wpmu and !is_site_admin())
84
  return;
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  if( $frm_update->pro_is_authorized() and !$frm_update->pro_is_installed()){
87
  $frm_update->queue_update(true);
88
  $inst_install_url = wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $frm_update->plugin_name, 'upgrade-plugin_' . $frm_update->plugin_name);
89
  ?>
90
- <div class="error" style="padding:7px;"><?php printf(__('Your Formidable Pro installation isn\'t quite complete yet.<br/>%1$sAutomatically Upgrade to Enable Formidable Pro%2$s', FRM_PLUGIN_NAME), '<a href="'.$inst_install_url.'">','</a>'); ?></div>
91
  <?php
92
  }
93
  }
@@ -109,18 +133,52 @@ class FrmAppController{
109
  }
110
 
111
  function front_head(){
112
- global $frm_settings, $frm_version;
113
 
114
  if (IS_WPMU){
115
- $db_version = 1.03; // this is the version of the database we're moving to
116
  $old_db_version = get_option('frm_db_version');
117
- if ($db_version != $old_db_version)
118
  $this->install();
119
  }
 
120
 
121
- if(!is_admin() and !$frm_settings->custom_stylesheet){
122
- $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css');
123
- wp_enqueue_style('frm-forms', $css, array(), $frm_version);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
125
  }
126
 
@@ -134,8 +192,10 @@ class FrmAppController{
134
  global $frmdb;
135
  $frmdb->uninstall();
136
  wp_die(__('Formidable was successfully uninstalled.', 'formidable'));
137
- }else
138
- wp_die(__('You don\'t have permission to do that!', 'formidable'));
 
 
139
  }
140
 
141
  // Routes for wordpress pages -- we're just replacing content here folks.
@@ -167,7 +227,7 @@ class FrmAppController{
167
  function standalone_route($controller, $action=''){
168
  global $frm_forms_controller;
169
 
170
- if($controller=='forms' and $action != 'export' and $action != 'import')
171
  $frm_forms_controller->preview($this->get_param('form'));
172
  else
173
  do_action('frm_standalone_route', $controller, $action);
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmAppController{
7
  function FrmAppController(){
8
  add_action('admin_menu', array( &$this, 'menu' ), 1);
9
+ add_action('admin_head', array(&$this, 'menu_css'));
10
  add_filter('frm_nav_array', array( &$this, 'frm_nav'), 1);
11
  add_filter('plugin_action_links_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( &$this, 'settings_link'), 10, 2 );
12
+ add_action('after_plugin_row_'.FRM_PLUGIN_NAME.'/'.FRM_PLUGIN_NAME.'.php', array( &$this,'pro_action_needed'));
13
+ add_action('admin_notices', array( &$this,'pro_get_started_headline'));
14
  add_filter('the_content', array( &$this, 'page_route' ), 1);
15
  add_action('init', array(&$this, 'front_head'));
16
+ add_action('wp_footer', array(&$this, 'footer_js'), 1);
17
  add_action('admin_init', array( &$this, 'admin_js'));
18
  register_activation_hook(FRM_PATH."/formidable.php", array( &$this, 'install' ));
19
  add_action('wp_ajax_frm_uninstall', array(&$this, 'uninstall') );
28
 
29
  function menu(){
30
  if(current_user_can('administrator') and !current_user_can('frm_view_forms')){
31
+ global $current_user;
32
  $frm_roles = FrmAppHelper::frm_capabilities();
33
  foreach($frm_roles as $frm_role => $frm_role_description)
34
+ $current_user->add_cap( $frm_role );
35
  }
36
  global $frmpro_is_installed;
37
  if(current_user_can('frm_view_forms')){
38
  global $frm_forms_controller;
39
+ add_object_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_forms', FRM_PLUGIN_NAME, array($frm_forms_controller,'route'), 'div');
40
  }elseif(current_user_can('frm_view_entries') and $frmpro_is_installed){
41
  global $frmpro_entries_controller;
42
+ add_object_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_entries', FRM_PLUGIN_NAME, array($frmpro_entries_controller,'route'), 'div');
43
  }
44
  }
45
 
46
+ function menu_css(){ ?>
47
+ <style type="text/css">
48
+ #adminmenu .toplevel_page_formidable div.wp-menu-image{background: url(<?php echo FRM_IMAGES_URL ?>/icon_16_bw.png) no-repeat center;}
49
+ #adminmenu .toplevel_page_formidable:hover div.wp-menu-image{background: url(<?php echo FRM_IMAGES_URL ?>/icon_16.png) no-repeat center;}
50
+ </style>
51
+ <?php
52
+ }
53
+
54
  function frm_nav(){
55
  $nav = array();
56
  if(current_user_can('frm_view_forms'))
57
+ $nav[FRM_PLUGIN_NAME] = __('Forms', 'formidable');
58
 
59
  if(current_user_can('frm_edit_forms'))
60
+ $nav[FRM_PLUGIN_NAME . '-new'] = __('Create a Form', 'formidable');
61
 
62
  if(current_user_can('frm_view_forms'))
63
+ $nav[FRM_PLUGIN_NAME . '-templates'] = __('Templates', 'formidable');
64
  return $nav;
65
  }
66
 
67
  // Adds a settings link to the plugins page
68
  function settings_link($links, $file){
69
+ $settings = '<a href="'.admin_url('admin.php?page='.FRM_PLUGIN_NAME).'">' . __('Settings', 'formidable') . '</a>';
70
  array_unshift($links, $settings);
71
 
72
  return $links;
73
  }
74
 
75
+ function pro_action_needed( $plugin ){
76
  global $frm_update;
77
 
78
  if( $frm_update->pro_is_authorized() and !$frm_update->pro_is_installed() ){
81
  $frm_update->queue_update(true);
82
  $inst_install_url = wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $plugin, 'upgrade-plugin_' . $plugin);
83
  ?>
84
+ <td colspan="3" class="plugin-update"><div class="update-message" style="-moz-border-radius:5px; border:1px solid #CC0000;; margin:5px; background-color:#FFEBE8; padding:3px 5px;"><?php printf(__('Your Formidable Pro installation isn\'t quite complete yet.<br/>%1$sAutomatically Upgrade to Enable Formidable Pro%2$s', 'formidable'), '<a href="'.$inst_install_url.'">', '</a>'); ?></div></td>
85
  <?php
86
  }
87
  }
88
 
89
+ function pro_get_started_headline(){
90
  global $frm_update;
91
 
92
  // Don't display this error as we're upgrading the thing... cmon
95
 
96
  if (IS_WPMU and $frm_update->pro_wpmu and !is_site_admin())
97
  return;
98
+
99
+ if(!isset($_GET['activate'])){
100
+ global $frmpro_is_installed, $frm_db_version;
101
+ $db_version = get_option('frm_db_version');
102
+ $pro_db_version = ($frmpro_is_installed) ? get_option('frmpro_db_version') : false;
103
+ if((int)$db_version < (int)$frm_db_version or ($pro_db_version and (int)$pro_db_version < 4)){ //this number should match the db_version in FrmDb.php
104
+ ?>
105
+ <div class="error" style="padding:7px;"><?php _e('Your Formidable database needs to be updated.<br/>Please deactivate and reactivate the plugin to fix this.', 'formidable'); ?></div>
106
+ <?php
107
+ }
108
+ }
109
 
110
  if( $frm_update->pro_is_authorized() and !$frm_update->pro_is_installed()){
111
  $frm_update->queue_update(true);
112
  $inst_install_url = wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $frm_update->plugin_name, 'upgrade-plugin_' . $frm_update->plugin_name);
113
  ?>
114
+ <div class="error" style="padding:7px;"><?php printf(__('Your Formidable Pro installation isn\'t quite complete yet.<br/>%1$sAutomatically Upgrade to Enable Formidable Pro%2$s', 'formidable'), '<a href="'.$inst_install_url.'">','</a>'); ?></div>
115
  <?php
116
  }
117
  }
133
  }
134
 
135
  function front_head(){
136
+ global $frm_settings, $frm_version, $frm_db_version;
137
 
138
  if (IS_WPMU){
139
+ //$frm_db_version is the version of the database we're moving to
140
  $old_db_version = get_option('frm_db_version');
141
+ if ((int)$frm_db_version != (int)$old_db_version)
142
  $this->install();
143
  }
144
+ wp_enqueue_script('jquery');
145
 
146
+ if(!is_admin() and $frm_settings->load_style == 'all'){
147
+ $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css', 'header');
148
+ if(is_array($css)){
149
+ foreach($css as $css_key => $file)
150
+ wp_enqueue_style('frm-forms'.$css_key, $file, array(), $frm_version);
151
+ }else
152
+ wp_enqueue_style('frm-forms', $css, array(), $frm_version);
153
+
154
+ global $frm_css_loaded;
155
+ $frm_css_loaded = true;
156
+ }
157
+ }
158
+
159
+ function footer_js($location='footer'){
160
+ global $frm_load_css, $frm_settings, $frm_version, $frm_css_loaded;
161
+
162
+ if($frm_load_css and !is_admin() and ($frm_settings->load_style != 'none')){
163
+ if($frm_css_loaded)
164
+ $css = apply_filters('get_frm_stylesheet', '', $location);
165
+ else
166
+ $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css', $location);
167
+
168
+ if(!empty($css)){
169
+ echo "\n".'<script type="text/javascript">';
170
+ if(is_array($css)){
171
+ foreach($css as $css_key => $file){
172
+ echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\'frm-forms'. ($css_key + $frm_css_loaded) .'-css\' href=\''. $file. '\' type=\'text/css\' media=\'all\' /%3E"));';
173
+ //wp_enqueue_style('frm-forms'.$css_key, $file, array(), $frm_version);
174
+ }
175
+ }else{
176
+ echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\'frm-forms-css\' href=\''. $css. '\' type=\'text/css\' media=\'all\' /%3E"));';
177
+ }
178
+
179
+ //wp_enqueue_style('frm-forms', $css, array(), $frm_version);
180
+ echo '</script>'."\n";
181
+ }
182
  }
183
  }
184
 
192
  global $frmdb;
193
  $frmdb->uninstall();
194
  wp_die(__('Formidable was successfully uninstalled.', 'formidable'));
195
+ }else{
196
+ global $frm_settings;
197
+ wp_die($frm_settings->admin_permission);
198
+ }
199
  }
200
 
201
  // Routes for wordpress pages -- we're just replacing content here folks.
227
  function standalone_route($controller, $action=''){
228
  global $frm_forms_controller;
229
 
230
+ if($controller=='forms' and !in_array($action, array('export','import','xml')))
231
  $frm_forms_controller->preview($this->get_param('form'));
232
  else
233
  do_action('frm_standalone_route', $controller, $action);
classes/controllers/FrmEntriesController.php CHANGED
@@ -1,7 +1,9 @@
1
  <?php
2
-
 
 
 
3
  class FrmEntriesController{
4
- var $views;
5
 
6
  function FrmEntriesController(){
7
  add_action('admin_menu', array( &$this, 'menu' ), 20);
@@ -10,7 +12,7 @@ class FrmEntriesController{
10
  function menu(){
11
  global $frmpro_is_installed;
12
  if(!$frmpro_is_installed){
13
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' |'. __('Pro Entries', FRM_PLUGIN_NAME), __('Pro Entries', FRM_PLUGIN_NAME), 'administrator', FRM_PLUGIN_NAME.'-entries',array($this,'list_entries'));
14
  //add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-entries', array($this,'head'));
15
  }
16
  }
@@ -24,13 +26,15 @@ class FrmEntriesController{
24
  if ($id) $form = $frm_form->getOne($id);
25
  else if ($key) $form = $frm_form->getOne($key);
26
 
27
- $form_options = stripslashes_deep(maybe_unserialize($form->options));
28
  if (!$form or $form->is_template or $form->status == 'draft')
29
- return __('Please select a valid form', FRM_PLUGIN_NAME);
30
  else if ($form->logged_in and !$user_ID){
31
  global $frm_settings;
32
  return $frm_settings->login_msg;
33
- }else if($form->logged_in and $user_ID and isset($form_options['logged_in_role']) and $form_options['logged_in_role'] != ''){
 
 
 
34
  if(FrmAppHelper::user_has_permission($form_options['logged_in_role']))
35
  return FrmEntriesController::get_form(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php', $form, $title, $description);
36
  else{
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmEntriesController{
 
7
 
8
  function FrmEntriesController(){
9
  add_action('admin_menu', array( &$this, 'menu' ), 20);
12
  function menu(){
13
  global $frmpro_is_installed;
14
  if(!$frmpro_is_installed){
15
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' |'. __('Pro Entries', 'formidable'), __('Pro Entries', 'formidable'), 'administrator', FRM_PLUGIN_NAME.'-entries',array($this,'list_entries'));
16
  //add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-entries', array($this,'head'));
17
  }
18
  }
26
  if ($id) $form = $frm_form->getOne($id);
27
  else if ($key) $form = $frm_form->getOne($key);
28
 
 
29
  if (!$form or $form->is_template or $form->status == 'draft')
30
+ return __('Please select a valid form', 'formidable');
31
  else if ($form->logged_in and !$user_ID){
32
  global $frm_settings;
33
  return $frm_settings->login_msg;
34
+ }
35
+
36
+ $form_options = stripslashes_deep(maybe_unserialize($form->options));
37
+ if($form->logged_in and $user_ID and isset($form_options['logged_in_role']) and $form_options['logged_in_role'] != ''){
38
  if(FrmAppHelper::user_has_permission($form_options['logged_in_role']))
39
  return FrmEntriesController::get_form(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php', $form, $title, $description);
40
  else{
classes/controllers/FrmFieldsController.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
-
 
 
 
3
  class FrmFieldsController{
4
  function FrmFieldsController(){
5
  add_action('wp_ajax_frm_insert_field', array(&$this, 'create') );
@@ -8,6 +11,7 @@ class FrmFieldsController{
8
  add_action('wp_ajax_frm_mark_required', array(&$this, 'mark_required') );
9
  add_action('wp_ajax_frm_clear_on_focus', array(&$this, 'clear_on_focus') );
10
  add_action('wp_ajax_frm_default_blank', array(&$this, 'default_blank') );
 
11
  add_action('wp_ajax_frm_delete_field', array(&$this, 'destroy') );
12
  add_action('wp_ajax_frm_add_field_option',array(&$this, 'add_option'));
13
  add_action('wp_ajax_frm_field_option_ipe', array(&$this, 'edit_option') );
@@ -81,6 +85,33 @@ class FrmFieldsController{
81
  die();
82
  }
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  function destroy(){
85
  global $frm_field;
86
  $field_id = $frm_field->destroy($_POST['field_id']);
@@ -94,7 +125,10 @@ class FrmFieldsController{
94
  $id = $_POST['field_id'];
95
  $field = $frm_field->getOne($id);
96
  $options = unserialize($field->options);
97
- $last = max(array_keys($options));
 
 
 
98
  $opt_key = $last + 1;
99
  $opt = 'Option '.(count($options)+1);
100
  $options[$opt_key] = $opt;
@@ -146,6 +180,11 @@ class FrmFieldsController{
146
 
147
  if ($frmpro_is_installed) return $type;
148
 
 
 
 
 
 
149
  $frm_field_selection = FrmFieldsHelper::field_selection();
150
  $types = array_keys($frm_field_selection);
151
  if (!in_array($type, $types) && $type != 'captcha')
@@ -175,24 +214,37 @@ class FrmFieldsController{
175
  $class = $field['type'];
176
  if($field['type'] == 'date')
177
  $class .= " frm_date";
178
-
179
- $action = FrmAppHelper::get_param('action');
180
- if(isset($field['required']) and $field['required']){
181
- if($field['type'] == 'file' and $action == 'edit'){
182
- //don't add the required class if this is a file upload when editing
183
- }else
184
- $class .= " required";
185
- }
186
-
187
- if(isset($field['size']) and $field['size'] > 0){
188
- if($field['type'] != 'textarea')
189
  echo ' size="'. $field['size'] .'"';
190
  $class .= " auto_width";
191
  }
192
- if(isset($field['max']) and !in_array($field['type'], array('textarea','rte')))
 
193
  echo ' maxlength="'. $field['max'] .'"';
194
- if(isset($field['clear_on_focus']) and $field['clear_on_focus'])
195
- echo ' onfocus="frmClearDefault(\''.$field['default_value'].'\', this)" onblur="frmReplaceDefault(\''.$field['default_value'].'\', this)"';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  echo ' class="'.$class.'"';
197
  }
198
  }
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmFieldsController{
7
  function FrmFieldsController(){
8
  add_action('wp_ajax_frm_insert_field', array(&$this, 'create') );
11
  add_action('wp_ajax_frm_mark_required', array(&$this, 'mark_required') );
12
  add_action('wp_ajax_frm_clear_on_focus', array(&$this, 'clear_on_focus') );
13
  add_action('wp_ajax_frm_default_blank', array(&$this, 'default_blank') );
14
+ add_action('wp_ajax_frm_duplicate_field', array(&$this, 'duplicate') );
15
  add_action('wp_ajax_frm_delete_field', array(&$this, 'destroy') );
16
  add_action('wp_ajax_frm_add_field_option',array(&$this, 'add_option'));
17
  add_action('wp_ajax_frm_field_option_ipe', array(&$this, 'edit_option') );
85
  die();
86
  }
87
 
88
+ function duplicate(){
89
+ global $frmdb, $frm_field, $frm_app_helper, $frm_ajax_url;
90
+
91
+ $copy_field = $frm_field->getOne($_POST['field_id']);
92
+ if (!$copy_field) return;
93
+
94
+ $values = array();
95
+ $values['field_key'] = FrmAppHelper::get_unique_key('', $frmdb->fields, 'field_key');
96
+ $values['field_options'] = unserialize($copy_field->field_options);
97
+ $values['form_id'] = $copy_field->form_id;
98
+ foreach (array('name','description','type','default_value','options','required') as $col)
99
+ $values[$col] = $copy_field->{$col};
100
+ $field_count = $frm_app_helper->getRecordCount("form_id=$copy_field->form_id", $frmdb->fields);
101
+ $values['field_order'] = $field_count + 1;
102
+
103
+ $field_id = $frm_field->create($values);
104
+
105
+ if ($field_id){
106
+ $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id));
107
+ $field_name = "item_meta[$field_id]";
108
+ $id = $field['form_id'];
109
+ require(FRM_VIEWS_PATH.'/frm-forms/add_field.php');
110
+ require(FRM_VIEWS_PATH.'/frm-forms/new-field-js.php');
111
+ }
112
+ die();
113
+ }
114
+
115
  function destroy(){
116
  global $frm_field;
117
  $field_id = $frm_field->destroy($_POST['field_id']);
125
  $id = $_POST['field_id'];
126
  $field = $frm_field->getOne($id);
127
  $options = unserialize($field->options);
128
+ if(!empty($options))
129
+ $last = max(array_keys($options));
130
+ else
131
+ $last = 0;
132
  $opt_key = $last + 1;
133
  $opt = 'Option '.(count($options)+1);
134
  $options[$opt_key] = $opt;
180
 
181
  if ($frmpro_is_installed) return $type;
182
 
183
+ if($type == 'scale' || $type == '10radio')
184
+ $type = 'radio';
185
+ else if($type == 'rte')
186
+ $type = 'textarea';
187
+
188
  $frm_field_selection = FrmFieldsHelper::field_selection();
189
  $types = array_keys($frm_field_selection);
190
  if (!in_array($type, $types) && $type != 'captcha')
214
  $class = $field['type'];
215
  if($field['type'] == 'date')
216
  $class .= " frm_date";
217
+
218
+ if(isset($field['size']) and $field['size'] > 0){
219
+ if($field['type'] != 'textarea' and $field['type'] != 'select')
 
 
 
 
 
 
 
 
220
  echo ' size="'. $field['size'] .'"';
221
  $class .= " auto_width";
222
  }
223
+
224
+ if(isset($field['max']) and !in_array($field['type'], array('textarea','rte')) and !empty($field['max']))
225
  echo ' maxlength="'. $field['max'] .'"';
226
+
227
+ if(!is_admin() or !isset($_GET) or !isset($_GET['page']) or $_GET['page'] == 'formidable_entries'){
228
+ $action = FrmAppHelper::get_param('action');
229
+ if(isset($field['required']) and $field['required']){
230
+ //echo ' required="required"';
231
+ if($field['type'] == 'file' and $action == 'edit'){
232
+ //don't add the required class if this is a file upload when editing
233
+ }else
234
+ $class .= " required";
235
+ }
236
+
237
+ if(isset($field['default_value']) and !empty($field['default_value']) and !in_array($field['type'], array('select','radio','checkbox','hidden')))
238
+ echo ' placeholder="'.$field['default_value'].'"';
239
+
240
+ if(isset($field['clear_on_focus']) and $field['clear_on_focus']){
241
+ echo ' onfocus="frmClearDefault(\''.$field['default_value'].'\', this)" onblur="frmReplaceDefault(\''.$field['default_value'].'\', this)"';
242
+
243
+ if($field['value'] == $field['default_value'])
244
+ echo ' style="font-style:italic;"';
245
+ }
246
+ }
247
+
248
  echo ' class="'.$class.'"';
249
  }
250
  }
classes/controllers/FrmFormsController.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
-
 
 
 
3
  class FrmFormsController{
4
  function FrmFormsController(){
5
  add_action('admin_menu', array( &$this, 'menu' ));
@@ -9,30 +12,34 @@ class FrmFormsController{
9
  add_action('wp_ajax_frm_form_name_in_place_edit', array(&$this, 'edit_name') );
10
  add_action('wp_ajax_frm_form_desc_in_place_edit', array(&$this, 'edit_description') );
11
  add_action('wp_ajax_frm_delete_form_wo_fields',array(&$this, 'destroy_wo_fields'));
 
 
 
12
  }
13
 
14
  function menu(){
15
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Forms', FRM_PLUGIN_NAME), __('Forms', FRM_PLUGIN_NAME), 'frm_view_forms', FRM_PLUGIN_NAME, array(&$this,'route'));
16
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Create a Form', FRM_PLUGIN_NAME), __('Create a Form', FRM_PLUGIN_NAME), 'frm_edit_forms', FRM_PLUGIN_NAME.'-new', array(&$this,'new_form'));
17
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Templates', FRM_PLUGIN_NAME), __('Templates', FRM_PLUGIN_NAME), 'frm_view_forms', FRM_PLUGIN_NAME.'-templates', array(&$this, 'template_list'));
18
  }
19
 
20
  function head(){
21
  global $frm_settings;
22
- if(!$frm_settings->custom_stylesheet)
23
- $css_file = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css');
24
  $js_file = array(FRM_URL . '/js/jquery/jquery-ui-themepicker.js', FRM_URL.'/js/jquery/jquery.editinplace.packed.js');
25
  require(FRM_VIEWS_PATH . '/shared/head.php');
26
  }
27
 
28
  function list_form(){
29
  $params = $this->get_params();
30
- $errors = apply_filters('frm_admin_list_form_action', $errors);
31
  return $this->display_forms_list($params, '', false, false, $errors);
32
  }
33
 
34
  function template_list(){
35
  $_POST['template'] = 1;
 
36
  return $this->display_forms_list();
37
  }
38
 
@@ -65,9 +72,8 @@ class FrmFormsController{
65
  $values = FrmAppHelper::setup_edit_vars($record,'forms',$fields,true);
66
  require_once(FRM_VIEWS_PATH.'/frm-forms/new.php');
67
  }else{
68
- $items = $frm_entry->getAll('',' ORDER BY it.name');
69
  $record = $frm_form->update( $id, $_POST, true );
70
- $message = __('Form was Successfully Created', FRM_PLUGIN_NAME);
71
  $params = $this->get_params();
72
  return $this->display_forms_list($params, $message);
73
  }
@@ -102,7 +108,7 @@ class FrmFormsController{
102
  return $this->get_edit_vars($id, $errors);
103
  }else{
104
  $record = $frm_form->update( $_POST['id'], $_POST );
105
- $message = __('Form was Successfully Updated', FRM_PLUGIN_NAME);
106
  return $this->get_edit_vars($id, '', $message);
107
  }
108
  }
@@ -112,11 +118,11 @@ class FrmFormsController{
112
 
113
  $params = $this->get_params();
114
  $record = $frm_form->duplicate( $params['id'], $params['template'] );
115
- $message = ($params['template']) ? __('Form template was Successfully Created', FRM_PLUGIN_NAME) : __('Form was Successfully Copied', FRM_PLUGIN_NAME);
116
  if ($record)
117
  return $this->get_edit_vars($record, '', $message, true);
118
  else
119
- return $this->display_forms_list($params, __('There was a problem creating new template.', FRM_PLUGIN_NAME));
120
  }
121
 
122
  function page_preview(){
@@ -146,20 +152,22 @@ class FrmFormsController{
146
  if (!$form) $form = $frm_form->getAll('','',' LIMIT 1');
147
  $form_options = stripslashes_deep(maybe_unserialize($form->options));
148
  $description = $title = true;
149
- $custom_style = (isset($form_options['custom_style'])) ? $form_options['custom_style'] : $frm_settings->custom_style;
150
 
151
  require_once(FRM_VIEWS_PATH.'/frm-entries/direct.php');
152
  }
153
 
154
  function destroy(){
155
- if(!current_user_can('frm_delete_forms'))
156
- wp_die(__('You don\'t have permission to delete forms', 'formidable'));
 
 
157
 
158
  global $frm_form;
159
  $params = $this->get_params();
160
  $message = '';
161
  if ($frm_form->destroy( $params['id'] ))
162
- $message = __('Form was Successfully Deleted', FRM_PLUGIN_NAME);
163
  $this->display_forms_list($params, $message, '', 1);
164
  }
165
 
@@ -170,6 +178,30 @@ class FrmFormsController{
170
  $frm_form->destroy($id);
171
  die();
172
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
175
  global $wpdb, $frmdb, $frm_app_helper, $frm_form, $frm_entry, $frm_page_size, $frmpro_is_installed;
@@ -181,7 +213,7 @@ class FrmFormsController{
181
  $message = FrmAppHelper::frm_get_main_message();
182
 
183
  $controller_file = FRM_PLUGIN_NAME;
184
- $page_params = '';
185
  $where_clause = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ".$params['template'];
186
 
187
  if ($params['template']){
@@ -197,9 +229,9 @@ class FrmFormsController{
197
  $current_page = $params['paged'];
198
 
199
  if($page_params_ov)
200
- $page_params = $page_params_ov;
201
  else
202
- $page_params = $form_vars['page_params'];
203
 
204
  $sort_str = $form_vars['sort_str'];
205
  $sdir_str = $form_vars['sdir_str'];
@@ -275,12 +307,11 @@ class FrmFormsController{
275
  function get_edit_vars($id, $errors = '', $message='', $create_link=false){
276
  global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed, $frm_ajax_url;
277
  $record = $frm_form->getOne( $id );
278
- $items = $frm_entry->getAll('',' ORDER BY it.name');
279
  $frm_field_selection = FrmFieldsHelper::field_selection();
280
  $fields = $frm_field->getAll("fi.form_id=$id", ' ORDER BY field_order');
281
  $values = FrmAppHelper::setup_edit_vars($record,'forms',$fields,true);
282
  if (isset($values['default_template']) && $values['default_template'])
283
- wp_die(__('That template cannot be edited', FRM_PLUGIN_NAME));
284
  else if($create_link)
285
  require_once(FRM_VIEWS_PATH.'/frm-forms/new.php');
286
  else
@@ -312,7 +343,7 @@ class FrmFormsController{
312
  $values['status'] = 'published';
313
  if($default) $values['default_template'] = 1;
314
 
315
- require_once($templates[$i]);
316
  }
317
  }
318
 
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmFormsController{
7
  function FrmFormsController(){
8
  add_action('admin_menu', array( &$this, 'menu' ));
12
  add_action('wp_ajax_frm_form_name_in_place_edit', array(&$this, 'edit_name') );
13
  add_action('wp_ajax_frm_form_desc_in_place_edit', array(&$this, 'edit_description') );
14
  add_action('wp_ajax_frm_delete_form_wo_fields',array(&$this, 'destroy_wo_fields'));
15
+ add_filter('frm_submit_button', array(&$this, 'submit_button_label'));
16
+ add_filter('media_buttons_context', array(&$this,'insert_form_button'));
17
+ add_action('admin_footer', array(&$this, 'insert_form_popup'));
18
  }
19
 
20
  function menu(){
21
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Forms', 'formidable'), __('Forms', 'formidable'), 'frm_view_forms', FRM_PLUGIN_NAME, array(&$this,'route'));
22
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Create a Form', 'formidable'), __('Create a Form', 'formidable'), 'frm_edit_forms', FRM_PLUGIN_NAME.'-new', array(&$this,'new_form'));
23
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Templates', 'formidable'), __('Templates', 'formidable'), 'frm_view_forms', FRM_PLUGIN_NAME.'-templates', array(&$this, 'template_list'));
24
  }
25
 
26
  function head(){
27
  global $frm_settings;
28
+ if($frm_settings->load_style != 'none')
29
+ $css_file = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css', 'header');
30
  $js_file = array(FRM_URL . '/js/jquery/jquery-ui-themepicker.js', FRM_URL.'/js/jquery/jquery.editinplace.packed.js');
31
  require(FRM_VIEWS_PATH . '/shared/head.php');
32
  }
33
 
34
  function list_form(){
35
  $params = $this->get_params();
36
+ $errors = apply_filters('frm_admin_list_form_action', array());
37
  return $this->display_forms_list($params, '', false, false, $errors);
38
  }
39
 
40
  function template_list(){
41
  $_POST['template'] = 1;
42
+ $errors = apply_filters('frm_admin_list_form_action', array());
43
  return $this->display_forms_list();
44
  }
45
 
72
  $values = FrmAppHelper::setup_edit_vars($record,'forms',$fields,true);
73
  require_once(FRM_VIEWS_PATH.'/frm-forms/new.php');
74
  }else{
 
75
  $record = $frm_form->update( $id, $_POST, true );
76
+ $message = __('Form was Successfully Created', 'formidable');
77
  $params = $this->get_params();
78
  return $this->display_forms_list($params, $message);
79
  }
108
  return $this->get_edit_vars($id, $errors);
109
  }else{
110
  $record = $frm_form->update( $_POST['id'], $_POST );
111
+ $message = __('Form was Successfully Updated', 'formidable');
112
  return $this->get_edit_vars($id, '', $message);
113
  }
114
  }
118
 
119
  $params = $this->get_params();
120
  $record = $frm_form->duplicate( $params['id'], $params['template'] );
121
+ $message = ($params['template']) ? __('Form template was Successfully Created', 'formidable') : __('Form was Successfully Copied', 'formidable');
122
  if ($record)
123
  return $this->get_edit_vars($record, '', $message, true);
124
  else
125
+ return $this->display_forms_list($params, __('There was a problem creating new template.', 'formidable'));
126
  }
127
 
128
  function page_preview(){
152
  if (!$form) $form = $frm_form->getAll('','',' LIMIT 1');
153
  $form_options = stripslashes_deep(maybe_unserialize($form->options));
154
  $description = $title = true;
155
+ $custom_style = (isset($form_options['custom_style'])) ? $form_options['custom_style'] : ($frm_settings->load_style != 'none');
156
 
157
  require_once(FRM_VIEWS_PATH.'/frm-entries/direct.php');
158
  }
159
 
160
  function destroy(){
161
+ if(!current_user_can('frm_delete_forms')){
162
+ global $frm_settings;
163
+ wp_die($frm_settings->admin_permission);
164
+ }
165
 
166
  global $frm_form;
167
  $params = $this->get_params();
168
  $message = '';
169
  if ($frm_form->destroy( $params['id'] ))
170
+ $message = __('Form was Successfully Deleted', 'formidable');
171
  $this->display_forms_list($params, $message, '', 1);
172
  }
173
 
178
  $frm_form->destroy($id);
179
  die();
180
  }
181
+
182
+ function submit_button_label($submit){
183
+ if (!$submit or empty($submit)){
184
+ global $frm_settings;
185
+ $submit = $frm_settings->submit_value;
186
+ }
187
+ return $submit;
188
+ }
189
+
190
+ function insert_form_button($content){
191
+ $content .= '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox" title="' . __("Add Formidable Form", 'formidable') . '"><img src="'.FRM_IMAGES_URL.'/icon_16_bw.png" alt="' . __("Add Formidable Form", 'formidable') . '" /></a>';
192
+ return $content;
193
+ }
194
+
195
+ function insert_form_popup(){
196
+ $page = basename($_SERVER['PHP_SELF']);
197
+ if(in_array($page, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))){
198
+ if(class_exists('FrmProDisplay')){
199
+ global $frmpro_display;
200
+ $displays = $frmpro_display->getAll();
201
+ }
202
+ require_once(FRM_VIEWS_PATH.'/frm-forms/insert_form_popup.php');
203
+ }
204
+ }
205
 
206
  function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
207
  global $wpdb, $frmdb, $frm_app_helper, $frm_form, $frm_entry, $frm_page_size, $frmpro_is_installed;
213
  $message = FrmAppHelper::frm_get_main_message();
214
 
215
  $controller_file = FRM_PLUGIN_NAME;
216
+ $page_params = '&action=0&page=formidable';
217
  $where_clause = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ".$params['template'];
218
 
219
  if ($params['template']){
229
  $current_page = $params['paged'];
230
 
231
  if($page_params_ov)
232
+ $page_params .= $page_params_ov;
233
  else
234
+ $page_params .= $form_vars['page_params'];
235
 
236
  $sort_str = $form_vars['sort_str'];
237
  $sdir_str = $form_vars['sdir_str'];
307
  function get_edit_vars($id, $errors = '', $message='', $create_link=false){
308
  global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed, $frm_ajax_url;
309
  $record = $frm_form->getOne( $id );
 
310
  $frm_field_selection = FrmFieldsHelper::field_selection();
311
  $fields = $frm_field->getAll("fi.form_id=$id", ' ORDER BY field_order');
312
  $values = FrmAppHelper::setup_edit_vars($record,'forms',$fields,true);
313
  if (isset($values['default_template']) && $values['default_template'])
314
+ wp_die(__('That template cannot be edited', 'formidable'));
315
  else if($create_link)
316
  require_once(FRM_VIEWS_PATH.'/frm-forms/new.php');
317
  else
343
  $values['status'] = 'published';
344
  if($default) $values['default_template'] = 1;
345
 
346
+ include_once($templates[$i]);
347
  }
348
  }
349
 
classes/controllers/FrmSettingsController.php CHANGED
@@ -1,14 +1,17 @@
1
  <?php
2
-
 
 
 
3
  class FrmSettingsController{
4
  function FrmSettingsController(){
5
- add_action('admin_menu', array( &$this, 'menu' ), 25);
6
  add_action('admin_menu', array( &$this, 'pro_menu' ), 19);
7
  //add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-settings', array($this,'head'));
8
  }
9
 
10
  function menu(){
11
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Settings', FRM_PLUGIN_NAME), __('Settings', FRM_PLUGIN_NAME), 'frm_change_settings', FRM_PLUGIN_NAME.'-settings', array($this,'route'));
12
  }
13
 
14
  function pro_menu(){
@@ -20,13 +23,17 @@ class FrmSettingsController{
20
  }
21
 
22
  function display_form(){
23
- global $frm_settings, $frm_ajax_url;
24
  $frm_roles = FrmAppHelper::frm_capabilities();
 
 
 
 
25
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
26
  }
27
 
28
  function process_form(){
29
- global $frm_settings, $frm_ajax_url;
30
 
31
  //$errors = $frm_settings->validate($_POST,array());
32
  $errors = array();
@@ -34,7 +41,7 @@ class FrmSettingsController{
34
 
35
  if( empty($errors) ){
36
  $frm_settings->store();
37
- $message = __('Settings Saved', FRM_PLUGIN_NAME);
38
  }
39
  $frm_roles = FrmAppHelper::frm_capabilities();
40
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmSettingsController{
7
  function FrmSettingsController(){
8
+ add_action('admin_menu', array( &$this, 'menu' ), 26);
9
  add_action('admin_menu', array( &$this, 'pro_menu' ), 19);
10
  //add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-settings', array($this,'head'));
11
  }
12
 
13
  function menu(){
14
+ add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. __('Settings', 'formidable'), __('Settings', 'formidable'), 'frm_change_settings', FRM_PLUGIN_NAME.'-settings', array(&$this,'route'));
15
  }
16
 
17
  function pro_menu(){
23
  }
24
 
25
  function display_form(){
26
+ global $frm_settings, $frm_ajax_url, $frmpro_is_installed;
27
  $frm_roles = FrmAppHelper::frm_capabilities();
28
+
29
+ $uploads = wp_upload_dir();
30
+ $target_path = $uploads['basedir'] . "/formidable/css";
31
+
32
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
33
  }
34
 
35
  function process_form(){
36
+ global $frm_settings, $frm_ajax_url, $frmpro_is_installed;
37
 
38
  //$errors = $frm_settings->validate($_POST,array());
39
  $errors = array();
41
 
42
  if( empty($errors) ){
43
  $frm_settings->store();
44
+ $message = __('Settings Saved', 'formidable');
45
  }
46
  $frm_roles = FrmAppHelper::frm_capabilities();
47
  require_once(FRM_VIEWS_PATH . '/frm-settings/form.php');
classes/controllers/FrmStatisticsController.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
-
 
 
 
3
  class FrmStatisticsController{
4
  function FrmStatisticsController(){
5
  add_action('admin_menu', array( &$this, 'menu' ), 30);
1
  <?php
2
+ /**
3
+ * @package Formidable
4
+ */
5
+
6
  class FrmStatisticsController{
7
  function FrmStatisticsController(){
8
  add_action('admin_menu', array( &$this, 'menu' ), 30);
classes/helpers/FrmAppHelper.php CHANGED
@@ -8,17 +8,17 @@ class FrmAppHelper{
8
  }
9
 
10
  function get_pages(){
11
- return get_posts( array('post_type' => 'page', 'post_status' => 'published', 'numberposts' => 99, 'orderby' => 'title', 'order' => 'ASC'));
12
  }
13
 
14
- function wp_pages_dropdown($field_name, $page_id){
15
  $field_value = FrmAppHelper::get_param($field_name);
16
  $pages = FrmAppHelper::get_pages();
17
  ?>
18
  <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown frm-pages-dropdown">
19
  <option value=""></option>
20
  <?php foreach($pages as $page){ ?>
21
- <option value="<?php echo $page->ID; ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $page->ID) or (!isset($_POST[$field_name]) and $page_id == $page->ID))?' selected="selected"':''); ?>><?php echo $page->post_title; ?> </option>
22
  <?php } ?>
23
  </select>
24
  <?php
@@ -92,8 +92,12 @@ class FrmAppHelper{
92
  $max_slug_value = pow(36,$num_chars);
93
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
94
  $key = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
95
- }else
96
- $key = sanitize_title_with_dashes($name);
 
 
 
 
97
 
98
  if (is_numeric($key) or in_array($key, array('id','key','created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
99
  $key = $key .'a';
@@ -125,15 +129,22 @@ class FrmAppHelper{
125
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default_val));
126
  $values['description'] = wpautop($values['description']);
127
  $values['fields'] = array();
 
128
  if ($fields){
129
  foreach($fields as $field){
130
-
 
131
  if ($default)
132
  $meta_value = $field->default_value;
133
- else
134
- $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id, true);
135
-
136
- $field_options = stripslashes_deep(unserialize($field->field_options));
 
 
 
 
 
137
  $field_type = isset($_POST['field_options']['type_'.$field->id]) ? $_POST['field_options']['type_'.$field->id] : $field->type;
138
  $new_value = (isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $meta_value;
139
  $new_value = stripslashes_deep(maybe_unserialize($new_value));
@@ -144,7 +155,7 @@ class FrmAppHelper{
144
  'name' => stripslashes($field->name),
145
  'description' => stripslashes($field->description),
146
  'type' => apply_filters('frm_field_type',$field_type, $field),
147
- 'options' => str_replace('"', '&quot;', stripslashes_deep(unserialize($field->options))),
148
  'required' => $field->required,
149
  'field_key' => $field->field_key,
150
  'field_order' => $field->field_order,
@@ -153,9 +164,9 @@ class FrmAppHelper{
153
  foreach (array('size' => '', 'max' => '', 'label' => 'top', 'invalid' => '', 'required_indicator' => '*', 'blank' => '', 'clear_on_focus' => 0, 'custom_html' => '', 'default_blank' => 0) as $opt => $default_opt){
154
  $field_array[$opt] = ($_POST and isset($_POST['field_options'][$opt.'_'.$field->id]) ) ? $_POST['field_options'][$opt.'_'.$field->id] : (isset($field_options[$opt]) ? $field_options[$opt] : $default_opt);
155
  if($opt == 'blank' and $field_array[$opt] == '')
156
- $field_array[$opt] = $field_array['name'] . ' ' . __('can\'t be blank', FRM_PLUGIN_NAME);
157
  else if($opt == 'invalid' and $field_array[$opt] == '')
158
- $field_array[$opt] = $field_array['name'] . ' ' . __('is an invalid format', FRM_PLUGIN_NAME);
159
  }
160
 
161
  if ($field_array['custom_html'] == '')
@@ -180,7 +191,7 @@ class FrmAppHelper{
180
  }
181
 
182
  $email = get_option('admin_email');
183
- foreach (array('custom_style' => $frm_settings->custom_style, 'email_to' => $email) as $opt => $default){
184
  if (!isset($values[$opt]))
185
  $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
186
  }
@@ -193,7 +204,7 @@ class FrmAppHelper{
193
  $values['show_form'] = ($_POST and isset($_POST['options']['show_form'])) ? 1 : 0;
194
 
195
  if (!isset($values['custom_style']))
196
- $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->custom_style;
197
 
198
  if (!isset($values['akismet']))
199
  $values['akismet'] = ($_POST and isset($_POST['options']['akismet'])) ? 1 : 0;
@@ -217,7 +228,7 @@ class FrmAppHelper{
217
  include_once(ABSPATH."/wp-includes/class-IXR.php");
218
 
219
  $url = ($frmpro_is_installed) ? 'http://formidablepro.com/' : 'http://blog.strategy11.com/';
220
- $client = new IXR_Client($url.'xmlrpc.php');
221
 
222
  if ($client->query('frm.get_main_message'))
223
  $message = $client->getResponse();
@@ -225,22 +236,6 @@ class FrmAppHelper{
225
  return $message;
226
  }
227
 
228
- function display_recaptcha() {
229
- global $recaptcha_opt;
230
-
231
- $format = <<<END
232
- <script type='text/javascript'>var RecaptchaOptions={theme:'{$recaptcha_opt['re_theme_reg']}',lang:'{$recaptcha_opt['re_lang']}',tabindex:30};</script>
233
- END;
234
-
235
- $comment_string = <<<COMMENT_FORM
236
- <script type='text/javascript'>document.getElementById('recaptcha_table').style.direction='ltr';</script>
237
- COMMENT_FORM;
238
-
239
- $use_ssl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? true : false;
240
-
241
- echo $format . recaptcha_wp_get_html(isset($_GET['rerror'])?$_GET['rerror']:'', $use_ssl);
242
- }
243
-
244
  function truncate($str, $length, $minword = 3, $continue = '...'){
245
  $sub = '';
246
  $len = 0;
8
  }
9
 
10
  function get_pages(){
11
+ return get_posts( array('post_type' => 'page', 'post_status' => 'publish', 'numberposts' => 999, 'orderby' => 'title', 'order' => 'ASC'));
12
  }
13
 
14
+ function wp_pages_dropdown($field_name, $page_id, $truncate=false){
15
  $field_value = FrmAppHelper::get_param($field_name);
16
  $pages = FrmAppHelper::get_pages();
17
  ?>
18
  <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-dropdown frm-pages-dropdown">
19
  <option value=""></option>
20
  <?php foreach($pages as $page){ ?>
21
+ <option value="<?php echo $page->ID; ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $page->ID) or (!isset($_POST[$field_name]) and $page_id == $page->ID))?' selected="selected"':''); ?>><?php echo ($truncate)? substr($page->post_title, 0, $truncate) : $page->post_title; ?> </option>
22
  <?php } ?>
23
  </select>
24
  <?php
92
  $max_slug_value = pow(36,$num_chars);
93
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
94
  $key = base_convert( rand($min_slug_value,$max_slug_value), 10, 36 );
95
+ }else{
96
+ if(function_exists('sanitize_key'))
97
+ $key = sanitize_key($name);
98
+ else
99
+ $key = sanitize_title_with_dashes($name);
100
+ }
101
 
102
  if (is_numeric($key) or in_array($key, array('id','key','created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
103
  $key = $key .'a';
129
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default_val));
130
  $values['description'] = wpautop($values['description']);
131
  $values['fields'] = array();
132
+
133
  if ($fields){
134
  foreach($fields as $field){
135
+ $field_options = stripslashes_deep(unserialize($field->field_options));
136
+
137
  if ($default)
138
  $meta_value = $field->default_value;
139
+ else{
140
+ if($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field_options['post_field']) and $field_options['post_field']){
141
+ $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field_options['post_field'], $field_options['custom_field'], array('truncate' => false, 'type' => $field->type));
142
+ }else if(isset($record->metas))
143
+ $meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false;
144
+ else
145
+ $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id, true);
146
+ }
147
+
148
  $field_type = isset($_POST['field_options']['type_'.$field->id]) ? $_POST['field_options']['type_'.$field->id] : $field->type;
149
  $new_value = (isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $meta_value;
150
  $new_value = stripslashes_deep(maybe_unserialize($new_value));
155
  'name' => stripslashes($field->name),
156
  'description' => stripslashes($field->description),
157
  'type' => apply_filters('frm_field_type',$field_type, $field),
158
+ 'options' => str_replace('"', '&quot;', stripslashes_deep(maybe_unserialize($field->options))),
159
  'required' => $field->required,
160
  'field_key' => $field->field_key,
161
  'field_order' => $field->field_order,
164
  foreach (array('size' => '', 'max' => '', 'label' => 'top', 'invalid' => '', 'required_indicator' => '*', 'blank' => '', 'clear_on_focus' => 0, 'custom_html' => '', 'default_blank' => 0) as $opt => $default_opt){
165
  $field_array[$opt] = ($_POST and isset($_POST['field_options'][$opt.'_'.$field->id]) ) ? $_POST['field_options'][$opt.'_'.$field->id] : (isset($field_options[$opt]) ? $field_options[$opt] : $default_opt);
166
  if($opt == 'blank' and $field_array[$opt] == '')
167
+ $field_array[$opt] = $field_array['name'] . ' ' . __('cannot be blank', 'formidable');
168
  else if($opt == 'invalid' and $field_array[$opt] == '')
169
+ $field_array[$opt] = $field_array['name'] . ' ' . __('is an invalid format', 'formidable');
170
  }
171
 
172
  if ($field_array['custom_html'] == '')
191
  }
192
 
193
  $email = get_option('admin_email');
194
+ foreach (array('custom_style' => ($frm_settings->load_style != 'none'), 'email_to' => $email) as $opt => $default){
195
  if (!isset($values[$opt]))
196
  $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
197
  }
204
  $values['show_form'] = ($_POST and isset($_POST['options']['show_form'])) ? 1 : 0;
205
 
206
  if (!isset($values['custom_style']))
207
+ $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : ($frm_settings->load_style != 'none');
208
 
209
  if (!isset($values['akismet']))
210
  $values['akismet'] = ($_POST and isset($_POST['options']['akismet'])) ? 1 : 0;
228
  include_once(ABSPATH."/wp-includes/class-IXR.php");
229
 
230
  $url = ($frmpro_is_installed) ? 'http://formidablepro.com/' : 'http://blog.strategy11.com/';
231
+ $client = new IXR_Client($url.'xmlrpc.php', false, 80, 15);
232
 
233
  if ($client->query('frm.get_main_message'))
234
  $message = $client->getResponse();
236
  return $message;
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  function truncate($str, $length, $minword = 3, $continue = '...'){
240
  $sub = '';
241
  $len = 0;
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -15,9 +15,9 @@ class FrmEntriesHelper{
15
 
16
  $field_options = unserialize($field->field_options);
17
  if ($reset)
18
- $new_value = $default;
19
  else
20
- $new_value = ($_POST and isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $default;
21
 
22
  $new_value = stripslashes_deep(maybe_unserialize($new_value));
23
  if (!is_array($new_value))
@@ -57,7 +57,7 @@ class FrmEntriesHelper{
57
  }
58
 
59
  if (!isset($values['custom_style']))
60
- $values['custom_style'] = $frm_settings->custom_style;
61
 
62
  if (!isset($values['email_to']))
63
  $values['email_to'] = '';
@@ -84,7 +84,7 @@ class FrmEntriesHelper{
84
  //$values['description'] = unserialize( $record->description );
85
  $values['item_key'] = ($_POST and isset($_POST['item_key']))?$_POST['item_key']:$record->item_key;
86
  $values['form_id'] = $record->form_id;
87
- return apply_filters('frm_setup_edit_entry_vars', $values);
88
  }
89
 
90
  function entries_dropdown( $form_id, $field_name, $field_value='', $blank=true, $blank_label='', $onchange=false ){
@@ -97,7 +97,7 @@ class FrmEntriesHelper{
97
  <option value=""><?php echo $blank_label; ?></option>
98
  <?php } ?>
99
  <?php foreach($entries as $entry){ ?>
100
- <option value="<?php echo $entry->id; ?>" <?php selected($field_value, $entry->id); ?>><?php echo (!empty($entry->name)) ? stripslashes($entry->name) : $entry->item_key; ?></option>
101
  <?php } ?>
102
  </select>
103
  <?php
15
 
16
  $field_options = unserialize($field->field_options);
17
  if ($reset)
18
+ $new_value = $default;
19
  else
20
+ $new_value = ($_POST and isset($_POST['item_meta'][$field->id]) and $_POST['item_meta'][$field->id] != '') ? $_POST['item_meta'][$field->id] : $default;
21
 
22
  $new_value = stripslashes_deep(maybe_unserialize($new_value));
23
  if (!is_array($new_value))
57
  }
58
 
59
  if (!isset($values['custom_style']))
60
+ $values['custom_style'] = ($frm_settings->load_style != 'none');
61
 
62
  if (!isset($values['email_to']))
63
  $values['email_to'] = '';
84
  //$values['description'] = unserialize( $record->description );
85
  $values['item_key'] = ($_POST and isset($_POST['item_key']))?$_POST['item_key']:$record->item_key;
86
  $values['form_id'] = $record->form_id;
87
+ return apply_filters('frm_setup_edit_entry_vars', $values, $record);
88
  }
89
 
90
  function entries_dropdown( $form_id, $field_name, $field_value='', $blank=true, $blank_label='', $onchange=false ){
97
  <option value=""><?php echo $blank_label; ?></option>
98
  <?php } ?>
99
  <?php foreach($entries as $entry){ ?>
100
+ <option value="<?php echo $entry->id; ?>" <?php selected($field_value, $entry->id); ?>><?php echo substr((!empty($entry->name)) ? stripslashes($entry->name) : $entry->item_key, 0, 50); ?></option>
101
  <?php } ?>
102
  </select>
103
  <?php
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -4,37 +4,38 @@ class FrmFieldsHelper{
4
 
5
  function field_selection(){
6
  $fields = apply_filters('frm_available_fields', array(
7
- 'text' => __('Text Input (One Line)', FRM_PLUGIN_NAME),
8
- 'textarea' => __('Paragraph Input (Multiple Lines)', FRM_PLUGIN_NAME),
9
- 'checkbox' => __('Multiple Selection (Check Boxes)', FRM_PLUGIN_NAME),
10
- 'radio' => __('Select One (Radio)', FRM_PLUGIN_NAME),
11
- 'select' => __('Drop-Down (Select)', FRM_PLUGIN_NAME)
 
 
12
  ));
13
 
14
- if ( in_array('wp-recaptcha/wp-recaptcha.php', get_option('active_plugins')) )
15
- $fields['captcha'] = 'reCAPTCHA Field';
16
  return $fields;
17
  }
18
 
19
  function pro_field_selection(){
20
  return apply_filters('frm_pro_available_fields', array(
21
- 'divider' => __('Section Heading', FRM_PLUGIN_NAME),
22
- 'break' => __('Page Break', FRM_PLUGIN_NAME),
23
- 'file' => __('File Upload', FRM_PLUGIN_NAME),
24
- 'rte' => __('Rich Text Editor', FRM_PLUGIN_NAME),
25
- 'number' => __('Number', FRM_PLUGIN_NAME),
26
- 'phone' => __('Phone Number', FRM_PLUGIN_NAME),
27
- 'email' => __('Email Address', FRM_PLUGIN_NAME),
28
- 'date' => __('Date', FRM_PLUGIN_NAME),
29
- //'time' => 'Time',
30
- 'website' => __('Website/URL', FRM_PLUGIN_NAME),
31
- 'image' => __('Image URL', FRM_PLUGIN_NAME),
32
- '10radio' => __('Scale', FRM_PLUGIN_NAME),
33
- //'grid' => __('Grid', FRM_PLUGIN_NAME),
34
- 'data' => __('Data from Entries', FRM_PLUGIN_NAME),
35
- 'hidden' => __('Hidden Field', FRM_PLUGIN_NAME),
36
- 'user_id' => __('Hidden User Id', FRM_PLUGIN_NAME),
37
- 'tag' => __('Tags', FRM_PLUGIN_NAME)
 
38
  //'multiple' => 'Multiple Select Box', //http://code.google.com/p/jquery-asmselect/
39
  //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
40
  //'city_selector' => 'US State/County/City selector',
@@ -51,7 +52,7 @@ class FrmFieldsHelper{
51
  $key = FrmAppHelper::get_unique_key('', $frmdb->fields, 'field_key');
52
 
53
  $values = array();
54
- foreach (array('name' => __('Untitled', FRM_PLUGIN_NAME), 'description' => '', 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'', 'field_order' => $field_count+1, 'required' => false, 'blank' => __('Untitled can\'t be blank', FRM_PLUGIN_NAME), 'invalid' => __('Untitled is an invalid format', FRM_PLUGIN_NAME), 'form_id' => $form_id) as $var => $default)
55
  $values[$var] = $default;
56
 
57
  $values['field_options'] = array();
@@ -82,8 +83,8 @@ class FrmFieldsHelper{
82
  foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default)
83
  $values[$var] = FrmAppHelper::get_param($var, $default);
84
 
85
- $values['options'] = unserialize($record->options);
86
- $field_options = unserialize($record->field_options);
87
  $values['field_options'] = $field_options;
88
  $values['size'] = (isset($field_options['size']))?($field_options['size']):('');
89
  $values['max'] = (isset($field_options['max']))?($field_options['max']):('');
@@ -114,7 +115,7 @@ class FrmFieldsHelper{
114
  <span class="frm_required">[required_label]</span>
115
  </label>
116
  [input]
117
- [if description]<p class="description">[description]</p>[/if description]
118
  </div>
119
  DEFAULT_HTML;
120
  }else
@@ -123,11 +124,14 @@ DEFAULT_HTML;
123
  return apply_filters('frm_custom_html', $default_html, $type);
124
  }
125
 
126
- function replace_shortcodes($html, $field, $error_keys=array()){
127
  $field_name = "item_meta[". $field['id'] ."]";
128
  //replace [id]
129
  $html = str_replace('[id]', $field['id'], $html);
130
 
 
 
 
131
  //replace [description] and [required_label]
132
  $required = ($field['required'] == '0')?(''):($field['required_indicator']);
133
  foreach (array('description' => $field['description'], 'required_label' => $required) as $code => $value){
@@ -151,7 +155,7 @@ DEFAULT_HTML;
151
  $html = str_replace('[field_name]', $field['name'], $html);
152
 
153
  //replace [error_class]
154
- $error_class = in_array('field'.$field['id'], $error_keys) ? ' frm_blank_field':'';
155
  $html = str_replace('[error_class]', $error_class, $html);
156
 
157
  //replace [entry_key]
@@ -159,22 +163,67 @@ DEFAULT_HTML;
159
  $html = str_replace('[entry_key]', $entry_key, $html);
160
 
161
  //replace [input]
162
- ob_start();
163
- include(FRM_VIEWS_PATH.'/frm-fields/input.php');
164
- $contents = ob_get_contents();
165
- ob_end_clean();
166
- $html = str_replace('[input]', $contents, $html);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  return apply_filters('frm_replace_shortcodes', $html, $field);
169
  }
170
 
171
- function show_onfocus_js($field_id, $clear_on_focus){ ?>
172
- <a href="javascript:frm_clear_on_focus(<?php echo $field_id; ?>,<?php echo $clear_on_focus; ?>)" class="<?php echo ($clear_on_focus) ?'':'frm_inactive_icon '; ?>frm-show-hover" id="clear_field_<?php echo $field_id; ?>" title="<?php printf(__('Set this field to %1$sclear on click', FRM_PLUGIN_NAME), ($clear_on_focus) ? __('not ', FRM_PLUGIN_NAME) :'' ); ?>"><img src="<?php echo FRM_IMAGES_URL?>/reload.png"></a>
 
 
 
 
 
 
 
 
 
 
 
 
173
  <?php
174
  }
175
 
176
- function show_default_blank_js($field_id, $default_blank){ ?>
177
- <a href="javascript:frm_default_blank(<?php echo $field_id; ?>,<?php echo $default_blank ?>)" class="<?php echo ($default_blank) ?'':'frm_inactive_icon '; ?>frm-show-hover" id="default_blank_<?php echo $field_id; ?>" title="<?php printf(__('This default value should %1$sbe considered blank', FRM_PLUGIN_NAME), ($default_blank) ? __('not ', FRM_PLUGIN_NAME) :'' ); ?>"><img src="<?php echo FRM_IMAGES_URL?>/error.png"></a>
 
178
  <?php
179
  }
180
 
4
 
5
  function field_selection(){
6
  $fields = apply_filters('frm_available_fields', array(
7
+ 'text' => __('Text Input (One Line)', 'formidable'),
8
+ 'textarea' => __('Paragraph Input (Multiple Lines)', 'formidable'),
9
+ 'checkbox' => __('Multiple Selection (Check Boxes)', 'formidable'),
10
+ 'radio' => __('Select One (Radio)', 'formidable'),
11
+ 'select' => __('Drop-Down (Select)', 'formidable'),
12
+ 'captcha' => __('reCAPTCHA (SPAM Control)', 'formidable')
13
+ //'nucaptcha' => __('NuCaptcha (SPAM Control)', 'formidable')
14
  ));
15
 
 
 
16
  return $fields;
17
  }
18
 
19
  function pro_field_selection(){
20
  return apply_filters('frm_pro_available_fields', array(
21
+ 'divider' => __('Section Heading', 'formidable'),
22
+ 'break' => __('Page Break', 'formidable'),
23
+ 'file' => __('File Upload', 'formidable'),
24
+ 'rte' => __('Rich Text', 'formidable'),
25
+ 'number' => __('Number', 'formidable'),
26
+ 'phone' => __('Phone Number', 'formidable'),
27
+ 'email' => __('Email Address', 'formidable'),
28
+ 'date' => __('Date', 'formidable'),
29
+ 'time' => __('Time', 'formidable'),
30
+ 'url' => __('Website/URL', 'formidable'),
31
+ 'image' => __('Image URL', 'formidable'),
32
+ 'scale' => __('Scale', 'formidable'),
33
+ //'grid' => __('Grid', 'formidable'),
34
+ 'data' => __('Data from Entries', 'formidable'),
35
+ 'hidden' => __('Hidden Field', 'formidable'),
36
+ 'user_id' => __('Hidden User ID', 'formidable'),
37
+ 'html' => __('HTML', 'formidable'),
38
+ 'tag' => __('Tags', 'formidable')
39
  //'multiple' => 'Multiple Select Box', //http://code.google.com/p/jquery-asmselect/
40
  //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
41
  //'city_selector' => 'US State/County/City selector',
52
  $key = FrmAppHelper::get_unique_key('', $frmdb->fields, 'field_key');
53
 
54
  $values = array();
55
+ foreach (array('name' => __('Untitled', 'formidable'), 'description' => '', 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'', 'field_order' => $field_count+1, 'required' => false, 'blank' => __('Untitled cannot be blank', 'formidable'), 'invalid' => __('Untitled is an invalid format', 'formidable'), 'form_id' => $form_id) as $var => $default)
56
  $values[$var] = $default;
57
 
58
  $values['field_options'] = array();
83
  foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default)
84
  $values[$var] = FrmAppHelper::get_param($var, $default);
85
 
86
+ $field_options = maybe_unserialize($record->field_options);
87
+ $values['options'] = stripslashes_deep(maybe_unserialize($record->options));
88
  $values['field_options'] = $field_options;
89
  $values['size'] = (isset($field_options['size']))?($field_options['size']):('');
90
  $values['max'] = (isset($field_options['max']))?($field_options['max']):('');
115
  <span class="frm_required">[required_label]</span>
116
  </label>
117
  [input]
118
+ [if description]<div class="frm_description">[description]</div>[/if description]
119
  </div>
120
  DEFAULT_HTML;
121
  }else
124
  return apply_filters('frm_custom_html', $default_html, $type);
125
  }
126
 
127
+ function replace_shortcodes($html, $field, $error_keys=array(), $form=false){
128
  $field_name = "item_meta[". $field['id'] ."]";
129
  //replace [id]
130
  $html = str_replace('[id]', $field['id'], $html);
131
 
132
+ //replace [key]
133
+ $html = str_replace('[key]', $field['field_key'], $html);
134
+
135
  //replace [description] and [required_label]
136
  $required = ($field['required'] == '0')?(''):($field['required_indicator']);
137
  foreach (array('description' => $field['description'], 'required_label' => $required) as $code => $value){
155
  $html = str_replace('[field_name]', $field['name'], $html);
156
 
157
  //replace [error_class]
158
+ $error_class = (in_array('field'.$field['id'], $error_keys)) ? ' frm_blank_field':'';
159
  $html = str_replace('[error_class]', $error_class, $html);
160
 
161
  //replace [entry_key]
163
  $html = str_replace('[entry_key]', $entry_key, $html);
164
 
165
  //replace [input]
166
+ preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
167
+
168
+ foreach ($shortcodes[0] as $short_key => $tag){
169
+ $atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
170
+
171
+ if(!empty($shortcodes[2][$short_key])){
172
+ $tag = str_replace('[', '',$shortcodes[0][$short_key]);
173
+ $tag = str_replace(']', '', $tag);
174
+ $tags = explode(' ', $tag);
175
+ if(is_array($tags))
176
+ $tag = $tags[0];
177
+ }else
178
+ $tag = $shortcodes[1][$short_key];
179
+
180
+ $replace_with = '';
181
+
182
+ if($tag == 'input'){
183
+ if(isset($atts['opt'])) $atts['opt']--;
184
+ ob_start();
185
+ include(FRM_VIEWS_PATH.'/frm-fields/input.php');
186
+ $replace_with = ob_get_contents();
187
+ ob_end_clean();
188
+ }else if($tag == 'deletelink' and class_exists('FrmProEntriesController'))
189
+ $replace_with = FrmProEntriesController::entry_delete_link($atts);
190
+
191
+ $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
192
+ }
193
+
194
+ if($form){
195
+ $form = (array)$form;
196
+
197
+ //replace [form_key]
198
+ $html = str_replace('[form_key]', $form['form_key'], $html);
199
+
200
+ //replace [form_name]
201
+ $html = str_replace('[form_name]', $form['name'], $html);
202
+ }
203
 
204
  return apply_filters('frm_replace_shortcodes', $html, $field);
205
  }
206
 
207
+ function display_recaptcha($field, $error=null){
208
+ global $frm_settings;
209
+
210
+ if(!function_exists('recaptcha_get_html'))
211
+ require_once(FRM_PATH.'/classes/recaptchalib.php');
212
+ ?>
213
+ <script type="text/javascript">var RecaptchaOptions={theme:'<?php echo $frm_settings->re_theme ?>',lang:'<?php echo $frm_settings->re_lang ?>'};</script>
214
+ <div id="frm_field_<?php echo $field['id'] ?>_container"><?php echo recaptcha_get_html($frm_settings->pubkey, $error, is_ssl()) ?></div>
215
+ <?php
216
+ }
217
+
218
+ function show_onfocus_js($field_id, $clear_on_focus){
219
+ global $frm_ajax_url; ?>
220
+ <a href="javascript:frm_clear_on_focus(<?php echo $field_id; ?>,<?php echo $clear_on_focus; ?>,'<?php echo FRM_IMAGES_URL ?>','<?php echo $frm_ajax_url?>')" class="<?php echo ($clear_on_focus) ?'':'frm_inactive_icon '; ?>frm-show-hover" id="clear_field_<?php echo $field_id; ?>" title="<?php printf(__('Set this field to %1$sclear on click', 'formidable'), ($clear_on_focus) ? __('not', 'formidable').' ' :'' ); ?>"><img src="<?php echo FRM_IMAGES_URL?>/reload.png"></a>
221
  <?php
222
  }
223
 
224
+ function show_default_blank_js($field_id, $default_blank){
225
+ global $frm_ajax_url; ?>
226
+ <a href="javascript:frm_default_blank(<?php echo $field_id; ?>,<?php echo $default_blank ?>,'<?php echo FRM_IMAGES_URL ?>','<?php echo $frm_ajax_url?>')" class="<?php echo ($default_blank) ?'':'frm_inactive_icon '; ?>frm-show-hover" id="default_blank_<?php echo $field_id; ?>" title="<?php printf(__('This default value should %1$sbe considered blank', 'formidable'), ($default_blank) ? __('not', 'formidable').' ' :'' ); ?>"><img src="<?php echo FRM_IMAGES_URL?>/error.png"></a>
227
  <?php
228
  }
229
 
classes/helpers/FrmFormsHelper.php CHANGED
@@ -13,13 +13,13 @@ class FrmFormsHelper{
13
 
14
  function get_template_dropdown($templates){ ?>
15
  <select id="select_form" name="select_form" onChange='createFromFrmTemplate(this.value)'>
16
- <option value=""><?php _e('Create Form from Template', FRM_PLUGIN_NAME) ?>: </option>
17
  <?php foreach ($templates as $temp){ ?>
18
  <option value="<?php echo $temp->id ?>"><?php echo $temp->name ?></option>
19
  <?php }?>
20
  </select>
21
  <script type="text/javascript">
22
- function createFromFrmTemplate(form){window.location='<?php $_SERVER["REQUEST_URI"] ?>?page=<?php echo FRM_PLUGIN_NAME; ?>&action=duplicate&id='+form}
23
  </script>
24
  <?php
25
  }
@@ -45,7 +45,7 @@ class FrmFormsHelper{
45
  function setup_new_vars(){
46
  global $frmdb, $frm_settings;
47
  $values = array();
48
- foreach (array('name' => __('Untitled Form', FRM_PLUGIN_NAME), 'description' => '') as $var => $default)
49
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
50
 
51
  $values['description'] = wpautop($values['description']);
@@ -53,9 +53,9 @@ class FrmFormsHelper{
53
  foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default)
54
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
55
 
56
- $values['form_key'] = ($_POST and isset($_POST['form_key']))?$_POST['form_key']:(FrmAppHelper::get_unique_key('', $frmdb->forms, 'form_key'));
57
  $values['email_to'] = ($_POST and isset($_POST['options']['email_to'])) ? $_POST['options']['email_to'] : $frm_settings->email_to;
58
- $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->custom_style;
59
  $values['submit_value'] = ($_POST and isset($_POST['options']['submit_value'])) ? $_POST['options']['submit_value'] : $frm_settings->submit_value;
60
  $values['success_action'] = ($_POST and isset($_POST['options']['success_action'])) ? $_POST['options']['success_action'] : 'message';
61
  $values['success_msg'] = ($_POST and isset($_POST['options']['success_msg'])) ? $_POST['options']['success_msg'] : $frm_settings->success_msg;
@@ -107,33 +107,14 @@ BEFORE_HTML;
107
  $html = str_replace('['.$code.']', $replace_with, $html);
108
  }
109
 
 
 
 
 
 
 
110
  return apply_filters('frm_form_replace_shortcodes', $html, $form);
111
  }
112
-
113
- function get_default_email(){
114
- $email = <<<DEFAULT_EMAIL
115
- <table style="border-bottom: 1px solid rgb(238, 238, 238); width: 100%; font-size: 12px; line-height: 135%; font-family: Lucida Grande,Tahoma,Arial,sans-serif;" cellspacing="0">
116
- <tbody><tr style="background-color: rgb(245, 245, 245);">
117
- <th style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px; vertical-align: top; color: rgb(34, 34, 34); text-align: left;">
118
- Number
119
- </th>
120
- <td style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px 7px 0pt; vertical-align: top; color: rgb(51, 51, 51); width: 60%;">
121
- <div>89</div>
122
-
123
- </td>
124
- </tr>
125
- <tr style="background-color: rgb(255, 255, 255);">
126
- <th style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px; vertical-align: top; color: rgb(34, 34, 34); text-align: left;">
127
- Email
128
- </th>
129
- <td style="border-top: 1px solid rgb(238, 238, 238); padding: 7px 9px 7px 0pt; vertical-align: top; color: rgb(51, 51, 51); width: 60%;">
130
- <a href="mailto:stephywells@gmail.com" target="_blank">stephywells@gmail.com</a>
131
- </td>
132
- </tr>
133
- </tbody></table>
134
- DEFAULT_EMAIL;
135
- return $email;
136
- }
137
 
138
  }
139
  ?>
13
 
14
  function get_template_dropdown($templates){ ?>
15
  <select id="select_form" name="select_form" onChange='createFromFrmTemplate(this.value)'>
16
+ <option value=""><?php _e('Create Form from Template', 'formidable') ?>: </option>
17
  <?php foreach ($templates as $temp){ ?>
18
  <option value="<?php echo $temp->id ?>"><?php echo $temp->name ?></option>
19
  <?php }?>
20
  </select>
21
  <script type="text/javascript">
22
+ function createFromFrmTemplate(form){window.location='?page=<?php echo FRM_PLUGIN_NAME; ?>&action=duplicate&id='+form}
23
  </script>
24
  <?php
25
  }
45
  function setup_new_vars(){
46
  global $frmdb, $frm_settings;
47
  $values = array();
48
+ foreach (array('name' => __('Untitled Form', 'formidable'), 'description' => '') as $var => $default)
49
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
50
 
51
  $values['description'] = wpautop($values['description']);
53
  foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default)
54
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default));
55
 
56
+ $values['form_key'] = ($_POST and isset($_POST['form_key'])) ? $_POST['form_key'] : (FrmAppHelper::get_unique_key('', $frmdb->forms, 'form_key'));
57
  $values['email_to'] = ($_POST and isset($_POST['options']['email_to'])) ? $_POST['options']['email_to'] : $frm_settings->email_to;
58
+ $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : ($frm_settings->load_style != 'none');
59
  $values['submit_value'] = ($_POST and isset($_POST['options']['submit_value'])) ? $_POST['options']['submit_value'] : $frm_settings->submit_value;
60
  $values['success_action'] = ($_POST and isset($_POST['options']['success_action'])) ? $_POST['options']['success_action'] : 'message';
61
  $values['success_msg'] = ($_POST and isset($_POST['options']['success_msg'])) ? $_POST['options']['success_msg'] : $frm_settings->success_msg;
107
  $html = str_replace('['.$code.']', $replace_with, $html);
108
  }
109
 
110
+ //replace [form_key]
111
+ $html = str_replace('[form_key]', $form->form_key, $html);
112
+
113
+ if(class_exists('FrmProEntriesController'))
114
+ $html = str_replace('[deletelink]', FrmProEntriesController::entry_delete_link(array()), $html);
115
+
116
  return apply_filters('frm_form_replace_shortcodes', $html, $form);
117
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  }
120
  ?>
classes/models/FrmDb.php CHANGED
@@ -14,11 +14,11 @@ class FrmDb{
14
  }
15
 
16
  function upgrade(){
17
- global $wpdb, $frm_form, $frm_field;
18
- $db_version = 1.03; // this is the version of the database we're moving to
19
  $old_db_version = get_option('frm_db_version');
20
 
21
- if ($db_version != $old_db_version){
22
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
23
 
24
  $charset_collate = '';
@@ -43,8 +43,9 @@ class FrmDb{
43
  field_options longtext default NULL,
44
  form_id int(11) default NULL,
45
  created_at datetime NOT NULL,
46
- PRIMARY KEY (id),
47
- KEY form_id (form_id)
 
48
  ) {$charset_collate};";
49
 
50
  dbDelta($sql);
@@ -62,9 +63,9 @@ class FrmDb{
62
  status varchar(255) default NULL,
63
  prli_link_id int(11) default NULL,
64
  options longtext default NULL,
65
- notifications longtext default NULL,
66
  created_at datetime NOT NULL,
67
- PRIMARY KEY (id)
 
68
  ) {$charset_collate};";
69
 
70
  dbDelta($sql);
@@ -77,9 +78,14 @@ class FrmDb{
77
  description text default NULL,
78
  ip text default NULL,
79
  form_id int(11) default NULL,
 
 
80
  created_at datetime NOT NULL,
81
- PRIMARY KEY (id),
82
- KEY form_id (form_id)
 
 
 
83
  ) {$charset_collate};";
84
 
85
  dbDelta($sql);
@@ -87,12 +93,11 @@ class FrmDb{
87
  /* Create/Upgrade Meta Table */
88
  $sql = "CREATE TABLE {$this->entry_metas} (
89
  id int(11) NOT NULL auto_increment,
90
- meta_key varchar(255) default NULL,
91
  meta_value longtext default NULL,
92
  field_id int(11) NOT NULL,
93
  item_id int(11) NOT NULL,
94
  created_at datetime NOT NULL,
95
- PRIMARY KEY (id),
96
  KEY field_id (field_id),
97
  KEY item_id (item_id)
98
  ) {$charset_collate};";
@@ -100,7 +105,7 @@ class FrmDb{
100
  dbDelta($sql);
101
 
102
  /**** MIGRATE DATA ****/
103
- if ($db_version == 1.03){
104
  global $frm_entry;
105
  $all_entries = $frm_entry->getAll();
106
  foreach($all_entries as $ent){
@@ -108,6 +113,10 @@ class FrmDb{
108
  if(is_array($opts))
109
  $wpdb->update( $this->entries, array('ip' => $opts['ip']), array( 'id' => $ent->id ) );
110
  }
 
 
 
 
111
  }
112
 
113
  /**** ADD DEFAULT TEMPLATES ****/
@@ -115,7 +124,7 @@ class FrmDb{
115
 
116
 
117
  /***** SAVE DB VERSION *****/
118
- update_option('frm_db_version',$db_version);
119
  }
120
 
121
  do_action('frm_after_install');
@@ -153,18 +162,40 @@ class FrmDb{
153
 
154
  return compact('where','values');
155
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
- function get_one_record($table, $args=array()){
158
  global $wpdb;
159
 
160
  extract(FrmDb::get_where_clause_and_values( $args ));
161
 
162
- $query = "SELECT * FROM {$table}{$where} LIMIT 1";
163
  $query = $wpdb->prepare($query, $values);
164
  return $wpdb->get_row($query);
165
  }
166
 
167
- function get_records($table, $args=array(), $order_by='', $limit=''){
168
  global $wpdb;
169
 
170
  extract(FrmDb::get_where_clause_and_values( $args ));
@@ -175,14 +206,16 @@ class FrmDb{
175
  if(!empty($limit))
176
  $limit = " LIMIT {$limit}";
177
 
178
- $query = "SELECT * FROM {$table}{$where}{$order_by}{$limit}";
179
  $query = $wpdb->prepare($query, $values);
180
  return $wpdb->get_results($query);
181
  }
182
 
183
  function uninstall(){
184
- if(!current_user_can('administrator'))
185
- wp_die(__('You don\'t have permission to do that!', 'formidable'));
 
 
186
 
187
  global $frm_update, $wpdb;
188
  $wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
14
  }
15
 
16
  function upgrade(){
17
+ global $wpdb, $frm_form, $frm_field, $frm_db_version;
18
+ //$frm_db_version is the version of the database we're moving to
19
  $old_db_version = get_option('frm_db_version');
20
 
21
+ if ($frm_db_version != $old_db_version){
22
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
23
 
24
  $charset_collate = '';
43
  field_options longtext default NULL,
44
  form_id int(11) default NULL,
45
  created_at datetime NOT NULL,
46
+ PRIMARY KEY id (id),
47
+ KEY form_id (form_id),
48
+ UNIQUE KEY field_key (field_key)
49
  ) {$charset_collate};";
50
 
51
  dbDelta($sql);
63
  status varchar(255) default NULL,
64
  prli_link_id int(11) default NULL,
65
  options longtext default NULL,
 
66
  created_at datetime NOT NULL,
67
+ PRIMARY KEY id (id),
68
+ UNIQUE KEY form_key (form_key)
69
  ) {$charset_collate};";
70
 
71
  dbDelta($sql);
78
  description text default NULL,
79
  ip text default NULL,
80
  form_id int(11) default NULL,
81
+ post_id int(11) default NULL,
82
+ user_id int(11) default NULL,
83
  created_at datetime NOT NULL,
84
+ PRIMARY KEY id (id),
85
+ KEY form_id (form_id),
86
+ KEY post_id (post_id),
87
+ KEY user_id (user_id),
88
+ UNIQUE KEY item_key (item_key)
89
  ) {$charset_collate};";
90
 
91
  dbDelta($sql);
93
  /* Create/Upgrade Meta Table */
94
  $sql = "CREATE TABLE {$this->entry_metas} (
95
  id int(11) NOT NULL auto_increment,
 
96
  meta_value longtext default NULL,
97
  field_id int(11) NOT NULL,
98
  item_id int(11) NOT NULL,
99
  created_at datetime NOT NULL,
100
+ PRIMARY KEY id (id),
101
  KEY field_id (field_id),
102
  KEY item_id (item_id)
103
  ) {$charset_collate};";
105
  dbDelta($sql);
106
 
107
  /**** MIGRATE DATA ****/
108
+ if ($frm_db_version == 1.03){
109
  global $frm_entry;
110
  $all_entries = $frm_entry->getAll();
111
  foreach($all_entries as $ent){
113
  if(is_array($opts))
114
  $wpdb->update( $this->entries, array('ip' => $opts['ip']), array( 'id' => $ent->id ) );
115
  }
116
+ }else if($frm_db_version >= 4 and $old_db_version < 4){
117
+ $user_ids = FrmEntryMeta::getAll("fi.type='user_id'");
118
+ foreach($user_ids as $user_id)
119
+ $wpdb->update( $this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id) );
120
  }
121
 
122
  /**** ADD DEFAULT TEMPLATES ****/
124
 
125
 
126
  /***** SAVE DB VERSION *****/
127
+ update_option('frm_db_version',$frm_db_version);
128
  }
129
 
130
  do_action('frm_after_install');
162
 
163
  return compact('where','values');
164
  }
165
+
166
+ function get_var($table, $args=array(), $field='id', $order_by=''){
167
+ global $wpdb;
168
+
169
+ extract(FrmDb::get_where_clause_and_values( $args ));
170
+ if(!empty($order_by))
171
+ $order_by = " ORDER BY {$order_by}";
172
+
173
+ $query = $wpdb->prepare("SELECT {$field} FROM {$table}{$where}{$order_by} LIMIT 1", $values);
174
+ return $wpdb->get_var($query);
175
+ }
176
+
177
+ function get_col($table, $args=array(), $field='id', $order_by=''){
178
+ global $wpdb;
179
+
180
+ extract(FrmDb::get_where_clause_and_values( $args ));
181
+ if(!empty($order_by))
182
+ $order_by = " ORDER BY {$order_by}";
183
+
184
+ $query = $wpdb->prepare("SELECT {$field} FROM {$table}{$where}{$order_by}", $values);
185
+ return $wpdb->get_col($query);
186
+ }
187
 
188
+ function get_one_record($table, $args=array(), $fields='*'){
189
  global $wpdb;
190
 
191
  extract(FrmDb::get_where_clause_and_values( $args ));
192
 
193
+ $query = "SELECT {$fields} FROM {$table}{$where} LIMIT 1";
194
  $query = $wpdb->prepare($query, $values);
195
  return $wpdb->get_row($query);
196
  }
197
 
198
+ function get_records($table, $args=array(), $order_by='', $limit='', $fields='*'){
199
  global $wpdb;
200
 
201
  extract(FrmDb::get_where_clause_and_values( $args ));
206
  if(!empty($limit))
207
  $limit = " LIMIT {$limit}";
208
 
209
+ $query = "SELECT {$fields} FROM {$table}{$where}{$order_by}{$limit}";
210
  $query = $wpdb->prepare($query, $values);
211
  return $wpdb->get_results($query);
212
  }
213
 
214
  function uninstall(){
215
+ if(!current_user_can('administrator')){
216
+ global $frm_settings;
217
+ wp_die($frm_settings->admin_permission);
218
+ }
219
 
220
  global $frm_update, $wpdb;
221
  $wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
classes/models/FrmEntry.php CHANGED
@@ -1,9 +1,5 @@
1
  <?php
2
  class FrmEntry{
3
- var $table_name;
4
-
5
- function FrmEntry(){
6
- }
7
 
8
  function create( $values ){
9
  global $wpdb, $frmdb, $frm_entry_meta;
@@ -12,14 +8,57 @@ class FrmEntry{
12
  $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $frmdb->entries, 'item_key');
13
  $new_values['name'] = isset($values['name']) ? $values['name'] : $values['item_key'];
14
  $new_values['ip'] = $_SERVER['REMOTE_ADDR'];
15
- $new_values['description'] = serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'],
 
 
 
 
16
  'referrer' => $_SERVER['HTTP_REFERER']));
17
  $new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id']: null;
18
  $new_values['created_at'] = current_time('mysql', 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- $query_results = $wpdb->insert( $frmdb->entries, $new_values );
21
-
22
- if($query_results){
23
  $entry_id = $wpdb->insert_id;
24
  if (isset($values['item_meta']))
25
  $frm_entry_meta->update_entry_metas($entry_id, $values['item_meta']);
@@ -37,6 +76,7 @@ class FrmEntry{
37
  $new_values = array();
38
  $new_values['item_key'] = FrmAppHelper::get_unique_key('', $frmdb->entries, 'item_key');
39
  $new_values['name'] = $values->name;
 
40
  $new_values['form_id'] = ($values->form_id)?(int)$values->form_id: null;
41
  $new_values['created_at'] = current_time('mysql', 1);
42
 
@@ -59,9 +99,10 @@ class FrmEntry{
59
 
60
  $new_values['name'] = isset($values['name'])?$values['name']:'';
61
  $new_values['form_id'] = isset($values['form_id'])?(int)$values['form_id']: null;
62
- //$new_values['parent_item_id'] = isset($values['parent_item_id'])?(int)$values['parent_item_id']: null;
 
63
 
64
- $query_results = $wpdb->update( $frmdb->entries, $new_values, array( 'id' => $id ) );
65
 
66
  if (isset($values['item_meta']))
67
  $frm_entry_meta->update_entry_metas($id, $values['item_meta']);
@@ -74,10 +115,11 @@ class FrmEntry{
74
 
75
  // Disconnect the child items from this parent item
76
  //$query_results = $wpdb->update( $frmdb->entries, array('parent_item_id' => null), array( 'parent_item_id' => $id ) );
77
-
 
78
  $reset = 'DELETE FROM ' . $frmdb->entry_metas . ' WHERE item_id=' . $id;
79
  $destroy = 'DELETE FROM ' . $frmdb->entries . ' WHERE id=' . $id;
80
-
81
  $wpdb->query($reset);
82
  return $wpdb->query($destroy);
83
  }
@@ -88,7 +130,7 @@ class FrmEntry{
88
  return $wpdb->update( $frmdb->entries, array('form_id' => $form_id), array( 'id' => $id ) );
89
  }
90
 
91
- function getOne( $id ){
92
  global $wpdb, $frmdb;
93
  $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM $frmdb->entries it
94
  LEFT OUTER JOIN $frmdb->forms fr ON it.form_id=fr.id";
@@ -96,7 +138,17 @@ class FrmEntry{
96
  $query .= ' WHERE it.id=' . $id;
97
  else
98
  $query .= " WHERE it.item_key='" . $id ."'";
99
- return $wpdb->get_row($query);
 
 
 
 
 
 
 
 
 
 
100
  }
101
 
102
  function exists( $id ){
@@ -113,12 +165,23 @@ class FrmEntry{
113
  return false;
114
  }
115
 
116
- function getAll($where = '', $order_by = '', $limit = ''){
117
  global $wpdb, $frmdb, $frm_app_helper;
118
  $query = "SELECT it.*, fr.name as form_name,fr.form_key as form_key
119
  FROM $frmdb->entries it LEFT OUTER JOIN $frmdb->forms fr ON it.form_id=fr.id" .
120
  $frm_app_helper->prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
121
- return $wpdb->get_results($query);
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
 
124
  // Pagination Methods
@@ -133,15 +196,11 @@ class FrmEntry{
133
  return ceil((int)$this->getRecordCount($where) / (int)$p_size);
134
  }
135
 
136
- function getPage($current_p,$p_size, $where = "", $order_by = ''){
137
  global $wpdb, $frmdb, $frm_app_helper;
138
  $end_index = $current_p * $p_size;
139
  $start_index = $end_index - $p_size;
140
- $query = "SELECT it.*, fr.name as form_name FROM $frmdb->entries it
141
- LEFT OUTER JOIN $frmdb->forms fr ON it.form_id=fr.id" .
142
- $frm_app_helper->prepend_and_or_where(' WHERE ', $where) . $order_by .
143
- " LIMIT $start_index,$p_size;";
144
- $results = $wpdb->get_results($query);
145
  return $results;
146
  }
147
 
@@ -166,38 +225,42 @@ class FrmEntry{
166
  $_POST['item_meta'][$posted_field->id] = $value = '';
167
 
168
  if ($posted_field->required == '1' and $value == ''){
169
- $errors['field'.$posted_field->id] = (!isset($field_options['blank']) or $field_options['blank'] == __('Untitled cannot be blank', FRM_PLUGIN_NAME) or $field_options['blank'] == '') ? ($posted_field->name . ' '. __('can\'t be blank', FRM_PLUGIN_NAME)) : $field_options['blank'];
170
  }else if ($posted_field->type == 'text' and !isset($_POST['name']))
171
  $_POST['name'] = $value;
172
 
173
  $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value);
174
  }
175
 
176
- if (isset($_POST['recaptcha_challenge_field']) and $_POST['action'] == 'create'){
177
- global $recaptcha_opt;
178
-
179
- if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') {
180
- $errors['field_captcha'] = $recaptcha_opt['error_blank'];
181
- }else{
182
- $response = recaptcha_check_answer($recaptcha_opt['privkey'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
183
-
184
- if (!$response->is_valid)
185
- if ($response->error == 'incorrect-captcha-sol')
186
- $errors['field_captcha'] = $recaptcha_opt['error_incorrect'];
187
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
 
189
  }
190
 
191
- if ( empty($errors) && function_exists( 'akismet_http_post' ) && (get_option('wordpress_api_key') || $wpcom_api_key) && $this->akismet($values)){
 
192
  global $frm_form;
193
- $form = $frm_form->getOne($field->form_id);
194
  $form_options = stripslashes_deep(unserialize($form->options));
195
 
196
  if (isset($form_options['akismet']) && $form_options['akismet'])
197
- $errors['spam'] = __('Your entry appears to be spam!', FRM_PLUGIN_NAME);
198
  }
199
 
200
- return $errors;
201
  }
202
 
203
  //Check entries for spam -- returns true if is spam
@@ -205,7 +268,7 @@ class FrmEntry{
205
  global $akismet_api_host, $akismet_api_port, $frm_blogurl;
206
 
207
  $content = '';
208
- foreach ( $values as $val ) {
209
  if ( $content != '' )
210
  $content .= "\n\n";
211
  $content .= $val;
1
  <?php
2
  class FrmEntry{
 
 
 
 
3
 
4
  function create( $values ){
5
  global $wpdb, $frmdb, $frm_entry_meta;
8
  $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $frmdb->entries, 'item_key');
9
  $new_values['name'] = isset($values['name']) ? $values['name'] : $values['item_key'];
10
  $new_values['ip'] = $_SERVER['REMOTE_ADDR'];
11
+
12
+ if(isset($values['description']) and !empty($values['description']))
13
+ $new_values['description'] = $values['description'];
14
+ else
15
+ $new_values['description'] = serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'],
16
  'referrer' => $_SERVER['HTTP_REFERER']));
17
  $new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id']: null;
18
  $new_values['created_at'] = current_time('mysql', 1);
19
+
20
+ //if(isset($values['id']) and is_numeric($values['id']))
21
+ // $new_values['id'] = $values['id'];
22
+
23
+ if(isset($values['frm_user_id']) and is_numeric($values['frm_user_id']))
24
+ $new_values['user_id'] = $values['frm_user_id'];
25
+
26
+ //check for duplicate entries created in the last 5 minutes
27
+ $check_val = $new_values;
28
+ $check_val['created_at >'] = date('Y-m-d H:i:s', (strtotime($new_values['created_at']) - (60*60*5)));
29
+ unset($check_val['created_at']);
30
+ unset($check_val['id']);
31
+ unset($check_val['item_key']);
32
+ if($new_values['item_key'] == $new_values['name'])
33
+ unset($check_val['name']);
34
+
35
+ $create_entry = true;
36
+ $entry_exists = $frmdb->get_records($frmdb->entries, $check_val, 'created_at DESC', '', 'id');
37
+ if($entry_exists and !empty($entry_exists)){
38
+ foreach($entry_exists as $entry_exist){
39
+ if($create_entry){
40
+ $create_entry = false;
41
+ //add more checks here to make sure it's a duplicate
42
+ if (isset($values['item_meta'])){
43
+ $metas = FrmEntryMeta::get_entry_meta_info($entry_exist->id);
44
+ $field_metas = array();
45
+ foreach($metas as $meta)
46
+ $field_metas[$meta->field_id] = $meta->meta_value;
47
+
48
+ $diff = array_diff_assoc($field_metas, $values['item_meta']);
49
+ foreach($diff as $field_id => $meta_value){
50
+ if(!empty($meta_value) and !$create_entry)
51
+ $create_entry = true;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ if($create_entry)
59
+ $query_results = $wpdb->insert( $frmdb->entries, $new_values );
60
 
61
+ if(isset($query_results) and $query_results){
 
 
62
  $entry_id = $wpdb->insert_id;
63
  if (isset($values['item_meta']))
64
  $frm_entry_meta->update_entry_metas($entry_id, $values['item_meta']);
76
  $new_values = array();
77
  $new_values['item_key'] = FrmAppHelper::get_unique_key('', $frmdb->entries, 'item_key');
78
  $new_values['name'] = $values->name;
79
+ $new_values['user_id'] = $values->user_id;
80
  $new_values['form_id'] = ($values->form_id)?(int)$values->form_id: null;
81
  $new_values['created_at'] = current_time('mysql', 1);
82
 
99
 
100
  $new_values['name'] = isset($values['name'])?$values['name']:'';
101
  $new_values['form_id'] = isset($values['form_id'])?(int)$values['form_id']: null;
102
+ if(isset($values['frm_user_id']) and is_numeric($values['frm_user_id']))
103
+ $new_values['user_id'] = $values['frm_user_id'];
104
 
105
+ $query_results = $wpdb->update( $frmdb->entries, $new_values, compact('id') );
106
 
107
  if (isset($values['item_meta']))
108
  $frm_entry_meta->update_entry_metas($id, $values['item_meta']);
115
 
116
  // Disconnect the child items from this parent item
117
  //$query_results = $wpdb->update( $frmdb->entries, array('parent_item_id' => null), array( 'parent_item_id' => $id ) );
118
+ do_action('frm_before_destroy_entry', $id);
119
+
120
  $reset = 'DELETE FROM ' . $frmdb->entry_metas . ' WHERE item_id=' . $id;
121
  $destroy = 'DELETE FROM ' . $frmdb->entries . ' WHERE id=' . $id;
122
+
123
  $wpdb->query($reset);
124
  return $wpdb->query($destroy);
125
  }
130
  return $wpdb->update( $frmdb->entries, array('form_id' => $form_id), array( 'id' => $id ) );
131
  }
132
 
133
+ function getOne( $id, $meta=false){
134
  global $wpdb, $frmdb;
135
  $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM $frmdb->entries it
136
  LEFT OUTER JOIN $frmdb->forms fr ON it.form_id=fr.id";
138
  $query .= ' WHERE it.id=' . $id;
139
  else
140
  $query .= " WHERE it.item_key='" . $id ."'";
141
+ $entry = $wpdb->get_row($query);
142
+
143
+ if($meta and $entry){
144
+ $metas = FrmEntryMeta::getAll("item_id=$entry->id");
145
+ $entry_metas = array();
146
+ foreach($metas as $meta_val)
147
+ $entry_metas[$meta_val->field_id] = $entry_metas[$meta_val->field_key] = $meta_val->meta_value;
148
+
149
+ $entry->metas = $entry_metas;
150
+ }
151
+ return $entry;
152
  }
153
 
154
  function exists( $id ){
165
  return false;
166
  }
167
 
168
+ function getAll($where = '', $order_by = '', $limit = '', $meta=false){
169
  global $wpdb, $frmdb, $frm_app_helper;
170
  $query = "SELECT it.*, fr.name as form_name,fr.form_key as form_key
171
  FROM $frmdb->entries it LEFT OUTER JOIN $frmdb->forms fr ON it.form_id=fr.id" .
172
  $frm_app_helper->prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
173
+ $entries = $wpdb->get_results($query);
174
+ if($meta){
175
+ foreach($entries as $key => $entry){
176
+ $metas = FrmEntryMeta::getAll("item_id=$entry->id");
177
+ $entry_metas = array();
178
+ foreach($metas as $meta_val)
179
+ $entry_metas[$meta_val->field_id] = $entry_metas[$meta_val->field_key] = $meta_val->meta_value;
180
+
181
+ $entries[$key]->metas = $entry_metas;
182
+ }
183
+ }
184
+ return $entries;
185
  }
186
 
187
  // Pagination Methods
196
  return ceil((int)$this->getRecordCount($where) / (int)$p_size);
197
  }
198
 
199
+ function getPage($current_p,$p_size, $where = '', $order_by = ''){
200
  global $wpdb, $frmdb, $frm_app_helper;
201
  $end_index = $current_p * $p_size;
202
  $start_index = $end_index - $p_size;
203
+ $results = $this->getAll($where, $order_by, " LIMIT $start_index,$p_size;", true);
 
 
 
 
204
  return $results;
205
  }
206
 
225
  $_POST['item_meta'][$posted_field->id] = $value = '';
226
 
227
  if ($posted_field->required == '1' and $value == ''){
228
+ $errors['field'.$posted_field->id] = (!isset($field_options['blank']) or $field_options['blank'] == __('Untitled cannot be blank', 'formidable') or $field_options['blank'] == '') ? ($posted_field->name . ' '. __('cannot be blank', 'formidable')) : $field_options['blank'];
229
  }else if ($posted_field->type == 'text' and !isset($_POST['name']))
230
  $_POST['name'] = $value;
231
 
232
  $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value);
233
  }
234
 
235
+ if (isset($_POST['recaptcha_challenge_field'])){
236
+ global $frm_settings;
 
 
 
 
 
 
 
 
 
237
 
238
+ if(!function_exists('recaptcha_check_answer'))
239
+ require_once(FRM_PATH.'/classes/recaptchalib.php');
240
+
241
+ $response = recaptcha_check_answer($frm_settings->privkey,
242
+ $_SERVER["REMOTE_ADDR"],
243
+ $_POST["recaptcha_challenge_field"],
244
+ $_POST["recaptcha_response_field"]);
245
+
246
+ if (!$response->is_valid) {
247
+ // What happens when the CAPTCHA was entered incorrectly
248
+ $errors['captcha-'.$response->error] = $frm_settings->re_msg;
249
  }
250
+
251
  }
252
 
253
+ global $wpcom_api_key;
254
+ if (isset($values['item_meta']) and !empty($values['item_meta']) and empty($errors) and function_exists( 'akismet_http_post' ) and ((get_option('wordpress_api_key') or $wpcom_api_key)) and $this->akismet($values)){
255
  global $frm_form;
256
+ $form = $frm_form->getOne($values['form_id']);
257
  $form_options = stripslashes_deep(unserialize($form->options));
258
 
259
  if (isset($form_options['akismet']) && $form_options['akismet'])
260
+ $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
261
  }
262
 
263
+ return apply_filters('frm_validate_entry', $errors, $values);
264
  }
265
 
266
  //Check entries for spam -- returns true if is spam
268
  global $akismet_api_host, $akismet_api_port, $frm_blogurl;
269
 
270
  $content = '';
271
+ foreach ( $values['item_meta'] as $val ) {
272
  if ( $content != '' )
273
  $content .= "\n\n";
274
  $content .= $val;
classes/models/FrmEntryMeta.php CHANGED
@@ -1,73 +1,65 @@
1
  <?php
2
  class FrmEntryMeta{
3
- var $table_name;
4
 
5
- function FrmEntryMeta(){
6
- }
7
-
8
- function add_entry_meta($item_id, $field_id, $meta_key, $meta_value){
9
  global $wpdb, $frmdb;
10
 
11
  $new_values = array();
12
- $new_values['meta_key'] = $meta_key;
13
  $new_values['meta_value'] = trim($meta_value);
14
- $new_values['item_id'] = $item_id;
15
  $new_values['field_id'] = $field_id;
16
  $new_values['created_at'] = current_time('mysql', 1);
17
  $new_values = apply_filters('frm_add_entry_meta', $new_values);
18
 
19
- return $wpdb->insert( $frmdb->entry_metas, $new_values );
20
  }
21
 
22
- function update_entry_meta($item_id, $field_id, $meta_key, $meta_value){
23
  global $wpdb;
24
- //$this->delete_entry_meta($item_id, $field_id);
25
  if ($meta_value)
26
- $this->add_entry_meta($item_id, $field_id, $meta_key, $meta_value);
27
  }
28
 
29
- function update_entry_metas($item_id, $values){
30
  global $frm_field;
31
- $this->delete_entry_metas($item_id);
32
  foreach($values as $field_id => $meta_value){
33
- $field = $frm_field->getOne( $field_id );
34
- $meta_key = $field->field_key;
35
- $meta_value = maybe_serialize($values[$field_id]);
36
- $this->update_entry_meta($item_id, $field_id, $meta_key, $meta_value);
37
  }
38
  }
39
 
40
- function duplicate_entry_metas($item_id){
41
- foreach ($this->get_entry_meta_info($item_id) as $meta)
42
- $this->update_entry_meta($item_id, $meta->field_id, $meta->meta_key, $meta->meta_value);
43
  }
44
 
45
- function delete_entry_meta($item_id, $field_id){
46
  global $wpdb, $frmdb;
47
- return $wpdb->query("DELETE FROM $frmdb->entry_metas WHERE field_id={$field_id} AND item_id={$item_id}");
48
  }
49
 
50
- function delete_entry_metas($item_id){
51
  global $wpdb, $frmdb;
52
- return $wpdb->query("DELETE FROM $frmdb->entry_metas WHERE item_id={$item_id}");
53
  }
54
 
55
- function get_entry_meta_by_field($item_id, $field_id, $return_var=false){
56
  global $wpdb, $frmdb;
57
  if (is_numeric($field_id))
58
- $query = "SELECT meta_value FROM $frmdb->entry_metas WHERE field_id='{$field_id}' and item_id='{$item_id}'";
59
  else
60
- $query = "SELECT meta_value FROM $frmdb->entry_metas it LEFT OUTER JOIN $frmdb->fields fi ON it.field_id=fi.id WHERE fi.field_key='{$field_id}' and item_id='{$item_id}'";
61
  if($return_var)
62
- return $wpdb->get_var("{$query} LIMIT 1");
63
  else
64
  return $wpdb->get_col($query, 0);
65
  }
66
 
67
- function get_entry_meta($item_id,$meta_key<