Formidable Forms – Form Builder for WordPress - Version 1.06.05

Version Description

  • Fixed WP 3.4 layout issues with missing sidebars
  • Added responsive css for WP 3.4 to keep the form builder sidebar box showing on small screens
  • Updated the delete option trash can to appear more easily
  • Use absolute path for php includes() and requires() to prevent them from using files from other plugins or themes
  • Updated translations
  • PRO: Prevent wp_redirect from stripping square brackets from urls
  • PRO: Fixed calculations for fields hidden in a collapsible section
Download this release

Release Info

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

Code changes from version 1.05.05 to 1.06.05

Files changed (108) hide show
  1. classes/controllers/FrmAppController.php +77 -34
  2. classes/controllers/FrmEntriesController.php +160 -11
  3. classes/controllers/FrmFieldsController.php +130 -52
  4. classes/controllers/FrmFormsController.php +243 -67
  5. classes/controllers/FrmSettingsController.php +14 -12
  6. classes/controllers/FrmStatisticsController.php +14 -7
  7. classes/helpers/FrmAppHelper.php +93 -36
  8. classes/helpers/FrmEntriesHelper.php +23 -6
  9. classes/helpers/FrmFieldsHelper.php +96 -38
  10. classes/helpers/FrmFormsHelper.php +34 -14
  11. classes/helpers/FrmListHelper.php +257 -0
  12. classes/models/FrmDb.php +83 -59
  13. classes/models/FrmEntry.php +132 -50
  14. classes/models/FrmEntryMeta.php +38 -10
  15. classes/models/FrmField.php +44 -20
  16. classes/models/FrmForm.php +94 -45
  17. classes/models/FrmNotification.php +20 -8
  18. classes/models/FrmSettings.php +37 -10
  19. classes/models/FrmUpdate.php +342 -274
  20. classes/templates/contact.php +14 -5
  21. classes/views/frm-entries/direct.php +8 -6
  22. classes/views/frm-entries/errors.php +18 -3
  23. classes/views/frm-entries/form.php +10 -10
  24. classes/views/frm-entries/frm-entry.php +12 -11
  25. classes/views/frm-entries/list.php +20 -3
  26. classes/views/frm-entries/new.php +8 -6
  27. classes/views/frm-entries/no_entries.php +48 -0
  28. classes/views/frm-fields/import_choices.php +17 -14
  29. classes/views/frm-fields/input.php +9 -4
  30. classes/views/frm-fields/radio.php +6 -2
  31. classes/views/frm-fields/single-option.php +12 -4
  32. classes/views/frm-forms/add_field.php +102 -64
  33. classes/views/frm-forms/add_field_links.php +68 -70
  34. classes/views/frm-forms/default-templates.php +3 -3
  35. classes/views/frm-forms/edit.php +33 -17
  36. classes/views/frm-forms/footer.php +10 -40
  37. classes/views/frm-forms/form.php +1 -127
  38. classes/views/frm-forms/insert_form_popup.php +2 -2
  39. classes/views/frm-forms/list.php +103 -51
  40. classes/views/frm-forms/new-field-js.php +16 -30
  41. classes/views/frm-forms/new-option-js.php +1 -8
  42. classes/views/frm-forms/new-selection.php +47 -6
  43. classes/views/frm-forms/new.php +25 -8
  44. classes/views/frm-forms/settings.php +254 -0
  45. classes/views/frm-forms/sidebar-html.php +25 -0
  46. classes/views/frm-forms/translate.php +63 -0
  47. classes/views/frm-settings/form.php +113 -42
  48. classes/views/frm-statistics/list.php +5 -3
  49. classes/views/frm-statistics/list_displays.php +14 -0
  50. classes/views/shared/form-nav.php +9 -0
  51. classes/views/shared/head.php +1 -1
  52. classes/views/shared/item-table-nav.php +1 -1
  53. classes/views/shared/nav.php +1 -3
  54. classes/views/shared/pagination.php +9 -9
  55. classes/views/shared/update_message.php +4 -0
  56. css/frm_admin.css +259 -264
  57. css/frm_display.css +28 -4
  58. formidable.php +43 -40
  59. images/add.png +0 -0
  60. images/arrow_down.png +0 -0
  61. images/arrow_up.png +0 -0
  62. images/black_arrow.png +0 -0
  63. images/black_arrow_big.png +0 -0
  64. images/blackglass-captcha.png +0 -0
  65. images/clean-captcha.png +0 -0
  66. images/duplicate.png +0 -0
  67. images/error.png +0 -0
  68. images/form_16.png +0 -0
  69. images/form_32.png +0 -0
  70. images/form_nav_bg6.png +0 -0
  71. images/grey_bg.png +0 -0
  72. images/help.png +0 -0
  73. images/icon.png +0 -0
  74. images/icon_128.png +0 -0
  75. images/icon_16.png +0 -0
  76. images/icon_16_bw.png +0 -0
  77. images/icon_32.png +0 -0
  78. images/icon_48.png +0 -0
  79. images/icon_color_arrow.gif +0 -0
  80. images/icons.png +0 -0
  81. images/marker.png +0 -0
  82. images/mask.png +0 -0
  83. images/menu-bits-vs.gif +0 -0
  84. images/menuhoverbg.png +0 -0
  85. images/move.png +0 -0
  86. images/readonly.png +0 -0
  87. images/red-captcha.png +0 -0
  88. images/reload.png +0 -0
  89. images/report_icon.png +0 -0
  90. images/required.png +0 -0
  91. images/required_loader.gif +0 -0
  92. images/tooltip.png +0 -0
  93. images/tooltip_white.png +0 -0
  94. images/tr_icons_white.png +0 -0
  95. images/trash.png +0 -0
  96. images/wheel.png +0 -0
  97. images/white-captcha.png +0 -0
  98. js/formidable.js +215 -78
  99. js/formidable_admin.js +245 -65
  100. js/jquery/jquery-ui-themepicker.js +6 -122
  101. js/jquery/jquery.editinplace.js +1 -1
  102. js/jquery/jquery.editinplace.packed.js +1 -1
  103. js/jquery/jquery.tools.min.js +0 -20
  104. languages/formidable-de_DE.mo +0 -0
  105. languages/formidable-de_DE.po +6194 -0
  106. languages/formidable-en_US.po +2353 -1506
  107. languages/formidable-nl_NL.mo +0 -0
  108. languages/formidable-nl_NL.po +1408 -1683
classes/controllers/FrmAppController.php CHANGED
@@ -8,16 +8,17 @@ class 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, 0);
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_install', array(&$this, 'install') );
20
  add_action('wp_ajax_frm_uninstall', array(&$this, 'uninstall') );
 
21
 
22
  // Used to process standalone requests
23
  add_action('init', array(&$this, 'parse_standalone_request'));
@@ -30,6 +31,8 @@ class FrmAppController{
30
  }
31
 
32
  function menu(){
 
 
33
  if(current_user_can('administrator') and !current_user_can('frm_view_forms')){
34
  global $current_user;
35
  $frm_roles = FrmAppHelper::frm_capabilities();
@@ -39,13 +42,13 @@ class FrmAppController{
39
  unset($frm_role);
40
  unset($frm_role_description);
41
  }
42
- global $frmpro_is_installed;
43
  if(current_user_can('frm_view_forms')){
44
  global $frm_forms_controller;
45
- add_object_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_forms', FRM_PLUGIN_NAME, array($frm_forms_controller, 'route'), 'div');
46
  }elseif(current_user_can('frm_view_entries') and $frmpro_is_installed){
47
  global $frmpro_entries_controller;
48
- add_object_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE, 'frm_view_entries', FRM_PLUGIN_NAME, array($frmpro_entries_controller, 'route'), 'div');
49
  }
50
  }
51
 
@@ -59,15 +62,22 @@ class FrmAppController{
59
 
60
  function frm_nav($nav=array()){
61
  if(current_user_can('frm_view_forms')){
62
- $nav[FRM_PLUGIN_NAME] = __('Forms', 'formidable');
63
- $nav[FRM_PLUGIN_NAME . '-templates'] = __('Templates', 'formidable');
64
  }
65
  return $nav;
66
  }
 
 
 
 
 
 
 
67
 
68
  // Adds a settings link to the plugins page
69
  function settings_link($links, $file){
70
- $settings = '<a href="'.admin_url('admin.php?page='.FRM_PLUGIN_NAME).'">' . __('Settings', 'formidable') . '</a>';
71
  array_unshift($links, $settings);
72
 
73
  return $links;
@@ -101,9 +111,9 @@ class FrmAppController{
101
  global $frmpro_is_installed, $frm_db_version, $frm_ajax_url;
102
  $db_version = get_option('frm_db_version');
103
  $pro_db_version = ($frmpro_is_installed) ? get_option('frmpro_db_version') : false;
104
- if((int)$db_version < (int)$frm_db_version or ($frmpro_is_installed and (int)$pro_db_version < 9)){ //this number should match the db_version in FrmDb.php
105
  ?>
106
- <div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your Formidable database needs to be updated.<br/>Please deactivate and reactivate the plugin to fix this or', 'formidable'); ?> <a id="frm_install_link" href="javascript:frm_install_now()"><?php _e('Update Now', 'formidable') ?></a></div>
107
  <script type="text/javascript">
108
  function frm_install_now(){
109
  jQuery('#frm_install_link').replaceWith('<img src="<?php echo FRM_IMAGES_URL; ?>/wpspin_light.gif" alt="<?php _e('Loading...', 'formidable'); ?>" />');
@@ -112,7 +122,7 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
112
  });
113
  };
114
  </script>
115
- <?php
116
  }
117
  }
118
 
@@ -131,11 +141,12 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
131
  wp_enqueue_script('jquery-ui-core');
132
 
133
  if(isset($_GET) and isset($_GET['page']) and preg_match('/formidable*/', $_GET['page'])){
134
- wp_enqueue_script('jquery-tools', FRM_URL.'/js/jquery/jquery.tools.min.js', array('jquery'), '1.1.2');
135
  wp_enqueue_script('jquery-ui-sortable');
136
  wp_enqueue_script('jquery-ui-draggable');
137
- wp_enqueue_script('formidable_admin', FRM_URL . '/js/formidable_admin.js', array('jquery'), $frm_version);
138
- wp_enqueue_script('formidable', FRM_URL . '/js/formidable.js', array('jquery'), $frm_version);
 
 
139
  wp_enqueue_style('formidable-admin', FRM_URL. '/css/frm_admin.css', $frm_version);
140
  wp_enqueue_script('jquery-elastic', FRM_URL.'/js/jquery/jquery.elastic.js', array('jquery'));
141
  add_thickbox();
@@ -146,11 +157,15 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
146
  global $frm_settings, $frm_version, $frm_db_version;
147
 
148
  if (IS_WPMU){
 
149
  //$frm_db_version is the version of the database we're moving to
150
  $old_db_version = get_option('frm_db_version');
151
- if ((int)$frm_db_version != (int)$old_db_version)
 
152
  $this->install($old_db_version);
153
  }
 
 
154
  wp_enqueue_script('jquery');
155
 
156
  if(!is_admin() and $frm_settings->load_style == 'all'){
@@ -178,7 +193,7 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
178
  else
179
  $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css', $location);
180
 
181
- if(!empty($css)){
182
  echo "\n".'<script type="text/javascript">';
183
  if(is_array($css)){
184
  foreach($css as $css_key => $file){
@@ -197,8 +212,10 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
197
  }
198
  }
199
 
200
- if(!is_admin() and $location != 'header' and !empty($frm_forms_loaded)) //load formidable js
201
- echo '<script type="text/javascript" src="'. FRM_URL .'/js/formidable.js?ver='.$frm_version.'"></script>'."\n";
 
 
202
  }
203
 
204
  function install($old_db_version=false){
@@ -210,21 +227,26 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
210
  if(current_user_can('administrator')){
211
  global $frmdb;
212
  $frmdb->uninstall();
213
- wp_die(__('Formidable was successfully uninstalled.', 'formidable'));
 
214
  }else{
215
  global $frm_settings;
216
  wp_die($frm_settings->admin_permission);
217
  }
218
  }
219
 
 
 
 
 
 
220
  // Routes for wordpress pages -- we're just replacing content here folks.
221
  function page_route($content){
222
  global $post, $frm_settings;
223
 
224
  if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
225
  global $frm_forms_controller;
226
- $frm_forms_controller->page_preview();
227
- return;
228
  }
229
 
230
  return $content;
@@ -233,41 +255,50 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
233
  function referer_session() {
234
  global $frm_siteurl, $frm_settings;
235
 
236
- if(!isset($frm_settings->track) or !$frm_settings->track)
237
  return;
238
 
239
  if ( !isset($_SESSION) )
240
  session_start();
241
 
242
  if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) )
243
- $_SESSION['frm_http_pages'] = array();
244
 
245
  if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) )
246
  $_SESSION['frm_http_referer'] = array();
247
 
248
  if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], $frm_siteurl) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) {
249
- if (! isset($_SERVER['HTTP_REFERER']))
250
- $_SESSION['frm_http_referer'][] = "Type-in or bookmark";
251
- else
 
 
252
  $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
 
253
  }
254
 
255
  if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']))
256
  $_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
257
 
 
258
  if(count($_SESSION['frm_http_pages']) > 100){
259
- $first = reset($_SESSION['frm_http_pages']);
260
- unset($first);
 
 
 
 
261
  }
262
  }
263
 
264
  // The tight way to process standalone requests dogg...
265
  function parse_standalone_request(){
266
  $plugin = $this->get_param('plugin');
267
- $action = $this->get_param('action');
 
268
  $controller = $this->get_param('controller');
269
 
270
- if( !empty($plugin) and $plugin == FRM_PLUGIN_NAME and !empty($controller) ){
271
  $this->standalone_route($controller, $action);
272
  exit;
273
  }
@@ -287,10 +318,11 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
287
 
288
  // Utility function to grab the parameter whether it's a get or post
289
  function get_param($param, $default=''){
290
- return (isset($_POST[$param])?$_POST[$param]:(isset($_GET[$param])?$_GET[$param]:$default));
291
  }
292
 
293
 
 
294
  function get_form_shortcode($atts){
295
  global $frm_entries_controller;
296
  extract(shortcode_atts(array('id' => '', 'key' => '', 'title' => false, 'description' => false, 'readonly' => false, 'entry_id' => false, 'fields' => array()), $atts));
@@ -298,7 +330,7 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
298
  return $frm_entries_controller->show_form($id, $key, $title, $description);
299
  }
300
 
301
-
302
  function widget_text_filter( $content ){
303
  $regex = '/\[\s*formidable\s+.*\]/';
304
  return preg_replace_callback( $regex, array($this, 'widget_text_filter_callback'), $content );
@@ -308,6 +340,17 @@ success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
308
  function widget_text_filter_callback( $matches ) {
309
  return do_shortcode( $matches[0] );
310
  }
 
 
 
 
 
 
 
 
 
 
 
311
 
312
  }
313
  ?>
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_formidable/formidable.php', array( &$this, 'settings_link'), 10, 2 );
12
+ add_action('after_plugin_row_formidable/formidable.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' ), 10);
15
  add_action('init', array(&$this, 'front_head'));
16
  add_action('wp_footer', array(&$this, 'footer_js'), 1, 0);
17
+ add_action('admin_init', array( &$this, 'admin_js'), 11);
18
  register_activation_hook(FRM_PATH.'/formidable.php', array( &$this, 'install' ));
19
  add_action('wp_ajax_frm_install', array(&$this, 'install') );
20
  add_action('wp_ajax_frm_uninstall', array(&$this, 'uninstall') );
21
+ add_action('wp_ajax_frm_deauthorize', array(&$this, 'deauthorize') );
22
 
23
  // Used to process standalone requests
24
  add_action('init', array(&$this, 'parse_standalone_request'));
31
  }
32
 
33
  function menu(){
34
+ global $frmpro_is_installed, $frm_settings;
35
+
36
  if(current_user_can('administrator') and !current_user_can('frm_view_forms')){
37
  global $current_user;
38
  $frm_roles = FrmAppHelper::frm_capabilities();
42
  unset($frm_role);
43
  unset($frm_role_description);
44
  }
45
+
46
  if(current_user_can('frm_view_forms')){
47
  global $frm_forms_controller;
48
+ add_object_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', array($frm_forms_controller, 'route'), 'div');
49
  }elseif(current_user_can('frm_view_entries') and $frmpro_is_installed){
50
  global $frmpro_entries_controller;
51
+ add_object_page('Formidable', $frm_settings->menu, 'frm_view_entries', 'formidable', array($frmpro_entries_controller, 'route'), 'div');
52
  }
53
  }
54
 
62
 
63
  function frm_nav($nav=array()){
64
  if(current_user_can('frm_view_forms')){
65
+ $nav['formidable'] = __('Forms', 'formidable');
66
+ $nav['formidable-templates'] = __('Templates', 'formidable');
67
  }
68
  return $nav;
69
  }
70
+
71
+ function get_form_nav($id, $show_nav=false){
72
+ $show_nav = FrmAppHelper::get_param('show_nav', $show_nav);
73
+
74
+ if($show_nav)
75
+ include(FRM_VIEWS_PATH.'/shared/form-nav.php');
76
+ }
77
 
78
  // Adds a settings link to the plugins page
79
  function settings_link($links, $file){
80
+ $settings = '<a href="'.admin_url('admin.php?page=formidable').'">' . __('Settings', 'formidable') . '</a>';
81
  array_unshift($links, $settings);
82
 
83
  return $links;
111
  global $frmpro_is_installed, $frm_db_version, $frm_ajax_url;
112
  $db_version = get_option('frm_db_version');
113
  $pro_db_version = ($frmpro_is_installed) ? get_option('frmpro_db_version') : false;
114
+ if(((int)$db_version < (int)$frm_db_version) or ($frmpro_is_installed and (int)$pro_db_version < 15)){ //this number should match the db_version in FrmDb.php
115
  ?>
116
+ <div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your Formidable database needs to be updated.<br/>Please deactivate and reactivate the plugin to fix this or', 'formidable'); ?> <a id="frm_install_link" href="javascript:frm_install_now()"><?php _e('Update Now', 'formidable') ?></a></div>
117
  <script type="text/javascript">
118
  function frm_install_now(){
119
  jQuery('#frm_install_link').replaceWith('<img src="<?php echo FRM_IMAGES_URL; ?>/wpspin_light.gif" alt="<?php _e('Loading...', 'formidable'); ?>" />');
122
  });
123
  };
124
  </script>
125
+ <?php
126
  }
127
  }
128
 
141
  wp_enqueue_script('jquery-ui-core');
142
 
143
  if(isset($_GET) and isset($_GET['page']) and preg_match('/formidable*/', $_GET['page'])){
 
144
  wp_enqueue_script('jquery-ui-sortable');
145
  wp_enqueue_script('jquery-ui-draggable');
146
+ wp_enqueue_script('admin-widgets');
147
+ wp_enqueue_style('widgets');
148
+ wp_enqueue_script('formidable_admin', FRM_URL . '/js/formidable_admin.js', array('jquery', 'jquery-ui-draggable'), $frm_version);
149
+ wp_enqueue_script('formidable');
150
  wp_enqueue_style('formidable-admin', FRM_URL. '/css/frm_admin.css', $frm_version);
151
  wp_enqueue_script('jquery-elastic', FRM_URL.'/js/jquery/jquery.elastic.js', array('jquery'));
152
  add_thickbox();
157
  global $frm_settings, $frm_version, $frm_db_version;
158
 
159
  if (IS_WPMU){
160
+ global $frmpro_is_installed;
161
  //$frm_db_version is the version of the database we're moving to
162
  $old_db_version = get_option('frm_db_version');
163
+ $pro_db_version = ($frmpro_is_installed) ? get_option('frmpro_db_version') : false;
164
+ if(((int)$old_db_version < (int)$frm_db_version) or ($frmpro_is_installed and (int)$pro_db_version < 15))
165
  $this->install($old_db_version);
166
  }
167
+
168
+ wp_register_script('formidable', FRM_URL . '/js/formidable.js', array('jquery'), $frm_version, true);
169
  wp_enqueue_script('jquery');
170
 
171
  if(!is_admin() and $frm_settings->load_style == 'all'){
193
  else
194
  $css = apply_filters('get_frm_stylesheet', FRM_URL .'/css/frm_display.css', $location);
195
 
196
+ if(!empty($css)){
197
  echo "\n".'<script type="text/javascript">';
198
  if(is_array($css)){
199
  foreach($css as $css_key => $file){
212
  }
213
  }
214
 
215
+ if(!is_admin() and $location != 'header' and !empty($frm_forms_loaded)){ //load formidable js
216
+ global $wp_scripts;
217
+ $wp_scripts->do_items( array('formidable') );
218
+ }
219
  }
220
 
221
  function install($old_db_version=false){
227
  if(current_user_can('administrator')){
228
  global $frmdb;
229
  $frmdb->uninstall();
230
+ return true;
231
+ //wp_die(__('Formidable was successfully uninstalled.', 'formidable'));
232
  }else{
233
  global $frm_settings;
234
  wp_die($frm_settings->admin_permission);
235
  }
236
  }
237
 
238
+ function deauthorize(){
239
+ delete_option('frmpro-credentials');
240
+ delete_option('frmpro-authorized');
241
+ }
242
+
243
  // Routes for wordpress pages -- we're just replacing content here folks.
244
  function page_route($content){
245
  global $post, $frm_settings;
246
 
247
  if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
248
  global $frm_forms_controller;
249
+ $content = $frm_forms_controller->page_preview();
 
250
  }
251
 
252
  return $content;
255
  function referer_session() {
256
  global $frm_siteurl, $frm_settings;
257
 
258
+ if(!isset($frm_settings->track) or !$frm_settings->track or defined('WP_IMPORTING'))
259
  return;
260
 
261
  if ( !isset($_SESSION) )
262
  session_start();
263
 
264
  if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) )
265
+ $_SESSION['frm_http_pages'] = array("http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
266
 
267
  if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) )
268
  $_SESSION['frm_http_referer'] = array();
269
 
270
  if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], $frm_siteurl) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) {
271
+ if (! isset($_SERVER['HTTP_REFERER'])){
272
+ $direct = __('Type-in or bookmark', 'formidable');
273
+ if(!in_array($direct, $_SESSION['frm_http_referer']))
274
+ $_SESSION['frm_http_referer'][] = $direct;
275
+ }else{
276
  $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
277
+ }
278
  }
279
 
280
  if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']))
281
  $_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
282
 
283
+ //keep the page history below 100
284
  if(count($_SESSION['frm_http_pages']) > 100){
285
+ foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
286
+ if(count($_SESSION['frm_http_pages']) <= 100)
287
+ break;
288
+
289
+ unset($_SESSION['frm_http_pages'][$pkey]);
290
+ }
291
  }
292
  }
293
 
294
  // The tight way to process standalone requests dogg...
295
  function parse_standalone_request(){
296
  $plugin = $this->get_param('plugin');
297
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
298
+ $action = $this->get_param($action);
299
  $controller = $this->get_param('controller');
300
 
301
+ if( !empty($plugin) and $plugin == 'formidable' and !empty($controller) ){
302
  $this->standalone_route($controller, $action);
303
  exit;
304
  }
318
 
319
  // Utility function to grab the parameter whether it's a get or post
320
  function get_param($param, $default=''){
321
+ return (isset($_POST[$param]) ? $_POST[$param] : (isset($_GET[$param])?$_GET[$param]:$default));
322
  }
323
 
324
 
325
+ //formidable shortcode
326
  function get_form_shortcode($atts){
327
  global $frm_entries_controller;
328
  extract(shortcode_atts(array('id' => '', 'key' => '', 'title' => false, 'description' => false, 'readonly' => false, 'entry_id' => false, 'fields' => array()), $atts));
330
  return $frm_entries_controller->show_form($id, $key, $title, $description);
331
  }
332
 
333
+ //filter form shortcode in text widgets
334
  function widget_text_filter( $content ){
335
  $regex = '/\[\s*formidable\s+.*\]/';
336
  return preg_replace_callback( $regex, array($this, 'widget_text_filter_callback'), $content );
340
  function widget_text_filter_callback( $matches ) {
341
  return do_shortcode( $matches[0] );
342
  }
343
+
344
+ function update_message($features){
345
+ include(FRM_VIEWS_PATH .'/shared/update_message.php');
346
+ }
347
+
348
+ function get_postbox_class(){
349
+ if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
350
+ return 'postbox-container';
351
+ else
352
+ return 'inner-sidebar';
353
+ }
354
 
355
  }
356
  ?>
classes/controllers/FrmEntriesController.php CHANGED
@@ -7,26 +7,47 @@ class FrmEntriesController{
7
 
8
  function FrmEntriesController(){
9
  add_action('admin_menu', array( &$this, 'menu' ), 20);
 
 
 
 
 
 
10
  }
11
 
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
  }
19
 
20
  function list_entries(){
 
 
 
 
 
 
 
 
 
 
 
21
  require(FRM_VIEWS_PATH.'/frm-entries/list.php');
22
  }
23
 
24
  function show_form($id='', $key='', $title=false, $description=false){
25
- global $frm_form, $user_ID;
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;
@@ -56,22 +77,147 @@ class FrmEntriesController{
56
  return false;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  function get_params($form=null){
60
- global $frm_form;
61
 
62
  if(!$form)
63
- $form = $frm_form->getAll('', ' ORDER BY name', ' LIMIT 1');
64
 
65
- $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param('action', 'new'), $form);
66
- $default_values = array('id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id, 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action);
 
 
 
67
 
 
 
 
 
 
68
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
69
  if (!is_numeric($values['posted_form_id']))
70
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
71
 
72
  if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
73
  foreach ($default_values as $var => $default){
74
- $values[$var] = FrmAppHelper::get_param($var, $default);
 
 
 
75
  unset($var);
76
  unset($default);
77
  }
@@ -83,6 +229,9 @@ class FrmEntriesController{
83
  }
84
  }
85
 
 
 
 
86
  return $values;
87
  }
88
 
7
 
8
  function FrmEntriesController(){
9
  add_action('admin_menu', array( &$this, 'menu' ), 20);
10
+ add_action('wp', array(&$this, 'process_entry'));
11
+ add_action('frm_wp', array(&$this, 'process_entry'));
12
+ add_filter('frm_redirect_msg', array( &$this, 'delete_entry_before_redirect'), 50, 3);
13
+ add_filter('frm_redirect_url', array( &$this, 'delete_entry_before_wpredirect'), 50, 3);
14
+ add_action('frm_after_entry_processed', array(&$this, 'delete_entry_after_save'), 100);
15
+ add_filter('frm_email_value', array(&$this, 'filter_email_value'), 10, 3);
16
  }
17
 
18
  function menu(){
19
  global $frmpro_is_installed;
20
  if(!$frmpro_is_installed){
21
+ add_submenu_page('formidable', 'Formidable |'. __('Entries', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Entries', 'formidable') .'</span>', 'administrator', 'formidable-entries',array(&$this, 'list_entries'));
 
22
  }
23
  }
24
 
25
  function list_entries(){
26
+ global $frm_form, $frm_entry;
27
+ $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
28
+ $form_id = FrmAppHelper::get_param('form', false);
29
+ if($form_id)
30
+ $form = $frm_form->getOne($form_id);
31
+ else
32
+ $form = (isset($form_select[0])) ? $form_select[0] : 0;
33
+
34
+ if($form)
35
+ $entry_count = $frm_entry->getRecordCount($form->id);
36
+
37
  require(FRM_VIEWS_PATH.'/frm-entries/list.php');
38
  }
39
 
40
  function show_form($id='', $key='', $title=false, $description=false){
41
+ global $frm_form, $user_ID, $frm_settings, $post;
42
+ if ($id) $form = $frm_form->getOne((int)$id);
43
  else if ($key) $form = $frm_form->getOne($key);
44
+
45
+ $form = apply_filters('frm_pre_display_form', $form);
46
+
47
+ if(!$form or
48
+ (($form->is_template or $form->status == 'draft') and !isset($_GET) and !isset($_GET['form']) and
49
+ (!isset($_GET['preview']) or $post and $post->ID != $frm_settings->preview_page_id))
50
+ ){
51
  return __('Please select a valid form', 'formidable');
52
  }else if ($form->logged_in and !$user_ID){
53
  global $frm_settings;
77
  return false;
78
  }
79
 
80
+ function process_entry(){
81
+ if(is_admin() or !isset($_POST) or !isset($_POST['form_id']) or !is_numeric($_POST['form_id']) or !isset($_POST['item_key']))
82
+ return;
83
+
84
+ global $frm_entry, $frm_form, $frm_created_entry, $frm_form_params;
85
+
86
+ $form = $frm_form->getOne($_POST['form_id']);
87
+ if(!$form)
88
+ return;
89
+
90
+ if(!$frm_form_params)
91
+ $frm_form_params = array();
92
+ $params = FrmEntriesController::get_params($form);
93
+ $frm_form_params[$form->id] = $params;
94
+
95
+ if(!$frm_created_entry)
96
+ $frm_created_entry = array();
97
+
98
+ if(isset($frm_created_entry[$_POST['form_id']]))
99
+ return;
100
+
101
+ $errors = $frm_entry->validate($_POST);
102
+ $frm_created_entry[$_POST['form_id']] = array('errors' => $errors);
103
+
104
+ if( empty($errors) ){
105
+ $_POST['frm_skip_cookie'] = 1;
106
+ if($params['action'] == 'create'){
107
+ if (apply_filters('frm_continue_to_create', true, $_POST['form_id']))
108
+ $frm_created_entry[$_POST['form_id']]['entry_id'] = $frm_entry->create( $_POST );
109
+ }
110
+
111
+ do_action('frm_process_entry', $params, $errors, $form);
112
+ unset($_POST['frm_skip_cookie']);
113
+ }
114
+ }
115
+
116
+ //Delete entry if it shouldn't be saved before redirect
117
+ function delete_entry_before_redirect($redirect_msg, $atts){
118
+ $this->_delete_entry($atts['entry_id'], $atts['form']);
119
+ return $redirect_msg;
120
+ }
121
+
122
+ function delete_entry_before_wpredirect($url, $form, $atts){
123
+ $this->_delete_entry($atts['id'], $form);
124
+ return $url;
125
+ }
126
+
127
+ //Delete entry if not redirected
128
+ function delete_entry_after_save($atts){
129
+ $this->_delete_entry($atts['entry_id'], $atts['form']);
130
+ }
131
+
132
+ function _delete_entry($entry_id, $form){
133
+ if(!$form)
134
+ return;
135
+
136
+ $form->options = maybe_unserialize($form->options);
137
+ if(isset($form->options['no_save']) and $form->options['no_save']){
138
+ global $frm_entry;
139
+ $frm_entry->destroy( $entry_id );
140
+ }
141
+ }
142
+
143
+ function &filter_email_value($value, $meta, $entry){
144
+ global $frm_field;
145
+
146
+ $field = $frm_field->getOne($meta->field_id);
147
+ if(!$field)
148
+ return $value;
149
+
150
+ $value = $this->filter_display_value($value, $field);
151
+ return $value;
152
+ }
153
+
154
+ function &filter_display_value($value, $field){
155
+ $field->field_options = maybe_unserialize($field->field_options);
156
+
157
+ if(!in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) or !isset($field->field_options['separate_value']) or !$field->field_options['separate_value'])
158
+ return $value;
159
+
160
+ $field->options = maybe_unserialize($field->options);
161
+ $f_values = array();
162
+ $f_labels = array();
163
+ foreach($field->options as $opt_key => $opt){
164
+ if(!is_array($opt))
165
+ continue;
166
+
167
+ $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
168
+ $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
169
+ if($f_labels[$opt_key] == $f_values[$opt_key]){
170
+ unset($f_values[$opt_key]);
171
+ unset($f_labels[$opt_key]);
172
+ }
173
+ unset($opt_key);
174
+ unset($opt);
175
+ }
176
+
177
+ if(!empty($f_values)){
178
+ foreach((array)$value as $v_key => $val){
179
+ if(in_array($val, $f_values)){
180
+ $opt = array_search($val, $f_values);
181
+ if(is_array($value))
182
+ $value[$v_key] = $f_labels[$opt];
183
+ else
184
+ $value = $f_labels[$opt];
185
+ }
186
+ unset($v_key);
187
+ unset($val);
188
+ }
189
+ }
190
+
191
+ return $value;
192
+ }
193
+
194
  function get_params($form=null){
195
+ global $frm_form, $frm_form_params;
196
 
197
  if(!$form)
198
+ $form = $frm_form->getAll(array(), 'name', 1);
199
 
200
+ if($frm_form_params and isset($frm_form_params[$form->id]))
201
+ return $frm_form_params[$form->id];
202
+
203
+ $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
204
+ $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
205
 
206
+ $default_values = array(
207
+ 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
208
+ 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
209
+ );
210
+
211
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
212
  if (!is_numeric($values['posted_form_id']))
213
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
214
 
215
  if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
216
  foreach ($default_values as $var => $default){
217
+ if($var == 'action')
218
+ $values[$var] = FrmAppHelper::get_param($action_var, $default);
219
+ else
220
+ $values[$var] = FrmAppHelper::get_param($var, $default);
221
  unset($var);
222
  unset($default);
223
  }
229
  }
230
  }
231
 
232
+ if(in_array($values['action'], array('create', 'update')) and (!isset($_POST) or (!isset($_POST['action']) and !isset($_POST['frm_action']))))
233
+ $values['action'] = 'new';
234
+
235
  return $values;
236
  }
237
 
classes/controllers/FrmFieldsController.php CHANGED
@@ -9,18 +9,19 @@ class FrmFieldsController{
9
  add_action('wp_ajax_frm_field_name_in_place_edit', array(&$this, 'edit_name') );
10
  add_action('wp_ajax_frm_field_desc_in_place_edit', array(&$this, 'edit_description') );
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') );
18
- add_action('wp_ajax_frm_delete_field_option',array(&$this, 'delete_option'));
19
  add_action('wp_ajax_frm_import_options', array(&$this, 'import_options') );
20
  add_action('wp_ajax_frm_update_field_order', array(&$this, 'update_order') );
21
  add_filter('frm_field_type' ,array( &$this, 'change_type'));
22
  add_filter('frm_display_field_options', array(&$this, 'display_field_options'));
23
  add_action('frm_field_input_html', array(&$this, 'input_html'));
 
 
24
  }
25
 
26
  function create(){
@@ -71,20 +72,22 @@ class FrmFieldsController{
71
  die();
72
  }
73
 
74
- function clear_on_focus(){
75
  global $frm_field;
76
  $field = $frm_field->getOne($_POST['field']);
77
  $field->field_options = maybe_unserialize($field->field_options);
78
- $field->field_options['clear_on_focus'] = $_POST['active'];
79
- $frm_field->update($_POST['field'], array('field_options' => $field->field_options));
80
- die();
81
- }
82
-
83
- function default_blank(){
84
- global $frm_field;
85
- $field = $frm_field->getOne($_POST['field']);
86
- $field->field_options = maybe_unserialize($field->field_options);
87
- $field->field_options['default_blank'] = $_POST['active'];
 
 
88
  $frm_field->update($_POST['field'], array('field_options' => $field->field_options));
89
  die();
90
  }
@@ -135,28 +138,53 @@ class FrmFieldsController{
135
  $last = 0;
136
  $opt_key = $last + 1;
137
  $opt = 'Option '.(count($options)+1);
 
138
  $options[$opt_key] = $opt;
139
  $frm_field->update($id, array('options' => maybe_serialize($options)));
140
  $checked = '';
141
 
142
  $field_data = $frm_field->getOne($id);
 
143
  $field = array();
144
  $field['type'] = $field_data->type;
145
  $field['id'] = $id;
 
146
  $field_name = "item_meta[$id]";
147
-
148
- require(FRM_VIEWS_PATH.'/frm-fields/single-option.php');
149
- require(FRM_VIEWS_PATH.'/frm-forms/new-option-js.php');
150
  die();
151
  }
152
 
153
  function edit_option(){
154
  global $frm_field;
155
- $ids = explode('-',$_POST['element_id']);
156
  $id = str_replace('field_', '', $ids[0]);
 
 
 
 
 
 
157
  $field = $frm_field->getOne($id);
158
  $options = maybe_unserialize($field->options);
159
- $options[$ids[1]] = $_POST['update_value'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  $frm_field->update($id, array('options' => maybe_serialize($options)));
161
  echo stripslashes($_POST['update_value']);
162
  die();
@@ -185,7 +213,7 @@ class FrmFieldsController{
185
  if ( get_user_setting('mfold') == 'f' )
186
  $admin_body_class .= ' folded';
187
 
188
- if ( is_admin_bar_showing() )
189
  $admin_body_class .= ' admin-bar';
190
 
191
  if ( is_rtl() )
@@ -221,7 +249,8 @@ class FrmFieldsController{
221
  );
222
 
223
  $field = FrmField::getOne($field_id);
224
- $field->options = maybe_unserialize($field->options);
 
225
 
226
  include(FRM_VIEWS_PATH.'/frm-fields/import_choices.php');
227
  die();
@@ -240,22 +269,37 @@ class FrmFieldsController{
240
  if(!in_array($field->type, array('radio', 'checkbox', 'select')))
241
  return;
242
 
 
243
  $opts = stripslashes($opts);
244
  $opts = explode("\n", rtrim($opts, "\n"));
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  $frm_field->update($field_id, array('options' => maybe_serialize($opts)));
246
 
247
- $field = FrmFieldsHelper::setup_edit_vars($field);
248
- $field['options'] = $opts;
249
  $field_name = $field['name'];
250
 
251
  if ($field['type'] == 'radio' or $field['type'] == 'checkbox'){
252
  require(FRM_VIEWS_PATH.'/frm-fields/radio.php');
253
  }else{
254
- foreach ($field['options'] as $opt_key => $opt)
 
 
255
  require(FRM_VIEWS_PATH.'/frm-fields/single-option.php');
 
256
  }
257
 
258
- $partial_js = true;
259
  require(FRM_VIEWS_PATH.'/frm-forms/new-field-js.php');
260
 
261
  die();
@@ -290,43 +334,50 @@ class FrmFieldsController{
290
  }
291
 
292
  function display_field_options($display){
293
- if ($display['type'] == 'captcha'){
294
- $display['required'] = false;
295
- $display['invalid'] = true;
296
- $display['default_blank'] = false;
297
- }else if ($display['type'] == 'radio'){
298
- $display['default_blank'] = false;
299
- }else if ($display['type'] == 'text'){
300
- $display['size'] = true;
301
- $display['clear_on_focus'] = true;
302
- }else if ($display['type'] == 'textarea'){
303
- $display['size'] = true;
304
- $display['clear_on_focus'] = true;
 
 
 
 
 
305
  }
306
 
307
  return $display;
308
  }
309
 
310
- function input_html($field){
311
  global $frm_settings;
312
 
313
  $class = $field['type'];
314
- if($field['type'] == 'date')
315
- $class .= " frm_date";
316
 
317
  if(isset($field['size']) and $field['size'] > 0){
318
- if($field['type'] != 'textarea' and $field['type'] != 'select' and $field['type'] != 'data')
319
- echo ' size="'. $field['size'] .'"';
320
  $class .= " auto_width";
321
  }
322
 
323
  if(isset($field['max']) and !in_array($field['type'], array('textarea', 'rte')) and !empty($field['max']))
324
- echo ' maxlength="'. $field['max'] .'"';
325
 
326
  if(!is_admin() or !isset($_GET) or !isset($_GET['page']) or $_GET['page'] == 'formidable_entries'){
327
- $action = FrmAppHelper::get_param('action');
 
 
328
  if(isset($field['required']) and $field['required']){
329
- //echo ' required="required"';
 
330
 
331
  if($field['type'] == 'file' and $action == 'edit'){
332
  //don't add the required class if this is a file upload when editing
@@ -334,19 +385,46 @@ class FrmFieldsController{
334
  $class .= " required";
335
  }
336
 
337
- if($frm_settings->use_html and isset($field['default_value']) and !empty($field['default_value']) and !in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden')))
338
- echo ' placeholder="'.$field['default_value'].'"';
339
 
340
- if(isset($field['clear_on_focus']) and $field['clear_on_focus']){
341
- echo ' onfocus="frmClearDefault('."'". addslashes($field['default_value']) ."'". ', this)" onblur="frmReplaceDefault('."'".addslashes($field['default_value'])."'". ', this)"';
 
342
 
343
  if($field['value'] == $field['default_value'])
344
- echo ' style="font-style:italic;"';
345
  }
346
  }
347
 
 
 
 
348
  $class = apply_filters('frm_field_classes', $class, $field);
349
- echo ' class="'.$class.'"';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  }
351
  }
352
  ?>
9
  add_action('wp_ajax_frm_field_name_in_place_edit', array(&$this, 'edit_name') );
10
  add_action('wp_ajax_frm_field_desc_in_place_edit', array(&$this, 'edit_description') );
11
  add_action('wp_ajax_frm_mark_required', array(&$this, 'mark_required') );
12
+ add_action('wp_ajax_frm_update_ajax_option', array(&$this, 'update_ajax_option') );
 
13
  add_action('wp_ajax_frm_duplicate_field', array(&$this, 'duplicate') );
14
  add_action('wp_ajax_frm_delete_field', array(&$this, 'destroy') );
15
+ add_action('wp_ajax_frm_add_field_option', array(&$this, 'add_option'));
16
  add_action('wp_ajax_frm_field_option_ipe', array(&$this, 'edit_option') );
17
+ add_action('wp_ajax_frm_delete_field_option', array(&$this, 'delete_option'));
18
  add_action('wp_ajax_frm_import_options', array(&$this, 'import_options') );
19
  add_action('wp_ajax_frm_update_field_order', array(&$this, 'update_order') );
20
  add_filter('frm_field_type' ,array( &$this, 'change_type'));
21
  add_filter('frm_display_field_options', array(&$this, 'display_field_options'));
22
  add_action('frm_field_input_html', array(&$this, 'input_html'));
23
+ add_filter('frm_field_value_saved', array( &$this, 'check_value'), 50, 3);
24
+ add_filter('frm_field_label_seen', array( &$this, 'check_label'), 10, 3);
25
  }
26
 
27
  function create(){
72
  die();
73
  }
74
 
75
+ function update_ajax_option(){
76
  global $frm_field;
77
  $field = $frm_field->getOne($_POST['field']);
78
  $field->field_options = maybe_unserialize($field->field_options);
79
+ foreach(array('clear_on_focus', 'separate_value', 'default_blank') as $val){
80
+ if(isset($_POST[$val])){
81
+ $new_val = $_POST[$val];
82
+ if($val == 'separate_value')
83
+ $new_val = (isset($field->field_options[$val]) and $field->field_options[$val]) ? 0 : 1;
84
+
85
+ $field->field_options[$val] = $new_val;
86
+ unset($new_val);
87
+ }
88
+ unset($val);
89
+ }
90
+
91
  $frm_field->update($_POST['field'], array('field_options' => $field->field_options));
92
  die();
93
  }
138
  $last = 0;
139
  $opt_key = $last + 1;
140
  $opt = 'Option '.(count($options)+1);
141
+ $field_val = $opt;
142
  $options[$opt_key] = $opt;
143
  $frm_field->update($id, array('options' => maybe_serialize($options)));
144
  $checked = '';
145
 
146
  $field_data = $frm_field->getOne($id);
147
+ $field_data->field_options = maybe_unserialize($field_data->field_options);
148
  $field = array();
149
  $field['type'] = $field_data->type;
150
  $field['id'] = $id;
151
+ $field['separate_value'] = isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0;
152
  $field_name = "item_meta[$id]";
153
+
154
+ require(FRM_VIEWS_PATH.'/frm-forms/new-option-js.php');
155
+ require(FRM_VIEWS_PATH.'/frm-fields/single-option.php');
156
  die();
157
  }
158
 
159
  function edit_option(){
160
  global $frm_field;
161
+ $ids = explode('-', $_POST['element_id']);
162
  $id = str_replace('field_', '', $ids[0]);
163
+ if(strpos($_POST['element_id'], 'key_')){
164
+ $id = str_replace('key_', '', $id);
165
+ $new_value = $_POST['update_value'];
166
+ }else{
167
+ $new_label = $_POST['update_value'];
168
+ }
169
  $field = $frm_field->getOne($id);
170
  $options = maybe_unserialize($field->options);
171
+ $this_opt = (array)$options[$ids[1]];
172
+
173
+ $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
174
+ if(isset($this_opt['value']))
175
+ $value = $this_opt['value'];
176
+
177
+ if(!isset($new_label))
178
+ $new_label = $label;
179
+
180
+ if(isset($new_value) or isset($value))
181
+ $update_value = isset($new_value) ? $new_value : $value;
182
+
183
+ if(isset($update_value) and $update_value != $new_label)
184
+ $options[$ids[1]] = array('value' => $update_value, 'label' => $new_label);
185
+ else
186
+ $options[$ids[1]] = $_POST['update_value'];
187
+
188
  $frm_field->update($id, array('options' => maybe_serialize($options)));
189
  echo stripslashes($_POST['update_value']);
190
  die();
213
  if ( get_user_setting('mfold') == 'f' )
214
  $admin_body_class .= ' folded';
215
 
216
+ if ( function_exists('is_admin_bar_showing') and is_admin_bar_showing() )
217
  $admin_body_class .= ' admin-bar';
218
 
219
  if ( is_rtl() )
249
  );
250
 
251
  $field = FrmField::getOne($field_id);
252
+ $field->options = stripslashes_deep(maybe_unserialize($field->options));
253
+ $field->field_options = maybe_unserialize($field->field_options);
254
 
255
  include(FRM_VIEWS_PATH.'/frm-fields/import_choices.php');
256
  die();
269
  if(!in_array($field->type, array('radio', 'checkbox', 'select')))
270
  return;
271
 
272
+ $field = FrmFieldsHelper::setup_edit_vars($field);
273
  $opts = stripslashes($opts);
274
  $opts = explode("\n", rtrim($opts, "\n"));
275
+ if($field['separate_value']){
276
+ foreach($opts as $opt_key => $opt){
277
+ if(strpos($opt, '|') !== false){
278
+ $vals = explode('|', $opt);
279
+ if($vals[0] != $vals[1])
280
+ $opts[$opt_key] = array('label' => $vals[0], 'value' => $vals[1]);
281
+ unset($vals);
282
+ }
283
+ unset($opt_key);
284
+ unset($opt);
285
+ }
286
+ }
287
+
288
  $frm_field->update($field_id, array('options' => maybe_serialize($opts)));
289
 
290
+ $field['options'] = stripslashes_deep($opts);
 
291
  $field_name = $field['name'];
292
 
293
  if ($field['type'] == 'radio' or $field['type'] == 'checkbox'){
294
  require(FRM_VIEWS_PATH.'/frm-fields/radio.php');
295
  }else{
296
+ foreach ($field['options'] as $opt_key => $opt){
297
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
298
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
299
  require(FRM_VIEWS_PATH.'/frm-fields/single-option.php');
300
+ }
301
  }
302
 
 
303
  require(FRM_VIEWS_PATH.'/frm-forms/new-field-js.php');
304
 
305
  die();
334
  }
335
 
336
  function display_field_options($display){
337
+ switch($display['type']){
338
+ case 'captcha':
339
+ $display['required'] = false;
340
+ $display['invalid'] = true;
341
+ $display['default_blank'] = false;
342
+ break;
343
+ case 'radio':
344
+ $display['default_blank'] = false;
345
+ break;
346
+ case 'text':
347
+ case 'textarea':
348
+ $display['size'] = true;
349
+ $display['clear_on_focus'] = true;
350
+ break;
351
+ case 'select':
352
+ $display['size'] = true;
353
+ break;
354
  }
355
 
356
  return $display;
357
  }
358
 
359
+ function input_html($field, $echo=true){
360
  global $frm_settings;
361
 
362
  $class = $field['type'];
363
+ $add_html = '';
 
364
 
365
  if(isset($field['size']) and $field['size'] > 0){
366
+ if(!in_array($field['type'], array('textarea', 'select', 'data', 'time')))
367
+ $add_html .= ' size="'. $field['size'] .'"';
368
  $class .= " auto_width";
369
  }
370
 
371
  if(isset($field['max']) and !in_array($field['type'], array('textarea', 'rte')) and !empty($field['max']))
372
+ $add_html .= ' maxlength="'. $field['max'] .'"';
373
 
374
  if(!is_admin() or !isset($_GET) or !isset($_GET['page']) or $_GET['page'] == 'formidable_entries'){
375
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
376
+ $action = FrmAppHelper::get_param($action);
377
+
378
  if(isset($field['required']) and $field['required']){
379
+ //if($field['type'] != 'checkbox')
380
+ // $add_html .= ' required="required"';
381
 
382
  if($field['type'] == 'file' and $action == 'edit'){
383
  //don't add the required class if this is a file upload when editing
385
  $class .= " required";
386
  }
387
 
388
+ //if($frm_settings->use_html and isset($field['default_value']) and !empty($field['default_value']) and isset($field['clear_on_focus']) and $field['clear_on_focus'] and !in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden')))
389
+ // $add_html .= ' placeholder="'.$field['default_value'].'"';
390
 
391
+ if(isset($field['clear_on_focus']) and $field['clear_on_focus'] and !empty($field['default_value'])){
392
+ $val = str_replace(array("\r\n", "\n"), '\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
393
+ $add_html .= ' onfocus="frmClearDefault('."'". $val ."'". ',this)" onblur="frmReplaceDefault('."'". $val ."'". ',this)"';
394
 
395
  if($field['value'] == $field['default_value'])
396
+ $add_html .= ' style="font-style:italic;"';
397
  }
398
  }
399
 
400
+ if(isset($field['input_class']) and !empty($field['input_class']))
401
+ $class .= ' '. $field['input_class'];
402
+
403
  $class = apply_filters('frm_field_classes', $class, $field);
404
+ $add_html .= ' class="'.$class.'"';
405
+
406
+ if($echo)
407
+ echo $add_html;
408
+
409
+ return $add_html;
410
+ }
411
+
412
+ function check_value($opt, $opt_key, $field){
413
+ if(is_array($opt)){
414
+ if(isset($field['separate_value']) and $field['separate_value']){
415
+ $opt = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
416
+ }else{
417
+ $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
418
+ }
419
+ }
420
+ return $opt;
421
+ }
422
+
423
+ function check_label($opt, $opt_key, $field){
424
+ if(is_array($opt))
425
+ $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
426
+
427
+ return $opt;
428
  }
429
  }
430
  ?>
classes/controllers/FrmFormsController.php CHANGED
@@ -6,27 +6,44 @@
6
  class FrmFormsController{
7
  function FrmFormsController(){
8
  add_action('admin_menu', array( &$this, 'menu' ));
9
- add_action('admin_head-toplevel_page_'.FRM_PLUGIN_NAME, array(&$this, 'head'));
10
- add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-new', array(&$this, 'head'));
11
- add_action('admin_head-'.FRM_PLUGIN_NAME.'_page_'.FRM_PLUGIN_NAME.'-templates', array(&$this, 'head'));
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 .' | '. __('Add New Form', 'formidable'), __('Add New 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
  }
@@ -46,40 +63,40 @@ class FrmFormsController{
46
  function new_form(){
47
  global $frm_form, $frmpro_is_installed, $frm_ajax_url;
48
 
49
- $action = FrmAppHelper::get_param('action');
50
- if ($action == 'create')
 
51
  return $this->create();
52
- else if ($action == 'new'){
53
  $frm_field_selection = FrmFieldsHelper::field_selection();
54
  $values = FrmFormsHelper::setup_new_vars();
55
  $id = $frm_form->create( $values );
56
  $values['id'] = $id;
57
  require(FRM_VIEWS_PATH.'/frm-forms/new.php');
58
  }else{
59
- $all_templates = $frm_form->getAll('is_template=1', ' ORDER BY name');
60
  require(FRM_VIEWS_PATH.'/frm-forms/new-selection.php');
61
  }
62
  }
63
 
64
  function create(){
65
- global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed;
66
  $errors = $frm_form->validate($_POST);
67
- $id = FrmAppHelper::get_param('id');
68
 
69
  if( count($errors) > 0 ){
70
  $hide_preview = true;
71
  $frm_field_selection = FrmFieldsHelper::field_selection();
72
  $record = $frm_form->getOne( $id );
73
- $fields = $frm_field->getAll("fi.form_id='$id'", ' ORDER BY field_order');
74
  $values = FrmAppHelper::setup_edit_vars($record, 'forms', $fields, true);
75
  require(FRM_VIEWS_PATH.'/frm-forms/new.php');
76
  }else{
77
  $record = $frm_form->update( $id, $_POST, true );
78
- $message = __('Form was Successfully Created', 'formidable');
79
- $params = $this->get_params();
80
- return $this->display_forms_list($params, $message);
81
  }
82
-
83
  }
84
 
85
  function edit(){
@@ -87,6 +104,34 @@ class FrmFormsController{
87
  return $this->get_edit_vars($id);
88
  }
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  function edit_name(){
91
  global $frm_form;
92
  $values = array('name' => trim($_POST['update_value']));
@@ -98,7 +143,10 @@ class FrmFormsController{
98
  function edit_description(){
99
  global $frm_form;
100
  $form = $frm_form->update($_POST['form_id'], array('description' => $_POST['update_value']));
101
- echo wpautop(stripslashes($_POST['update_value']));
 
 
 
102
  die();
103
  }
104
 
@@ -129,29 +177,35 @@ class FrmFormsController{
129
 
130
  function page_preview(){
131
  global $frm_form;
132
- $description = $title = true;
133
  $params = $this->get_params();
134
  if (!$params['form']) return;
135
  $form = $frm_form->getOne($params['form']);
136
- require(FRM_VIEWS_PATH.'/frm-entries/frm-entry.php');
 
137
  }
138
 
139
  function preview(){
140
- global $frm_form, $frm_settings;
 
 
141
  if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
 
142
  $root = dirname(dirname(dirname(dirname(__FILE__))));
143
  include_once( $root.'/wp-config.php' );
144
  $wp->init();
145
  $wp->register_globals();
146
  }
147
-
 
 
 
148
  header("Content-Type: text/html; charset=utf-8");
149
 
150
  $plugin = FrmAppHelper::get_param('plugin');
151
  $controller = FrmAppHelper::get_param('controller');
152
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
153
- $form = $frm_form->getAll("form_key='$key'", '', ' LIMIT 1');
154
- if (!$form) $form = $frm_form->getAll('', '', ' LIMIT 1');
155
 
156
  require(FRM_VIEWS_PATH.'/frm-entries/direct.php');
157
  }
@@ -187,16 +241,23 @@ class FrmFormsController{
187
  }
188
 
189
  function insert_form_button($content){
190
- $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.'/form_16.png" alt="' . __("Add Formidable Form", 'formidable') . '" /></a>';
 
191
  return $content;
192
  }
193
 
 
 
 
 
 
 
194
  function insert_form_popup(){
195
  $page = basename($_SERVER['PHP_SELF']);
196
- if(in_array($page, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))){
197
  if(class_exists('FrmProDisplay')){
198
  global $frmpro_display;
199
- $displays = $frmpro_display->getAll();
200
  }
201
  require(FRM_VIEWS_PATH.'/frm-forms/insert_form_popup.php');
202
  }
@@ -210,37 +271,54 @@ class FrmFormsController{
210
 
211
  if($message=='')
212
  $message = FrmAppHelper::frm_get_main_message();
213
-
214
- $controller_file = FRM_PLUGIN_NAME;
215
- $page_params = '&action=0&page=formidable';
216
- $where_clause = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ".$params['template'];
217
-
218
  if ($params['template']){
219
- $default_templates = $frm_form->getAll('default_template=1');
220
- $all_templates = $frm_form->getAll('is_template=1', ' ORDER BY name');
221
  }
 
 
 
 
 
 
 
 
222
 
223
- $form_vars = $this->get_form_sort_vars($params, $where_clause);
224
 
225
- if($current_page_ov)
226
- $current_page = $current_page_ov;
227
- else
228
- $current_page = $params['paged'];
229
 
230
- if($page_params_ov)
231
- $page_params .= $page_params_ov;
232
- else
233
- $page_params .= $form_vars['page_params'];
 
 
 
 
 
 
 
234
 
235
- $sort_str = $form_vars['sort_str'];
236
- $sdir_str = $form_vars['sdir_str'];
237
- $search_str = $form_vars['search_str'];
238
 
239
- $record_count = $frm_app_helper->getRecordCount($form_vars['where_clause'], $frmdb->forms);
240
- $page_count = $frm_app_helper->getPageCount($frm_page_size, $record_count, $frmdb->forms);
241
- $forms = $frm_app_helper->getPage($current_page, $frm_page_size, $form_vars['where_clause'], $form_vars['order_by'], $frmdb->forms);
242
- $page_last_record = $frm_app_helper->getLastRecordNum($record_count,$current_page,$frm_page_size);
243
- $page_first_record = $frm_app_helper->getFirstRecordNum($record_count,$current_page,$frm_page_size);
 
 
 
 
 
 
 
 
 
244
  require(FRM_VIEWS_PATH.'/frm-forms/list.php');
245
  }
246
 
@@ -297,13 +375,76 @@ class FrmFormsController{
297
 
298
  return compact('order_by', 'sort_str', 'sdir_str', 'search_str', 'where_clause', 'page_params');
299
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  function get_edit_vars($id, $errors = '', $message='', $create_link=false){
302
- global $frm_app_helper, $frm_entry, $frm_form, $frm_field, $frmpro_is_installed, $frm_ajax_url;
303
  $record = $frm_form->getOne( $id );
304
  $frm_field_selection = FrmFieldsHelper::field_selection();
305
- $fields = $frm_field->getAll("fi.form_id='$id'", ' ORDER BY field_order');
306
  $values = FrmAppHelper::setup_edit_vars($record, 'forms', $fields, true);
 
 
 
 
 
307
  if (isset($values['default_template']) && $values['default_template'])
308
  wp_die(__('That template cannot be edited', 'formidable'));
309
  else if($create_link)
@@ -312,6 +453,19 @@ class FrmFormsController{
312
  require(FRM_VIEWS_PATH.'/frm-forms/edit.php');
313
  }
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  function get_params(){
316
  $values = array();
317
  foreach (array('template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default)
@@ -326,10 +480,10 @@ class FrmFormsController{
326
 
327
  for($i = count($templates) - 1; $i >= 0; $i--){
328
  $filename = str_replace('.php', '', str_replace($path.'/', '', $templates[$i]));
329
- $template_query = "form_key='{$filename}'";
330
- if($template) $template_query .= " and is_template='1'";
331
- if($default) $template_query .= " and default_template='1'";
332
- $form = $frm_form->getAll($template_query, '', ' LIMIT 1');
333
 
334
  $values = FrmFormsHelper::setup_new_vars();
335
  $values['form_key'] = $filename;
@@ -342,23 +496,45 @@ class FrmFormsController{
342
  }
343
 
344
  function route(){
345
- $action = FrmAppHelper::get_param('action');
 
 
346
  if($action == 'new')
347
  return $this->new_form();
348
- else if($action=='create')
349
  return $this->create();
350
- else if($action=='edit')
351
  return $this->edit();
352
- else if($action=='update')
353
  return $this->update();
354
- else if($action=='duplicate')
355
  return $this->duplicate();
356
  else if($action == 'destroy')
357
  return $this->destroy();
358
  else if($action == 'list-form')
359
- return $this->list_form();
360
- else
361
- return $this->display_forms_list();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  }
363
 
364
  }
6
  class FrmFormsController{
7
  function FrmFormsController(){
8
  add_action('admin_menu', array( &$this, 'menu' ));
9
+ add_action('admin_menu', array( &$this, 'lower_menu' ), 90);
10
+ add_action('admin_head-toplevel_page_formidable', array(&$this, 'head'));
 
11
  add_action('wp_ajax_frm_form_name_in_place_edit', array(&$this, 'edit_name') );
12
  add_action('wp_ajax_frm_form_desc_in_place_edit', array(&$this, 'edit_description') );
13
  add_action('wp_ajax_frm_delete_form_wo_fields',array(&$this, 'destroy_wo_fields'));
14
  add_filter('frm_submit_button', array(&$this, 'submit_button_label'));
15
  add_filter('media_buttons_context', array(&$this, 'insert_form_button'));
16
+ //add_action('media_buttons', array(&$this, 'show_form_button'), 20);
17
  add_action('admin_footer', array(&$this, 'insert_form_popup'));
18
+
19
+ add_filter('set-screen-option', array(&$this, 'save_per_page'), 10, 3);
20
  }
21
 
22
  function menu(){
23
+ global $frm_settings;
24
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Forms', 'formidable'), __('Forms', 'formidable'), 'frm_view_forms', 'formidable', array(&$this, 'route'));
25
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Templates', 'formidable'), __('Templates', 'formidable'), 'frm_view_forms', 'formidable-templates', array(&$this, 'template_list'));
26
+
27
+ add_action('admin_head-'. sanitize_title($frm_settings->menu) .'_page_formidable-new', array(&$this, 'head'));
28
+ add_action('admin_head-'. sanitize_title($frm_settings->menu) .'_page_formidable-templates', array(&$this, 'head'));
29
+
30
+ if(class_exists('WP_List_Table')){
31
+ add_filter('manage_toplevel_page_formidable_columns', array( &$this, 'get_columns' ), 0 );
32
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_columns', array( &$this, 'get_columns' ), 0 );
33
+ add_filter('manage_toplevel_page_formidable_sortable_columns', array(&$this, 'get_sortable_columns'));
34
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_sortable_columns', array(&$this, 'get_sortable_columns'));
35
+ add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', array(&$this, 'hidden_columns'));
36
+ add_filter('get_user_option_manage'. sanitize_title($frm_settings->menu) .'_page_formidable-templatescolumnshidden', array(&$this, 'hidden_columns'));
37
+ }
38
+ }
39
+
40
+ function lower_menu(){
41
+ add_submenu_page('formidable', 'Formidable | '. __('Add New Form', 'formidable'), '<span style="display:none;">'. __('Add New Form', 'formidable') .'</span>', 'frm_edit_forms', 'formidable-new', array(&$this, 'new_form'));
42
  }
43
 
44
  function head(){
45
  global $frm_settings;
46
+
 
47
  $js_file = array(FRM_URL . '/js/jquery/jquery-ui-themepicker.js', FRM_URL.'/js/jquery/jquery.editinplace.packed.js');
48
  require(FRM_VIEWS_PATH . '/shared/head.php');
49
  }
63
  function new_form(){
64
  global $frm_form, $frmpro_is_installed, $frm_ajax_url;
65
 
66
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
67
+ $action = FrmAppHelper::get_param($action);
68
+ if ($action == 'create'){
69
  return $this->create();
70
+ }else if ($action == 'new'){
71
  $frm_field_selection = FrmFieldsHelper::field_selection();
72
  $values = FrmFormsHelper::setup_new_vars();
73
  $id = $frm_form->create( $values );
74
  $values['id'] = $id;
75
  require(FRM_VIEWS_PATH.'/frm-forms/new.php');
76
  }else{
77
+ $all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
78
  require(FRM_VIEWS_PATH.'/frm-forms/new-selection.php');
79
  }
80
  }
81
 
82
  function create(){
83
+ global $frm_entry, $frm_form, $frm_field, $frmpro_is_installed;
84
  $errors = $frm_form->validate($_POST);
85
+ $id = (int)FrmAppHelper::get_param('id');
86
 
87
  if( count($errors) > 0 ){
88
  $hide_preview = true;
89
  $frm_field_selection = FrmFieldsHelper::field_selection();
90
  $record = $frm_form->getOne( $id );
91
+ $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
92
  $values = FrmAppHelper::setup_edit_vars($record, 'forms', $fields, true);
93
  require(FRM_VIEWS_PATH.'/frm-forms/new.php');
94
  }else{
95
  $record = $frm_form->update( $id, $_POST, true );
96
+ die('<script type="text/javascript">window.location="'. admin_url('admin.php?page=formidable&frm_action=settings&id='. $id) .'"</script>');
97
+ //$message = __('Form was Successfully Created', 'formidable');
98
+ //return $this->settings($record, $message);
99
  }
 
100
  }
101
 
102
  function edit(){
104
  return $this->get_edit_vars($id);
105
  }
106
 
107
+ function settings($id=false, $message=''){
108
+ if(!$id or !is_numeric($id))
109
+ $id = FrmAppHelper::get_param('id');
110
+ return $this->get_settings_vars($id, '', $message);
111
+ }
112
+
113
+ function update_settings(){
114
+ global $frm_form;
115
+
116
+ $id = FrmAppHelper::get_param('id');
117
+ $errors = $frm_form->validate($_POST);
118
+ if( count($errors) > 0 ){
119
+ return $this->get_settings_vars($id, $errors);
120
+ }else{
121
+ $record = $frm_form->update( $_POST['id'], $_POST );
122
+ $message = __('Settings Successfully Updated', 'formidable');
123
+ return $this->get_settings_vars($id, '', $message);
124
+ }
125
+ }
126
+
127
+ function translate($action){
128
+ global $frmpro_is_installed, $frm_form;
129
+ $id = FrmAppHelper::get_param('id', false);
130
+ $form = $frm_form->getOne($id);
131
+ $values = (array)$form;
132
+ include(FRM_VIEWS_PATH . '/frm-forms/translate.php');
133
+ }
134
+
135
  function edit_name(){
136
  global $frm_form;
137
  $values = array('name' => trim($_POST['update_value']));
143
  function edit_description(){
144
  global $frm_form;
145
  $form = $frm_form->update($_POST['form_id'], array('description' => $_POST['update_value']));
146
+ $description = stripslashes($_POST['update_value']);
147
+ if(apply_filters('frm_use_wpautop', true))
148
+ $description = wpautop($description);
149
+ echo $description;
150
  die();
151
  }
152
 
177
 
178
  function page_preview(){
179
  global $frm_form;
 
180
  $params = $this->get_params();
181
  if (!$params['form']) return;
182
  $form = $frm_form->getOne($params['form']);
183
+ if(!$form) return;
184
+ return FrmEntriesController::show_form($form->id, '', true, true);
185
  }
186
 
187
  function preview(){
188
+ do_action('frm_wp');
189
+
190
+ global $frm_form, $frm_settings, $frmpro_is_installed;
191
  if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
192
+ global $wp;
193
  $root = dirname(dirname(dirname(dirname(__FILE__))));
194
  include_once( $root.'/wp-config.php' );
195
  $wp->init();
196
  $wp->register_globals();
197
  }
198
+
199
+ if($frmpro_is_installed)
200
+ FrmProEntriesController::register_scripts();
201
+
202
  header("Content-Type: text/html; charset=utf-8");
203
 
204
  $plugin = FrmAppHelper::get_param('plugin');
205
  $controller = FrmAppHelper::get_param('controller');
206
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
207
+ $form = $frm_form->getAll(array('form_key' => $key), '', 1);
208
+ if (!$form) $form = $frm_form->getAll(array(), '', 1);
209
 
210
  require(FRM_VIEWS_PATH.'/frm-entries/direct.php');
211
  }
241
  }
242
 
243
  function insert_form_button($content){
244
+ if(current_user_can('frm_view_forms'))
245
+ $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.'/form_16.png" alt="' . __("Add Formidable Form", 'formidable') . '" /></a>';
246
  return $content;
247
  }
248
 
249
+ function show_form_button($id){
250
+ if($id != 'content')
251
+ return;
252
+ echo '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox" title="' . __("Add Formidable Form", 'formidable') . '"><img src="'. esc_url(FRM_IMAGES_URL.'/form_16.png'). '" alt="' . __("Add Formidable Form", 'formidable') . '" /></a>';
253
+ }
254
+
255
  function insert_form_popup(){
256
  $page = basename($_SERVER['PHP_SELF']);
257
+ if(in_array($page, array('post.php', 'page.php', 'page-new.php', 'post-new.php')) or (isset($_GET) and isset($_GET['page']) and $_GET['page'] == 'formidable-entry-templates')){
258
  if(class_exists('FrmProDisplay')){
259
  global $frmpro_display;
260
+ $displays = $frmpro_display->getAll('', ' ORDER BY name');
261
  }
262
  require(FRM_VIEWS_PATH.'/frm-forms/insert_form_popup.php');
263
  }
271
 
272
  if($message=='')
273
  $message = FrmAppHelper::frm_get_main_message();
274
+
275
+ $page_params = '&action=0&&frm_action=0&page=formidable';
276
+
 
 
277
  if ($params['template']){
278
+ $default_templates = $frm_form->getAll(array('default_template' => 1));
279
+ $all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
280
  }
281
+
282
+ if(class_exists('WP_List_Table')){
283
+ require_once( FRM_PATH .'/classes/helpers/FrmListHelper.php' );
284
+
285
+ $args = array('table_name' => $frmdb->forms, 'params' => $params);
286
+ $args['page_name'] = $params['template'] ? '-template' : '';
287
+ $wp_list_table = new FrmListHelper($args);
288
+ unset($args);
289
 
290
+ $pagenum = $wp_list_table->get_pagenum();
291
 
292
+ $wp_list_table->prepare_items();
 
 
 
293
 
294
+ $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
295
+ if ( $pagenum > $total_pages && $total_pages > 0 ) {
296
+ wp_redirect( add_query_arg( 'paged', $total_pages ) );
297
+ exit;
298
+ }
299
+
300
+ if ( ! empty( $_REQUEST['s'] ) )
301
+ $page_params .= '&s='. urlencode($_REQUEST['s']);
302
+ }else{
303
+
304
+ $where_clause = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ".$params['template'];
305
 
306
+ $form_vars = $this->get_form_sort_vars($params, $where_clause);
 
 
307
 
308
+ $current_page = ($current_page_ov) ? $current_page_ov : $params['paged'];
309
+ $page_params .= ($page_params_ov) ? $page_params_ov : $form_vars['page_params'];
310
+
311
+ $sort_str = $form_vars['sort_str'];
312
+ $sdir_str = $form_vars['sdir_str'];
313
+ $search_str = $form_vars['search_str'];
314
+
315
+ $record_count = $frm_app_helper->getRecordCount($form_vars['where_clause'], $frmdb->forms);
316
+ $page_count = $frm_app_helper->getPageCount($frm_page_size, $record_count, $frmdb->forms);
317
+ $forms = $frm_app_helper->getPage($current_page, $frm_page_size, $form_vars['where_clause'], $form_vars['order_by'], $frmdb->forms);
318
+ $page_last_record = $frm_app_helper->getLastRecordNum($record_count,$current_page,$frm_page_size);
319
+ $page_first_record = $frm_app_helper->getFirstRecordNum($record_count,$current_page,$frm_page_size);
320
+ }
321
+
322
  require(FRM_VIEWS_PATH.'/frm-forms/list.php');
323
  }
324
 
375
 
376
  return compact('order_by', 'sort_str', 'sdir_str', 'search_str', 'where_clause', 'page_params');
377
  }
378
+
379
+ function get_columns($columns){
380
+ $columns['cb'] = '<input type="checkbox" />';
381
+ $columns['id'] = 'ID';
382
+ $columns['name'] = __('Name', 'formidable');
383
+ $columns['description'] = __('Description', 'formidable');
384
+ $columns['form_key'] = __('Key', 'formidable');
385
+
386
+ if($_GET['page'] == 'formidable-templates'){
387
+ add_screen_option( 'per_page', array('label' => __('Templates', 'formidable'), 'default' => 10, 'option' => 'formidable_page_formidable_templates_per_page') );
388
+ }else{
389
+ $columns['entries'] = __('Entries', 'formidable');
390
+ $columns['link'] = __('Direct Link', 'formidable');
391
+ $columns['shortcode'] = __('ShortCodes', 'formidable');
392
+ add_screen_option( 'per_page', array('label' => __('Forms', 'formidable'), 'default' => 20, 'option' => 'formidable_page_formidable_per_page') );
393
+ }
394
+
395
+ $columns['created_at'] = __('Date', 'formidable');
396
+
397
+ return $columns;
398
+ }
399
+
400
+ function get_sortable_columns() {
401
+ return array(
402
+ 'id' => 'id',
403
+ 'name' => 'name',
404
+ 'description' => 'description',
405
+ 'form_key' => 'form_key',
406
+ 'created_at' => 'created_at'
407
+ );
408
+ }
409
+
410
+ function hidden_columns($result){
411
+ $return = false;
412
+ foreach((array)$result as $r){
413
+ if(!empty($r)){
414
+ $return = true;
415
+ break;
416
+ }
417
+ }
418
+
419
+ if($return)
420
+ return $result;
421
+
422
+ $result[] = 'created_at';
423
+ if($_GET['page'] == 'formidable-templates'){
424
+ $result[] = 'id';
425
+ $result[] = 'form_key';
426
+ }
427
+
428
+ return $result;
429
+ }
430
+
431
+ function save_per_page($save, $option, $value){
432
+ if($option == 'formidable_page_formidable_per_page' or $option == 'formidable_page_formidable_templates_per_page')
433
+ $save = (int)$value;
434
+ return $save;
435
+ }
436
 
437
  function get_edit_vars($id, $errors = '', $message='', $create_link=false){
438
+ global $frm_entry, $frm_form, $frm_field, $frmpro_is_installed, $frm_ajax_url;
439
  $record = $frm_form->getOne( $id );
440
  $frm_field_selection = FrmFieldsHelper::field_selection();
441
+ $fields = $frm_field->getAll(array('fi.form_id' => $record->id), 'field_order');
442
  $values = FrmAppHelper::setup_edit_vars($record, 'forms', $fields, true);
443
+
444
+ $edit_message = __('Form was Successfully Updated', 'formidable');
445
+ if ($values['is_template'] and $message == $edit_message)
446
+ $message = __('Template was Successfully Updated', 'formidable');
447
+
448
  if (isset($values['default_template']) && $values['default_template'])
449
  wp_die(__('That template cannot be edited', 'formidable'));
450
  else if($create_link)
453
  require(FRM_VIEWS_PATH.'/frm-forms/edit.php');
454
  }
455
 
456
+ function get_settings_vars($id, $errors = '', $message=''){
457
+ global $frm_entry, $frm_form, $frm_field, $frmpro_is_installed, $frm_ajax_url;
458
+ $record = $frm_form->getOne( $id );
459
+ $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
460
+ $values = FrmAppHelper::setup_edit_vars($record, 'forms', $fields, true);
461
+ $sections = apply_filters('frm_add_form_settings_section', array(), $values);
462
+ $pro_feature = ($frmpro_is_installed) ? '' : ' class="pro_feature"';
463
+ if (isset($values['default_template']) && $values['default_template'])
464
+ wp_die(__('That template cannot be edited', 'formidable'));
465
+ else
466
+ require(FRM_VIEWS_PATH.'/frm-forms/settings.php');
467
+ }
468
+
469
  function get_params(){
470
  $values = array();
471
  foreach (array('template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default)
480
 
481
  for($i = count($templates) - 1; $i >= 0; $i--){
482
  $filename = str_replace('.php', '', str_replace($path.'/', '', $templates[$i]));
483
+ $template_query = array('form_key' => $filename);
484
+ if($template) $template_query['is_template'] = 1;
485
+ if($default) $template_query['default_template'] = 1;
486
+ $form = $frm_form->getAll($template_query, '', 1);
487
 
488
  $values = FrmFormsHelper::setup_new_vars();
489
  $values['form_key'] = $filename;
496
  }
497
 
498
  function route(){
499
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
500
+ $action = FrmAppHelper::get_param($action);
501
+
502
  if($action == 'new')
503
  return $this->new_form();
504
+ else if($action == 'create')
505
  return $this->create();
506
+ else if($action == 'edit')
507
  return $this->edit();
508
+ else if($action == 'update')
509
  return $this->update();
510
+ else if($action == 'duplicate')
511
  return $this->duplicate();
512
  else if($action == 'destroy')
513
  return $this->destroy();
514
  else if($action == 'list-form')
515
+ return $this->list_form();
516
+ else if($action == 'settings')
517
+ return $this->settings();
518
+ else if($action == 'update_settings')
519
+ return $this->update_settings();
520
+ else if($action == 'translate' or $action == 'update_translate')
521
+ return $this->translate($action);
522
+ else{
523
+ $action = FrmAppHelper::get_param('action');
524
+ if($action == -1)
525
+ $action = FrmAppHelper::get_param('action2');
526
+
527
+ if(strpos($action, 'bulk_') === 0){
528
+ if(isset($_GET) and isset($_GET['action']))
529
+ $_SERVER['REQUEST_URI'] = str_replace('&action='.$_GET['action'], '', $_SERVER['REQUEST_URI']);
530
+ if(isset($_GET) and isset($_GET['action2']))
531
+ $_SERVER['REQUEST_URI'] = str_replace('&action='.$_GET['action2'], '', $_SERVER['REQUEST_URI']);
532
+
533
+ return $this->list_form();
534
+ }else{
535
+ return $this->display_forms_list();
536
+ }
537
+ }
538
  }
539
 
540
  }
classes/controllers/FrmSettingsController.php CHANGED
@@ -6,34 +6,33 @@
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(){
18
- global $frm_update;
19
- if (IS_WPMU and !FrmAppHelper::is_super_admin() and get_site_option($frm_update->pro_wpmu_store))
20
- return;
21
-
22
- add_submenu_page(FRM_PLUGIN_NAME, FRM_PLUGIN_TITLE .' | '. FRM_PLUGIN_TITLE . ' Pro', FRM_PLUGIN_TITLE . ' Pro', 'administrator', FRM_PLUGIN_NAME.'-pro-settings', array($frm_update, 'pro_cred_form'));
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(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();
@@ -44,11 +43,14 @@ class FrmSettingsController{
44
  $message = __('Settings Saved', 'formidable');
45
  }
46
  $frm_roles = FrmAppHelper::frm_capabilities();
 
 
47
  require(FRM_VIEWS_PATH . '/frm-settings/form.php');
48
  }
49
 
50
  function route(){
51
- $action = FrmAppHelper::get_param('action');
 
52
  if($action == 'process-form')
53
  return $this->process_form();
54
  else
6
  class FrmSettingsController{
7
  function FrmSettingsController(){
8
  add_action('admin_menu', array( &$this, 'menu' ), 26);
9
+ add_filter('frm_nav_array', array( &$this, 'frm_nav'), 30);
 
10
  }
11
 
12
  function menu(){
13
+ add_submenu_page('formidable', 'Formidable | '. __('Settings', 'formidable'), __('Settings', 'formidable'), 'frm_change_settings', 'formidable-settings', array(&$this, 'route'));
14
  }
15
 
16
+ function frm_nav($nav=array()){
17
+ if(current_user_can('frm_change_settings'))
18
+ $nav['formidable-settings'] = __('Settings', 'formidable');
19
+
20
+ return $nav;
 
21
  }
22
 
23
  function display_form(){
24
+ global $frm_settings, $frm_ajax_url, $frmpro_is_installed, $frm_update;
25
  $frm_roles = FrmAppHelper::frm_capabilities();
26
 
27
  $uploads = wp_upload_dir();
28
  $target_path = $uploads['basedir'] . "/formidable/css";
29
+ $sections = apply_filters('frm_add_settings_section', array());
30
 
31
  require(FRM_VIEWS_PATH . '/frm-settings/form.php');
32
  }
33
 
34
  function process_form(){
35
+ global $frm_settings, $frm_ajax_url, $frmpro_is_installed, $frm_update;
36
 
37
  //$errors = $frm_settings->validate($_POST,array());
38
  $errors = array();
43
  $message = __('Settings Saved', 'formidable');
44
  }
45
  $frm_roles = FrmAppHelper::frm_capabilities();
46
+ $sections = apply_filters('frm_add_settings_section', array());
47
+
48
  require(FRM_VIEWS_PATH . '/frm-settings/form.php');
49
  }
50
 
51
  function route(){
52
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
53
+ $action = FrmAppHelper::get_param($action);
54
  if($action == 'process-form')
55
  return $this->process_form();
56
  else
classes/controllers/FrmStatisticsController.php CHANGED
@@ -1,22 +1,29 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
 
6
  class FrmStatisticsController{
7
  function FrmStatisticsController(){
8
- add_action('admin_menu', array( &$this, 'menu' ), 30);
9
  }
10
 
11
  function menu(){
12
  global $frmpro_is_installed;
13
- if(!$frmpro_is_installed)
14
- add_submenu_page(FRM_PLUGIN_TITLE, FRM_PLUGIN_TITLE .' | Statistics', 'Statistics', 'administrator', FRM_PLUGIN_TITLE.'-statistics', array(&$this, ''));
 
 
 
 
15
  }
16
 
17
- function list_entries(){
 
18
  require(FRM_VIEWS_PATH . '/frm-statistics/list.php');
19
  }
 
 
 
 
 
20
 
21
  }
22
 
1
  <?php
 
 
 
2
 
3
  class FrmStatisticsController{
4
  function FrmStatisticsController(){
5
+ add_action('admin_menu', array( &$this, 'menu' ), 24);
6
  }
7
 
8
  function menu(){
9
  global $frmpro_is_installed;
10
+ if($frmpro_is_installed)
11
+ return;
12
+
13
+ add_submenu_page('formidable', 'Formidable | '. __('Custom Displays', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Custom Displays', 'formidable') .'</span>', 'administrator', 'formidable-entry-templates', array(&$this, 'list_displays'));
14
+
15
+ add_submenu_page('formidable', 'Formidable | '. __('Reports', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Reports', 'formidable') .'</span>', 'administrator', 'formidable-reports', array(&$this, 'list_reports'));
16
  }
17
 
18
+ function list_reports(){
19
+ $form = FrmAppHelper::get_param('form', false);
20
  require(FRM_VIEWS_PATH . '/frm-statistics/list.php');
21
  }
22
+
23
+ function list_displays(){
24
+ $form = FrmAppHelper::get_param('form', false);
25
+ require(FRM_VIEWS_PATH . '/frm-statistics/list_displays.php');
26
+ }
27
 
28
  }
29
 
classes/helpers/FrmAppHelper.php CHANGED
<
@@ -1,18 +1,37 @@
1
  <?php
2
 
3
  class FrmAppHelper{
4
- function FrmAppHelper(){}
5
 
6
  function get_param($param, $default=''){
7
- return (isset($_POST[$param])?$_POST[$param]:(isset($_GET[$param])?$_GET[$param]:$default));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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">
@@ -84,6 +103,9 @@ class FrmAppHelper{
84
  }
85
 
86
  function check_selected($values, $current){
 
 
 
87
  if(is_array($values))
88
  $values = array_map('trim', $values);
89
  else
@@ -98,8 +120,7 @@ class FrmAppHelper{
98
  $values = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $values);
99
  $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
100
  */
101
-
102
-
103
  if((is_array($values) && in_array($current, $values)) or (!is_array($values) and $values == $current))
104
  return true;
105
  else
@@ -142,16 +163,20 @@ class FrmAppHelper{
142
  function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
143
  global $wpdb;
144
 
145
- if ($name == ''){
146
- $max_slug_value = pow(36, $num_chars);
147
- $min_slug_value = 37; // we want to have at least 2 characters in the slug
148
- $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
149
- }else{
150
  if(function_exists('sanitize_key'))
151
  $key = sanitize_key($name);
152
  else
153
  $key = sanitize_title_with_dashes($name);
154
  }
 
 
 
 
 
 
155
 
156
  if (is_numeric($key) or in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
157
  $key = $key .'a';
@@ -181,7 +206,8 @@ class FrmAppHelper{
181
 
182
  foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default_val)
183
  $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default_val));
184
- $values['description'] = wpautop($values['description']);
 
185
  $values['fields'] = array();
186
 
187
  if ($fields){
@@ -192,33 +218,48 @@ class FrmAppHelper{
192
  $meta_value = $field->default_value;
193
  }else{
194
  if($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']){
 
 
195
  $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
196
  }else if(isset($record->metas)){
197
  $meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false;
198
  }else{
199
- $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id, true);
200
  }
201
  }
202
 
203
  $field_type = isset($_POST['field_options']['type_'.$field->id]) ? $_POST['field_options']['type_'.$field->id] : $field->type;
204
  $new_value = (isset($_POST['item_meta'][$field->id])) ? $_POST['item_meta'][$field->id] : $meta_value;
205
- $new_value = stripslashes_deep(maybe_unserialize($new_value));
206
-
 
 
207
  $field_array = array(
208
  'id' => $field->id,
209
- 'value' => str_replace('"', '&quot;', $new_value),
210
- 'default_value' => str_replace('"', '&quot;', stripslashes_deep(maybe_unserialize($field->default_value))),
211
  'name' => stripslashes($field->name),
212
  'description' => stripslashes($field->description),
213
  'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
214
- 'options' => str_replace('"', '&quot;', stripslashes_deep(maybe_unserialize($field->options))),
215
  'required' => $field->required,
216
  'field_key' => $field->field_key,
217
  'field_order' => $field->field_order,
218
  'form_id' => $field->form_id
219
  );
220
 
221
- foreach (array('size' => '', 'max' => '', 'label' => 'top', 'invalid' => '', 'required_indicator' => '*', 'blank' => '', 'clear_on_focus' => 0, 'custom_html' => '', 'default_blank' => 0) as $opt => $default_opt){
 
 
 
 
 
 
 
 
 
 
 
222
  $field_array[$opt] = ($_POST and isset($_POST['field_options'][$opt.'_'.$field->id]) ) ? $_POST['field_options'][$opt.'_'.$field->id] : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt);
223
  if($opt == 'blank' and $field_array[$opt] == ''){
224
  $field_array[$opt] = __('This field cannot be blank', 'formidable');
@@ -229,6 +270,8 @@ class FrmAppHelper{
229
  $field_array[$opt] = $field_array['name'] . ' ' . __('is invalid', 'formidable');
230
  }
231
  }
 
 
232
 
233
  if ($field_array['custom_html'] == '')
234
  $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
@@ -254,26 +297,21 @@ class FrmAppHelper{
254
  $values[$opt] = FrmAppHelper::get_param($opt, $value);
255
  }
256
  }
257
-
258
- $email = get_option('admin_email');
259
- foreach (array('custom_style' => ($frm_settings->load_style != 'none'), 'email_to' => $email) as $opt => $default){
260
- if (!isset($values[$opt]))
261
- $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
262
- }
263
 
264
- foreach (array('submit_value' => $frm_settings->submit_value, 'success_action' => 'message', 'success_msg' => $frm_settings->success_msg, 'show_form' => 1) as $opt => $default){
 
 
 
 
265
  if (!isset($values[$opt]) or $values[$opt] == '')
266
  $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default;
 
 
267
  }
268
- if (!isset($values['show_form']))
269
- $values['show_form'] = ($_POST and isset($_POST['options']['show_form'])) ? 1 : 0;
270
 
271
  if (!isset($values['custom_style']))
272
  $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : ($frm_settings->load_style != 'none');
273
 
274
- if (!isset($values['akismet']))
275
- $values['akismet'] = ($_POST and isset($_POST['options']['akismet'])) ? 1 : 0;
276
-
277
  if (!isset($values['before_html']))
278
  $values['before_html'] = (isset($_POST['options']['before_html']) ? $_POST['options']['before_html'] : FrmFormsHelper::get_default_html('before'));
279
 
@@ -290,7 +328,7 @@ class FrmAppHelper{
290
 
291
  function get_us_states(){
292
  return apply_filters('frm_us_states', array(
293
- 'AL' => 'Alabama', 'AK' => 'Alaska', 'AS' => 'Arkansas', 'AZ' => 'Arizona',
294
  'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
295
  'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
296
  'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
@@ -385,10 +423,14 @@ class FrmAppHelper{
385
 
386
  function frm_get_main_message( $message = ''){
387
  global $frmpro_is_installed;
388
- include_once(ABSPATH."/wp-includes/class-IXR.php");
 
 
 
 
389
 
390
  $url = ($frmpro_is_installed) ? 'http://formidablepro.com/' : 'http://blog.strategy11.com/';
391
- $client = new IXR_Client($url.'xmlrpc.php', false, 80, 15);
392
 
393
  if ($client->query('frm.get_main_message'))
394
  $message = $client->getResponse();
@@ -397,7 +439,14 @@ class FrmAppHelper{
397
  }