Formidable Forms – Form Builder for WordPress - Version 2.0b8

Version Description

Download this release

Release Info

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

Code changes from version 1.07.10 to 2.0b8

Files changed (101) hide show
  1. .gitignore +1 -0
  2. classes/controllers/FrmAppController.php +250 -244
  3. classes/controllers/FrmEntriesController.php +515 -318
  4. classes/controllers/FrmFieldsController.php +453 -294
  5. classes/controllers/FrmFormActionsController.php +343 -0
  6. classes/controllers/FrmFormsController.php +671 -450
  7. classes/controllers/FrmHooksController.php +209 -0
  8. classes/controllers/FrmSettingsController.php +19 -40
  9. classes/controllers/FrmStatisticsController.php +4 -16
  10. classes/controllers/FrmStylesController.php +395 -0
  11. classes/controllers/FrmXMLController.php +148 -174
  12. classes/helpers/FrmAppHelper.php +1191 -399
  13. classes/helpers/FrmEntriesHelper.php +562 -115
  14. classes/helpers/FrmEntriesListHelper.php +255 -0
  15. classes/helpers/FrmFieldsHelper.php +748 -256
  16. classes/helpers/FrmFormActionsHelper.php +106 -0
  17. classes/helpers/FrmFormsHelper.php +367 -122
  18. classes/helpers/FrmFormsListHelper.php +331 -0
  19. classes/helpers/FrmListHelper.php +2 -202
  20. classes/helpers/FrmStylesHelper.php +192 -0
  21. classes/helpers/FrmXMLHelper.php +389 -92
  22. classes/models/FrmDb.php +483 -177
  23. classes/models/FrmEntry.php +511 -318
  24. classes/models/FrmEntryMeta.php +201 -159
  25. classes/models/FrmField.php +257 -133
  26. classes/models/FrmForm.php +356 -150
  27. classes/models/FrmFormAction.php +522 -0
  28. classes/models/FrmNotification.php +275 -91
  29. classes/models/FrmSettings.php +174 -80
  30. classes/models/FrmStyle.php +418 -0
  31. classes/recaptchalib.php +0 -274
  32. classes/views/frm-entries/_sidebar-shared-pub.php +21 -0
  33. classes/views/frm-entries/direct.php +6 -7
  34. classes/views/frm-entries/errors.php +37 -26
  35. classes/views/frm-entries/form.php +22 -27
  36. classes/views/frm-entries/frm-entry.php +0 -52
  37. classes/views/frm-entries/list.php +29 -26
  38. classes/views/frm-entries/new.php +7 -7
  39. classes/views/frm-entries/no_entries.php +16 -46
  40. classes/views/frm-entries/show.php +83 -0
  41. classes/views/frm-entries/sidebar-show.php +36 -0
  42. classes/views/frm-fields/import_choices.php +22 -15
  43. classes/views/frm-fields/input.php +115 -45
  44. classes/views/frm-fields/radio.php +23 -9
  45. classes/views/frm-fields/show-build.php +67 -0
  46. classes/views/frm-fields/show.php +4 -1
  47. classes/views/frm-fields/single-option.php +11 -14
  48. classes/views/frm-form-actions/_action_inside.php +53 -0
  49. classes/views/frm-form-actions/_email_settings.php +64 -0
  50. classes/views/frm-form-actions/default_actions.php +65 -0
  51. classes/views/frm-form-actions/email_action.php +40 -0
  52. classes/views/frm-form-actions/form_action.php +40 -0
  53. classes/views/frm-forms/_publish_box.php +110 -0
  54. classes/views/frm-forms/add_field.php +170 -175
  55. classes/views/frm-forms/add_field_links.php +101 -63
  56. classes/views/frm-forms/default-templates.php +0 -47
  57. classes/views/frm-forms/edit.php +18 -29
  58. classes/views/frm-forms/form.php +28 -9
  59. classes/views/frm-forms/insert_form_popup.php +143 -59
  60. classes/views/frm-forms/list.php +9 -6
  61. classes/views/frm-forms/mb_html_tab.php +12 -13
  62. classes/views/frm-forms/mb_insert_fields.php +2 -19
  63. classes/views/frm-forms/new-field-js.php +1 -1
  64. classes/views/frm-forms/new-selection.php +10 -10
  65. classes/views/frm-forms/new.php +18 -33
  66. classes/views/frm-forms/notification.php +0 -94
  67. classes/views/frm-forms/settings.php +148 -109
  68. classes/views/frm-forms/sidebar-settings.php +9 -31
  69. classes/views/frm-settings/form.php +58 -68
  70. classes/views/frm-settings/license_box.php +2 -2
  71. classes/views/frm-settings/styling_tab.php +0 -4
  72. classes/views/frm-statistics/list.php +6 -4
  73. classes/views/frm-statistics/list_displays.php +5 -3
  74. classes/views/shared/errors.php +16 -4
  75. classes/views/shared/form-nav.php +26 -6
  76. classes/views/shared/head.php +5 -5
  77. classes/views/shared/mb_adv_info.php +262 -0
  78. classes/views/shared/nav.php +0 -1
  79. classes/views/shared/update_message.php +1 -1
  80. classes/views/styles/_buttons.php +134 -0
  81. classes/views/styles/_check-box-radio-fields.php +33 -0
  82. classes/views/styles/_date-fields.php +40 -0
  83. classes/views/styles/_field-colors.php +114 -0
  84. classes/views/styles/_field-description.php +31 -0
  85. classes/views/styles/_field-labels.php +57 -0
  86. classes/views/styles/_field-sizes.php +35 -0
  87. classes/views/styles/_form-messages.php +59 -0
  88. classes/views/styles/_general.php +74 -0
  89. classes/views/styles/_sample_form.php +100 -0
  90. classes/views/styles/_section-fields.php +113 -0
  91. classes/views/styles/custom_css.php +32 -0
  92. classes/views/styles/manage.php +59 -0
  93. classes/views/styles/show.php +110 -0
  94. classes/views/xml/default-templates.xml +0 -0
  95. classes/views/xml/forms_xml.php +5 -6
  96. classes/views/xml/import_form.php +15 -15
  97. classes/views/xml/posts_xml.php +81 -0
  98. classes/views/xml/xml.php +7 -8
  99. classes/widgets/FrmShowForm.php +35 -25
  100. css/_single_theme.css.php +786 -0
  101. css/codemirror.css +136 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
1
+ .DS_Store
classes/controllers/FrmAppController.php CHANGED
@@ -1,152 +1,121 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
6
-
7
- if(class_exists('FrmAppController'))
8
- return;
9
-
10
- class FrmAppController{
11
- public static function load_hooks(){
12
- add_action('admin_menu', 'FrmAppController::menu', 1);
13
- add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
14
- add_filter('plugin_action_links_formidable/formidable.php', 'FrmAppController::settings_link', 10, 2 );
15
- add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
16
- add_action('admin_notices', 'FrmAppController::pro_get_started_headline');
17
- add_filter('the_content', 'FrmAppController::page_route', 10);
18
- add_action('plugins_loaded', 'FrmAppController::load_lang');
19
- add_action('init', 'FrmAppController::front_head');
20
- add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
21
- add_action('admin_init', 'FrmAppController::admin_js', 11);
22
- register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::install');
23
- add_action('wp_ajax_frm_install', 'FrmAppController::install');
24
- add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall');
25
- add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize');
26
-
27
- // Used to process standalone requests
28
- add_action('init', 'FrmAppController::parse_standalone_request', 40);
29
- // Update the session data
30
- add_action('init', 'FrmAppController::referer_session', 1);
31
- }
32
-
33
- public static function menu(){
34
- global $frm_vars, $frm_settings;
35
-
36
- if ( current_user_can('administrator') && !current_user_can('frm_view_forms') ) {
37
- global $current_user;
38
- $frm_roles = FrmAppHelper::frm_capabilities();
39
- foreach($frm_roles as $frm_role => $frm_role_description)
40
- $current_user->add_cap( $frm_role );
41
- unset($frm_roles);
42
- unset($frm_role);
43
- unset($frm_role_description);
44
  }
45
-
46
  $count = count(get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ));
47
- $pos = ((int)$count > 0) ? '22.7' : '29.3';
48
  $pos = apply_filters('frm_menu_position', $pos);
49
-
50
- if(current_user_can('frm_view_forms')){
51
- add_menu_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
52
- }else if(current_user_can('frm_view_entries') and $frm_vars['pro_is_installed']){
53
- add_menu_page('Formidable', $frm_settings->menu, 'frm_view_entries', 'formidable', 'FrmProEntriesController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
54
- }
55
-
56
- add_filter('admin_body_class', 'FrmAppController::wp_admin_body_class');
57
  }
58
-
59
- public static function load_wp_admin_style(){
60
  wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version());
61
  }
62
-
63
- public static function get_form_nav($id, $show_nav=false){
64
  global $pagenow, $frm_vars;
65
-
66
  $show_nav = FrmAppHelper::get_param('show_nav', $show_nav);
67
- if(!$show_nav)
68
  return;
69
-
 
70
  $current_page = (isset($_GET['page'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None');
71
- if($id and is_numeric($id)){
72
- $frm_form = new FrmForm();
73
- $form = $frm_form->getOne($id);
74
- unset($frm_form);
75
- }else{
76
- $form = false;
 
 
 
 
77
  }
78
-
79
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
80
  }
81
 
82
  // Adds a settings link to the plugins page
83
- public static function settings_link($links, $file){
84
  $settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>';
85
  array_unshift($links, $settings);
86
-
87
  return $links;
88
  }
89
-
90
  public static function update_action_links( $actions, $plugin ) {
91
-
92
- if ( 'formidable/formidable.php' != $plugin )
93
  return $actions;
94
-
95
- global $frm_vars;
96
-
97
  $db_version = get_option('frm_db_version');
98
- $pro_db_version = $frm_vars['pro_is_installed'] ? get_option('frmpro_db_version') : false;
99
-
100
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
101
- ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
102
-
103
- return sprintf( '<a href="%s">%s</a>', add_query_arg(array('upgraded' => 'true'), menu_page_url( 'formidable', 0 )), __( 'Click here to complete the upgrade', 'formidable' ) );
104
-
105
- } else {
106
- return $actions;
107
  }
 
 
108
  }
109
 
110
  public static function pro_get_started_headline(){
111
- if ( isset($_GET['page']) && 'formidable' == $_GET['page'] && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) {
112
  self::install();
113
  ?>
114
  <div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div>
115
  <?php
116
  return;
117
  }
118
-
119
  // Don't display this error as we're upgrading the thing... cmon
120
- if(isset($_GET['action']) and $_GET['action'] == 'upgrade-plugin')
121
  return;
122
-
 
123
  if ( is_multisite() && !current_user_can('administrator') ) {
124
  return;
125
  }
126
-
127
- if(!isset($_GET['activate'])){
128
- global $frm_vars;
129
  $db_version = get_option('frm_db_version');
130
- $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false;
131
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
132
- ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
133
  ?>
134
- <div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or', 'formidable'); ?> <a id="frm_install_link" href="javascript:void(0)"><?php _e('Update Now', 'formidable') ?></a></div>
135
  <script type="text/javascript">
136
- jQuery(document).ready(function($){ $('#frm_install_link').click(frm_install_now); });
137
  function frm_install_now(){
138
- jQuery('#frm_install_message').html('<div style="line-height:24px;"><?php _e("Please wait while your site updates.", "formidable") ?><div class="spinner frm_spinner" style="float:left;display:block;"></div></div>');
 
139
  jQuery.ajax({
140
  type:"POST",url:ajaxurl,data:"action=frm_install",
141
- success:function(msg){jQuery("#frm_install_message").fadeOut("slow");}
142
  });
143
  }
144
  </script>
145
  <?php
146
  }
147
  }
148
-
149
- if ( self::pro_is_authorized() && !self::pro_is_installed()) {
 
150
  // user is authorized, but running free version
151
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
152
  ?>
@@ -162,55 +131,58 @@ success:function(msg){jQuery('.error').fadeOut('slow');}
162
  return false;
163
  }
164
  </script>
165
- <?php
166
  }
167
  }
168
-
169
  public static function admin_js(){
170
  global $pagenow;
171
-
172
  if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) {
173
  return;
174
  }
175
-
176
- wp_enqueue_script('jquery');
177
- wp_enqueue_script('jquery-ui-core');
178
- wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.0.3');
179
-
180
  if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
181
  ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
182
  ) {
183
  $version = FrmAppHelper::plugin_version();
184
- add_filter('admin_body_class', 'FrmAppController::admin_body_class');
185
-
186
  wp_enqueue_script('jquery-ui-sortable');
187
  wp_enqueue_script('jquery-ui-draggable');
188
  wp_enqueue_script('admin-widgets');
189
  wp_enqueue_style('widgets');
190
  wp_enqueue_script('formidable');
191
- wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() .'/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version, true);
192
  self::localize_script('admin');
193
-
194
  wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version);
195
  add_thickbox();
196
-
197
  wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
198
  wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
199
-
200
-
201
- }else if($pagenow == 'post.php' or ($pagenow == 'post-new.php' and isset($_REQUEST['post_type']) and $_REQUEST['post_type'] == 'frm_display')){
202
- if(isset($_REQUEST['post_type'])){
 
 
 
 
203
  $post_type = $_REQUEST['post_type'];
204
- }else if(isset($_REQUEST['post']) and !empty($_REQUEST['post'])){
205
  $post = get_post($_REQUEST['post']);
206
- if(!$post)
207
  return;
 
208
  $post_type = $post->post_type;
209
- }else{
210
  return;
211
  }
212
-
213
- if($post_type == 'frm_display'){
214
  $version = FrmAppHelper::plugin_version();
215
  wp_enqueue_script('jquery-ui-draggable');
216
  wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version);
@@ -219,60 +191,68 @@ return false;
219
  }
220
  }
221
  }
222
-
223
  public static function admin_body_class($classes){
224
  global $wp_version;
225
-
226
  //we only need this class on Formidable pages
227
- if(version_compare( $wp_version, '3.4.9', '>'))
228
  $classes .= ' frm_35_trigger';
229
-
 
230
  return $classes;
231
  }
232
-
233
  public static function wp_admin_body_class($classes){
234
  global $wp_version;
235
  //we need this class everywhere in the admin for the menu
236
- if(version_compare( $wp_version, '3.7.2', '>'))
237
  $classes .= ' frm_38_trigger';
238
-
 
239
  return $classes;
240
  }
241
-
242
  public static function load_lang(){
243
- load_plugin_textdomain('formidable', false, 'formidable/languages/' );
 
 
 
 
 
 
 
 
244
  }
245
-
246
- public static function front_head(){
247
- global $frm_settings;
248
 
 
249
  if (is_multisite()){
250
- global $frm_vars;
251
  $old_db_version = get_option('frm_db_version');
252
- $pro_db_version = ($frm_vars['pro_is_installed']) ? get_option('frmpro_db_version') : false;
253
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
254
- ( $frm_vars['pro_is_installed'] && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
255
  self::install($old_db_version);
256
  }
257
  }
258
-
259
  $version = FrmAppHelper::plugin_version();
260
  wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true);
261
  wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true);
262
- wp_register_script('recaptcha-ajax', 'http'. (is_ssl() ? 's' : '').'://www.google.com/recaptcha/api/js/recaptcha_ajax.js', '', true);
263
-
264
- if ( is_admin() && !defined('DOING_AJAX') ) {
265
  // don't load this in back-end
266
  return;
267
  }
268
-
269
  self::localize_script('front');
270
-
271
  wp_enqueue_script('jquery');
272
-
273
- $style = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
 
 
274
  if($style){
275
- foreach((array)$style as $k => $file){
276
  wp_register_style($k, $file, array(), $version);
277
  if ( 'all' == $frm_settings->load_style ) {
278
  wp_enqueue_style($k);
@@ -281,13 +261,13 @@ return false;
281
  }
282
  }
283
  unset($style);
284
-
285
- if ( $frm_settings->load_style == 'all' ) {
286
  global $frm_vars;
287
  $frm_vars['css_loaded'] = true;
288
  }
289
  }
290
-
291
  public static function localize_script($location){
292
  wp_localize_script('formidable', 'frm_js', array(
293
  'ajax_url' => admin_url( 'admin-ajax.php' ),
@@ -295,15 +275,17 @@ return false;
295
  'loading' => __('Loading&hellip;'),
296
  'remove' => __('Remove', 'formidable'),
297
  'offset' => apply_filters('frm_scroll_offset', 4),
 
298
  ));
299
-
300
  if($location == 'admin'){
301
- global $frm_settings;
302
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
303
  'confirm_uninstall' => __('Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable'),
304
  'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '',
305
- 'desc' => __('(Click here to add a description or instructions)', 'formidable'),
306
- 'blank' => __('(Blank)', 'formidable'),
 
307
  'saving' => esc_attr(__('Saving', 'formidable')),
308
  'saved' => esc_attr(__('Saved', 'formidable')),
309
  'ok' => __('OK'),
@@ -314,30 +296,64 @@ return false;
314
  'no_valid_default' => __('Default value will NOT pass form validation', 'formidable'),
315
  'deauthorize' => __('Are you sure you want to deactivate Formidable Pro on this site?', 'formidable'),
316
  'confirm' => __('Are you sure?', 'formidable'),
 
 
317
  'default_unique' => $frm_settings->unique_msg,
 
 
 
 
 
318
  'import_complete' => __('Import Complete', 'formidable'),
319
  'updating' => __('Please wait while your site updates.', 'formidable'),
320
  'nonce' => wp_create_nonce('frm_ajax'),
 
 
321
  ));
322
  }
323
  }
324
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  public static function footer_js($location='footer'){
326
- global $frm_settings, $frm_vars;
327
-
328
- if($frm_vars['load_css'] and (!is_admin() or defined('DOING_AJAX')) and ($frm_settings->load_style != 'none')){
329
- if(isset($frm_vars['css_loaded']) && $frm_vars['css_loaded'])
330
- $css = apply_filters('get_frm_stylesheet', array());
331
- else
332
- $css = apply_filters('get_frm_stylesheet', array('frm-forms' => FrmAppHelper::plugin_url() .'/css/frm_display.css'));
333
-
334
  if(!empty($css)){
335
  echo "\n".'<script type="text/javascript">';
336
- foreach((array)$css as $css_key => $file){
337
- echo 'jQuery("head").append(unescape("%3Clink rel=\'stylesheet\' id=\''. ($css_key + (isset($frm_vars['css_loaded']) ? $frm_vars['css_loaded'] : false)) .'-css\' href=\''. $file. '\' type=\'text/css\' media=\'all\' /%3E"));';
338
- //wp_enqueue_style($css_key);
339
- unset($css_key);
340
- unset($file);
341
  }
342
  unset($css);
343
 
@@ -345,138 +361,128 @@ return false;
345
  }
346
  }
347
 
348
- if((!is_admin() or defined('DOING_AJAX')) and $location != 'header' and !empty($frm_vars['forms_loaded'])) //load formidable js
349
- FrmAppHelper::load_scripts(array('formidable'));
 
 
 
 
 
 
 
 
350
  }
351
-
352
  public static function install($old_db_version=false){
353
- global $frmdb;
354
  $frmdb->upgrade($old_db_version);
355
  }
356
-
357
  public static function uninstall(){
358
  check_ajax_referer( 'frm_ajax', 'nonce' );
359
-
360
  if ( current_user_can('administrator') ) {
361
- global $frmdb;
362
  $frmdb->uninstall();
363
  echo true;
364
  } else {
365
- global $frm_settings;
366
  wp_die($frm_settings->admin_permission);
367
  }
368
  die();
369
  }
370
-
 
 
 
 
 
 
 
 
 
371
  // Routes for wordpress pages -- we're just replacing content here folks.
372
  public static function page_route($content){
373
- global $post, $frm_settings;
374
 
 
375
  if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
376
  $content = FrmFormsController::page_preview();
377
  }
378
 
379
  return $content;
380
  }
381
-
382
  public static function referer_session() {
383
- global $frm_settings;
384
-
385
  if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) {
386
  return;
387
  }
388
-
389
  // keep the page history below 100
390
  $max = 100;
391
-
392
  if ( !isset($_SESSION) )
393
  session_start();
394
-
395
- if ( !isset($_SESSION['frm_http_pages']) or !is_array($_SESSION['frm_http_pages']) )
396
- $_SESSION['frm_http_pages'] = array("http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
397
-
398
- if ( !isset($_SESSION['frm_http_referer']) or !is_array($_SESSION['frm_http_referer']) )
 
399
  $_SESSION['frm_http_referer'] = array();
400
-
401
- if (!isset($_SERVER['HTTP_REFERER']) or (isset($_SERVER['HTTP_REFERER']) and (strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false) and ! (in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer'])) )) {
402
- if (! isset($_SERVER['HTTP_REFERER'])){
403
- $direct = __('Type-in or bookmark', 'formidable');
404
- if(!in_array($direct, $_SESSION['frm_http_referer']))
405
- $_SESSION['frm_http_referer'][] = $direct;
406
- }else{
407
- $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
 
 
 
 
 
 
408
  }
409
  }
410
-
411
- if ($_SESSION['frm_http_pages'] and !empty($_SESSION['frm_http_pages']) and (end($_SESSION['frm_http_pages']) != "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']))
412
- $_SESSION['frm_http_pages'][] = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
413
-
414
  //keep the page history below the max
415
  if(count($_SESSION['frm_http_pages']) > $max){
416
  foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
417
  if(count($_SESSION['frm_http_pages']) <= $max)
418
  break;
419
-
420
  unset($_SESSION['frm_http_pages'][$pkey]);
421
  }
422
  }
423
  }
424
 
425
- public static function parse_standalone_request(){
426
- $plugin = FrmAppHelper::get_param('plugin');
427
- $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
428
- $action = FrmAppHelper::get_param($action);
429
- $controller = FrmAppHelper::get_param('controller');
430
-
431
- if( !empty($plugin) and $plugin == 'formidable' and !empty($controller) ){
432
- _deprecated_function( __FUNCTION__, '1.07.02', 'wp_ajax_nopriv()' );
433
-
434
- if($controller == 'forms')
435
- FrmFormsController::preview(FrmAppHelper::get_param('form'));
436
- else
437
- do_action('frm_standalone_route', $controller, $action);
438
-
439
- do_action('frm_ajax_'. $controller .'_'. $action);
440
- die();
441
- }
442
- }
443
-
444
- //formidable shortcode
445
- public static function get_form_shortcode($atts){
446
- _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
447
- return FrmFormsController::get_form_shortcode($atts);
448
- }
449
-
450
- public static function widget_text_filter_callback( $matches ) {
451
- return do_shortcode( $matches[0] );
452
- }
453
-
454
  public static function update_message($features){
455
- include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
456
- }
457
-
458
- public static function get_postbox_class(){
459
- if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
460
- return 'postbox-container';
461
- else
462
- return 'inner-sidebar';
463
  }
464
-
465
- public static function pro_is_installed(){
466
- return file_exists(FrmAppHelper::plugin_path() . '/pro/formidable-pro.php');
467
- }
468
-
469
- public static function pro_is_authorized(){
470
- return get_site_option('frmpro-authorized');
471
- }
472
-
473
  public static function deauthorize(){
474
  check_ajax_referer( 'frm_ajax', 'nonce' );
475
-
476
  delete_option('frmpro-credentials');
477
  delete_option('frmpro-authorized');
478
  delete_site_option('frmpro-credentials');
479
  delete_site_option('frmpro-authorized');
480
  die();
481
  }
 
 
 
 
 
 
 
 
 
 
 
482
  }
1
  <?php
2
+
3
+ class FrmAppController {
4
+
5
+ public static function menu() {
6
+ add_filter('plugin_action_links_'. FrmAppHelper::plugin_folder() .'/formidable.php', 'FrmAppController::settings_link' );
7
+ add_filter('admin_body_class', 'FrmAppController::wp_admin_body_class' );
8
+
9
+ FrmAppHelper::maybe_add_permissions();
10
+
11
+ if ( ! current_user_can('frm_view_forms') ) {
12
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
14
+
15
  $count = count(get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ));
16
+ $pos = ( (int) $count > 0 ) ? '22.7' : '29.3';
17
  $pos = apply_filters('frm_menu_position', $pos);
18
+
19
+ $frm_settings = FrmAppHelper::get_settings();
20
+ add_menu_page('Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() .'/images/form_16.png', $pos);
 
 
 
 
 
21
  }
22
+
23
+ public static function load_wp_admin_style() {
24
  wp_enqueue_style( 'frm_fonts', FrmAppHelper::plugin_url() .'/css/frm_fonts.css', array(), FrmAppHelper::plugin_version());
25
  }
26
+
27
+ public static function get_form_nav($form, $show_nav = '', $title = 'show') {
28
  global $pagenow, $frm_vars;
29
+
30
  $show_nav = FrmAppHelper::get_param('show_nav', $show_nav);
31
+ if ( empty($show_nav) ) {
32
  return;
33
+ }
34
+
35
  $current_page = (isset($_GET['page'])) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None');
36
+ if ( $form ) {
37
+ FrmFormsHelper::maybe_get_form( $form );
38
+
39
+ if ( is_object($form) ) {
40
+ $id = $form->id;
41
+ }
42
+ }
43
+
44
+ if ( !isset($id) ) {
45
+ $form = $id = false;
46
  }
47
+
48
  include(FrmAppHelper::plugin_path() .'/classes/views/shared/form-nav.php');
49
  }
50
 
51
  // Adds a settings link to the plugins page
52
+ public static function settings_link($links){
53
  $settings = '<a href="'. admin_url('admin.php?page=formidable-settings') .'">' . __('Settings', 'formidable') . '</a>';
54
  array_unshift($links, $settings);
55
+
56
  return $links;
57
  }
58
+
59
  public static function update_action_links( $actions, $plugin ) {
60
+
61
+ if ( FrmAppHelper::plugin_folder() .'/formidable.php' != $plugin )
62
  return $actions;
63
+
 
 
64
  $db_version = get_option('frm_db_version');
65
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option('frmpro_db_version') : false;
66
+
67
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
68
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
69
+
70
+ return '<a href="'. add_query_arg(array('upgraded' => 'true'), menu_page_url( 'formidable', 0 )) .'">'. __( 'Click here to complete the upgrade', 'formidable' ) .'</a>';
71
+
 
 
72
  }
73
+
74
+ return $actions;
75
  }
76
 
77
  public static function pro_get_started_headline(){
78
+ if ( FrmAppHelper::is_admin_page('formidable') && isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) {
79
  self::install();
80
  ?>
81
  <div id="message" class="frm_message updated"><?php _e('Congratulations! Formidable is ready to roll.', 'formidable') ?></div>
82
  <?php
83
  return;
84
  }
85
+
86
  // Don't display this error as we're upgrading the thing... cmon
87
+ if ( isset($_GET['action']) && 'upgrade-plugin' == $_GET['action'] ) {
88
  return;
89
+ }
90
+
91
  if ( is_multisite() && !current_user_can('administrator') ) {
92
  return;
93
  }
94
+
95
+ if ( ! isset($_GET['activate']) ) {
 
96
  $db_version = get_option('frm_db_version');
97
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option('frmpro_db_version') : false;
98
  if ( ( (int) $db_version < (int) FrmAppHelper::$db_version ) ||
99
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
100
  ?>
101
+ <div class="error" id="frm_install_message" style="padding:7px;"><?php _e('Your update is not complete yet.<br/>Please deactivate and reactivate the plugin to complete the update or', 'formidable'); ?> <a href="javascript:void(0)" id="frm_install_link"><?php _e('Update Now', 'formidable') ?></a></div>
102
  <script type="text/javascript">
103
+ jQuery(document).ready(function($){ $(document.getElementById('frm_install_link')).click(frm_install_now); });
104
  function frm_install_now(){
105
+ var $msg = jQuery(document.getElementById('frm_install_message'));
106
+ $msg.html('<div style="line-height:24px;"><?php _e('Please wait while your site updates.', 'formidable') ?><div class="spinner frm_spinner" style="float:left;display:block;"></div></div>');
107
  jQuery.ajax({
108
  type:"POST",url:ajaxurl,data:"action=frm_install",
109
+ success:function(){$msg.fadeOut('slow');}
110
  });
111
  }
112
  </script>
113
  <?php
114
  }
115
  }
116
+
117
+ global $frm_vars;
118
+ if ( $frm_vars['pro_is_authorized'] && ! file_exists(FrmAppHelper::plugin_path() . '/pro/formidable-pro.php') ) {
119
  // user is authorized, but running free version
120
  $inst_install_url = 'http://formidablepro.com/knowledgebase/manually-install-formidable-pro/';
121
  ?>
131
  return false;
132
  }
133
  </script>
134
+ <?php
135
  }
136
  }
137
+
138
  public static function admin_js(){
139
  global $pagenow;
140
+
141
  if ( 'admin-ajax.php' == $pagenow && isset($_GET['action']) && $_GET['action'] != 'frm_import_choices' ) {
142
  return;
143
  }
144
+
145
+ wp_register_script('bootstrap_tooltip', FrmAppHelper::plugin_url() .'/js/bootstrap.min.js', array('jquery'), '3.2.0');
146
+
 
 
147
  if ( isset($_GET) && ((isset($_GET['page']) && strpos($_GET['page'], 'formidable') === 0 ) ||
148
  ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'frm_display'))
149
  ) {
150
  $version = FrmAppHelper::plugin_version();
151
+ add_filter('admin_body_class', 'FrmAppController::admin_body_class' );
152
+
153
  wp_enqueue_script('jquery-ui-sortable');
154
  wp_enqueue_script('jquery-ui-draggable');
155
  wp_enqueue_script('admin-widgets');
156
  wp_enqueue_style('widgets');
157
  wp_enqueue_script('formidable');
158
+ wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() .'/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version, true);
159
  self::localize_script('admin');
160
+
161
  wp_enqueue_style('formidable-admin', FrmAppHelper::plugin_url() .'/css/frm_admin.css', array(), $version);
162
  add_thickbox();
163
+
164
  wp_register_script('formidable-editinplace', FrmAppHelper::plugin_url() .'/js/jquery/jquery.editinplace.packed.js', array('jquery'), '2.3.0');
165
  wp_register_script('jquery-frm-themepicker', FrmAppHelper::plugin_url() .'/js/jquery/jquery-ui-themepicker.js', array('jquery'), $version);
166
+
167
+ if ( FrmAppHelper::is_admin_page('formidable-settings') || FrmAppHelper::is_admin_page('formidable-styles') ) {
168
+ // load multselect js
169
+ wp_enqueue_script('bootstrap-multiselect', FrmAppHelper::plugin_url() .'/js/bootstrap-multiselect.js', array('jquery', 'bootstrap_tooltip'), '0.9.8', true);
170
+ }
171
+
172
+ } else if ( $pagenow == 'post.php' || ($pagenow == 'post-new.php' && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'frm_display') ) {
173
+ if ( isset($_REQUEST['post_type']) ) {
174
  $post_type = $_REQUEST['post_type'];
175
+ } else if ( isset($_REQUEST['post']) && !empty($_REQUEST['post']) ) {
176
  $post = get_post($_REQUEST['post']);
177
+ if ( !$post ) {
178
  return;
179
+ }
180
  $post_type = $post->post_type;
181
+ } else {
182
  return;
183
  }
184
+
185
+ if ( $post_type == 'frm_display' ) {
186
  $version = FrmAppHelper::plugin_version();
187
  wp_enqueue_script('jquery-ui-draggable');
188
  wp_enqueue_script('formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', array('formidable', 'jquery', 'jquery-ui-draggable', 'bootstrap_tooltip'), $version);
191
  }
192
  }
193
  }
194
+
195
  public static function admin_body_class($classes){
196
  global $wp_version;
197
+
198
  //we only need this class on Formidable pages
199
+ if ( version_compare( $wp_version, '3.4.9', '>') ) {
200
  $classes .= ' frm_35_trigger';
201
+ }
202
+
203
  return $classes;
204
  }
205
+
206
  public static function wp_admin_body_class($classes){
207
  global $wp_version;
208
  //we need this class everywhere in the admin for the menu
209
+ if ( version_compare( $wp_version, '3.7.2', '>') ) {
210
  $classes .= ' frm_38_trigger';
211
+ }
212
+
213
  return $classes;
214
  }
215
+
216
  public static function load_lang(){
217
+ load_plugin_textdomain('formidable', false, FrmAppHelper::plugin_folder() .'/languages/' );
218
+ }
219
+
220
+ /*
221
+ * Filter shortcodes in text widgets
222
+ */
223
+ public static function widget_text_filter( $content ) {
224
+ $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/';
225
+ return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content );
226
  }
 
 
 
227
 
228
+ public static function front_head(){
229
  if (is_multisite()){
 
230
  $old_db_version = get_option('frm_db_version');
231
+ $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option('frmpro_db_version') : false;
232
  if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) ||
233
+ ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) {
234
  self::install($old_db_version);
235
  }
236
  }
237
+
238
  $version = FrmAppHelper::plugin_version();
239
  wp_register_script('formidable', FrmAppHelper::plugin_url() . '/js/formidable.min.js', array('jquery'), $version, true);
240
  wp_register_script('jquery-placeholder', FrmAppHelper::plugin_url() .'/js/jquery/jquery.placeholder.js', array('jquery'), '2.0.7', true);
241
+
242
+ if ( FrmAppHelper::is_admin() ) {
 
243
  // don't load this in back-end
244
  return;
245
  }
246
+
247
  self::localize_script('front');
248
+
249
  wp_enqueue_script('jquery');
250
+
251
+ $frm_settings = FrmAppHelper::get_settings();
252
+
253
+ $style = apply_filters('get_frm_stylesheet', array());
254
  if($style){
255
+ foreach ( (array) $style as $k => $file ) {
256
  wp_register_style($k, $file, array(), $version);
257
  if ( 'all' == $frm_settings->load_style ) {
258
  wp_enqueue_style($k);
261
  }
262
  }
263
  unset($style);
264
+
265
+ if ( $frm_settings->load_style == 'all' ) {
266
  global $frm_vars;
267
  $frm_vars['css_loaded'] = true;
268
  }
269
  }
270
+
271
  public static function localize_script($location){
272
  wp_localize_script('formidable', 'frm_js', array(
273
  'ajax_url' => admin_url( 'admin-ajax.php' ),
275
  'loading' => __('Loading&hellip;'),
276
  'remove' => __('Remove', 'formidable'),
277
  'offset' => apply_filters('frm_scroll_offset', 4),
278
+ 'nonce' => wp_create_nonce('frm_form'),
279
  ));
280
+
281
  if($location == 'admin'){
282
+ $frm_settings = FrmAppHelper::get_settings();
283
  wp_localize_script('formidable_admin', 'frm_admin_js', array(
284
  'confirm_uninstall' => __('Are you sure you want to do this? Clicking OK will delete all forms, form data, and all other Formidable data. There is no Undo.', 'formidable'),
285
  'get_page' => (isset($_GET) && isset($_GET['page'])) ? $_GET['page'] : '',
286
+ 'desc' => __('(Click to add description)', 'formidable'),
287
+ 'blank' => __('(blank)', 'formidable'),
288
+ 'no_label' => __('(no label)', 'formidable'),
289
  'saving' => esc_attr(__('Saving', 'formidable')),
290
  'saved' => esc_attr(__('Saved', 'formidable')),
291
  'ok' => __('OK'),
296
  'no_valid_default' => __('Default value will NOT pass form validation', 'formidable'),
297
  'deauthorize' => __('Are you sure you want to deactivate Formidable Pro on this site?', 'formidable'),
298
  'confirm' => __('Are you sure?', 'formidable'),
299
+ 'conf_delete' => __('Are you sure you want to delete this field and all data associated with it?', 'formidable'),
300
+ 'conf_delete_sec' => __('WARNING: This will delete all fields inside of the section as well.', 'formidable'),
301
  'default_unique' => $frm_settings->unique_msg,
302
+ 'default_conf' => __('The entered values do not match', 'formidable'),
303
+ 'enter_email' => __('Enter Email', 'formidable'),
304
+ 'confirm_email' => __('Confirm Email', 'formidable'),
305
+ 'enter_password' => __('Enter Password', 'formidable'),
306
+ 'confirm_password' => __('Confirm Password', 'formidable'),
307
  'import_complete' => __('Import Complete', 'formidable'),
308
  'updating' => __('Please wait while your site updates.', 'formidable'),
309
  'nonce' => wp_create_nonce('frm_ajax'),
310
+ 'no_save_warning' => __('Warning: There is no way to retrieve unsaved entries.', 'formidable'),
311
+ 'jquery_ui_url' => FrmAppHelper::jquery_ui_base_url(),
312
  ));
313
  }
314
  }
315
+
316
+
317
+ public static function custom_stylesheet(){
318
+ global $frm_vars;
319
+ $css_file = array();
320
+
321
+ if ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) {
322
+ //include css in head
323
+ $uploads = FrmStylesHelper::get_upload_base();
324
+ if ( is_readable($uploads['basedir'] .'/formidable/css/formidablepro.css') ) {
325
+ $css_file['formidable'] = $uploads['baseurl'] .'/formidable/css/formidablepro.css';
326
+ } else {
327
+ $css_file['formidable'] = admin_url('admin-ajax.php') . '?action=frmpro_css';
328
+ }
329
+ }
330
+
331
+ if ( isset($frm_vars['datepicker_loaded']) && ! empty($frm_vars['datepicker_loaded']) ) {
332
+ FrmStylesHelper::enqueue_jquery_css();
333
+ }
334
+
335
+ return $css_file;
336
+ }
337
+
338
+ public static function load_css(){
339
+ $css = get_transient('frmpro_css');
340
+
341
+ include(FrmAppHelper::plugin_path() .'/css/custom_theme.css.php');
342
+ die();
343
+ }
344
+
345
  public static function footer_js($location='footer'){
346
+ global $frm_vars;
347
+
348
+ $frm_settings = FrmAppHelper::get_settings();
349
+ if ( $frm_vars['load_css'] && ! FrmAppHelper::is_admin() && $frm_settings->load_style != 'none' ) {
350
+ $css = apply_filters('get_frm_stylesheet', array());
351
+
 
 
352
  if(!empty($css)){
353
  echo "\n".'<script type="text/javascript">';
354
+ foreach ( (array) $css as $css_key => $file ) {
355
+ wp_enqueue_style($css_key);
356
+ unset($css_key, $file);
 
 
357
  }
358
  unset($css);
359
 
361
  }
362
  }
363
 
364
+ if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty($frm_vars['forms_loaded']) ) {
365
+ //load formidable js
366
+ wp_enqueue_script('formidable');
367
+ }
368
+ }
369
+
370
+ public static function activation_install() {
371
+ FrmAppHelper::delete_cache_and_transient('frm_plugin_version');
372
+ FrmFormActionsController::actions_init();
373
+ self::install();
374
  }
375
+
376
  public static function install($old_db_version=false){
377
+ $frmdb = new FrmDb();
378
  $frmdb->upgrade($old_db_version);
379
  }
380
+
381
  public static function uninstall(){
382
  check_ajax_referer( 'frm_ajax', 'nonce' );
383
+
384
  if ( current_user_can('administrator') ) {
385
+ $frmdb = new FrmDb();
386
  $frmdb->uninstall();
387
  echo true;
388
  } else {
389
+ $frm_settings = FrmAppHelper::get_settings();
390
  wp_die($frm_settings->admin_permission);
391
  }
392
  die();
393
  }
394
+
395
+ public static function drop_tables($tables) {
396
+ global $wpdb;
397
+ $tables[] = $wpdb->prefix .'frm_fields';
398
+ $tables[] = $wpdb->prefix .'frm_forms';
399
+ $tables[] = $wpdb->prefix .'frm_items';
400
+ $tables[] = $wpdb->prefix .'frm_item_metas';
401
+ return $tables;
402
+ }
403
+
404
  // Routes for wordpress pages -- we're just replacing content here folks.
405
  public static function page_route($content){
406
+ global $post;
407
 
408
+ $frm_settings = FrmAppHelper::get_settings();
409
  if( $post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])){
410
  $content = FrmFormsController::page_preview();
411
  }
412
 
413
  return $content;
414
  }
415
+
416
  public static function referer_session() {
417
+ $frm_settings = FrmAppHelper::get_settings();
418
+
419
  if ( !isset($frm_settings->track) || !$frm_settings->track || defined('WP_IMPORTING') ) {
420
  return;
421
  }
422
+
423
  // keep the page history below 100
424
  $max = 100;
425
+
426
  if ( !isset($_SESSION) )
427
  session_start();
428
+
429
+ if ( ! isset($_SESSION['frm_http_pages']) || ! is_array($_SESSION['frm_http_pages']) ) {
430
+ $_SESSION['frm_http_pages'] = array('http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']);
431
+ }
432
+
433
+ if ( ! isset($_SESSION['frm_http_referer']) || ! is_array($_SESSION['frm_http_referer']) ) {
434
  $_SESSION['frm_http_referer'] = array();
435
+ }
436
+
437
+ if ( ! isset($_SERVER['HTTP_REFERER']) ) {
438
+ $direct = __('Type-in or bookmark', 'formidable');
439
+ if(!in_array($direct, $_SESSION['frm_http_referer']))
440
+ $_SESSION['frm_http_referer'][] = $direct;
441
+ } else if ( strpos($_SERVER['HTTP_REFERER'], FrmAppHelper::site_url()) === false && ! in_array($_SERVER['HTTP_REFERER'], $_SESSION['frm_http_referer']) ) {
442
+ $_SESSION['frm_http_referer'][] = $_SERVER['HTTP_REFERER'];
443
+ }
444
+
445
+ if ( $_SESSION['frm_http_pages'] && ! empty($_SESSION['frm_http_pages']) && ( end($_SESSION['frm_http_pages']) != 'http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI']) ) {
446
+ $ext = substr(strrchr(substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '?')), '.'), 1);
447
+ if ( ! in_array($ext, array('css', 'js')) ) {
448
+ $_SESSION['frm_http_pages'][] = 'http://'. $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
449
  }
450
  }
451
+
 
 
 
452
  //keep the page history below the max
453
  if(count($_SESSION['frm_http_pages']) > $max){
454
  foreach($_SESSION['frm_http_pages'] as $pkey => $ppage){
455
  if(count($_SESSION['frm_http_pages']) <= $max)
456
  break;
457
+
458
  unset($_SESSION['frm_http_pages'][$pkey]);
459
  }
460
  }
461
  }
462
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  public static function update_message($features){
464
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' );
465
+ return FrmAppHelper::update_message($features);
 
 
 
 
 
 
466
  }
467
+
 
 
 
 
 
 
 
 
468
  public static function deauthorize(){
469
  check_ajax_referer( 'frm_ajax', 'nonce' );
470
+
471
  delete_option('frmpro-credentials');
472
  delete_option('frmpro-authorized');
473
  delete_site_option('frmpro-credentials');
474
  delete_site_option('frmpro-authorized');
475
  die();
476
  }
477
+
478
+ //formidable shortcode
479
+ public static function get_form_shortcode($atts){
480
+ _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' );
481
+ return FrmFormsController::get_form_shortcode($atts);
482
+ }
483
+
484
+ public static function get_postbox_class(){
485
+ _deprecated_function( __FUNCTION__, '2.0');
486
+ return 'postbox-container';
487
+ }
488
  }
classes/controllers/FrmEntriesController.php CHANGED
@@ -1,114 +1,473 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
-
6
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
-
8
- if(class_exists('FrmEntriesController'))
9
- return;
10
 
11
  class FrmEntriesController{
12
-
13
- public static function load_hooks(){
14
- add_action('admin_menu', 'FrmEntriesController::menu', 11);
15
- add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
16
- add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
17
- add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
18
- add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
19
- add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
-
22
- public static function menu(){
 
 
 
 
 
 
 
 
23
  global $frm_vars;
24
- if(!$frm_vars['pro_is_installed']){
25
- add_submenu_page('formidable', 'Formidable |'. __('Entries', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Entries', 'formidable') .'</span>', 'administrator', 'formidable-entries', 'FrmEntriesController::list_entries');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
 
 
27
  }
28
-
29
- public static function list_entries(){
30
- global $frm_entry;
31
- $frm_form = new FrmForm();
32
- $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
33
- $form_id = FrmAppHelper::get_param('form', false);
34
- if($form_id)
35
- $form = $frm_form->getOne($form_id);
36
- else
37
- $form = (isset($form_select[0])) ? $form_select[0] : 0;
38
-
39
- if($form)
40
- $entry_count = $frm_entry->getRecordCount($form->id);
41
-
42
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
-
45
  public static function show_form($id='', $key='', $title=false, $description=false){
46
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
47
  return FrmFormsController::show_form($id, $key, $title, $description);
48
  }
49
-
50
  public static function get_form($filename, $form, $title, $description) {
51
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
52
  return FrmFormsController::get_form($form, $title, $description);
53
  }
54
-
55
  public static function process_entry($errors='', $ajax=false){
56
- if((is_admin() and !defined('DOING_AJAX')) or !isset($_POST) or !isset($_POST['form_id']) or !is_numeric($_POST['form_id']) or !isset($_POST['item_key']))
57
  return;
 
58
 
59
- global $frm_entry, $frm_vars;
60
-
61
- $frm_form = new FrmForm();
62
- $form = $frm_form->getOne($_POST['form_id']);
63
  if(!$form)
64
  return;
65
-
66
- $params = FrmEntriesController::get_params($form);
67
-
68
  if(!isset($frm_vars['form_params']))
69
  $frm_vars['form_params'] = array();
70
  $frm_vars['form_params'][$form->id] = $params;
71
-
72
  if(isset($frm_vars['created_entries'][$_POST['form_id']]))
73
  return;
74
-
75
- if($errors == '')
76
- $errors = $frm_entry->validate($_POST);
 
77
  $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
78
-
79
  if( empty($errors) ){
80
  $_POST['frm_skip_cookie'] = 1;
81
  if($params['action'] == 'create'){
82
- if (apply_filters('frm_continue_to_create', true, $_POST['form_id']) and !isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']))
83
- $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = $frm_entry->create( $_POST );
 
84
  }
85
-
86
  do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
87
  unset($_POST['frm_skip_cookie']);
88
  }
89
  }
90
-
91
  public static function delete_entry_before_redirect($url, $form, $atts){
92
  self::_delete_entry($atts['id'], $form);
93
  return $url;
94
  }
95
-
96
  //Delete entry if not redirected
97
  public static function delete_entry_after_save($atts){
98
  self::_delete_entry($atts['entry_id'], $atts['form']);
99
  }
100
-
101
  private static function _delete_entry($entry_id, $form){
102
  if(!$form)
103
  return;
104
-
105
  $form->options = maybe_unserialize($form->options);
106
- if(isset($form->options['no_save']) and $form->options['no_save']){
107
- global $frm_entry;
108
- $frm_entry->destroy( $entry_id );
109
  }
110
  }
111
-
112
  public static function show_entry_shortcode($atts){
113
  $atts = shortcode_atts(array(
114
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
@@ -116,300 +475,137 @@ class FrmEntriesController{
116
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
117
  'font_size' => '', 'text_color' => '',
118
  'border_width' => '', 'border_color' => '',
119
- 'bg_color' => '', 'alt_bg_color' => '',
120
  ), $atts);
121
- extract($atts);
122
-
123
- if ( $format != 'text' ) {
124
  //format options are text, array, or json
125
- $plain_text = true;
126
- }
127
-
128
- global $frm_entry;
129
-
130
- if ( !$entry || !is_object($entry) ) {
131
- if ( !$id && !$default_email ) {
132
- return '';
133
- }
134
-
135
- if($id)
136
- $entry = $frm_entry->getOne($id, true);
137
- }
138
-
139
- if ( $entry ) {
140
- $form_id = $entry->form_id;
141
- $id = $entry->id;
142
- }
143
-
144
- if ( !$fields || !is_array($fields) ) {
145
- global $frm_field;
146
- $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
147
- }
148
-
149
- $content = ( $format != 'text' ) ? array() : '';
150
- $odd = true;
151
-
152
- if ( !$plain_text ) {
153
- global $frmpro_settings;
154
-
155
- $default_settings = array(
156
- 'border_color' => 'dddddd',
157
- 'bg_color' => 'f7f7f7',
158
- 'text_color' => '444444',
159
- 'font_size' => '12px',
160
- 'border_width' => '1px',
161
- 'alt_bg_color' => 'ffffff',
162
- );
163
-
164
- // merge defaults, global settings, and shortcode options
165
- foreach ( $default_settings as $key => $setting ) {
166
- if ( $atts[$key] != '' ) {
167
- continue;
168
- }
169
-
170
- if ( $frmpro_settings ) {
171
- if ( 'alt_bg_color' == $key ) {
172
- $atts[$key] = $frmpro_settings->bg_color_active;
173
- } else if ( 'border_width' == $key ) {
174
- $atts[$key] = $frmpro_settings->field_border_width;
175
- } else {
176
- $atts[$key] = $frmpro_settings->{$key};
177
- }
178
- } else {
179
- $atts[$key] = $setting;
180
- }
181
- unset($key, $setting);
182
- }
183
-
184
- unset($default_settings);
185
-
186
- $content .= "<table cellspacing='0' style='font-size:{$atts['font_size']};line-height:135%; border-bottom:{$atts['border_width']} solid #{$atts['border_color']};'><tbody>\r\n";
187
- $bg_color = " style='background-color:#{$atts['bg_color']};'";
188
- $bg_color_alt = " style='background-color:#{$atts['alt_bg_color']};'";
189
- $row_style = "style='text-align:". ( $direction == 'rtl' ? 'right' : 'left' ) .";color:#{$atts['text_color']};padding:7px 9px;border-top:{$atts['border_width']} solid #{$atts['border_color']}'";
190
- }
191
-
192
- foreach ( $fields as $f ) {
193
- if ( in_array($f->type, array('divider', 'captcha', 'break', 'html')) )
194
- continue;
195
-
196
- if ( $entry && !isset($entry->metas[$f->id]) ) {
197
- if ( $entry->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
198
- $p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
199
- 'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
200
- 'form_id' => $entry->form_id, 'field' => $f, 'type' => $f->type,
201
- 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
202
- ));
203
- if ( $p_val != '' ) {
204
- $entry->metas[$f->id] = $p_val;
205
- }
206
- }
207
-
208
- if ( !isset($entry->metas[$f->id]) && !$include_blank && !$default_email ) {
209
- continue;
210
- }
211
-
212
- $entry->metas[$f->id] = $default_email ? '['. $f->id .']' : '';
213
- }
214
-
215
- $val = '';
216
- if ( $entry ) {
217
- $prev_val = maybe_unserialize($entry->metas[$f->id]);
218
- $meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
219
-
220
- $val = $default_email ? $prev_val : apply_filters('frm_email_value', $prev_val, (object) $meta, $entry);
221
- } else if ( $default_email ) {
222
- $val = '['. $f->id .']';
223
- }
224
 
225
- if ( $f->type == 'textarea' and !$plain_text ) {
226
- $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val);
227
- }
228
-
229
- //Remove signature from default-message shortcode
230
- if ( $f->type == 'signature' && !$default_email ) {
231
- continue;
232
- }
233
-
234
- if ( is_array($val) && $format == 'text' ) {
235
- $val = implode(', ', $val);
236
  }
237
-
238
- $fname = $default_email ? '['. $f->id .' show=field_label]' : $f->name;
239
-
240
- if ( $format != 'text' ){
241
- $content[$f->field_key] = $val;
242
- } else if ( $plain_text ) {
243
- if ( 'rtl' == $direction ) {
244
- $content .= $val . ' :' . $fname . "\r\n\r\n";
245
- } else {
246
- $content .= $fname . ': ' . $val . "\r\n\r\n";
247
- }
248
- } else {
249
- if (!$default_email){
250
- $content .= '<tr'. ( $odd ? $bg_color : $bg_color_alt ) .'>';
251
- if ( 'rtl' == $direction ) {
252
- $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
253
- } else {
254
- $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
255
- }
256
- $content .= '</tr>'. "\r\n";
257
- $odd = ($odd) ? false : true;
258
- }else{
259
- $content .= '[if '. $f->id .']<tr style="[frm-alt-color]">';
260
- if ( 'rtl' == $direction ) {
261
- $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
262
- } else {
263
- $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
264
- }
265
- $content .= "</tr>\r\n[/if $f->id]";
266
- }
267
-
268
- }
269
-
270
- unset($fname, $f);
271
- }
272
-
273
- if ( $user_info ) {
274
- if ( isset($entry->description) ) {
275
- $data = maybe_unserialize($entry->description);
276
- } else if ( $default_email ) {
277
- $entry->ip = '[ip]';
278
- $data = array(
279
- 'browser' => '[browser]',
280
- 'referrer' => '[referrer]',
281
- );
282
- }
283
- if ( $format != 'text' ) {
284
- $content['ip'] = $entry->ip;
285
- $content['browser'] = $data['browser'];
286
- $content['referrer'] = $data['referrer'];
287
- } else if ( $plain_text ) {
288
- $content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
289
- if ( 'rtl' == $direction ) {
290
- $content .= $entry->ip . ' :'. __('IP Address', 'formidable') ."\r\n";
291
- $content .= $data['browser'] .' :'. __('User-Agent (Browser/OS)', 'formidable') ."\r\n";
292
- $content .= $data['referrer'] .' :'. __('Referrer', 'formidable') ."\r\n";
293
- } else {
294
- $content .= __('IP Address', 'formidable') . ': '. $entry->ip ."\r\n";
295
- $content .= __('User-Agent (Browser/OS)', 'formidable') . ': '. $data['browser']."\r\n";
296
- $content .= __('Referrer', 'formidable') . ': '. $data['referrer']."\r\n";
297
- }
298
- } else {
299
- $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
300
- if ( 'rtl' == $direction ) {
301
- $content .= "<td $row_style>". $entry->ip ."</td><th $row_style>". __('IP Address', 'formidable') . "</th>";
302
- } else {
303
- $content .= "<th $row_style>". __('IP Address', 'formidable') . "</th><td $row_style>". $entry->ip ."</td>";
304
- }
305
- $content .= '</tr>'. "\r\n";
306
- $odd = ($odd) ? false : true;
307
-
308
- if ( isset($data['browser']) ) {
309
- $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
310
- if ( 'rtl' == $direction ) {
311
- $content .= "<td $row_style>". $data['browser']."</td><th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th>";
312
- } else {
313
- $content .= "<th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th><td $row_style>". $data['browser']."</td>";
314
- }
315
- $content .= '</tr>'. "\r\n";
316
- }
317
- $odd = ($odd) ? false : true;
318
-
319
- if ( isset($data['referrer']) ) {
320
- $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
321
- if ( 'rtl' == $direction ) {
322
- $content .= "<td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td><th $row_style>".__('Referrer', 'formidable') . "</th>";
323
- } else {
324
- $content .= "<th $row_style>".__('Referrer', 'formidable') . "</th><td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td>";
325
- }
326
- $content .= '</tr>'. "\r\n";
327
- }
328
  }
329
  }
330
 
331
- if ( ! $plain_text ) {
332
- $content .= '</tbody></table>';
 
 
 
 
 
333
  }
334
-
335
- if ( $format == 'json' ) {
336
- $content = json_encode($content);
 
 
337
  }
338
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  return $content;
340
  }
341
-
342
  public static function &filter_email_value($value, $meta, $entry, $atts=array()){
343
- $frm_field = new FrmField();
344
- $field = $frm_field->getOne($meta->field_id);
345
- if(!$field)
346
- return $value;
347
-
348
  $value = self::filter_display_value($value, $field, $atts);
349
  return $value;
350
  }
351
-
 
 
 
 
 
 
 
 
 
 
 
352
  public static function &filter_display_value($value, $field, $atts=array()){
353
- $field->field_options = maybe_unserialize($field->field_options);
354
-
355
- $saved_value = (isset($atts['saved_value']) and $atts['saved_value']) ? true : false;
356
- if(!in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) or !isset($field->field_options['separate_value']) or !$field->field_options['separate_value'] or $saved_value)
357
  return $value;
358
-
359
- $field->options = maybe_unserialize($field->options);
360
- $f_values = array();
361
- $f_labels = array();
362
- foreach($field->options as $opt_key => $opt){
363
- if(!is_array($opt))
364
  continue;
365
-
 
366
  $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
367
  $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
368
- if($f_labels[$opt_key] == $f_values[$opt_key]){
369
- unset($f_values[$opt_key]);
370
- unset($f_labels[$opt_key]);
371
  }
372
- unset($opt_key);
373
- unset($opt);
374
  }
375
 
376
- if(!empty($f_values)){
377
- foreach((array)$value as $v_key => $val){
378
- if(in_array($val, $f_values)){
379
  $opt = array_search($val, $f_values);
380
- if(is_array($value))
381
  $value[$v_key] = $f_labels[$opt];
382
- else
383
  $value = $f_labels[$opt];
 
384
  }
385
- unset($v_key);
386
- unset($val);
387
  }
388
  }
389
-
390
  return $value;
391
  }
392
-
393
  public static function get_params($form=null){
394
  global $frm_vars;
395
-
396
- $frm_form = new FrmForm();
397
- if(!$form)
398
- $form = $frm_form->getAll(array(), 'name', 1);
399
- else if(!is_object($form))
400
- $form = $frm_form->getOne($form);
401
-
402
  if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
403
  return $frm_vars['form_params'][$form->id];
404
-
405
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
406
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
407
-
408
  $default_values = array(
409
- 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
410
  'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
411
  );
412
-
 
413
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
414
  if (!is_numeric($values['posted_form_id']))
415
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
@@ -431,10 +627,11 @@ class FrmEntriesController{
431
  }
432
  }
433
 
434
- if(in_array($values['action'], array('create', 'update')) and (!isset($_POST) or (!isset($_POST['action']) and !isset($_POST['frm_action']))))
435
  $values['action'] = 'new';
 
436
 
437
  return $values;
438
  }
439
-
440
  }
1
  <?php
 
 
 
 
 
 
 
 
2
 
3
  class FrmEntriesController{
4
+
5
+ public static function menu() {
6
+ if ( current_user_can('administrator') && !current_user_can('frm_view_entries') ) {
7
+ global $wp_roles;
8
+ $wp_roles->add_cap( 'administrator', 'frm_view_entries' );
9
+ $wp_roles->add_cap( 'administrator', 'frm_delete_entries' );
10
+ }
11
+
12
+ $frm_settings = FrmAppHelper::get_settings();
13
+
14
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Entries', 'formidable'), __('Entries', 'formidable'), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
15
+
16
+ if ( ! isset($_GET['frm_action']) || ! in_array($_GET['frm_action'], array('edit', 'show')) ) {
17
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' );
18
+ add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' );
19
+ add_filter('get_user_option_manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' );
20
+ }
21
+ }
22
+
23
+ /* Display in Back End */
24
+ public static function route(){
25
+ $action = FrmAppHelper::get_param('frm_action');
26
+
27
+ switch ( $action ) {
28
+ case 'show':
29
+ case 'destroy':
30
+ case 'destroy_all':
31
+ return self::$action();
32
+
33
+ default:
34
+ do_action('frm_entry_action_route', $action);
35
+ if ( apply_filters('frm_entry_stop_action_route', false, $action) ) {
36
+ return;
37
+ }
38
+
39
+ return self::display_list();
40
+ }
41
+ }
42
+
43
+ public static function contextual_help($help, $screen_id, $screen) {
44
+ // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
45
+ if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ){
46
+ return $help;
47
+ }
48
+
49
+ if ( ! isset($_GET) || ! isset($_GET['page']) || $_GET['page'] != 'formidable-entries' || ( isset($_GET['frm_action']) && $_GET['frm_action'] != 'list' ) ) {
50
+ return $help;
51
+ }
52
+
53
+ $screen->add_help_tab( array(
54
+ 'id' => 'formidable-entries-tab',
55
+ 'title' => __( 'Overview', 'formidable' ),
56
+ 'content' => '<p>' . __('This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable') .'</p>
57
+ <p>'. __('Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable') . '</p>',
58
+ ));
59
+
60
+ $screen->set_help_sidebar(
61
+ '<p><strong>' . __('For more information:', 'formidable') . '</strong></p>' .
62
+ '<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . __('Documentation on Entries', 'formidable') . '</a></p>' .
63
+ '<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . __('Support', 'formidable') . '</a></p>'
64
+ );
65
+
66
+ return $help;
67
+ }
68
+
69
+ public static function manage_columns($columns){
70
+ global $frm_vars, $wpdb;
71
+ $form_id = FrmEntriesHelper::get_current_form_id();
72
+
73
+ $columns[$form_id .'_id'] = 'ID';
74
+ $columns[$form_id .'_item_key'] = __('Entry Key', 'formidable');
75
+
76
+ if ( ! $form_id ) {
77
+ return $columns;
78
+ }
79
+
80
+ $form_cols = FrmField::get_all_for_form($form_id, '', 'include');
81
+
82
+ foreach ( $form_cols as $form_col ) {
83
+ if ( FrmFieldsHelper::is_no_save_field($form_col->type) ) {
84
+ continue;
85
+ }
86
+
87
+ if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) {
88
+ $columns[$form_id .'_frmsep_'. $form_col->field_key] = FrmAppHelper::truncate($form_col->name, 35);
89
+ }
90
+
91
+ if ( $form_col->type == 'form' && isset($form_col->field_options['form_select']) && !empty($form_col->field_options['form_select']) ) {
92
+ $sub_form_cols = FrmField::get_all_for_form($form_col->field_options['form_select']);
93
+
94
+ if ( $sub_form_cols ) {
95
+ foreach ( $sub_form_cols as $k => $sub_form_col ) {
96
+ if ( in_array($sub_form_col->type, FrmFieldsHelper::no_save_fields()) ) {
97
+ unset($sub_form_cols[$k]);
98
+ continue;
99
+ }
100
+ $columns[$form_id .'_'. $sub_form_col->field_key .'-_-'. $form_col->id] = FrmAppHelper::truncate($sub_form_col->name, 35);
101
+ unset($sub_form_col);
102
+ }
103
+ }
104
+ unset($sub_form_cols);
105
+ } else if ( $form_col->form_id != $form_id ) {
106
+ $columns[$form_id .'_'. $form_col->field_key .'-_-form'. $form_col->form_id] = FrmAppHelper::truncate($form_col->name, 35);
107
+ } else {
108
+ $columns[$form_id .'_'. $form_col->field_key] = FrmAppHelper::truncate($form_col->name, 35);
109
+ }
110
+
111
+ }
112
+
113
+ $columns[$form_id .'_created_at'] = __('Entry creation date', 'formidable');
114
+ $columns[$form_id .'_updated_at'] = __('Entry update date', 'formidable');
115
+ $columns[$form_id .'_ip'] = 'IP';
116
+
117
+ $frm_vars['cols'] = $columns;
118
+
119
+ if ( FrmAppHelper::is_admin_page('formidable-entries') && ( ! isset($_GET['frm_action']) || $_GET['frm_action'] == 'list' || $_GET['frm_action'] == 'destroy' ) ) {
120
+ add_screen_option( 'per_page', array('label' => __('Entries', 'formidable'), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page') );
121
+ }
122
+
123
+ return $columns;
124
  }
125
+
126
+ public static function check_hidden_cols($check, $object_id, $meta_key, $meta_value, $prev_value){
127
+ $frm_settings = FrmAppHelper::get_settings();
128
+ if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) {
129
+ return $check;
130
+ }
131
+
132
+ if ( empty($prev_value) )
133
+ $prev_value = get_metadata('user', $object_id, $meta_key, true);
134
+
135
  global $frm_vars;
136
+ //add a check so we don't create a loop
137
+ $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
138
+
139
+ return $check;
140
+ }
141
+
142
+ //add hidden columns back from other forms
143
+ public static function update_hidden_cols($meta_id, $object_id, $meta_key, $meta_value ){
144
+ $frm_settings = FrmAppHelper::get_settings();
145
+
146
+ if($meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden')
147
+ return;
148
+
149
+ global $frm_vars;
150
+ if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
151
+ return; //don't continue if there's no previous value
152
+ }
153
+
154
+ foreach($meta_value as $mk => $mv){
155
+ //remove blank values
156
+ if(empty($mv))
157
+ unset($meta_value[$mk]);
158
+ }
159
+
160
+ $cur_form_prefix = reset($meta_value);
161
+ $cur_form_prefix = explode('_', $cur_form_prefix);
162
+ $cur_form_prefix = $cur_form_prefix[0];
163
+ $save = false;
164
+
165
+ foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
166
+ if ( empty($prev_hidden) || in_array($prev_hidden, $meta_value) ) {
167
+ //don't add blank cols or process included cols
168
+ continue;
169
+ }
170
+
171
+ $form_prefix = explode('_', $prev_hidden);
172
+ $form_prefix = $form_prefix[0];
173
+ if($form_prefix == $cur_form_prefix) //don't add back columns that are meant to be hidden
174
+ continue;
175
+
176
+ $meta_value[] = $prev_hidden;
177
+ $save = true;
178
+ unset($form_prefix);
179
+ }
180
+
181
+ if($save){
182
+ $user = wp_get_current_user();
183
+ update_user_option($user->ID, 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden', $meta_value, true);
184
+ }
185
+ }
186
+
187
+ public static function save_per_page($save, $option, $value){
188
+ if ( $option == 'formidable_page_formidable_entries_per_page' ) {
189
+ $save = (int) $value;
190
+ }
191
+ return $save;
192
+ }
193
+
194
+ public static function sortable_columns(){
195
+ $form_id = FrmEntriesHelper::get_current_form_id();
196
+
197
+ $fields = FrmField::get_all_for_form($form_id);
198
+
199
+ $columns = array(
200
+ $form_id .'_id' => 'id',
201
+ $form_id .'_created_at' => 'created_at',
202
+ $form_id .'_updated_at' => 'updated_at',
203
+ $form_id .'_ip' => 'ip',
204
+ $form_id .'_item_key' => 'item_key',
205
+ $form_id .'_is_draft' => 'is_draft'
206
+ );
207
+
208
+ foreach ( $fields as $field ) {
209
+ if ( $field->type != 'checkbox' && ( ! isset($field->field_options['post_field']) || $field->field_options['post_field'] == '' ) ) {
210
+ // Can't sort on checkboxes because they are stored serialized, or post fields
211
+ $columns[ $form_id .'_'. $field->field_key ] = 'meta_'. $field->id;
212
+ }
213
+ }
214
+
215
+ return $columns;
216
+ }
217
+
218
+ public static function hidden_columns($result){
219
+ global $frm_vars;
220
+
221
+ $form_id = FrmEntriesHelper::get_current_form_id();
222
+
223
+ $return = false;
224
+ foreach ( (array) $result as $r ) {
225
+ if(!empty($r)){
226
+ $form_prefix = explode('_', $r);
227
+ $form_prefix = $form_prefix[0];
228
+
229
+ if ( (int) $form_prefix == (int) $form_id ) {
230
+ $return = true;
231
+ break;
232
+ }
233
+
234
+ unset($form_prefix);
235
+ }
236
+ }
237
+
238
+ if($return)
239
+ return $result;
240
+
241
+ $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
242
+ $max_columns = 8;
243
+ if($i <= $max_columns)
244
+ return $result;
245
+
246
+ global $frm_vars;
247
+ if(isset($frm_vars['current_form']) and $frm_vars['current_form'])
248
+ $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
249
+
250
+ if(isset($frm_vars['current_form']) and $frm_vars['current_form'] and isset($frm_vars['current_form']->options['hidden_cols']) and !empty($frm_vars['current_form']->options['hidden_cols'])){
251
+ $result = $frm_vars['current_form']->options['hidden_cols'];
252
+ }else{
253
+ $cols = $frm_vars['cols'];
254
+ $cols = array_reverse($cols, true);
255
+
256
+ $result[] = $form_id .'_id';
257
+ $i--;
258
+
259
+ $result[] = $form_id .'_item_key';
260
+ $i--;
261
+
262
+ foreach($cols as $col_key => $col){
263
+ if($i > $max_columns)
264
+ $result[] = $col_key; //remove some columns by default
265
+ $i--;
266
+ unset($col_key);
267
+ unset($col);
268
+ }
269
+ }
270
+
271
+ return $result;
272
+ }
273
+
274
+ public static function display_list($params=array(), $message='', $errors = array()){
275
+ global $wpdb, $frm_vars;
276
+
277
+ $form = FrmEntriesHelper::get_current_form();
278
+ $params = FrmEntriesHelper::get_admin_params( $form );
279
+
280
+ if($form){
281
+ $params['form'] = $form->id;
282
+ $frm_vars['current_form'] = $form;
283
+ $where_clause = " it.form_id=$form->id";
284
+
285
+ if ( 'trash' == $form->status ) {
286
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
287
+ $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, (isset($form->options['trash_time']) ? ($form->options['trash_time']) : time()));
288
+ $errors['trash'] = sprintf(__('This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable'), $time_to_delete);
289
+ unset($time_to_delete, $delete_timestamp);
290
+ }
291
+ }else{
292
+ $where_clause = '';
293
+ }
294
+
295
+ $table_class = apply_filters('frm_entries_list_class', 'FrmEntriesListHelper');
296
+
297
+ $wp_list_table = new $table_class( array('params' => $params) );
298
+
299
+ $pagenum = $wp_list_table->get_pagenum();
300
+
301
+ $wp_list_table->prepare_items();
302
+
303
+ $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
304
+ if ( $pagenum > $total_pages && $total_pages > 0 ) {
305
+ $url = add_query_arg( 'paged', $total_pages );
306
+ if ( headers_sent() ) {
307
+ echo FrmAppHelper::js_redirect($url);
308
+ } else {
309
+ wp_redirect($url);
310
+ }
311
+ die();
312
+ }
313
+
314
+ if ( empty($message) && isset($_GET['import-message']) ) {
315
+ $message = __('Your import is complete', 'formidable');
316
+ }
317
+
318
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
319
+ }
320
+
321
+ /* Back End CRUD */
322
+ public static function show($id = false){
323
+ FrmAppHelper::permission_check('frm_view_entries');
324
+
325
+ if ( ! $id ) {
326
+ $id = FrmAppHelper::get_param('id');
327
+
328
+ if ( ! $id ) {
329
+ $id = FrmAppHelper::get_param('item_id');
330
+ }
331
+ }
332
+
333
+ $entry = FrmEntry::getOne($id, true);
334
+
335
+ $data = maybe_unserialize($entry->description);
336
+ if ( ! is_array($data) || ! isset($data['referrer']) ) {
337
+ $data = array('referrer' => $data);
338
+ }
339
+
340
+ $fields = FrmField::get_all_for_form($entry->form_id);
341
+ $date_format = get_option('date_format');
342
+ $time_format = get_option('time_format');
343
+ $to_emails = array();
344
+
345
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php');
346
+ }
347
+
348
+ public static function destroy(){
349
+ FrmAppHelper::permission_check('frm_delete_entries');
350
+
351
+ $params = FrmEntriesHelper::get_admin_params();
352
+
353
+ if ( isset($params['keep_post']) && $params['keep_post'] ) {
354
+ //unlink entry from post
355
+ global $wpdb;
356
+ $wpdb->update( $wpdb->prefix .'frm_items', array('post_id' => ''), array('id' => $params['id']) );
357
+ }
358
+
359
+ $message = '';
360
+ if ( FrmEntry::destroy( $params['id'] ) ) {
361
+ $message = __('Entry was Successfully Destroyed', 'formidable');
362
  }
363
+
364
+ self::display_list($params, $message);
365
  }
366
+
367
+ public static function destroy_all(){
368
+ if ( ! current_user_can('frm_delete_entries') ) {
369
+ $frm_settings = FrmAppHelper::get_settings();
370
+ wp_die($frm_settings->admin_permission);
371
+ }
372
+
373
+ global $wpdb;
374
+ $params = FrmEntriesHelper::get_admin_params();
375
+ $message = '';
376
+ $errors = array();
377
+ $form_id = (int) $params['form'];
378
+
379
+ if ( $form_id ) {
380
+ $entry_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
381
+ $action = FrmFormActionsHelper::get_action_for_form($form_id, 'wppost', 1);
382
+
383
+ if ( $action ) {
384
+ // this action takes a while, so only trigger it if there are posts to delete
385
+ foreach ( $entry_ids as $entry_id ) {
386
+ do_action('frm_before_destroy_entry', $entry_id);
387
+ unset($entry_id);
388
+ }
389
+ }
390
+
391
+ $wpdb->query($wpdb->prepare("DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id));
392
+ $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
393
+ if ( $results ) {
394
+ $message = __('Entries were Successfully Destroyed', 'formidable');
395
+ }
396
+ } else {
397
+ $errors = __('No entries were specified', 'formidable');
398
+ }
399
+
400
+ self::display_list($params, $message, $errors);
401
  }
402
+
403
  public static function show_form($id='', $key='', $title=false, $description=false){
404
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
405
  return FrmFormsController::show_form($id, $key, $title, $description);
406
  }
407
+
408
  public static function get_form($filename, $form, $title, $description) {
409
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
410
  return FrmFormsController::get_form($form, $title, $description);
411
  }
412
+
413
  public static function process_entry($errors='', $ajax=false){
414
+ if ( FrmAppHelper::is_admin() || ! isset($_POST) || ! isset($_POST['form_id']) || ! is_numeric($_POST['form_id']) || ! isset($_POST['item_key']) ) {
415
  return;
416
+ }
417
 
418
+ global $frm_vars;
419
+
420
+ $form = FrmForm::getOne($_POST['form_id']);
 
421
  if(!$form)
422
  return;
423
+
424
+ $params = self::get_params($form);
425
+
426
  if(!isset($frm_vars['form_params']))
427
  $frm_vars['form_params'] = array();
428
  $frm_vars['form_params'][$form->id] = $params;
429
+
430
  if(isset($frm_vars['created_entries'][$_POST['form_id']]))
431
  return;
432
+
433
+ if ( $errors == '' ) {
434
+ $errors = FrmEntry::validate($_POST);
435
+ }
436
  $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
437
+
438
  if( empty($errors) ){
439
  $_POST['frm_skip_cookie'] = 1;
440
  if($params['action'] == 'create'){
441
+ if ( apply_filters('frm_continue_to_create', true, $_POST['form_id']) && ! isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']) ) {
442
+ $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = FrmEntry::create( $_POST );
443
+ }
444
  }
445
+
446
  do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
447
  unset($_POST['frm_skip_cookie']);
448
  }
449
  }
450
+
451
  public static function delete_entry_before_redirect($url, $form, $atts){
452
  self::_delete_entry($atts['id'], $form);
453
  return $url;
454
  }
455
+
456
  //Delete entry if not redirected
457
  public static function delete_entry_after_save($atts){
458
  self::_delete_entry($atts['entry_id'], $atts['form']);
459
  }
460
+
461
  private static function _delete_entry($entry_id, $form){
462
  if(!$form)
463
  return;
464
+
465
  $form->options = maybe_unserialize($form->options);
466
+ if ( isset($form->options['no_save']) && $form->options['no_save'] ) {
467
+ FrmEntry::destroy( $entry_id );
 
468
  }
469
  }
470
+
471
  public static function show_entry_shortcode($atts){
472
  $atts = shortcode_atts(array(
473
  'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
475
  'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
476
  'font_size' => '', 'text_color' => '',
477
  'border_width' => '', 'border_color' => '',
478
+ 'bg_color' => '', 'alt_bg_color' => '',
479
  ), $atts);
480
+
481
+ if ( $atts['format'] != 'text' ) {
 
482
  //format options are text, array, or json
483
+ $atts['plain_text'] = true;
484
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
 
486
+ if ( ! $atts['entry'] || ! is_object($atts['entry']) ) {
487
+ if ( ! $atts['id'] && ! $atts['default_email'] ) {
488
+ return;
 
 
 
 
 
 
 
 
489
  }
490
+
491
+ if ( $atts['id'] ) {
492
+ $atts['entry'] = FrmEntry::getOne($atts['id'], true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  }
494
  }
495
 
496
+ if ( $atts['entry'] ) {
497
+ $atts['form_id'] = $atts['entry']->form_id;
498
+ $atts['id'] = $atts['entry']->id;
499
+ }
500
+
501
+ if ( ! $atts['fields'] || ! is_array($atts['fields']) ) {
502
+ $atts['fields'] = FrmField::get_all_for_form($atts['form_id']);
503
  }
504
+
505
+ $values = array();
506
+ foreach ( $atts['fields'] as $f ) {
507
+ FrmEntriesHelper::fill_entry_values($atts, $f, $values);
508
+ unset($f);
509
  }
510
+
511
+ FrmEntriesHelper::fill_entry_user_info($atts, $values);
512
+
513
+ if ( $atts['format'] == 'json' ) {
514
+ return json_encode($values);
515
+ } else if ( $atts['format'] == 'array' ) {
516
+ return $values;
517
+ }
518
+
519
+ $content = array();
520
+ FrmEntriesHelper::convert_entry_to_content($values, $atts, $content);
521
+
522
+ if ( 'text' == $atts['format'] ) {
523
+ $content = implode('', $content);
524
+ }
525
+
526
  return $content;
527
  }
528
+
529
  public static function &filter_email_value($value, $meta, $entry, $atts=array()){
530
+ $field = FrmField::getOne($meta->field_id);
531
+ if ( ! $field ) {
532
+ return $value;
533
+ }
534
+
535
  $value = self::filter_display_value($value, $field, $atts);
536
  return $value;
537
  }
538
+
539
+ public static function &filter_shortcode_value($value, $tag, $atts, $field) {
540
+ $plain_text = add_filter('frm_plain_text_email', true);
541
+ FrmEntriesHelper::textarea_display_value( $value, $field->type, $plain_text );
542
+
543
+ if ( isset($atts['show']) && $atts['show'] == 'value' ) {
544
+ return $value;
545
+ }
546
+
547
+ return self::filter_display_value($value, $field, $atts);
548
+ }
549
+
550
  public static function &filter_display_value($value, $field, $atts=array()){
551
+ $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false;
552
+ if ( ! in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) || ! isset($field->field_options['separate_value']) || ! $field->field_options['separate_value'] || $saved_value ) {
 
 
553
  return $value;
554
+ }
555
+
556
+ $f_values = $f_labels = array();
557
+
558
+ foreach ( $field->options as $opt_key => $opt ) {
559
+ if ( ! is_array($opt) ) {
560
  continue;
561
+ }
562
+
563
  $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
564
  $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
565
+ if ( $f_labels[$opt_key] == $f_values[$opt_key] ) {
566
+ unset($f_values[$opt_key], $f_labels[$opt_key]);
 
567
  }
568
+ unset($opt_key, $opt);
 
569
  }
570
 
571
+ if ( ! empty($f_values) ) {
572
+ foreach ( (array) $value as $v_key => $val ) {
573
+ if ( in_array($val, $f_values) ) {
574
  $opt = array_search($val, $f_values);
575
+ if ( is_array($value) ) {
576
  $value[$v_key] = $f_labels[$opt];
577
+ } else {
578
  $value = $f_labels[$opt];
579
+ }
580
  }
581
+ unset($v_key, $val);
 
582
  }
583
  }
584
+
585
  return $value;
586
  }
587
+
588
  public static function get_params($form=null){
589
  global $frm_vars;
590
+
591
+ if ( ! $form ) {
592
+ $form = FrmForm::getAll(array(), 'name', 1);
593
+ } else {
594
+ FrmFormsHelper::maybe_get_form( $form );
595
+ }
596
+
597
  if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
598
  return $frm_vars['form_params'][$form->id];
599
+
600
  $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
601
  $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
602
+
603
  $default_values = array(
604
+ 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
605
  'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
606
  );
607
+
608
+ $values = array();
609
  $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
610
  if (!is_numeric($values['posted_form_id']))
611
  $values['posted_form_id'] = FrmAppHelper::get_param('form');
627
  }
628
  }
629
 
630
+ if ( in_array($values['action'], array('create', 'update')) && ( ! isset($_POST) || ( ! isset($_POST['action']) && ! isset($_POST['frm_action']) ) ) ) {
631
  $values['action'] = 'new';
632
+ }
633
 
634
  return $values;
635
  }
636
+
637
  }
classes/controllers/FrmFieldsController.php CHANGED
@@ -1,270 +1,332 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
 
6
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
-
8
- if(class_exists('FrmFieldsController'))
9
- return;
10
-
11
  class FrmFieldsController{
12
- public static function load_hooks(){
13
- add_action('wp_ajax_frm_load_field', 'FrmFieldsController::load_field');
14
- add_action('wp_ajax_frm_insert_field', 'FrmFieldsController::create');
15
- add_action('wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name');
16
- add_action('wp_ajax_frm_field_desc_in_place_edit', 'FrmFieldsController::edit_description');
17
- add_action('wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option');
18
- add_action('wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate');
19
- add_action('wp_ajax_frm_delete_field', 'FrmFieldsController::destroy');
20
- add_action('wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option');
21
- add_action('wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option');
22
- add_action('wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option');
23
- add_action('wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices');
24
- add_action('wp_ajax_frm_import_options', 'FrmFieldsController::import_options');
25
- add_action('wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order');
26
- add_filter('frm_field_type', 'FrmFieldsController::change_type');
27
- add_filter('frm_display_field_options', 'FrmFieldsController::display_field_options');
28
- add_action('frm_field_input_html', 'FrmFieldsController::input_html');
29
- add_filter('frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3);
30
- add_filter('frm_field_label_seen', 'FrmFieldsController::check_label', 10, 3);
31
- }
32
-
33
  public static function load_field(){
34
  $fields = $_POST['field'];
35
  if ( empty($fields) ) {
36
  die();
37
  }
38
-
39
  $_GET['page'] = 'formidable';
40
  $fields = stripslashes_deep($fields);
41
-
42
  $ajax = true;
43
  $values = array();
44
  $path = FrmAppHelper::plugin_path();
45
  $field_html = array();
46
-
47
  foreach ( $fields as $field ) {
48
  $field = htmlspecialchars_decode(nl2br($field));
49
  $field = json_decode($field, true);
50
-
51
  $field_id = $field['id'];
52
-
53
  if ( !isset($field['value']) ) {
54
  $field['value'] = '';
55
  }
56
-
57
- $field_name = "item_meta[$field_id]";
58
-
 
59
  ob_start();
60
  include($path .'/classes/views/frm-forms/add_field.php');
61
  $field_html[$field_id] = ob_get_contents();
62
  ob_end_clean();
63
  }
64
-
65
  unset($path);
66
-
67
  echo json_encode($field_html);
68
-
69
  die();
70
  }
71
-
72
  public static function create(){
73
- $field_data = $_POST['field'];
74
  $form_id = $_POST['form_id'];
 
 
 
 
 
 
 
 
 
 
75
  $values = array();
76
- if(class_exists('FrmProForm'))
77
  $values['post_type'] = FrmProFormsHelper::post_type($form_id);
78
-
79
- $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_data, $form_id));
80
-
81
- $frm_field = new FrmField();
82
- $field_id = $frm_field->create( $field_values );
83
-
84
- if ($field_id){
85
- $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id));
86
- $field_name = "item_meta[$field_id]";
87
- $id = $form_id;
88
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
89
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  die();
91
  }
92
-
93
  public static function edit_name($field = 'name', $id = '') {
94
  if ( empty($field) ) {
95
  $field = 'name';
96
  }
97
-
98
  if ( empty($id) ) {
99
  $id = str_replace('field_label_', '', $_POST['element_id']);
100
  }
101
-
102
  $value = trim($_POST['update_value']);
103
  if ( trim(strip_tags($value)) == '' ) {
104
  // set blank value if there is no content
105
  $value = '';
106
  }
107
-
108
- $frm_field = new FrmField();
109
- $form = $frm_field->update($id, array($field => $value));
110
- echo stripslashes($value);
111
- die();
112
- }
113
-
114
 
115
- public static function edit_description(){
116
- $id = str_replace('field_description_', '', $_POST['element_id']);
117
- self::edit_name('description', $id);
118
  }
119
-
120
  public static function update_ajax_option(){
121
- $frm_field = new FrmField();
122
- $field = $frm_field->getOne($_POST['field']);
123
  foreach ( array('clear_on_focus', 'separate_value', 'default_blank') as $val ) {
124
  if ( isset($_POST[$val]) ) {
125
  $new_val = $_POST[$val];
126
  if ( $val == 'separate_value' ) {
127
  $new_val = (isset($field->field_options[$val]) && $field->field_options[$val]) ? 0 : 1;
128
  }
129
-
130
- $field->field_options[$val] = $new_val;
131
- unset($new_val);
132
- }
133
  unset($val);
134
  }
135
 
136
- $frm_field->update($_POST['field'], array('field_options' => $field->field_options));
 
 
 
137
  die();
138
  }
139
-
140
  public static function duplicate(){
141
  global $wpdb;
142
-
143
- $frm_field = new FrmField();
144
- $copy_field = $frm_field->getOne($_POST['field_id']);
145
- if (!$copy_field) return;
146
-
 
 
 
 
 
 
147
  $values = array();
148
- $values['field_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_fields', 'field_key');
149
- $values['options'] = maybe_serialize($copy_field->options);
150
- $values['default_value'] = maybe_serialize($copy_field->default_value);
151
- $values['form_id'] = $copy_field->form_id;
152
- foreach (array('name', 'description', 'type', 'field_options', 'required') as $col)
153
- $values[$col] = $copy_field->{$col};
154
- $field_count = FrmAppHelper::getRecordCount(array('form_id' => $copy_field->form_id), $wpdb->prefix . 'frm_fields');
155
  $values['field_order'] = $field_count + 1;
156
-
157
- $field_id = $frm_field->create($values);
158
-
159
- if ($field_id){
160
- $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id));
161
- $field_name = "item_meta[$field_id]";
162
- $id = $field['form_id'];
163
- if($field['type'] == 'html')
164
- $field['stop_filter'] = true;
165
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
166
  }
 
 
 
167
  die();
168
  }
169
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  public static function destroy(){
171
- $frm_field = new FrmField();
172
- $field_id = $frm_field->destroy($_POST['field_id']);
173
  die();
174
- }
175
 
176
  /* Field Options */
177
- public static function add_option(){
178
- $frm_field = new FrmField();
179
 
 
 
180
  $id = $_POST['field_id'];
181
- $field = $frm_field->getOne($id);
 
 
 
182
  $options = maybe_unserialize($field->options);
183
- if(!empty($options))
184
- $last = max(array_keys($options));
185
- else
 
186
  $last = 0;
187
-
188
  $opt_key = $last + 1;
189
- $first_opt = reset($options);
190
- $next_opt = count($options);
191
- if($first_opt != '')
192
- $next_opt++;
193
- $opt = __('Option', 'formidable') .' '. $next_opt;
194
- unset($next_opt);
195
-
 
 
 
 
 
 
 
 
 
 
 
 
196
  $field_val = $opt;
197
  $options[$opt_key] = $opt;
198
- $frm_field->update($id, array('options' => maybe_serialize($options)));
199
- $checked = '';
200
 
201
- $field_data = $frm_field->getOne($id);
202
- $field_data->field_options = maybe_unserialize($field_data->field_options);
203
- $field = array();
204
- $field['type'] = $field_data->type;
205
- $field['id'] = $id;
206
- $field['separate_value'] = isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0;
 
 
 
 
 
 
207
  $field_name = "item_meta[$id]";
208
-
209
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
 
 
 
 
 
 
210
  die();
211
  }
212
 
213
- public static function edit_option(){
214
  $ids = explode('-', $_POST['element_id']);
215
- $id = str_replace('field_', '', $ids[0]);
 
216
  if ( strpos($_POST['element_id'], 'key_') ) {
217
- $id = str_replace('key_', '', $id);
218
- $new_value = trim($_POST['update_value']);
219
  } else {
220
- $new_label = trim($_POST['update_value']);
221
  }
222
-
223
- $frm_field = new FrmField();
224
- $field = $frm_field->getOne($id);
225
  $options = maybe_unserialize($field->options);
226
- $this_opt = (array) $options[$ids[1]];
227
-
 
 
 
228
  $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
229
- if ( isset($this_opt['value']) ) {
230
- $value = $this_opt['value'];
231
- }
232
-
233
  if ( !isset($new_label) ) {
234
  $new_label = $label;
235
  }
236
-
237
  if ( isset($new_value) || isset($value) ) {
238
  $update_value = isset($new_value) ? $new_value : $value;
239
  }
240
-
241
- if ( isset($update_value) && $update_value != $new_label ) {
242
- $options[$ids[1]] = array('value' => $update_value, 'label' => $new_label);
243
  } else {
244
- $options[$ids[1]] = trim($_POST['update_value']);
245
  }
246
-
247
- $frm_field->update($id, array('options' => maybe_serialize($options)));
248
  echo (trim($_POST['update_value']) == '') ? __('(Blank)', 'formidable') : stripslashes($_POST['update_value']);
249
  die();
250
  }
251
 
252
  public static function delete_option(){
253
- $frm_field = new FrmField();
254
- $field = $frm_field->getOne($_POST['field_id']);
255
  $options = maybe_unserialize($field->options);
256
- unset($options[$_POST['opt_key']]);
257
- $frm_field->update($_POST['field_id'], array('options' => maybe_serialize($options)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  die();
259
  }
260
-
261
  public static function import_choices(){
262
  if ( !current_user_can('frm_edit_forms') ) {
263
  return;
264
  }
265
-
266
  $field_id = $_REQUEST['field_id'];
267
-
268
  global $current_screen, $hook_suffix;
269
 
270
  // Catch plugins that include admin-header.php before admin.php completes.
@@ -272,80 +334,86 @@ class FrmFieldsController{
272
  $hook_suffix = '';
273
  set_current_screen();
274
  }
275
-
276
  if ( function_exists('register_admin_color_schemes') ) {
277
  register_admin_color_schemes();
278
  }
279
-
280
  $hook_suffix = $admin_body_class = '';
281
-
282
- if ( get_user_setting('mfold') == 'f' )
283
  $admin_body_class .= ' folded';
 
284
 
285
  if ( function_exists('is_admin_bar_showing') && is_admin_bar_showing() ) {
286
  $admin_body_class .= ' admin-bar';
287
  }
288
 
289
- if ( is_rtl() )
290
  $admin_body_class .= ' rtl';
 
291
 
292
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
293
  $prepop = array();
 
 
 
 
 
 
 
 
 
294
  $prepop[__('Countries', 'formidable')] = FrmAppHelper::get_countries();
295
-
296
  $states = FrmAppHelper::get_us_states();
297
  $state_abv = array_keys($states);
298
  sort($state_abv);
299
  $prepop[__('U.S. State Abbreviations', 'formidable')] = $state_abv;
 
300
  $states = array_values($states);
301
  sort($states);
302
  $prepop[__('U.S. States', 'formidable')] = $states;
303
- unset($state_abv);
304
- unset($states);
305
-
306
  $prepop[__('Age', 'formidable')] = array(
307
- __('Under 18', 'formidable'), __('18-24', 'formidable'), __('25-34', 'formidable'),
308
  __('35-44', 'formidable'), __('45-54', 'formidable'), __('55-64', 'formidable'),
309
  __('65 or Above', 'formidable'), __('Prefer Not to Answer', 'formidable')
310
  );
311
-
312
  $prepop[__('Satisfaction', 'formidable')] = array(
313
- __('Very Satisfied', 'formidable'), __('Satisfied', 'formidable'), __('Neutral', 'formidable'),
314
  __('Unsatisfied', 'formidable'), __('Very Unsatisfied', 'formidable'), __('N/A', 'formidable')
315
  );
316
 
317
  $prepop[__('Importance', 'formidable')] = array(
318
- __('Very Important', 'formidable'), __('Important', 'formidable'), __('Neutral', 'formidable'),
319
  __('Somewhat Important', 'formidable'), __('Not at all Important', 'formidable'), __('N/A', 'formidable')
320
  );
321
-
322
  $prepop[__('Agreement', 'formidable')] = array(
323
- __('Strongly Agree', 'formidable'), __('Agree', 'formidable'), __('Neutral', 'formidable'),
324
  __('Disagree', 'formidable'), __('Strongly Disagree', 'formidable'), __('N/A', 'formidable')
325
  );
326
-
327
  $prepop = apply_filters('frm_bulk_field_choices', $prepop);
328
-
329
- $frm_field = new FrmField();
330
- $field = $frm_field->getOne($field_id);
331
-
332
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
333
- die();
334
  }
335
-
336
  public static function import_options(){
337
- if(!is_admin() or !current_user_can('frm_edit_forms'))
338
  return;
339
-
340
- extract(stripslashes_deep($_POST));
341
-
342
- $frm_field = new FrmField();
343
- $field = $frm_field->getOne($field_id);
344
-
345
- if(!in_array($field->type, array('radio', 'checkbox', 'select')))
346
  return;
347
-
 
348
  $field = FrmFieldsHelper::setup_edit_vars($field);
 
349
  $opts = explode("\n", rtrim($opts, "\n"));
350
  if ( $field['separate_value'] ) {
351
  foreach ( $opts as $opt_key => $opt ) {
@@ -360,53 +428,63 @@ class FrmFieldsController{
360
  unset($opt);
361
  }
362
  }
363
-
364
- $frm_field->update($field_id, array('options' => maybe_serialize($opts)));
365
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  $field['options'] = $opts;
367
  $field_name = $field['name'];
368
-
369
  if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
370
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
371
  } else {
372
- foreach ( $field['options'] as $opt_key => $opt ) {
373
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
374
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
375
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
376
- }
377
  }
378
-
379
  die();
380
  }
381
 
382
  public static function update_order(){
383
- if(isset($_POST) and isset($_POST['frm_field_id'])){
384
- $frm_field = new FrmField();
385
-
386
  foreach ($_POST['frm_field_id'] as $position => $item)
387
- $frm_field->update($item, array('field_order' => $position));
388
  }
389
  die();
390
  }
391
-
392
  public static function change_type($type){
393
- global $frm_vars;
 
 
 
 
 
 
 
 
394
 
395
- if ($frm_vars['pro_is_installed']) return $type;
396
-
397
- if($type == 'scale' || $type == '10radio')
398
- $type = 'radio';
399
- else if($type == 'rte')
400
- $type = 'textarea';
401
-
402
  $frm_field_selection = FrmFieldsHelper::field_selection();
403
  $types = array_keys($frm_field_selection);
404
- if (!in_array($type, $types) && $type != 'captcha')
405
  $type = 'text';
 
406
 
407
  return $type;
408
  }
409
-
410
  public static function display_field_options($display){
411
  switch($display['type']){
412
  case 'captcha':
@@ -425,107 +503,188 @@ class FrmFieldsController{
425
  case 'select':
426
  $display['size'] = true;
427
  break;
 
 
 
 
 
 
428
  }
429
-
430
  return $display;
431
  }
432
-
433
  public static function input_html($field, $echo=true){
434
- global $frm_settings, $frm_vars;
435
-
436
- $class = ''; //$field['type'];
437
-
438
- if ( is_admin() && (!isset($frm_vars['preview']) || !$frm_vars['preview']) && !in_array($field['type'], array('scale', 'radio', 'checkbox', 'data')) ) {
439
- $class .= 'dyn_default_value';
440
- }
441
-
442
- $add_html = '';
443
-
444
- if(isset($field['size']) and $field['size'] > 0){
445
- if(!in_array($field['type'], array('textarea', 'select', 'data', 'time', 'hidden')))
446
- $add_html .= ' size="'. $field['size'] .'"';
447
- $class .= " auto_width";
448
- }
449
-
450
- if ( isset($field['max']) && !in_array($field['type'], array('textarea', 'rte', 'hidden')) && !empty($field['max']) && (!is_admin() || !isset($_GET) || !isset($_GET['page']) || $_GET['page'] != 'formidable') ) {
451
- $add_html .= ' maxlength="'. $field['max'] .'"';
452
- }
453
-
454
- if(!is_admin() or defined('DOING_AJAX') or !isset($_GET) or !isset($_GET['page']) or $_GET['page'] == 'formidable-entries'){
455
- /*if(isset($field['required']) and $field['required']){
456
- $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
457
- $action = FrmAppHelper::get_param($action);
458
-
459
- //if($field['type'] != 'checkbox')
460
- // $add_html .= ' required="required"';
461
-
462
- if($field['type'] == 'file' and $action == 'edit'){
463
- //don't add the required class if this is a file upload when editing
464
- }else{
465
- $class .= " required";
466
- }
467
- unset($action);
468
- }*/
469
-
470
- if(isset($field['clear_on_focus']) and $field['clear_on_focus'] and !empty($field['default_value'])){
471
-
472
- if($frm_settings->use_html and !in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden'))){
473
- $add_html .= ' placeholder="'. esc_attr($field['default_value']) .'"';
474
- FrmAppHelper::load_scripts('jquery-placeholder');
475
- }else if(!$frm_settings->use_html){
476
- $val = str_replace(array("\r\n", "\n"), '\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
477
- $add_html .= ' onfocus="frmClearDefault('."'". $val ."'". ',this)" onblur="frmReplaceDefault('."'". $val ."'". ',this)"';
478
- if($field['value'] == $field['default_value'])
479
- $class .= ' frm_default';
480
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  }
482
  }
483
-
484
- if(isset($field['input_class']) and !empty($field['input_class']))
485
- $class .= ' '. $field['input_class'];
486
-
487
- $class = apply_filters('frm_field_classes', $class, $field);
488
-
489
- if(!empty($class))
490
- $add_html .= ' class="'. trim($class) .'"';
491
-
492
- if ( isset($field['shortcodes']) && !empty($field['shortcodes']) ) {
493
- foreach ( $field['shortcodes'] as $k => $v ) {
494
- if ( 'opt' === $k || (!is_numeric($k) && strpos($add_html, " $k=")) ) {
495
- continue;
496
- }
497
-
498
- if ( is_numeric($k) && strpos($v, '=') ) {
499
- $add_html .= ' '. $v;
500
- } else {
501
- $add_html .= ' '. $k .'="'. $v .'"';
502
- }
503
-
504
- unset($k, $v);
505
  }
 
 
 
 
 
 
 
 
 
 
506
  }
507
-
508
- if($echo)
509
- echo $add_html;
510
-
511
- return $add_html;
512
  }
513
-
514
  public static function check_value($opt, $opt_key, $field){
515
  if(is_array($opt)){
516
- if(isset($field['separate_value']) and $field['separate_value']){
517
  $opt = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
518
- }else{
519
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
520
  }
521
  }
522
  return $opt;
523
  }
524
-
525
- public static function check_label($opt, $opt_key, $field){
526
- if(is_array($opt))
527
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
528
-
 
529
  return $opt;
530
  }
 
 
 
 
 
 
531
  }
1
  <?php
 
 
 
2
 
 
 
 
 
 
3
  class FrmFieldsController{
4
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  public static function load_field(){
6
  $fields = $_POST['field'];
7
  if ( empty($fields) ) {
8
  die();
9
  }
10
+
11
  $_GET['page'] = 'formidable';
12
  $fields = stripslashes_deep($fields);
13
+
14
  $ajax = true;
15
  $values = array();
16
  $path = FrmAppHelper::plugin_path();
17
  $field_html = array();
18
+
19
  foreach ( $fields as $field ) {
20
  $field = htmlspecialchars_decode(nl2br($field));
21
  $field = json_decode($field, true);
22
+
23
  $field_id = $field['id'];
24
+
25
  if ( !isset($field['value']) ) {
26
  $field['value'] = '';
27
  }
28
+
29
+ $field_name = 'item_meta['. $field_id .']';
30
+ $html_id = FrmFieldsHelper::get_html_id($field);
31
+
32
  ob_start();
33
  include($path .'/classes/views/frm-forms/add_field.php');
34
  $field_html[$field_id] = ob_get_contents();
35
  ob_end_clean();
36
  }
37
+
38
  unset($path);
39
+
40
  echo json_encode($field_html);
41
+
42
  die();
43
  }
44
+
45
  public static function create(){
46
+ $field_type = $_POST['field'];
47
  $form_id = $_POST['form_id'];
48
+
49
+ $field = self::include_new_field($field_type, $form_id);
50
+
51
+ // this hook will allow for multiple fields to be added at once
52
+ do_action('frm_after_field_created', $field, $form_id);
53
+
54
+ wp_die();
55
+ }
56
+
57
+ public static function include_new_field($field_type, $form_id) {
58
  $values = array();
59
+ if ( FrmAppHelper::pro_is_installed() ) {
60
  $values['post_type'] = FrmProFormsHelper::post_type($form_id);
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
+
63
+ $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_type, $form_id));
64
+ $field_id = FrmField::create( $field_values );
65
+
66
+ if ( ! $field_id ) {
67
+ return false;
68
+ }
69
+
70
+ $field = self::include_single_field($field_id, $values, $form_id);
71
+
72
+ return $field;
73
+ }
74
+
75
+ public static function update_form_id() {
76
+ check_ajax_referer( 'frm_ajax', 'nonce' );
77
+
78
+ $field_id = (int) $_POST['field'];
79
+ $form_id = (int) $_POST['form_id'];
80
+ if ( !$field_id || !$form_id ) {
81
+ return;
82
+ }
83
+
84
+ FrmField::update( $field_id, compact('form_id') );
85
+
86
  die();
87
  }
88
+
89
  public static function edit_name($field = 'name', $id = '') {
90
  if ( empty($field) ) {
91
  $field = 'name';
92
  }
93
+
94
  if ( empty($id) ) {
95
  $id = str_replace('field_label_', '', $_POST['element_id']);
96
  }
97
+
98
  $value = trim($_POST['update_value']);
99
  if ( trim(strip_tags($value)) == '' ) {
100
  // set blank value if there is no content
101
  $value = '';
102
  }
 
 
 
 
 
 
 
103
 
104
+ FrmField::update($id, array($field => $value));
105
+ echo stripslashes($value);
106
+ wp_die();
107
  }
108
+
109
  public static function update_ajax_option(){
110
+ $field = FrmField::getOne($_POST['field']);
 
111
  foreach ( array('clear_on_focus', 'separate_value', 'default_blank') as $val ) {
112
  if ( isset($_POST[$val]) ) {
113
  $new_val = $_POST[$val];
114
  if ( $val == 'separate_value' ) {
115
  $new_val = (isset($field->field_options[$val]) && $field->field_options[$val]) ? 0 : 1;
116
  }
117
+
118
+ $field->field_options[$val] = $new_val;
119
+ unset($new_val);
120
+ }
121
  unset($val);
122
  }
123
 
124
+ FrmField::update( $_POST['field'], array(
125
+ 'field_options' => $field->field_options,
126
+ 'form_id' => $field->form_id
127
+ ) );
128
  die();
129
  }
130
+
131
  public static function duplicate(){
132
  global $wpdb;
133
+
134
+ $copy_field = FrmField::getOne($_POST['field_id']);
135
+ if ( ! $copy_field ) {
136
+ die();
137
+ }
138
+
139
+ $form_id = (int) $_POST['form_id'];
140
+
141
+ do_action('frm_duplicate_field', $copy_field, $form_id);
142
+ do_action('frm_duplicate_field_'. $copy_field->type, $copy_field, $form_id);
143
+
144
  $values = array();
145
+ FrmFieldsHelper::fill_field( $values, $copy_field, $form_id );
146
+
147
+ $field_count = $wpdb->get_var( $wpdb->prepare('SELECT COUNT(*) FROM '. $wpdb->prefix .'frm_fields fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id) WHERE fr.id = %d OR fr.parent_form_id = %d', $form_id, $form_id) );
148
+
 
 
 
149
  $values['field_order'] = $field_count + 1;
150
+
151
+ if ( ! $field_id = FrmField::create($values) ) {
152
+ die();
 
 
 
 
 
 
 
153
  }
154
+
155
+ self::include_single_field($field_id, $values);
156
+
157
  die();
158
  }
159
+
160
+ /*
161
+ * Load a single field in the form builder along with all needed variables
162
+ */
163
+ public static function include_single_field( $field_id, $values, $form_id = 0 ) {
164
+ $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id));
165
+ $field_name = 'item_meta['. $field_id .']';
166
+ $html_id = FrmFieldsHelper::get_html_id($field);
167
+ $id = $form_id ? $form_id : $field['form_id'];
168
+ if ( $field['type'] == 'html' ) {
169
+ $field['stop_filter'] = true;
170
+ }
171
+
172
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
173
+
174
+ return $field;
175
+ }
176
+
177
  public static function destroy(){
178
+ FrmField::destroy($_POST['field_id']);
 
179
  die();
180
+ }
181
 
182
  /* Field Options */
 
 
183
 
184
+ //Add Single Option or Other Option
185
+ public static function add_option(){
186
  $id = $_POST['field_id'];
187
+ $opt_type = $_POST['opt_type'];
188
+
189
+ //Get the field
190
+ $field = FrmField::getOne($id);
191
  $options = maybe_unserialize($field->options);
192
+ if ( !empty($options) ) {
193
+ $keys = array_keys( $options );
194
+ $last = str_replace( 'other_', '', end( $keys ) );
195
+ } else {
196
  $last = 0;
197
+ }
198
  $opt_key = $last + 1;
199
+
200
+ if ( 'other' == $opt_type ) {
201
+ $opt = __('Other', 'formidable');
202
+ $other_val = '';
203
+ $opt_key = 'other_' . $opt_key;
204
+
205
+ //Update value of "other" in DB
206
+ $field_options = maybe_unserialize( $field->field_options );
207
+ $field_options['other'] = 1;
208
+ FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) );
209
+ } else {
210
+ $first_opt = reset($options);
211
+ $next_opt = count($options);
212
+ if ( $first_opt != '' ) {
213
+ $next_opt++;
214
+ }
215
+ $opt = __('Option', 'formidable') .' '. $next_opt;
216
+ unset($next_opt);
217
+ }
218
  $field_val = $opt;
219
  $options[$opt_key] = $opt;
 
 
220
 
221
+ //Update options in DB
222
+ FrmField::update($id, array('options' => maybe_serialize($options)));
223
+
224
+ $field_data = $field;
225
+ $field = array(
226
+ 'type' => $field_data->type,
227
+ 'id' => $id,
228
+ 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0,
229
+ 'form_id' => $field_data->form_id,
230
+ 'field_key' => $field_data->field_key,
231
+ );
232
+
233
  $field_name = "item_meta[$id]";
234
+ $html_id = FrmFieldsHelper::get_html_id($field);
235
+ $checked = '';
236
+
237
+ if ( 'other' == $opt_type ) {
238
+ require(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
239
+ } else {
240
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
241
+ }
242
  die();
243
  }
244
 
245
+ public static function edit_option() {
246
  $ids = explode('-', $_POST['element_id']);
247
+ $id = $_POST['field_id'];
248
+ $update_value = trim($_POST['update_value']);
249
  if ( strpos($_POST['element_id'], 'key_') ) {
250
+ $new_value = $update_value;
 
251
  } else {
252
+ $new_label = $update_value;
253
  }
254
+
255
+ $field = FrmField::getOne($id);
256
+ $separate_values = ( isset($field->field_options['separate_value']) && $field->field_options['separate_value'] );
257
  $options = maybe_unserialize($field->options);
258
+
259
+ $this_opt_id = end($ids);
260
+ $this_opt = (array) $options[$this_opt_id];
261
+ $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ? true : false );
262
+
263
  $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt);
264
+ $value = isset($this_opt['value']) ? $this_opt['value'] : '';
265
+
 
 
266
  if ( !isset($new_label) ) {
267
  $new_label = $label;
268
  }
269
+
270
  if ( isset($new_value) || isset($value) ) {
271
  $update_value = isset($new_value) ? $new_value : $value;
272
  }
273
+
274
+ if ( $update_value != $new_label && $other_opt == false && $separate_values ) {
275
+ $options[$this_opt_id] = array('value' => $update_value, 'label' => $new_label);
276
  } else {
277
+ $options[$this_opt_id] = trim($_POST['update_value']);
278
  }
279
+
280
+ FrmField::update($field->id, array('options' => $options));
281
  echo (trim($_POST['update_value']) == '') ? __('(Blank)', 'formidable') : stripslashes($_POST['update_value']);
282
  die();
283
  }
284
 
285
  public static function delete_option(){
286
+ $field = FrmField::getOne($_POST['field_id']);
287
+ $opt_key = $_POST['opt_key'];
288
  $options = maybe_unserialize($field->options);
289
+ unset($options[$opt_key]);
290
+ $response = array( 'other' => true );
291
+
292
+ //If the deleted option is an "other" option
293
+ if ( strpos( $opt_key, 'other' ) !== false ) {
294
+ //Assume all other options are gone, unless proven otherwise
295
+ $other = false;
296
+
297
+ //Check if all other options are really gone in CB field
298
+ if ( $field->type == 'checkbox' ) {
299
+ foreach ( $options as $o_key => $o_val ) {
300
+ //If there is still an other option in the field, set other to true
301
+ if ( $o_key && strpos( $o_key, 'other' ) !== false ) {
302
+ $other = true;
303
+ break;
304
+ }
305
+ unset( $o_key, $o_val );
306
+ }
307
+ }
308
+ //If all other options are gone
309
+ if ( false === $other ) {
310
+ $field_options = maybe_unserialize( $field->field_options );
311
+ $field_options['other'] = 0;
312
+ FrmField::update( $_POST['field_id'], array( 'field_options' => maybe_serialize( $field_options ) ) );
313
+ $response = array('other' => false );
314
+ }
315
+ }
316
+ echo json_encode( $response );
317
+
318
+ FrmField::update($_POST['field_id'], array('options' => maybe_serialize($options)));
319
+
320
  die();
321
  }
322
+
323
  public static function import_choices(){
324
  if ( !current_user_can('frm_edit_forms') ) {
325
  return;
326
  }
327
+
328
  $field_id = $_REQUEST['field_id'];
329
+
330
  global $current_screen, $hook_suffix;
331
 
332
  // Catch plugins that include admin-header.php before admin.php completes.
334
  $hook_suffix = '';
335
  set_current_screen();
336
  }
337
+
338
  if ( function_exists('register_admin_color_schemes') ) {
339
  register_admin_color_schemes();
340
  }
341
+
342
  $hook_suffix = $admin_body_class = '';
343
+
344
+ if ( get_user_setting('mfold') == 'f' ) {
345
  $admin_body_class .= ' folded';
346
+ }
347
 
348
  if ( function_exists('is_admin_bar_showing') && is_admin_bar_showing() ) {
349
  $admin_body_class .= ' admin-bar';
350
  }
351
 
352
+ if ( is_rtl() ) {
353
  $admin_body_class .= ' rtl';
354
+ }
355
 
356
  $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
357
  $prepop = array();
358
+ self::get_bulk_prefilled_opts($prepop);
359
+
360
+ $field = FrmField::getOne($field_id);
361
+
362
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/import_choices.php');
363
+ die();
364
+ }
365
+
366
+ private static function get_bulk_prefilled_opts(array &$prepop) {
367
  $prepop[__('Countries', 'formidable')] = FrmAppHelper::get_countries();
368
+
369
  $states = FrmAppHelper::get_us_states();
370
  $state_abv = array_keys($states);
371
  sort($state_abv);
372
  $prepop[__('U.S. State Abbreviations', 'formidable')] = $state_abv;
373
+
374
  $states = array_values($states);
375
  sort($states);
376
  $prepop[__('U.S. States', 'formidable')] = $states;
377
+ unset($state_abv, $states);
378
+
 
379
  $prepop[__('Age', 'formidable')] = array(
380
+ __('Under 18', 'formidable'), __('18-24', 'formidable'), __('25-34', 'formidable'),
381
  __('35-44', 'formidable'), __('45-54', 'formidable'), __('55-64', 'formidable'),
382
  __('65 or Above', 'formidable'), __('Prefer Not to Answer', 'formidable')
383
  );
384
+
385
  $prepop[__('Satisfaction', 'formidable')] = array(
386
+ __('Very Satisfied', 'formidable'), __('Satisfied', 'formidable'), __('Neutral', 'formidable'),
387
  __('Unsatisfied', 'formidable'), __('Very Unsatisfied', 'formidable'), __('N/A', 'formidable')
388
  );
389
 
390
  $prepop[__('Importance', 'formidable')] = array(
391
+ __('Very Important', 'formidable'), __('Important', 'formidable'), __('Neutral', 'formidable'),
392
  __('Somewhat Important', 'formidable'), __('Not at all Important', 'formidable'), __('N/A', 'formidable')
393
  );
394
+
395
  $prepop[__('Agreement', 'formidable')] = array(
396
+ __('Strongly Agree', 'formidable'), __('Agree', 'formidable'), __('Neutral', 'formidable'),
397
  __('Disagree', 'formidable'), __('Strongly Disagree', 'formidable'), __('N/A', 'formidable')
398
  );
399
+
400
  $prepop = apply_filters('frm_bulk_field_choices', $prepop);
 
 
 
 
 
 
401
  }
402
+
403
  public static function import_options(){
404
+ if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) {
405
  return;
406
+ }
407
+
408
+ $field_id = $_POST['field_id'];
409
+ $field = FrmField::getOne($field_id);
410
+
411
+ if ( ! in_array($field->type, array('radio', 'checkbox', 'select')) ) {
 
412
  return;
413
+ }
414
+
415
  $field = FrmFieldsHelper::setup_edit_vars($field);
416
+ $opts = stripslashes_deep($_POST['opts']);
417
  $opts = explode("\n", rtrim($opts, "\n"));
418
  if ( $field['separate_value'] ) {
419
  foreach ( $opts as $opt_key => $opt ) {
428
  unset($opt);
429
  }
430
  }
431
+
432
+ //Keep other options after bulk update
433
+ if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
434
+ $other_array = array();
435
+ foreach ( $field['options'] as $opt_key => $opt ) {
436
+ if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
437
+ $other_array[$opt_key] = $opt;
438
+ }
439
+ unset($opt_key,$opt);
440
+ }
441
+ if ( $other_array ) {
442
+ $opts = array_merge( $opts, $other_array);
443
+ }
444
+ }
445
+
446
+ FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) );
447
+
448
  $field['options'] = $opts;
449
  $field_name = $field['name'];
450
+
451
  if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
452
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php');
453
  } else {
454
+ FrmFieldsHelper::show_single_option($field);
 
 
 
 
455
  }
456
+
457
  die();
458
  }
459
 
460
  public static function update_order(){
461
+ if ( isset($_POST) && isset($_POST['frm_field_id']) ) {
 
 
462
  foreach ($_POST['frm_field_id'] as $position => $item)
463
+ FrmField::update($item, array('field_order' => $position));
464
  }
465
  die();
466
  }
467
+
468
  public static function change_type($type){
469
+ $type_switch = array(
470
+ 'scale' => 'radio',
471
+ '10radio' => 'radio',
472
+ 'rte' => 'textarea',
473
+ 'website' => 'url',
474
+ );
475
+ if ( isset($type_switch[$type]) ) {
476
+ $type = $type_switch[$type];
477
+ }
478
 
 
 
 
 
 
 
 
479
  $frm_field_selection = FrmFieldsHelper::field_selection();
480
  $types = array_keys($frm_field_selection);
481
+ if ( ! in_array($type, $types) && $type != 'captcha' ) {
482
  $type = 'text';
483
+ }
484
 
485
  return $type;
486
  }
487
+
488
  public static function display_field_options($display){
489
  switch($display['type']){
490
  case 'captcha':
503
  case 'select':
504
  $display['size'] = true;
505
  break;
506
+ case 'url':
507
+ case 'website':
508
+ case 'email':
509
+ $display['size'] = true;
510
+ $display['clear_on_focus'] = true;
511
+ $display['invalid'] = true;
512
  }
513
+
514
  return $display;
515
  }
516
+
517
  public static function input_html($field, $echo=true){
518
+ $class = array(); //$field['type'];
519
+ self::add_input_classes($field, $class);
520
+
521
+ $add_html = array();
522
+ self::add_html_size($field, $add_html);
523
+ self::add_html_length($field, $add_html);
524
+ self::add_html_placeholder($field, $add_html, $class);
525
+
526
+ $class = apply_filters('frm_field_classes', implode(' ', $class), $field);
527
+
528
+ if ( ! empty($class) ) {
529
+ $add_html['class'] = 'class="'. trim($class) .'"';
530
+ }
531
+
532
+ self::add_shortcodes_to_html($field, $add_html);
533
+
534
+ $add_html = implode(' ', $add_html);
535
+
536
+ if ( $echo ) {
537
+ echo $add_html;
538
+ }
539
+
540
+ return $add_html;
541
+ }
542
+
543
+ private static function add_input_classes($field, array &$class) {
544
+ global $frm_vars;
545
+ if ( is_admin() && ! FrmAppHelper::is_preview_page() && ! in_array($field['type'], array('scale', 'radio', 'checkbox', 'data')) ) {
546
+ $class[] = 'dyn_default_value';
547
+ }
548
+
549
+ if ( isset($field['size']) && $field['size'] > 0 ) {
550
+ $class[] = 'auto_width';
551
+ }
552
+
553
+ if ( isset($field['input_class']) && ! empty($field['input_class']) ) {
554
+ $class[] = $field['input_class'];
555
+ }
556
+ }
557
+
558
+ private static function add_html_size($field, array &$add_html) {
559
+ if ( ! isset($field['size']) || $field['size'] <= 0 || in_array($field['type'], array('select', 'data', 'time', 'hidden')) ) {
560
+ return;
561
+ }
562
+
563
+ if ( FrmAppHelper::is_admin_page('formidable') ) {
564
+ return;
565
+ }
566
+
567
+ if ( is_numeric($field['size']) ) {
568
+ $field['size'] .= 'px';
569
+ }
570
+
571
+ $important = apply_filters('frm_use_important_width', 1, $field);
572
+ $add_html['style'] = 'style="width:'. $field['size'] . ( $important ? ' !important' : '' ) .'"';
573
+
574
+ self::add_html_cols($field, $add_html);
575
+ }
576
+
577
+ private static function add_html_cols($field, array &$add_html) {
578
+ if ( ! in_array($field['type'], array('textarea', 'rte')) ) {
579
+ return;
580
+ }
581
+
582
+ // convert to cols for textareas
583
+ $calc = array(
584
+ '' => 7.08,
585
+ 'px' => 7.08,
586
+ 'rem' => 0.444,
587
+ 'em' => 0.544,
588
+ );
589
+
590
+ // include "col" for valid html
591
+ $unit = trim(preg_replace('/[0-9]+/', '', $field['size']));
592
+
593
+ if ( ! isset($calc[$unit]) ) {
594
+ return;
595
+ }
596
+
597
+ $size = (float) str_replace($unit, '', $field['size']) / $calc[$unit];
598
+
599
+ $add_html['cols'] = 'cols="'. (int) $size .'"';
600
+ }
601
+
602
+ private static function add_html_length($field, array &$add_html) {
603
+ // check for max setting and if this field accepts maxlength
604
+ if ( ! isset($field['max']) || empty($field['max']) || in_array( $field['type'], array('textarea', 'rte', 'hidden') ) ) {
605
+ return;
606
+ }
607
+
608
+ if ( FrmAppHelper::is_admin_page('formidable') ) {
609
+ // don't load on form builder page
610
+ return;
611
+ }
612
+
613
+ $add_html['maxlength'] = 'maxlength="'. $field['max'] .'"';
614
+ }
615
+
616
+ private static function add_html_placeholder($field, array &$add_html, array &$class) {
617
+ // check for a default value and placeholder setting
618
+ if ( ! isset($field['clear_on_focus']) || ! $field['clear_on_focus'] || empty($field['default_value']) ) {
619
+ return;
620
+ }
621
+
622
+ // don't apply this to the form builder page
623
+ if ( FrmAppHelper::is_admin_page('formidable') ) {
624
+ return;
625
+ }
626
+
627
+ $frm_settings = FrmAppHelper::get_settings();
628
+
629
+ if ( $frm_settings->use_html && ! in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden')) ) {
630
+ // use HMTL5 placeholder with js fallback
631
+ $add_html['placeholder'] = 'placeholder="'. esc_attr($field['default_value']) .'"';
632
+ wp_enqueue_script('jquery-placeholder');
633
+ } else if ( ! $frm_settings->use_html ) {
634
+ $val = str_replace(array("\r\n", "\n"), '\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
635
+ $add_html['data-frmval'] = 'data-frmval="'. esc_attr($val) .'"';
636
+ $class[] = 'frm_toggle_default';
637
+
638
+ if ( $field['value'] == $field['default_value'] ) {
639
+ $class[] = 'frm_default';
640
  }
641
  }
642
+ }
643
+
644
+ private static function add_shortcodes_to_html($field, array &$add_html) {
645
+ if ( ! isset($field['shortcodes']) || empty($field['shortcodes']) ) {
646
+ return;
647
+ }
648
+
649
+ foreach ( $field['shortcodes'] as $k => $v ) {
650
+ if ( 'opt' === $k ) {
651
+ continue;
 
 
 
 
 
 
 
 
 
 
 
 
652
  }
653
+
654
+ if ( is_numeric($k) && strpos($v, '=') ) {
655
+ $add_html[] = $v;
656
+ } else if ( ! empty($k) && isset($add_html[$k]) ) {
657
+ $add_html[$k] = str_replace($k .'="', $k .'="'. $v, $add_html[$k]);
658
+ } else {
659
+ $add_html[$k] = $k .'="'. $v .'"';
660
+ }
661
+
662
+ unset($k, $v);
663
  }
 
 
 
 
 
664
  }
665
+
666
  public static function check_value($opt, $opt_key, $field){
667
  if(is_array($opt)){
668
+ if ( isset($field['separate_value']) && $field['separate_value'] ) {
669
  $opt = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
670
+ } else {
671
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
672
  }
673
  }
674
  return $opt;
675
  }
676
+
677
+ public static function check_label($opt){
678
+ if ( is_array($opt) ) {
679
  $opt = (isset($opt['label']) ? $opt['label'] : reset($opt));
680
+ }
681
+
682
  return $opt;
683
  }
684
+
685
+ public static function add_conditional_update_msg() {
686
+ echo '<tr><td colspan="2">';
687
+ FrmAppHelper::update_message('calculate and conditionally hide and show fields');
688
+ echo '</td></tr>';
689
+ }
690
  }
classes/controllers/FrmFormActionsController.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmFormActionsController{
4
+ public static $action_post_type = 'frm_form_actions';
5
+ public static $registered_actions;
6
+
7
+ public static function register_post_types() {
8
+ register_post_type(self::$action_post_type, array(
9
+ 'label' => __('Form Actions', 'formidable'),
10
+ 'description' => '',
11
+ 'public' => false,
12
+ 'show_ui' => false,
13
+ 'exclude_from_search' => true,
14
+ 'show_in_nav_menus' => false,
15
+ 'show_in_menu' => true,
16
+ 'capability_type' => 'page',
17
+ 'supports' => array(
18
+ 'title', 'editor', 'excerpt', 'custom-fields',
19
+ 'page-attributes',
20
+ ),
21
+ 'has_archive' => false,
22
+ ) );
23
+
24
+ /*
25
+ * post_content: json settings
26
+ * menu_order: form id
27
+ * post_excerpt: action type
28
+ */
29
+ }
30
+
31
+ public static function actions_init() {
32
+ self::$registered_actions = new Frm_Form_Action_Factory();
33
+ do_action( 'frm_form_actions_init' );
34
+ }
35
+
36
+ public static function register_actions() {
37
+ $action_classes = apply_filters('frm_registered_form_actions', array(
38
+ 'email' => 'FrmEmailAction',
39
+ 'wppost' => 'FrmDefPostAction',
40
+ 'register' => 'FrmDefRegAction',
41
+ 'paypal' => 'FrmDefPayPalAction',
42
+ 'aweber' => 'FrmDefAweberAction',
43
+ 'mailchimp' => 'FrmDefMlcmpAction',
44
+ 'twilio' => 'FrmDefTwilioAction',
45
+ 'highrise' => 'FrmDefHrsAction',
46
+ ) );
47
+
48
+ include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php');
49
+ include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php');
50
+
51
+ foreach ( $action_classes as $action_class ) {
52
+ self::$registered_actions->register($action_class);
53
+ }
54
+ }
55
+
56
+ public static function get_form_actions($action = 'all' ) {
57
+ $temp_actions = self::$registered_actions;
58
+ if ( empty($temp_actions) ) {
59
+ self::actions_init();
60
+ $temp_actions = self::$registered_actions->actions;
61
+ } else {
62
+ $temp_actions = $temp_actions->actions;
63
+ }
64
+
65
+ $actions = array();
66
+
67
+ foreach ( $temp_actions as $a ) {
68
+ if ( 'all' != $action && $a->id_base == $action ) {
69
+ return $a;
70
+ }
71
+
72
+ $actions[$a->id_base] = $a;
73
+ }
74
+ unset($temp_actions, $a);
75
+
76
+ $action_limit = 10;
77
+ if ( count($actions) <= $action_limit ) {
78
+ return $actions;
79
+ }
80
+
81
+ // remove the last few inactive icons if there are too many
82
+ $temp_actions = $actions;
83
+ arsort($temp_actions);
84
+ foreach ( $temp_actions as $type => $a ) {
85
+ if ( ! isset($a->action_options['active']) || empty($a->action_options['active']) ) {
86
+ unset($actions[$type]);
87
+ if ( count($actions) <= $action_limit ) {
88
+ break;
89
+ }
90
+ }
91
+ unset($type, $a);
92
+ }
93
+
94
+ return $actions;
95
+ }
96
+
97
+ public static function list_actions($form, $values) {
98
+ if ( empty($form) ) {
99
+ return;
100
+ }
101
+
102
+ do_action('frm_before_list_actions', $form); // use this hook to migrate old settings into a new action
103
+
104
+ $form_actions = FrmFormActionsHelper::get_action_for_form($form->id) ;
105
+
106
+ $action_controls = self::get_form_actions();
107
+
108
+ $action_map = array();
109
+
110
+ foreach( $action_controls as $key => $control ) {
111
+ $action_map[$control->id_base] = $key;
112
+ }
113
+
114
+ foreach ( $form_actions as $action ) {
115
+ if ( !isset($action_map[$action->post_excerpt]) ) {
116
+ // don't try and show settings if action no longer exists
117
+ continue;
118
+ }
119
+
120
+ self::action_control( $action, $form, $action->ID, $action_controls[$action_map[$action->post_excerpt]], $values );
121
+ }
122
+ }
123
+
124
+ public static function action_control($form_action, $form, $action_key, $action_control, $values) {
125
+ $action_control->_set($action_key);
126
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php');
127
+ }
128
+
129
+ public static function add_form_action() {
130
+ global $frm_vars;
131
+
132
+ $action_key = $_POST['list_id'];
133
+ $action_type = $_POST['type'];
134
+
135
+ $action_control = self::get_form_actions( $action_type );
136
+ $action_control->_set($action_key);
137
+
138
+ $form_id = $_POST['form_id'];
139
+
140
+ $form_action = $action_control->prepare_new($form_id);
141
+
142
+ $values = array();
143
+ $form = self::fields_to_values($form_id, $values);
144
+
145
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php');
146
+ die();
147
+ }
148
+
149
+ public static function fill_action() {
150
+ $action_key = $_POST['action_id'];
151
+ $action_type = $_POST['action_type'];
152
+
153
+ $action_control = self::get_form_actions( $action_type );
154
+ if ( empty($action_control) ) {
155
+ die();
156
+ }
157
+
158
+ $form_action = $action_control->get_single_action( $action_key );
159
+
160
+ $values = array();
161
+ $form = self::fields_to_values($form_action->menu_order, $values);
162
+
163
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_action_inside.php');
164
+ die();
165
+ }
166
+
167
+ private static function fields_to_values($form_id, array &$values) {
168
+ $form = FrmForm::getOne($form_id);
169
+
170
+ $values = array('fields' => array(), 'id' => $form->id);
171
+
172
+ $fields = FrmField::get_all_for_form($form->id);
173
+ foreach ( $fields as $k => $f ) {
174
+ $f = (array) $f;
175
+ $opts = (array) $f['field_options'];
176
+ $f = array_merge($opts, $f);
177
+ if ( !isset($f['post_field']) ) {
178
+ $f['post_field'] = '';
179
+ }
180
+ $values['fields'][] = $f;
181
+ unset($k, $f);
182
+ }
183
+
184
+ return $form;
185
+ }
186
+
187
+ public static function update_settings($form_id) {
188
+ global $wpdb;
189
+
190
+ $registered_actions = self::$registered_actions->actions;
191
+
192
+ $old_actions = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE menu_order=%d", $form_id));
193
+ $new_actions = array();
194
+
195
+ foreach ( $registered_actions as $registered_action ) {
196
+ $action_ids = $registered_action->update_callback($form_id);
197
+ if ( !empty($action_ids) ) {
198
+ $new_actions[] = $action_ids;
199
+ }
200
+ }
201
+
202
+ //Only use array_merge if there are new actions
203
+ if ( !empty($new_actions) ) {
204
+ $new_actions = call_user_func_array('array_merge', $new_actions);
205
+ }
206
+ $old_actions = array_diff($old_actions, $new_actions);
207
+
208
+ // delete any actions that were not included on the page
209
+ if ( !empty($old_actions) ) {
210
+ foreach ( $old_actions as $old_id ) {
211
+ wp_delete_post($old_id);
212
+ }
213
+ }
214
+ }
215
+
216
+ public static function trigger_create_actions($entry_id, $form_id) {
217
+ self::trigger_actions('create', $form_id, $entry_id);
218
+ }
219
+
220
+ public static function trigger_actions($event, $form, $entry, $type = 'all') {
221
+ $form_actions = FrmFormActionsHelper::get_action_for_form((is_object($form) ? $form->id : $form), $type);
222
+
223
+ if ( empty($form_actions) ) {
224
+ return;
225
+ }
226
+
227
+ FrmFormsHelper::maybe_get_form( $form );
228
+
229
+ $link_settings = self::get_form_actions($type);
230
+ if ( 'all' != $type ) {
231
+ $link_settings = array($type => $link_settings);
232
+ }
233
+
234
+ $stored_actions = $action_priority = array();
235
+
236
+ foreach ( $form_actions as $action ) {
237
+
238
+ if ( ! in_array($event, $action->post_content['event']) ) {
239
+ continue;
240
+ }
241
+
242
+ if ( ! is_object($entry) ) {
243
+ $entry = FrmEntry::getOne($entry, true);
244
+ }
245
+
246
+ if ( ! $form || ( is_numeric($form->parent_form_id) && $form->parent_form_id ) || ! $entry || $entry->form_id != $form->id ) {
247
+ //don't trigger actions for sub forms
248
+ continue;
249
+ }
250
+
251
+ if ( $entry->is_draft ) {
252
+ // TODO: add trigger actions for drafts
253
+ continue;
254
+ }
255
+
256
+ // check conditional logic
257
+ $stop = FrmFormActionsHelper::action_conditions_met($action, $entry);
258
+ if ( $stop ) {
259
+ continue;
260
+ }
261
+
262
+ // store actions so they can be triggered with the correct priority
263
+ $stored_actions[$action->ID] = $action;
264
+ $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority'];
265
+
266
+ unset($action);
267
+ }
268
+
269
+ if ( !empty($stored_actions) ) {
270
+ asort($action_priority);
271
+
272
+ // make sure hooks are loaded
273
+ new FrmNotification();
274
+
275
+ foreach ( $action_priority as $action_id => $priority ) {
276
+ $action = $stored_actions[$action_id];
277
+ do_action('frm_trigger_'. $action->post_excerpt .'_action', $action, $entry, $form, $event);
278
+ do_action('frm_trigger_'. $action->post_excerpt .'_'. $event .'_action', $action, $entry, $form);
279
+
280
+ // If post is created, get updated $entry object
281
+ if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
282
+ $entry = FrmEntry::getOne($entry->id, true);
283
+ }
284
+ }
285
+ }
286
+ }
287
+
288
+ public static function duplicate_form_actions($form_id, $values, $args = array() ) {
289
+ if ( ! isset($args['old_id']) || empty($args['old_id']) ) {
290
+ // continue if we know which actions to copy
291
+ return;
292
+ }
293
+
294
+ $action_controls = FrmFormActionsController::get_form_actions( );
295
+
296
+ foreach ( $action_controls as $action_control ) {
297
+ $action_control->duplicate_form_actions($form_id, $args['old_id']);
298
+ unset($action_control);
299
+ }
300
+ }
301
+
302
+ public static function limit_by_type( $where ) {
303
+ global $frm_vars, $wpdb;
304
+
305
+ if ( !isset($frm_vars['action_type']) ) {
306
+ return $where;
307
+ }
308
+
309
+ $where .= $wpdb->prepare(' AND post_excerpt = %s ', $frm_vars['action_type']);
310
+ return $where;
311
+ }
312
+
313
+ }
314
+
315
+
316
+ class Frm_Form_Action_Factory {
317
+ public $actions = array();
318
+
319
+ public function __construct() {
320
+ add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
321
+ }
322
+
323
+ public function register($action_class) {
324
+ $this->actions[$action_class] = new $action_class();
325
+ }
326
+
327
+ public function unregister($action_class) {
328
+ if ( isset($this->actions[$action_class]) ) {
329
+ unset($this->actions[$action_class]);
330
+ }
331
+ }
332
+
333
+ public function _register_actions() {
334
+ $keys = array_keys($this->actions);
335
+
336
+ foreach ( $keys as $key ) {
337
+ // don't register new action if old action with the same id is already registered
338
+ if ( !isset($this->actions[$key]) ) {
339
+ $this->actions[$key]->_register();
340
+ }
341
+ }
342
+ }
343
+ }
classes/controllers/FrmFormsController.php CHANGED
@@ -1,217 +1,193 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
 
6
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
-
8
- if(class_exists('FrmFormsController'))
9
- return;
10
-
11
  class FrmFormsController{
12
- public static function load_hooks(){
13
- add_action('admin_menu', 'FrmFormsController::menu', 10);
14
- add_action('admin_menu', 'FrmFormsController::mid_menu', 40);
15
- add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head');
16
- add_action('widgets_init', 'FrmFormsController::register_widgets');
17
- add_action('wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key');
18
- add_action('wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description');
19
- add_action('wp_ajax_frm_delete_form_wo_fields', 'FrmFormsController::destroy_wo_fields');
20
- add_action('frm_after_duplicate_form', 'FrmFormsController::after_duplicate', 10, 2);
21
- add_action('wp_ajax_frm_save_form', 'FrmFormsController::route');
22
- add_filter('frm_submit_button', 'FrmFormsController::submit_button_label');
23
- add_filter('media_buttons_context', 'FrmFormsController::insert_form_button');
24
- //add_action('media_buttons', 'FrmFormsController::show_form_button', 20);
25
- add_action('admin_footer', 'FrmFormsController::insert_form_popup');
26
-
27
- add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
28
-
29
- add_action('wp_ajax_frm_forms_preview', 'FrmFormsController::preview');
30
- add_action('wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview');
31
-
32
- add_filter('frm_admin_list_form_action', 'FrmFormsController::process_bulk_form_actions');
33
-
34
- add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' );
35
- add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
36
-
37
- //Shortcodes
38
- add_shortcode('formidable', 'FrmFormsController::get_form_shortcode');
39
- add_filter( 'widget_text', 'FrmFormsController::widget_text_filter', 9 );
40
- }
41
-
42
  public static function menu(){
43
- global $frm_settings;
44
- add_submenu_page('formidable', $frm_settings->menu .' | '. __('Forms', 'formidable'), __('Forms', 'formidable'), 'frm_view_forms', 'formidable', 'FrmFormsController::route');
45
-
46
- add_action('admin_head-'. sanitize_title($frm_settings->menu) .'_page_formidable-templates', 'FrmFormsController::head');
47
-
48
- add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
49
- add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_columns', 'FrmFormsController::get_columns', 0 );
50
- add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns');
51
- add_filter('manage_'. sanitize_title($frm_settings->menu) .'_page_formidable-templates_sortable_columns', 'FrmFormsController::get_sortable_columns');
52
- add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns');
53
- add_filter('get_user_option_manage'. sanitize_title($frm_settings->menu) .'_page_formidable-templatescolumnshidden', 'FrmFormsController::hidden_columns');
54
- }
55
-
56
- public static function mid_menu(){
57
- global $frm_settings;
58
- add_submenu_page('formidable', $frm_settings->menu .' | '. __('Templates', 'formidable'), __('Templates', 'formidable'), 'frm_view_forms', 'formidable-templates', 'FrmFormsController::template_list');
59
- }
60
-
61
- public static function head(){
62
- global $frm_settings;
63
 
 
64
  wp_enqueue_script('formidable-editinplace');
65
  wp_enqueue_script('jquery-frm-themepicker');
 
 
 
 
66
  }
67
-
68
  public static function register_widgets(){
69
  require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
70
  register_widget('FrmShowForm');
71
  }
72
-
73
  public static function list_form(){
74
- $params = self::get_params();
75
- $errors = apply_filters('frm_admin_list_form_action', array());
76
- return self::display_forms_list($params, '', false, false, $errors);
77
- }
78
-
79
- public static function template_list(){
80
- $_POST['template'] = 1;
81
  $errors = apply_filters('frm_admin_list_form_action', array());
82
- return self::display_forms_list();
83
  }
84
-
85
  public static function new_form($values=false){
 
 
86
  global $frm_vars;
87
-
88
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
89
  $action = ($values) ? $values[$action] : FrmAppHelper::get_param($action);
90
- $frm_form = new FrmForm();
91
-
92
  if ($action == 'create'){
93
  return self::create($values);
94
  }else if ($action == 'new'){
95
- $frm_field_selection = FrmFieldsHelper::field_selection();
96
  $values = FrmFormsHelper::setup_new_vars($values);
97
- $id = $frm_form->create( $values );
98
- $form = $frm_form->getOne($id);
 
 
 
 
 
99
  $values['id'] = $id;
100
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
101
  }else{
102
- $all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
103
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new-selection.php');
104
  }
105
  }
106
-
107
  public static function create($values=false){
108
- global $frm_entry, $frm_field, $frm_vars;
109
- if(!$values)
 
 
110
  $values = $_POST;
111
-
 
 
 
 
 
 
112
  if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce'))) ) {
113
- global $frm_settings;
114
- $errors['form'] = $frm_settings->admin_permission;
 
 
115
  }
116
-
117
- $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
118
-
119
- $frm_form = new FrmForm();
120
- $errors = $frm_form->validate($values);
121
-
122
- if( count($errors) > 0 ){
123
  $hide_preview = true;
124
  $frm_field_selection = FrmFieldsHelper::field_selection();
125
- $form = $frm_form->getOne( $id );
126
- $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
 
127
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
128
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
129
- }else{
130
- $form = $frm_form->update( $id, $values, true );
131
  die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
132
  //$message = __('Form was Successfully Created', 'formidable');
133
  //return self::settings($record, $message);
134
  }
135
  }
136
-
137
  public static function edit($values=false){
138
- if ( ! current_user_can('frm_edit_forms') ) {
139
- global $frm_settings;
140
- wp_die($frm_settings->admin_permission);
141
- }
142
-
143
- $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
144
  return self::get_edit_vars($id);
145
  }
146
-
147
  public static function settings($id=false, $message=''){
 
 
148
  if(!$id or !is_numeric($id))
149
- $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
150
  return self::get_settings_vars($id, '', $message);
151
  }
152
-
153
  public static function update_settings(){
 
 
154
  $id = FrmAppHelper::get_param('id');
155
-
156
- $frm_form = new FrmForm();
157
- $errors = $frm_form->validate($_POST);
158
-
159
- if( count($errors) > 0 ){
160
  return self::get_settings_vars($id, $errors);
161
- }else{
162
- $record = $frm_form->update( $_POST['id'], $_POST );
163
- $message = __('Settings Successfully Updated', 'formidable');
164
- return self::get_settings_vars($id, '', $message);
165
  }
 
 
 
 
 
 
 
166
  }
167
-
168
  public static function edit_key(){
169
- if ( ! current_user_can('frm_edit_forms') ) {
170
- die();
171
- }
172
-
173
  global $wpdb;
174
  $values = array('form_key' => trim($_POST['update_value']));
175
- $frm_form = new FrmForm();
176
- $form = $frm_form->update($_POST['form_id'], $values);
177
- $key = $wpdb->get_var($wpdb->prepare("SELECT form_key FROM {$wpdb->prefix}frm_forms WHERE id=%d", $_POST['form_id']));
178
- echo stripslashes($key);
179
  die();
180
  }
181
 
182
  public static function edit_description(){
183
- if ( ! current_user_can('frm_edit_forms') ) {
184
- die();
185
- }
186
-
187
- $frm_form = new FrmForm();
188
- $form = $frm_form->update($_POST['form_id'], array('description' => $_POST['update_value']));
189
- $description = stripslashes($_POST['update_value']);
190
- if(apply_filters('frm_use_wpautop', true))
191
- $description = wpautop(str_replace( '<br>', '<br />', $description));
192
  echo $description;
193
  die();
194
  }
195
-
196
  public static function update($values=false){
197
- $frm_form = new FrmForm();
198
 
199
- if(!$values)
200
  $values = $_POST;
201
-
202
- $errors = $frm_form->validate($values);
203
-
 
 
 
 
204
  if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce')) ) ) {
205
- global $frm_settings;
206
  $errors['form'] = $frm_settings->admin_permission;
207
  }
208
-
209
- $id = isset($values['id']) ? (int)$values['id'] : (int)FrmAppHelper::get_param('id');
210
-
211
  if( count($errors) > 0 ){
212
  return self::get_edit_vars($id, $errors);
213
  }else{
214
- $record = $frm_form->update( $id, $values );
215
  $message = __('Form was Successfully Updated', 'formidable');
216
  if ( defined('DOING_AJAX') ) {
217
  die($message);
@@ -219,17 +195,22 @@ class FrmFormsController{
219
  return self::get_edit_vars($id, '', $message);
220
  }
221
  }
222
-
 
 
 
 
 
 
 
 
 
 
223
  public static function duplicate(){
224
- if ( ! current_user_can('frm_edit_forms') ) {
225
- global $frm_settings;
226
- wp_die($frm_settings->admin_permission);
227
- }
228
-
229
- $frm_form = new FrmForm();
230
-
231
- $params = self::get_params();
232
- $form = $frm_form->duplicate( $params['id'], $params['template'], true );
233
  $message = ($params['template']) ? __('Form template was Successfully Created', 'formidable') : __('Form was Successfully Copied', 'formidable');
234
  if ( $form ) {
235
  return self::get_edit_vars($form, '', $message, true);
@@ -237,30 +218,22 @@ class FrmFormsController{
237
  return self::display_forms_list($params, __('There was a problem creating new template.', 'formidable'));
238
  }
239
  }
240
-
241
-
242
- public static function after_duplicate($form_id, $values) {
243
- $frm_form = new FrmForm();
244
- $frm_form->after_duplicate($form_id, $values);
245
- }
246
-
247
  public static function page_preview(){
248
- $params = self::get_params();
249
  if (!$params['form']) return;
250
-
251
- $frm_form = new FrmForm();
252
- $form = $frm_form->getOne($params['form']);
253
  if(!$form) return;
254
  return self::show_form($form->id, '', true, true);
255
  }
256
 
257
  public static function preview(){
258
  do_action('frm_wp');
259
-
260
- global $frm_settings, $frm_vars;
261
  $frm_vars['preview'] = true;
262
-
263
- $frm_form = new FrmForm();
264
  if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
265
  global $wp;
266
  $root = dirname(dirname(dirname(dirname(__FILE__))));
@@ -268,97 +241,213 @@ class FrmFormsController{
268
  $wp->init();
269
  $wp->register_globals();
270
  }
271
-
272
- if($frm_vars['pro_is_installed'])
273
  FrmProEntriesController::register_scripts();
274
-
 
275
  header("Content-Type: text/html; charset=". get_option( 'blog_charset' ));
276
 
277
  $plugin = FrmAppHelper::get_param('plugin');
278
  $controller = FrmAppHelper::get_param('controller');
279
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
280
- $form = $frm_form->getAll(array('form_key' => $key), '', 1);
281
- if (!$form) $form = $frm_form->getAll('', '', 1);
282
-
283
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
284
- die();
285
- }
286
-
287
- public static function destroy(){
288
- if(!current_user_can('frm_delete_forms')){
289
- global $frm_settings;
290
- wp_die($frm_settings->admin_permission);
291
- }
292
-
293
- $frm_form = new FrmForm();
294
- $params = self::get_params();
295
- $message = '';
296
- if ($frm_form->destroy( $params['id'] ))
297
- $message = __('Form was Successfully Deleted', 'formidable');
298
- self::display_forms_list($params, $message, '', 1);
299
- }
300
-
301
- public static function destroy_wo_fields(){
302
- global $frm_field, $frmdb, $wpdb;
303
- $id = $_POST['form_id'];
304
- if ($frmdb->get_count($wpdb->prefix . 'frm_fields', array('form_id' => $id)) <= 0){
305
- $frm_form = new FrmForm();
306
- $frm_form->destroy($id);
307
- }
308
  die();
309
  }
310
-
311
- public static function submit_button_label($submit){
312
- if (!$submit or empty($submit)){
313
- global $frm_settings;
314
- $submit = $frm_settings->submit_value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  }
316
- return $submit;
 
 
 
 
317
  }
318
-
319
- public static function insert_form_button($content){
320
- if(current_user_can('frm_view_forms'))
321
- $content .= '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . __("Add Formidable Form", 'formidable') . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> '. __('Add Form', 'formidable') . '</a>';
322
- return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  }
324
-
325
- public static function show_form_button($id){
326
- if($id != 'content')
 
 
 
 
 
327
  return;
328
- echo '<a href="#TB_inline?width=450&height=550&inlineId=frm_insert_form" class="thickbox" title="' . __("Add Formidable Form", 'formidable') . '"><img src="'. esc_url(FrmAppHelper::plugin_url() .'/images/form_16.png') .'" alt="' . __("Add Formidable Form", 'formidable') . '" /></a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  }
330
-
331
  public static function insert_form_popup(){
332
  $page = basename($_SERVER['PHP_SELF']);
333
- if(in_array($page, array('post.php', 'page.php', 'page-new.php', 'post-new.php')) or (isset($_GET) and isset($_GET['page']) and $_GET['page'] == 'formidable-entry-templates')){
334
- if(class_exists('FrmProDisplay')){
335
- global $frmpro_display;
336
- $displays = $frmpro_display->getAll('', 'post_title');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/insert_form_popup.php');
 
 
339
  }
 
 
 
340
  }
341
 
342
- public static function display_forms_list($params=false, $message='', $page_params_ov = false, $current_page_ov = false, $errors = array()){
343
- global $wpdb, $frmdb, $frm_entry, $frm_vars;
344
-
 
 
345
  if(!$params)
346
- $params = self::get_params();
347
-
348
- $page_params = '&action=0&&frm_action=0&page=formidable';
349
-
350
- $frm_form = new FrmForm();
351
- if ($params['template']){
352
- $default_templates = $frm_form->getAll(array('default_template' => 1));
353
- $all_templates = $frm_form->getAll(array('is_template' => 1), 'name');
354
- }
355
-
356
- require( FrmAppHelper::plugin_path() .'/classes/helpers/FrmListHelper.php' );
357
-
358
- $args = array('table_name' => $wpdb->prefix .'frm_forms', 'params' => $params);
359
- $args['page_name'] = $params['template'] ? '-template' : '';
360
- $wp_list_table = new FrmListHelper($args);
361
- unset($args);
362
 
363
  $pagenum = $wp_list_table->get_pagenum();
364
 
@@ -369,88 +458,107 @@ class FrmFormsController{
369
  wp_redirect( add_query_arg( 'paged', $total_pages ) );
370
  die();
371
  }
372
-
373
- if ( ! empty( $_REQUEST['s'] ) )
374
- $page_params .= '&s='. urlencode($_REQUEST['s']);
375
-
376
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
377
  }
378
-
379
- public static function get_columns($columns){
380
  $columns['cb'] = '<input type="checkbox" />';
381
- $columns['id'] = 'ID';
382
- $columns['name'] = __('Name');
383
- $columns['description'] = __('Description');
384
- $columns['form_key'] = __('Key', 'formidable');
385
-
386
- if($_GET['page'] == 'formidable-templates'){
387
- add_screen_option( 'per_page', array('label' => __('Templates', 'formidable'), 'default' => 10, 'option' => 'formidable_page_formidable_templates_per_page') );
388
- }else{
389
- $columns['entries'] = __('Entries', 'formidable');
390
- $columns['link'] = __('Actions', 'formidable');
391
- $columns['shortcode'] = __('Shortcodes', 'formidable');
392
- add_screen_option( 'per_page', array('label' => __('Forms', 'formidable'), 'default' => 20, 'option' => 'formidable_page_formidable_per_page') );
 
393
  }
394
-
395
  $columns['created_at'] = __('Date', 'formidable');
396
-
 
 
397
  return $columns;
398
  }
399
-
400
  public static function get_sortable_columns() {
401
  return array(
402
- 'id' => 'id',
403
- 'name' => 'name',
404
  'description' => 'description',
405
- 'form_key' => 'form_key',
406
- 'created_at' => 'created_at'
407
  );
408
  }
409
-
410
  public static function hidden_columns($result){
411
  $return = false;
412
- foreach((array)$result as $r){
413
  if(!empty($r)){
414
  $return = true;
415
  break;
416
  }
417
  }
418
-
419
  if($return)
420
  return $result;
421
 
 
 
422
  $result[] = 'created_at';
423
- if($_GET['page'] == 'formidable-templates'){
424
  $result[] = 'id';
425
  $result[] = 'form_key';
426
- }
427
-
428
  return $result;
429
  }
430
-
431
  public static function save_per_page($save, $option, $value){
432
- if($option == 'formidable_page_formidable_per_page' or $option == 'formidable_page_formidable_templates_per_page')
433
- $save = (int)$value;
 
434
  return $save;
435
  }
436
 
437
  private static function get_edit_vars($id, $errors = '', $message='', $create_link=false){
438
- global $frm_entry, $frm_field, $frm_vars;
439
- $frm_form = new FrmForm();
440
- $form = $frm_form->getOne( $id );
441
  if ( !$form ) {
442
  wp_die( __('You are trying to edit a form that does not exist.', 'formidable') );
443
  }
444
-
 
 
 
 
445
  $frm_field_selection = FrmFieldsHelper::field_selection();
446
- $fields = $frm_field->getAll(array('fi.form_id' => $form->id), 'field_order');
 
 
 
 
 
 
 
 
 
 
 
447
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
448
-
449
  $edit_message = __('Form was Successfully Updated', 'formidable');
450
  if ( $form->is_template && $message == $edit_message ) {
451
  $message = __('Template was Successfully Updated', 'formidable');
452
  }
453
-
454
  if ( $form->default_template ) {
455
  wp_die(__('That template cannot be edited', 'formidable'));
456
  } else if ( defined('DOING_AJAX') ) {
@@ -461,123 +569,195 @@ class FrmFormsController{
461
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
462
  }
463
  }
464
-
465
  public static function get_settings_vars($id, $errors = '', $message=''){
466
- global $frm_entry, $frm_field, $frm_vars;
467
- $frm_form = new FrmForm();
468
- $form = $frm_form->getOne( $id );
469
- $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
 
470
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
471
- $sections = apply_filters('frm_add_form_settings_section', array(), $values);
472
- $pro_feature = $frm_vars['pro_is_installed'] ? '' : ' class="pro_feature"';
473
- if (isset($values['default_template']) && $values['default_template'])
474
  wp_die(__('That template cannot be edited', 'formidable'));
475
- else
476
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/settings.php');
 
 
 
 
 
 
 
 
477
  }
478
-
479
- public static function get_params(){
480
- $values = array();
481
- foreach (array('template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default)
482
- $values[$var] = FrmAppHelper::get_param($var, $default);
483
 
484
- return $values;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
  }
486
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
487
  public static function process_bulk_form_actions($errors) {
488
- if ( !isset($_POST) ) return;
489
-
 
 
490
  $bulkaction = FrmAppHelper::get_param('action');
491
  if ( $bulkaction == -1 ) {
492
  $bulkaction = FrmAppHelper::get_param('action2');
493
  }
494
 
495
- if ( !empty($bulkaction) && strpos($bulkaction, 'bulk_') === 0 ) {
496
- if ( isset($_GET) && isset($_GET['action']) ) {
497
- $_SERVER['REQUEST_URI'] = str_replace('&action=' .$_GET['action'], '', $_SERVER['REQUEST_URI']);
498
- }
499
- if ( isset($_GET) && isset($_GET['action2']) ) {
500
- $_SERVER['REQUEST_URI'] = str_replace('&action=' .$_GET['action2'], '', $_SERVER['REQUEST_URI']);
501
- }
502
-
503
  $bulkaction = str_replace('bulk_', '', $bulkaction);
504
- } else {
505
- $bulkaction = '-1';
506
- if(isset($_POST['bulkaction']) && $_POST['bulkaction'] != '-1') {
507
- $bulkaction = $_POST['bulkaction'];
508
- } else if(isset($_POST['bulkaction2']) && $_POST['bulkaction2'] != '-1') {
509
- $bulkaction = $_POST['bulkaction2'];
510
- }
511
  }
512
 
513
  $ids = FrmAppHelper::get_param('item-action', '');
514
  if ( empty($ids) ) {
515
  $errors[] = __('No forms were specified', 'formidable');
516
- } else {
517
- if ( $bulkaction == 'delete' ) {
518
- if ( !current_user_can('frm_delete_forms') ) {
519
- global $frm_settings;
520
- $errors[] = $frm_settings->admin_permission;
521
- } else {
522
- if ( !is_array($ids) ) {
523
- $ids = explode(',', $ids);
524
- }
525
-
526
- if ( is_array($ids) ) {
527
- if ( $bulkaction == 'delete' ) {
528
- $frm_form = new FrmForm();
529
- foreach ( $ids as $form_id ) {
530
- $frm_form->destroy($form_id);
531
- }
532
- }
533
- }
534
- }
535
- }
536
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  return $errors;
538
  }
539
-
540
  public static function add_default_templates($path, $default=true, $template=true){
541
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
542
-
543
- global $frm_field;
544
  $path = untrailingslashit(trim($path));
545
  $templates = glob($path."/*.php");
546
-
547
- $frm_form = new FrmForm();
548
  for($i = count($templates) - 1; $i >= 0; $i--){
549
  $filename = str_replace('.php', '', str_replace($path.'/', '', $templates[$i]));
550
  $template_query = array('form_key' => $filename);
551
- if($template) $template_query['is_template'] = 1;
552
- if($default) $template_query['default_template'] = 1;
553
- $form = $frm_form->getAll($template_query, '', 1);
554
-
 
 
 
 
555
  $values = FrmFormsHelper::setup_new_vars();
556
  $values['form_key'] = $filename;
557
  $values['is_template'] = $template;
558
  $values['status'] = 'published';
559
  if($default) $values['default_template'] = 1;
560
-
561
  include($templates[$i]);
562
-
563
  //get updated form
564
  if ( isset($form) && $form ) {
565
- $form = $frm_form->getOne($form->id);
 
566
  } else {
567
- $form = $frm_form->getAll($template_query, '', 1);
 
 
 
 
 
568
  }
569
-
570
- if($form)
571
- do_action('frm_after_duplicate_form', $form->id, (array)$form);
572
  }
573
  }
574
 
575
  public static function route(){
576
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
577
- $vars = false;
578
  if(isset($_POST['frm_compact_fields'])){
579
  if ( !current_user_can('frm_edit_forms') && !current_user_can('administrator') ) {
580
- global $frm_settings;
581
  wp_die($frm_settings->admin_permission);
582
  }
583
  $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('&quot;', '\\\"', $_POST['frm_compact_fields'] ))));
@@ -588,8 +768,8 @@ class FrmFormsController{
588
  if ( 'edit' == $action ) {
589
  $action = 'update';
590
  }
591
-
592
- add_filter('frm_validate_form', array(__CLASS__, 'json_error'));
593
  } else {
594
  $vars = FrmAppHelper::json_to_array($json_vars);
595
  $action = $vars[$action];
@@ -597,68 +777,65 @@ class FrmFormsController{
597
  }else{
598
  $action = FrmAppHelper::get_param($action);
599
  }
600
-
601
- if($action == 'new' or $action == 'new-selection')
602
- return self::new_form($vars);
603
- else if($action == 'create')
604
- return self::create($vars);
605
- else if($action == 'edit')
606
- return self::edit($vars);
607
- else if($action == 'update')
608
- return self::update($vars);
609
- else if($action == 'duplicate')
610
- return self::duplicate();
611
- else if($action == 'destroy')
612
- return self::destroy();
613
- else if($action == 'list-form')
614
- return self::list_form();
615
- else if($action == 'settings')
616
- return self::settings();
617
- else if($action == 'update_settings')
618
- return self::update_settings();
619
- else{
620
- do_action('frm_form_action_'. $action);
621
- if(apply_filters('frm_form_stop_action_'. $action, false))
622
- return;
623
-
624
- $action = FrmAppHelper::get_param('action');
625
- if($action == -1)
626
- $action = FrmAppHelper::get_param('action2');
627
-
628
- if(strpos($action, 'bulk_') === 0){
629
- if(isset($_GET) and isset($_GET['action']))
630
- $_SERVER['REQUEST_URI'] = str_replace('&action='.$_GET['action'], '', $_SERVER['REQUEST_URI']);
631
- if(isset($_GET) and isset($_GET['action2']))
632
- $_SERVER['REQUEST_URI'] = str_replace('&action='.$_GET['action2'], '', $_SERVER['REQUEST_URI']);
633
-
634
- return self::list_form();
635
- }else{
636
  return self::display_forms_list();
637
- }
638
  }
639
  }
640
-
641
  public static function json_error($errors) {
642
  $errors['json'] = __('Abnormal HTML characters prevented your form from saving correctly', 'formidable');
643
  return $errors;
644
  }
645
-
646
-
647
  /* FRONT-END FORMS */
648
  public static function admin_bar_css() {
649
  FrmAppController::load_wp_admin_style();
650
  }
651
-
652
  public static function admin_bar_configure() {
653
  if ( is_admin() || !current_user_can('frm_edit_forms') ) {
654
  return;
655
  }
656
-
657
  global $frm_vars;
658
  if ( empty($frm_vars['forms_loaded']) ) {
659
  return;
660
  }
661
-
662
  $actions = array();
663
  foreach ($frm_vars['forms_loaded'] as $form ) {
664
  if ( is_object($form) ) {
@@ -666,22 +843,22 @@ class FrmFormsController{
666
  }
667
  unset($form);
668
  }
669
-
670
  if ( empty($actions) ) {
671
  return;
672
  }
673
-
674
  asort($actions);
675
-
676
  global $wp_admin_bar;
677
-
678
  if ( count($actions) == 1 ) {
679
  $wp_admin_bar->add_menu( array(
680
  'title' => 'Edit Form',
681
  'href' => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
682
  'id' => 'frm-forms'
683
  ) );
684
- } else {
685
  $wp_admin_bar->add_menu( array(
686
  'id' => 'frm-forms',
687
  'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
@@ -690,7 +867,7 @@ class FrmFormsController{
690
  'title' => __( 'Edit Forms', 'formidable' ),
691
  ),
692
  ) );
693
-
694
  foreach ( $actions as $form_id => $name ) {
695
 
696
  $wp_admin_bar->add_menu( array(
@@ -700,11 +877,9 @@ class FrmFormsController{
700
  'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
701
  ) );
702
  }
703
- }
704
  }
705
-
706
-
707
-
708
  //formidable shortcode
709
  public static function get_form_shortcode($atts) {
710
  global $frm_vars;
@@ -715,101 +890,147 @@ class FrmFormsController{
715
  }
716
  return $sc .']';
717
  }
718
-
719
  $shortcode_atts = shortcode_atts(array(
720
  'id' => '', 'key' => '', 'title' => false, 'description' => false,
721
  'readonly' => false, 'entry_id' => false, 'fields' => array(),
722
  'exclude_fields' => array(), 'minimize' => false,
723
  ), $atts);
724
  do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
725
- extract($shortcode_atts);
726
- return self::show_form($id, $key, $title, $description, $atts);
727
- }
728
-
729
- //filter form shortcode in text widgets
730
- public static function widget_text_filter( $content ) {
731
- $regex = '/\[\s*formidable\s+.*\]/';
732
- return preg_replace_callback( $regex, 'FrmAppController::widget_text_filter_callback', $content );
733
  }
734
-
735
  public static function show_form($id = '', $key = '', $title = false, $description = false, $atts = array()) {
736
- global $frm_settings, $post;
737
-
738
- $frm_form = new FrmForm();
739
  if ( empty($id) ) {
740
  $id = $key;
741
  }
742
-
743
  // no form id or key set
744
  if ( empty($id) ) {
745
  return __('Please select a valid form', 'formidable');
746
  }
747
-
748
- $form = $frm_form->getOne($id);
749
- if ( !$form ) {
750
  return __('Please select a valid form', 'formidable');
751
  }
 
 
 
 
752
  $form = apply_filters('frm_pre_display_form', $form);
753
-
 
 
754
  // don't show a draft form on a page
755
  if ( $form->status == 'draft' && (!$post || $post->ID != $frm_settings->preview_page_id) ) {
756
  return __('Please select a valid form', 'formidable');
757
  }
758
-
759
  // don't show the form if user should be logged in
760
  if ( $form->logged_in && !is_user_logged_in() ) {
761
  return do_shortcode($frm_settings->login_msg);
762
  }
763
-
764
  // don't show the form if user doesn't have permission
765
  if ( $form->logged_in && get_current_user_id() && isset($form->options['logged_in_role']) && $form->options['logged_in_role'] != '' && !FrmAppHelper::user_has_permission($form->options['logged_in_role']) ) {
766
  return do_shortcode($frm_settings->login_msg);
767
  }
768
-
769
  $form = self::get_form($form, $title, $description, $atts);
770
-
771
  // check for external shortcodes
772
  $form = do_shortcode($form);
773
-
774
  return $form;
775
  }
776
-
777
  public static function get_form($form, $title, $description, $atts = array()) {
778
- global $frm_field, $frm_entry, $frm_entry_meta, $frm_settings, $frm_vars;
779
- $form_name = $form->name;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
 
781
- $frm_form = new FrmForm();
782
  $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
783
- $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
784
-
785
  $user_ID = get_current_user_id();
786
-
787
  $params = FrmEntriesController::get_params($form);
788
 
789
  $message = $errors = '';
790
 
791
- FrmEntriesHelper::enqueue_scripts($params);
792
-
793
  if ( $params['posted_form_id'] == $form->id && $_POST ) {
794
  $errors = isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['errors'] : array();
795
  }
796
 
797
  $fields = FrmFieldsHelper::get_form_fields($form->id, (isset($errors) && !empty($errors)));
798
-
799
- $filename = FrmAppHelper::plugin_path() .'/classes/views/frm-entries/frm-entry.php';
800
-
801
- if ( is_file($filename) ) {
802
- ob_start();
803
- include $filename;
804
- $contents = ob_get_contents();
805
- ob_end_clean();
806
- // check if minimizing is turned on
807
- if ( isset($atts['minimize']) && !empty($atts['minimize']) ) {
808
- $contents = str_replace(array("\r\n", "\r", "\n", "\t", " "), '', $contents);
809
  }
810
- return $contents;
811
  }
812
- return false;
813
- }
814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
815
  }
1
  <?php
 
 
 
2
 
 
 
 
 
 
3
  class FrmFormsController{
4
+ public static $action_post_type = 'frm_form_actions';
5
+
6
+ public static function trigger_load_form_hooks() {
7
+ FrmHooksController::trigger_load_hook( 'load_form_hooks' );
8
+ }
9
+
10
+ /*
11
+ * The hooks only needed when a form is loaded
12
+ */
13
+ public static function load_form_hooks() {
14
+ add_filter('frm_form_classes', 'FrmFormsController::form_classes' );
15
+ }
16
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  public static function menu(){
18
+ $frm_settings = FrmAppHelper::get_settings();
19
+
20
+ add_submenu_page('formidable', $frm_settings->menu .' | '. __('Forms', 'formidable'), __('Forms', 'formidable'), 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
21
+
22
+ add_filter('get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
23
+
24
+ add_filter('manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
25
+ add_filter('manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
26
+ }
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ public static function head(){
29
  wp_enqueue_script('formidable-editinplace');
30
  wp_enqueue_script('jquery-frm-themepicker');
31
+
32
+ if ( wp_is_mobile() ) {
33
+ wp_enqueue_script( 'jquery-touch-punch' );
34
+ }
35
  }
36
+
37
  public static function register_widgets(){
38
  require_once(FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php');
39
  register_widget('FrmShowForm');
40
  }
41
+
42
  public static function list_form(){
43
+ FrmAppHelper::permission_check('frm_view_forms');
44
+
45
+ $params = FrmFormsHelper::get_params();
 
 
 
 
46
  $errors = apply_filters('frm_admin_list_form_action', array());
47
+ return self::display_forms_list($params, '', false, $errors);
48
  }
49
+
50
  public static function new_form($values=false){
51
+ FrmAppHelper::permission_check('frm_edit_forms');
52
+
53
  global $frm_vars;
54
+
55
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
56
  $action = ($values) ? $values[$action] : FrmAppHelper::get_param($action);
57
+
 
58
  if ($action == 'create'){
59
  return self::create($values);
60
  }else if ($action == 'new'){
61
+ $frm_field_selection = FrmFieldsHelper::field_selection();
62
  $values = FrmFormsHelper::setup_new_vars($values);
63
+ $id = FrmForm::create( $values );
64
+ $form = FrmForm::getOne($id);
65
+
66
+ // add default email notification
67
+ $action_control = FrmFormActionsController::get_form_actions( 'email' );
68
+ $action_control->create($form->id);
69
+
70
  $values['id'] = $id;
71
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
72
  }else{
73
+ $all_templates = FrmForm::getAll(array('is_template' => 1), 'name');
74
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new-selection.php');
75
  }
76
  }
77
+
78
  public static function create($values=false){
79
+ FrmAppHelper::permission_check('frm_edit_forms');
80
+
81
+ global $frm_vars;
82
+ if ( ! $values ) {
83
  $values = $_POST;
84
+ }
85
+
86
+ //Set radio button and checkbox meta equal to "other" value
87
+ $values = FrmEntriesHelper::set_other_vals( $values, true );
88
+
89
+ $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
90
+
91
  if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce'))) ) {
92
+ $frm_settings = FrmAppHelper::get_settings();
93
+ $errors = array( 'form' => $frm_settings->admin_permission );
94
+ } else {
95
+ $errors = FrmForm::validate($values);
96
  }
97
+
98
+ if ( count($errors) > 0 ) {
 
 
 
 
 
99
  $hide_preview = true;
100
  $frm_field_selection = FrmFieldsHelper::field_selection();
101
+ $form = FrmForm::getOne( $id );
102
+ $fields = FrmField::get_all_for_form($id);
103
+
104
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
105
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/new.php');
106
+ }else{
107
+ FrmForm::update( $id, $values, true );
108
  die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id='. $id)));
109
  //$message = __('Form was Successfully Created', 'formidable');
110
  //return self::settings($record, $message);
111
  }
112
  }
113
+
114
  public static function edit($values=false){
115
+ FrmAppHelper::permission_check('frm_edit_forms');
116
+
117
+ $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
 
 
 
118
  return self::get_edit_vars($id);
119
  }
120
+
121
  public static function settings($id=false, $message=''){
122
+ FrmAppHelper::permission_check('frm_edit_forms');
123
+
124
  if(!$id or !is_numeric($id))
125
+ $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
126
  return self::get_settings_vars($id, '', $message);
127
  }
128
+
129
  public static function update_settings(){
130
+ FrmAppHelper::permission_check('frm_edit_forms');
131
+
132
  $id = FrmAppHelper::get_param('id');
133
+
134
+ $errors = FrmForm::validate($_POST);
135
+ if ( count($errors) > 0 ) {
 
 
136
  return self::get_settings_vars($id, $errors);
 
 
 
 
137
  }
138
+
139
+ do_action('frm_before_update_form_settings', $id);
140
+
141
+ FrmForm::update( $_POST['id'], $_POST );
142
+
143
+ $message = __('Settings Successfully Updated', 'formidable');
144
+ return self::get_settings_vars($id, '', $message);
145
  }
146
+
147
  public static function edit_key(){
148
+ FrmAppHelper::ajax_permission_check('frm_edit_forms');
149
+
 
 
150
  global $wpdb;
151
  $values = array('form_key' => trim($_POST['update_value']));
152
+
153
+ FrmForm::update($_POST['form_id'], $values);
154
+ $key = FrmForm::getKeyById($_POST['form_id']);
155
+ echo stripslashes($key);
156
  die();
157
  }
158
 
159
  public static function edit_description(){
160
+ FrmAppHelper::ajax_permission_check('frm_edit_forms');
161
+
162
+ FrmForm::update($_POST['form_id'], array('description' => $_POST['update_value']));
163
+ $description = FrmAppHelper::use_wpautop(stripslashes($_POST['update_value']));
 
 
 
 
 
164
  echo $description;
165
  die();
166
  }
167
+
168
  public static function update($values=false){
169
+ FrmAppHelper::permission_check('frm_edit_forms');
170
 
171
+ if ( empty($values) ) {
172
  $values = $_POST;
173
+ }
174
+
175
+ //Set radio button and checkbox meta equal to "other" value
176
+ $values = FrmEntriesHelper::set_other_vals( $values, true );
177
+
178
+ $errors = FrmForm::validate($values);
179
+
180
  if ( ! current_user_can('frm_edit_forms') || ( $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce')) ) ) {
181
+ $frm_settings = FrmAppHelper::get_settings();
182
  $errors['form'] = $frm_settings->admin_permission;
183
  }
184
+
185
+ $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
186
+
187
  if( count($errors) > 0 ){
188
  return self::get_edit_vars($id, $errors);
189
  }else{
190
+ FrmForm::update( $id, $values );
191
  $message = __('Form was Successfully Updated', 'formidable');
192
  if ( defined('DOING_AJAX') ) {
193
  die($message);
195
  return self::get_edit_vars($id, '', $message);
196
  }
197
  }
198
+
199
+ public static function bulk_create_template($ids) {
200
+ FrmAppHelper::permission_check('frm_edit_forms');
201
+
202
+ foreach ( $ids as $id ) {
203
+ FrmForm::duplicate( $id, true, true );
204
+ }
205
+
206
+ return __('Form template was Successfully Created', 'formidable');
207
+ }
208
+
209
  public static function duplicate(){
210
+ FrmAppHelper::permission_check('frm_edit_forms');
211
+
212
+ $params = FrmFormsHelper::get_params();
213
+ $form = FrmForm::duplicate( $params['id'], $params['template'], true );
 
 
 
 
 
214
  $message = ($params['template']) ? __('Form template was Successfully Created', 'formidable') : __('Form was Successfully Copied', 'formidable');
215
  if ( $form ) {
216
  return self::get_edit_vars($form, '', $message, true);
218
  return self::display_forms_list($params, __('There was a problem creating new template.', 'formidable'));
219
  }
220
  }
221
+
 
 
 
 
 
 
222
  public static function page_preview(){
223
+ $params = FrmFormsHelper::get_params();
224
  if (!$params['form']) return;
225
+
226
+ $form = FrmForm::getOne($params['form']);
 
227
  if(!$form) return;
228
  return self::show_form($form->id, '', true, true);
229
  }
230
 
231
  public static function preview(){
232
  do_action('frm_wp');
233
+
234
+ global $frm_vars;
235
  $frm_vars['preview'] = true;
236
+
 
237
  if ( !defined( 'ABSPATH' ) && !defined( 'XMLRPC_REQUEST' )) {
238
  global $wp;
239
  $root = dirname(dirname(dirname(dirname(__FILE__))));
241
  $wp->init();
242
  $wp->register_globals();
243
  }
244
+
245
+ if ( FrmAppHelper::pro_is_installed() ) {
246
  FrmProEntriesController::register_scripts();
247
+ }
248
+
249
  header("Content-Type: text/html; charset=". get_option( 'blog_charset' ));
250
 
251
  $plugin = FrmAppHelper::get_param('plugin');
252
  $controller = FrmAppHelper::get_param('controller');
253
  $key = (isset($_GET['form']) ? $_GET['form'] : (isset($_POST['form']) ? $_POST['form'] : ''));
254
+ $form = FrmForm::getAll(array('form_key' => $key), '', 1);
255
+ if (!$form) $form = FrmForm::getAll('', '', 1);
256
+
257
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/direct.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  die();
259
  }
260
+
261
+ public static function untrash() {
262
+ FrmFormsHelper::change_form_status('untrash');
263
+ }
264
+
265
+ public static function bulk_untrash($ids) {
266
+ FrmAppHelper::permission_check('frm_edit_forms');
267
+
268
+ $count = FrmForm::set_status( $ids, 'published' );
269
+
270
+ $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
271
+ return $message;
272
+ }
273
+
274
+ public static function trash() {
275
+ FrmFormsHelper::change_form_status('trash');
276
+ }
277
+
278
+ public static function bulk_trash($ids) {
279
+ FrmAppHelper::permission_check('frm_delete_forms');
280
+
281
+ $count = 0;
282
+ foreach ( $ids as $id ) {
283
+ if ( FrmForm::trash( $id ) ) {
284
+ $count++;
285
+ }
286
  }
287
+
288
+ $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
289
+ $message = sprintf(_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="'. esc_url(wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type='. $current_page .'&item-action[]='. implode('item-action[]=', $ids), 'bulk-toplevel_page_formidable' )) .'">', '</a>' );
290
+
291
+ return $message;
292
  }
293
+
294
+ public static function destroy() {
295
+ FrmAppHelper::permission_check('frm_delete_forms');
296
+
297
+ $params = FrmFormsHelper::get_params();
298
+
299
+ //check nonce url
300
+ check_admin_referer('destroy_form_' . $params['id']);
301
+
302
+ $count = 0;
303
+ if ( FrmForm::destroy( $params['id'] ) ) {
304
+ $count++;
305
+ }
306
+
307
+ $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
308
+
309
+ self::display_forms_list($params, $message, 1);
310
+ }
311
+
312
+ public static function bulk_destroy($ids) {
313
+ FrmAppHelper::permission_check('frm_delete_forms');
314
+
315
+ $count = 0;
316
+ foreach ( $ids as $id ) {
317
+ $d = FrmForm::destroy( $id );
318
+ if ( $d ) {
319
+ $count++;
320
+ }
321
+ }
322
+
323
+ $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
324
+
325
+ return $message;
326
  }
327
+
328
+ // Delete trashed forms
329
+ public static function scheduled_delete() {
330
+ global $wpdb;
331
+
332
+ $trash_forms = $wpdb->get_results($wpdb->prepare("SELECT id, options FROM {$wpdb->prefix}frm_forms WHERE status = %s", 'trash'));
333
+
334
+ if ( !$trash_forms ) {
335
  return;
336
+ }
337
+
338
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
339
+
340
+ foreach ( $trash_forms as $form ) {
341
+ $form->options = maybe_unserialize($form->options);
342
+ if ( !isset($form->options['trash_time']) || $form->options['trash_time'] < $delete_timestamp ) {
343
+ FrmForm::destroy($form->id);
344
+ }
345
+
346
+ unset($form);
347
+ }
348
+
349
+ }
350
+
351
+ public static function insert_form_button($content){
352
+ if ( current_user_can('frm_view_forms') ) {
353
+ $content .= '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . __('Add forms and content', 'formidable') . '"><span class="frm-buttons-icon wp-media-buttons-icon"></span> Formidable</a>';
354
+
355
+ }
356
+ return $content;
357
  }
358
+
359
  public static function insert_form_popup(){
360
  $page = basename($_SERVER['PHP_SELF']);
361
+ if ( ! in_array($page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php') ) ) {
362
+ return;
363
+ }
364
+
365
+ $shortcodes = array(
366
+ 'formidable' => array('name' => __('Form', 'formidable'), 'label' => __('Insert a Form', 'formidable')),
367
+ );
368
+
369
+ $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
370
+
371
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/insert_form_popup.php');
372
+ }
373
+
374
+ public static function get_shortcode_opts() {
375
+ $shortcode = $_POST['shortcode'];
376
+ if ( empty($shortcode) ) {
377
+ die();
378
+ }
379
+
380
+ $form_id = '';
381
+ $opts = array();
382
+
383
+ echo '<div id="sc-opts-'. $shortcode .'" class="frm_shortcode_option">';
384
+ echo '<input type="radio" name="frmsc" value="'. esc_attr($shortcode) .'" id="sc-'. esc_attr($shortcode) .'" style="display:none;" />';
385
+ switch( $shortcode ) {
386
+ case 'formidable':
387
+ $form_id = 'id';
388
+ $opts = array(
389
+ //'key' => ',
390
+ 'title' => array('val' => 1, 'label' => __('Display form title', 'formidable')),
391
+ 'description' => array('val' => 1, 'label' => __('Display form description', 'formidable')),
392
+ 'minimize' => array('val' => 1, 'label' => __('Minimize form HTML', 'formidable')),
393
+ );
394
+ break;
395
+ }
396
+
397
+ $opts = apply_filters('frm_sc_popup_opts', $opts, $shortcode);
398
+
399
+ if ( ! empty($form_id) ) {
400
+ ?>
401
+ <h4 for="frmsc_<?php echo $shortcode .'_'. $form_id ?>" class="frm_left_label"><?php _e('Select a form:', 'formidable') ?></h4>
402
+ <?php FrmFormsHelper::forms_dropdown( 'frmsc_'. $shortcode .'_'. $form_id ); ?>
403
+ <div class="frm_box_line"></div>
404
+ <?php
405
+ }
406
+
407
+ if ( ! empty($opts) ) { ?>
408
+ <h4><?php _e('Options', 'formidable') ?></h4>
409
+ <ul>
410
+ <?php
411
+ foreach ( $opts as $opt => $val ) {
412
+ if ( isset($val['type']) && 'text' == $val['type'] ) { ?>
413
+ <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>">
414
+ <span><?php echo $val['label'] ?></span>
415
+ <input type="text" id="frmsc_<?php echo $shortcode .'_'. $opt ?>" value="<?php echo esc_attr($val['val']) ?>" />
416
+ </label>
417
+ <li>
418
+ <?php } else if ( isset($val['type']) && 'select' == $val['type'] ) { ?>
419
+ <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>">
420
+ <span><?php echo $val['label'] ?></span>
421
+ <select id="frmsc_<?php echo $shortcode .'_'. $opt ?>">
422
+ <?php foreach ( $val['opts'] as $select_opt => $select_label ) { ?>
423
+ <option value="<?php echo esc_attr($select_opt) ?>"><?php echo $select_label ?></option>
424
+ <?php } ?>
425
+ </select>
426
+ </label>
427
+ </li>
428
+ <?php } else { ?>
429
+ <li><label class="setting" for="frmsc_<?php echo $shortcode .'_'. $opt ?>"><input type="checkbox" id="frmsc_<?php echo $shortcode .'_'. $opt ?>" value="<?php echo esc_attr($val['val']) ?>" /> <?php echo $val['label'] ?></label><li>
430
+ <?php
431
+ }
432
  }
433
+ ?>
434
+ </ul>
435
+ <?php
436
  }
437
+ echo '</div>';
438
+
439
+ die();
440
  }
441
 
442
+ public static function display_forms_list($params=false, $message='', $current_page_ov = false, $errors = array()){
443
+ FrmAppHelper::permission_check('frm_view_forms');
444
+
445
+ global $wpdb, $frm_vars;
446
+
447
  if(!$params)
448
+ $params = FrmFormsHelper::get_params();
449
+
450
+ $wp_list_table = new FrmFormsListHelper( compact('params') );
 
 
 
 
 
 
 
 
 
 
 
 
 
451
 
452
  $pagenum = $wp_list_table->get_pagenum();
453
 
458
  wp_redirect( add_query_arg( 'paged', $total_pages ) );
459
  die();
460
  }
461
+
462
+
 
 
463
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/list.php');
464
  }
465
+
466
+ public static function get_columns($columns) {
467
  $columns['cb'] = '<input type="checkbox" />';
468
+ $columns['id'] = 'ID';
469
+
470
+ $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : 'published';
471
+
472
+ if ( 'template' == $type ) {
473
+ $columns['name'] = __('Template Name', 'formidable');
474
+ $columns['type'] = __('Type', 'formidable');
475
+ $columns['form_key'] = __('Key', 'formidable');
476
+ } else {
477
+ $columns['name'] = __('Form Title', 'formidable');
478
+ $columns['entries'] = __('Entries', 'formidable');
479
+ $columns['form_key'] = __('Key', 'formidable');
480
+ $columns['shortcode'] = __('Shortcodes', 'formidable');
481
  }
482
+
483
  $columns['created_at'] = __('Date', 'formidable');
484
+
485
+ add_screen_option( 'per_page', array('label' => __('Forms', 'formidable'), 'default' => 20, 'option' => 'formidable_page_formidable_per_page') );
486
+
487
  return $columns;
488
  }
489
+
490
  public static function get_sortable_columns() {
491
  return array(
492
+ 'id' => 'id',
493
+ 'name' => 'name',
494
  'description' => 'description',
495
+ 'form_key' => 'form_key',
496
+ 'created_at' => 'created_at'
497
  );
498
  }
499
+
500
  public static function hidden_columns($result){
501
  $return = false;
502
+ foreach ( (array) $result as $r ) {
503
  if(!empty($r)){
504
  $return = true;
505
  break;
506
  }
507
  }
508
+
509
  if($return)
510
  return $result;
511
 
512
+ $type = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
513
+
514
  $result[] = 'created_at';
515
+ if ( $type == 'template' ) {
516
  $result[] = 'id';
517
  $result[] = 'form_key';
518
+ }
519
+
520
  return $result;
521
  }
522
+
523
  public static function save_per_page($save, $option, $value){
524
+ if ( $option == 'formidable_page_formidable_per_page' ) {
525
+ $save = (int) $value;
526
+ }
527
  return $save;
528
  }
529
 
530
  private static function get_edit_vars($id, $errors = '', $message='', $create_link=false){
531
+ global $frm_vars;
532
+
533
+ $form = FrmForm::getOne( $id );
534
  if ( !$form ) {
535
  wp_die( __('You are trying to edit a form that does not exist.', 'formidable') );
536
  }
537
+
538
+ if ( $form->parent_form_id ) {
539
+ wp_die( sprintf(__('You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable'), '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable&frm_action=edit&id='. $form->parent_form_id) .'">', '</a>' ));
540
+ }
541
+
542
  $frm_field_selection = FrmFieldsHelper::field_selection();
543
+ $fields = FrmField::get_all_for_form($form->id);
544
+
545
+ // Automatically add end section fields if they don't exist (2.0 migration)
546
+ $reset_fields = false;
547
+ FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
548
+
549
+ if ( $reset_fields ) {
550
+ $fields = FrmField::get_all_for_form($form->id);
551
+ }
552
+
553
+ unset($end_section_values, $last_order, $open, $reset_fields);
554
+
555
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
556
+
557
  $edit_message = __('Form was Successfully Updated', 'formidable');
558
  if ( $form->is_template && $message == $edit_message ) {
559
  $message = __('Template was Successfully Updated', 'formidable');
560
  }
561
+
562
  if ( $form->default_template ) {
563
  wp_die(__('That template cannot be edited', 'formidable'));
564
  } else if ( defined('DOING_AJAX') ) {
569
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/edit.php');
570
  }
571
  }
572
+
573
  public static function get_settings_vars($id, $errors = '', $message=''){
574
+ global $frm_vars;
575
+
576
+ $form = FrmForm::getOne( $id );
577
+
578
+ $fields = FrmField::get_all_for_form($id);
579
  $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
580
+
581
+ if ( isset($values['default_template']) && $values['default_template'] ) {
 
582
  wp_die(__('That template cannot be edited', 'formidable'));
583
+ }
584
+
585
+ $action_controls = FrmFormActionsController::get_form_actions();
586
+
587
+ $sections = apply_filters('frm_add_form_settings_section', array(), $values);
588
+ $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
589
+
590
+ $styles = apply_filters('frm_get_style_opts', array());
591
+
592
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/settings.php');
593
  }
 
 
 
 
 
594
 
595
+ public static function mb_tags_box($form_id) {
596
+ $fields = FrmField::get_all_for_form($form_id, '', 'include');
597
+ $linked_forms = array();
598
+ $col = 'one';
599
+ $settings_tab = FrmAppHelper::is_admin_page('formidable') ? true : false;
600
+
601
+ $cond_shortcodes = apply_filters('frm_conditional_shortcodes', array());
602
+
603
+ $adv_shortcodes = array(
604
+ 'sep=&#34;, &#34;' => array('label' => __('Separator', 'formidable'), 'title' => __('Use a different separator for checkbox fields', 'formidable') ),
605
+ 'format=&#34;d-m-Y&#34;' => __('Date Format', 'formidable'),
606
+ 'show=&#34;field_label&#34;' => __('Field Label', 'formidable'),
607
+ 'wpautop=0' => array('label' => __('No Auto P', 'formidable'), 'title' => __('Do not automatically add any paragraphs or line breaks', 'formidable')),
608
+ );
609
+ $adv_shortcodes = apply_filters('frm_advanced_shortcodes', $adv_shortcodes);
610
+
611
+ // __('Leave blank instead of defaulting to User Login', 'formidable') : blank=1
612
+
613
+ $user_fields = apply_filters('frm_user_shortcodes', array());
614
+
615
+ include(FrmAppHelper::plugin_path() .'/classes/views/shared/mb_adv_info.php');
616
  }
617
+
618
+ // Insert the form class setting into the form
619
+ public static function form_classes($form) {
620
+ if ( isset($form->options['form_class']) ) {
621
+ echo esc_attr($form->options['form_class']);
622
+ }
623
+ }
624
+
625
+ public static function get_email_html(){
626
+ echo FrmEntriesController::show_entry_shortcode( array(
627
+ 'form_id' => $_POST['form_id'],
628
+ 'default_email' => true,
629
+ 'plain_text' => $_POST['plain_text'],
630
+ ) );
631
+ die();
632
+ }
633
+
634
+ public static function filter_content($content, $form, $entry=false){
635
+ if ( ! $entry || ! is_object($entry) ) {
636
+ if ( ! $entry || ! is_numeric($entry) ) {
637
+ $entry = ( $_POST && isset($_POST['id']) ) ? $_POST['id'] : false;
638
+ }
639
+
640
+ FrmEntriesHelper::maybe_get_entry($entry);
641
+ }
642
+
643
+ if ( !$entry ) {
644
+ return $content;
645
+ }
646
+
647
+ if ( is_object($form) ) {
648
+ $form = $form->id;
649
+ }
650
+
651
+ $shortcodes = FrmFieldsHelper::get_shortcodes($content, $form);
652
+ $content = apply_filters('frm_replace_content_shortcodes', $content, $entry, $shortcodes);
653
+
654
+ return $content;
655
+ }
656
+
657
+ public static function replace_content_shortcodes($content, $entry, $shortcodes) {
658
+ return FrmFieldsHelper::replace_content_shortcodes($content, $entry, $shortcodes);
659
+ }
660
+
661
  public static function process_bulk_form_actions($errors) {
662
+ if ( ! $_REQUEST ) {
663
+ return $errors;
664
+ }
665
+
666
  $bulkaction = FrmAppHelper::get_param('action');
667
  if ( $bulkaction == -1 ) {
668
  $bulkaction = FrmAppHelper::get_param('action2');
669
  }
670
 
671
+ if ( ! empty($bulkaction) && strpos($bulkaction, 'bulk_') === 0 ) {
672
+ FrmAppHelper::remove_get_action();
673
+
 
 
 
 
 
674
  $bulkaction = str_replace('bulk_', '', $bulkaction);
 
 
 
 
 
 
 
675
  }
676
 
677
  $ids = FrmAppHelper::get_param('item-action', '');
678
  if ( empty($ids) ) {
679
  $errors[] = __('No forms were specified', 'formidable');
680
+ return $errors;
681
+ }
682
+
683
+ if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-toplevel_page_formidable' ) ) {
684
+ $frm_settings = FrmAppHelper::get_settings();
685
+ $errors[] = $frm_settings->admin_permission;
686
+ return $errors;
 
 
 
 
 
 
 
 
 
 
 
 
 
687
  }
688
+
689
+ if ( !is_array($ids) ) {
690
+ $ids = explode(',', $ids);
691
+ }
692
+
693
+ switch ( $bulkaction ) {
694
+ case 'delete':
695
+ $message = self::bulk_destroy($ids);
696
+ break;
697
+ case 'trash':
698
+ $message = self::bulk_trash($ids);
699
+ break;
700
+ case 'untrash':
701
+ $message = self::bulk_untrash($ids);
702
+ break;
703
+ case 'create_template':
704
+ $message = self::bulk_create_template($ids);
705
+ break;
706
+ }
707
+
708
+ if ( isset($message) && !empty($message) ) {
709
+ echo '<div id="message" class="updated" style="padding:5px;">'. $message .'</div>';
710
+ }
711
+
712
  return $errors;
713
  }
714
+
715
  public static function add_default_templates($path, $default=true, $template=true){
716
  _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
717
+
 
718
  $path = untrailingslashit(trim($path));
719
  $templates = glob($path."/*.php");
720
+
 
721
  for($i = count($templates) - 1; $i >= 0; $i--){
722
  $filename = str_replace('.php', '', str_replace($path.'/', '', $templates[$i]));
723
  $template_query = array('form_key' => $filename);
724
+ if ( $template ) {
725
+ $template_query['is_template'] = 1;
726
+ }
727
+ if ( $default ) {
728
+ $template_query['default_template'] = 1;
729
+ }
730
+ $form = FrmForm::getAll($template_query, '', 1);
731
+
732
  $values = FrmFormsHelper::setup_new_vars();
733
  $values['form_key'] = $filename;
734
  $values['is_template'] = $template;
735
  $values['status'] = 'published';
736
  if($default) $values['default_template'] = 1;
737
+
738
  include($templates[$i]);
739
+
740
  //get updated form
741
  if ( isset($form) && $form ) {
742
+ $old_id = $form->id;
743
+ $form = FrmForm::getOne($form->id);
744
  } else {
745
+ $old_id = false;
746
+ $form = FrmForm::getAll($template_query, '', 1);
747
+ }
748
+
749
+ if ( $form ) {
750
+ do_action('frm_after_duplicate_form', $form->id, (array) $form, array('old_id' => $old_id));
751
  }
 
 
 
752
  }
753
  }
754
 
755
  public static function route(){
756
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
757
+ $vars = array();
758
  if(isset($_POST['frm_compact_fields'])){
759
  if ( !current_user_can('frm_edit_forms') && !current_user_can('administrator') ) {
760
+ $frm_settings = FrmAppHelper::get_settings();
761
  wp_die($frm_settings->admin_permission);
762
  }
763
  $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('&quot;', '\\\"', $_POST['frm_compact_fields'] ))));
768
  if ( 'edit' == $action ) {
769
  $action = 'update';
770
  }
771
+
772
+ add_filter('frm_validate_form', 'FrmFormsController::json_error');
773
  } else {
774
  $vars = FrmAppHelper::json_to_array($json_vars);
775
  $action = $vars[$action];
777
  }else{
778
  $action = FrmAppHelper::get_param($action);
779
  }
780
+
781
+ add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
782
+ FrmAppHelper::trigger_hook_load( 'form' );
783
+
784
+ switch ( $action ) {
785
+ case 'new':
786
+ case 'new-selection':
787
+ return self::new_form($vars);
788
+ case 'create':
789
+ case 'edit':
790
+ case 'update':
791
+ case 'duplicate':
792
+ case 'trash':
793
+ case 'untrash':
794
+ case 'destroy':
795
+ case 'settings':
796
+ case 'update_settings':
797
+ return self::$action($vars);
798
+ default:
799
+ do_action('frm_form_action_'. $action);
800
+ if ( apply_filters('frm_form_stop_action_'. $action, false) ) {
801
+ return;
802
+ }
803
+
804
+ $action = FrmAppHelper::get_param('action');
805
+ if ( $action == -1 ) {
806
+ $action = FrmAppHelper::get_param('action2');
807
+ }
808
+
809
+ if ( strpos($action, 'bulk_') === 0 ) {
810
+ FrmAppHelper::remove_get_action();
811
+ return self::list_form();
812
+ }
813
+
 
 
814
  return self::display_forms_list();
 
815
  }
816
  }
817
+
818
  public static function json_error($errors) {
819
  $errors['json'] = __('Abnormal HTML characters prevented your form from saving correctly', 'formidable');
820
  return $errors;
821
  }
822
+
823
+
824
  /* FRONT-END FORMS */
825
  public static function admin_bar_css() {
826
  FrmAppController::load_wp_admin_style();
827
  }
828
+
829
  public static function admin_bar_configure() {
830
  if ( is_admin() || !current_user_can('frm_edit_forms') ) {
831
  return;
832
  }
833
+
834
  global $frm_vars;
835
  if ( empty($frm_vars['forms_loaded']) ) {
836
  return;
837
  }
838
+
839
  $actions = array();
840
  foreach ($frm_vars['forms_loaded'] as $form ) {
841
  if ( is_object($form) ) {
843
  }
844
  unset($form);
845
  }
846
+
847
  if ( empty($actions) ) {
848
  return;
849
  }
850
+
851
  asort($actions);
852
+
853
  global $wp_admin_bar;
854
+
855
  if ( count($actions) == 1 ) {
856
  $wp_admin_bar->add_menu( array(
857
  'title' => 'Edit Form',
858
  'href' => admin_url('admin.php?page=formidable&frm_action=edit&id='. current( array_keys( $actions ) )),
859
  'id' => 'frm-forms'
860
  ) );
861
+ } else {
862
  $wp_admin_bar->add_menu( array(
863
  'id' => 'frm-forms',
864
  'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Edit Forms', 'formidable' ) . '</span>',
867
  'title' => __( 'Edit Forms', 'formidable' ),
868
  ),
869
  ) );
870
+
871
  foreach ( $actions as $form_id => $name ) {
872
 
873
  $wp_admin_bar->add_menu( array(
877
  'href' => admin_url( 'admin.php?page=formidable&frm_action=edit&id='. $form_id )
878
  ) );
879
  }
880
+ }
881
  }
882
+
 
 
883
  //formidable shortcode
884
  public static function get_form_shortcode($atts) {
885
  global $frm_vars;
890
  }
891
  return $sc .']';
892
  }
893
+
894
  $shortcode_atts = shortcode_atts(array(
895
  'id' => '', 'key' => '', 'title' => false, 'description' => false,
896
  'readonly' => false, 'entry_id' => false, 'fields' => array(),
897
  'exclude_fields' => array(), 'minimize' => false,
898
  ), $atts);
899
  do_action('formidable_shortcode_atts', $shortcode_atts, $atts);
900
+
901
+ return self::show_form(
902
+ $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
903
+ $shortcode_atts['description'], $atts
904
+ );
 
 
 
905
  }
906
+
907
  public static function show_form($id = '', $key = '', $title = false, $description = false, $atts = array()) {
908
+ global $post;
909
+
 
910
  if ( empty($id) ) {
911
  $id = $key;
912
  }
913
+
914
  // no form id or key set
915
  if ( empty($id) ) {
916
  return __('Please select a valid form', 'formidable');
917
  }
918
+
919
+ $form = FrmForm::getOne($id);
920
+ if ( ! $form || $form->parent_form_id ) {
921
  return __('Please select a valid form', 'formidable');
922
  }
923
+
924
+ add_action('frm_load_form_hooks', 'FrmFormsController::trigger_load_form_hooks');
925
+ FrmAppHelper::trigger_hook_load( 'form', $form );
926
+
927
  $form = apply_filters('frm_pre_display_form', $form);
928
+
929
+ $frm_settings = FrmAppHelper::get_settings();
930
+
931
  // don't show a draft form on a page
932
  if ( $form->status == 'draft' && (!$post || $post->ID != $frm_settings->preview_page_id) ) {
933
  return __('Please select a valid form', 'formidable');
934
  }
935
+
936
  // don't show the form if user should be logged in
937
  if ( $form->logged_in && !is_user_logged_in() ) {
938
  return do_shortcode($frm_settings->login_msg);
939
  }
940
+
941
  // don't show the form if user doesn't have permission
942
  if ( $form->logged_in && get_current_user_id() && isset($form->options['logged_in_role']) && $form->options['logged_in_role'] != '' && !FrmAppHelper::user_has_permission($form->options['logged_in_role']) ) {
943
  return do_shortcode($frm_settings->login_msg);
944
  }
945
+
946
  $form = self::get_form($form, $title, $description, $atts);
947
+
948
  // check for external shortcodes
949
  $form = do_shortcode($form);
950
+
951
  return $form;
952
  }
953
+
954
  public static function get_form($form, $title, $description, $atts = array()) {
955
+ ob_start();
956
+
957
+ self::get_form_contents($form, $title, $description, $atts);
958
+ FrmEntriesHelper::enqueue_scripts( FrmEntriesController::get_params($form) );
959
+
960
+ $contents = ob_get_contents();
961
+ ob_end_clean();
962
+
963
+ // check if minimizing is turned on
964
+ if ( isset($atts['minimize']) && !empty($atts['minimize']) ) {
965
+ $contents = str_replace(array("\r\n", "\r", "\n", "\t", " "), '', $contents);
966
+ }
967
+
968
+ return $contents;
969
+ }
970
+
971
+ public static function get_form_contents($form, $title, $description, $atts) {
972
+ global $frm_vars;
973
+
974
+ $frm_settings = FrmAppHelper::get_settings();
975
 
 
976
  $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
977
+
 
978
  $user_ID = get_current_user_id();
979
+
980
  $params = FrmEntriesController::get_params($form);
981
 
982
  $message = $errors = '';
983
 
 
 
984
  if ( $params['posted_form_id'] == $form->id && $_POST ) {
985
  $errors = isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['errors'] : array();
986
  }
987
 
988
  $fields = FrmFieldsHelper::get_form_fields($form->id, (isset($errors) && !empty($errors)));
989
+
990
+ if ( $params['action'] != 'create' || $params['posted_form_id'] != $form->id || ! $_POST ) {
991
+ do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
992
+ if ( apply_filters('frm_continue_to_new', true, $form->id, $params['action']) ) {
993
+ $values = FrmEntriesHelper::setup_new_vars($fields, $form);
994
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
 
 
 
 
 
995
  }
996
+ return;
997
  }
 
 
998
 
999
+ if ( ! empty($errors) ) {
1000
+ $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
1001
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1002
+ return;
1003
+ }
1004
+
1005
+ do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
1006
+ if ( ! apply_filters('frm_continue_to_create', true, $form->id) ) {
1007
+ return;
1008
+ }
1009
+
1010
+ $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
1011
+ $created = ( isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id]) ) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
1012
+ $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
1013
+
1014
+ if ( $created && is_numeric($created) && $conf_method != 'message' ) {
1015
+ do_action('frm_success_action', $conf_method, $form, $form->options, $created);
1016
+ do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
1017
+ return;
1018
+ }
1019
+
1020
+ $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
1021
+ $saved_message = apply_filters('frm_content', $saved_message, $form, $created);
1022
+ $message = ($created && is_numeric($created)) ? '<div class="frm_message" id="message">'. wpautop(do_shortcode($saved_message)) .'</div>' : '<div class="frm_error_style">'. $frm_settings->failed_msg .'</div>';
1023
+
1024
+ if ( ! isset($form->options['show_form']) || $form->options['show_form'] ) {
1025
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
1026
+ } else {
1027
+ global $frm_vars;
1028
+ FrmFormsHelper::form_loaded($form, $values['custom_style'], $frm_vars['load_css']);
1029
+
1030
+ $include_extra_container = 'frm_forms'. FrmFormsHelper::get_form_style_class($values);
1031
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
1032
+ }
1033
+
1034
+ do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
1035
+ }
1036
  }
classes/controllers/FrmHooksController.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmHooksController{
4
+ /*
5
+ * Trigger plugin-wide hook loading
6
+ */
7
+ public static function trigger_load_hook( $hooks = 'load_hooks' ) {
8
+ $controllers = apply_filters('frm_load_controllers', array( 'FrmHooksController' ) );
9
+
10
+ $trigger_hooks = $hooks;
11
+ $hooks = (array) $hooks;
12
+
13
+ if ( 'load_hooks' == $trigger_hooks ) {
14
+ if ( is_admin() ) {
15
+ $hooks[] = 'load_admin_hooks';
16
+ if ( defined('DOING_AJAX') ) {
17
+ $hooks[] = 'load_ajax_hooks';
18
+ $hooks[] = 'load_form_hooks';
19
+ }
20
+ }
21
+
22
+ if ( is_multisite() ) {
23
+ $hooks[] = 'load_multisite_hooks';
24
+ }
25
+ } else {
26
+ // Make sure the hooks are only triggered once
27
+ add_filter('frm'. str_replace('load', '', $trigger_hooks) .'_loaded', '__return_true');
28
+ }
29
+ unset($trigger_hooks);
30
+
31
+ // Instansiate Controllers
32
+ foreach ( $controllers as $c ) {
33
+ $class = new $c;
34
+ foreach ( $hooks as $hook ) {
35
+ $class->$hook();
36
+ unset($hook);
37
+ }
38
+ unset($c, $class);
39
+ }
40
+
41
+ }
42
+
43
+ public function load_hooks(){
44
+ if ( ! is_admin() ) {
45
+ add_filter('the_content', 'FrmAppController::page_route', 10);
46
+ }
47
+
48
+ add_action('plugins_loaded', 'FrmAppController::load_lang' );
49
+ add_action('init', 'FrmAppController::front_head' );
50
+ add_filter('widget_text', 'FrmAppController::widget_text_filter', 8 );
51
+ add_filter('get_frm_stylesheet', 'FrmAppController::custom_stylesheet' );
52
+
53
+ add_action('wp_footer', 'FrmAppController::footer_js', 1, 0);
54
+
55
+ // Update the session data
56
+ add_action('init', 'FrmAppController::referer_session', 1);
57
+
58
+ // Entries controller
59
+ add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
60
+ add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
61
+ add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
62
+ add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
63
+ add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
64
+ add_filter('frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4);
65
+
66
+ // Form Actions Controller
67
+ add_action('init', 'FrmFormActionsController::register_post_types', 0);
68
+ add_action('init', 'FrmFormActionsController::actions_init', 1);
69
+ add_action('frm_form_actions_init', 'FrmFormActionsController::register_actions');
70
+ add_action('frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 2);
71
+
72
+ // Forms Controller
73
+ add_action('widgets_init', 'FrmFormsController::register_widgets' );
74
+ add_filter('frm_content', 'FrmFormsController::filter_content', 10, 3);
75
+ add_filter('frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3);
76
+ add_action('admin_bar_init', 'FrmFormsController::admin_bar_css' );
77
+ add_action('wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
78
+ add_action('wp_scheduled_delete', 'FrmFormsController::scheduled_delete' );
79
+
80
+ // Form Shortcodes
81
+ add_shortcode('formidable', 'FrmFormsController::get_form_shortcode' );
82
+
83
+ // Styles Controller
84
+ add_action('init', 'FrmStylesController::register_post_types', 0);
85
+ add_filter('frm_get_style_opts', 'FrmStylesController::get_style_opts');
86
+ add_filter('frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2);
87
+ add_filter('frm_show_entry_styles', 'FrmStylesController::show_entry_styles');
88
+ }
89
+
90
+ public function load_admin_hooks() {
91
+ add_action('admin_menu', 'FrmAppController::menu', 1);
92
+ add_action('admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' );
93
+ add_filter('update_plugin_complete_actions', 'FrmAppController::update_action_links', 10, 2 );
94
+ add_action('admin_notices', 'FrmAppController::pro_get_started_headline' );
95
+ add_action('admin_init', 'FrmAppController::admin_js', 11);
96
+ register_activation_hook(FrmAppHelper::plugin_path().'/formidable.php', 'FrmAppController::activation_install' );
97
+
98
+ // Entries Controller
99
+ add_action('admin_menu', 'FrmEntriesController::menu', 12);
100
+ add_filter('contextual_help', 'FrmEntriesController::contextual_help', 10, 3 );
101
+ add_filter('set-screen-option', 'FrmEntriesController::save_per_page', 10, 3);
102
+ add_filter('update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5);
103
+ add_action('updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4);
104
+
105
+ // Fields Controller
106
+ add_filter('frm_display_field_options', 'FrmFieldsController::display_field_options');
107
+ add_action('frm_field_options_form', 'FrmFieldsController::add_conditional_update_msg', 50);
108
+
109
+ // Form Actions Controller
110
+ if ( FrmAppHelper::is_admin_page('formidable') ) {
111
+ add_action('frm_before_update_form_settings', 'FrmFormActionsController::update_settings');
112
+ }
113
+ add_action('frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3);
114
+
115
+ // Forms Controller
116
+ add_action('admin_menu', 'FrmFormsController::menu', 10);
117
+ add_action('admin_head-toplevel_page_formidable', 'FrmFormsController::head' );
118
+
119
+ add_filter('set-screen-option', 'FrmFormsController::save_per_page', 10, 3);
120
+ add_action('admin_footer', 'FrmFormsController::insert_form_popup' );
121
+ add_filter('media_buttons_context', 'FrmFormsController::insert_form_button' );
122
+
123
+ add_filter('frm_admin_list_form_action', 'FrmFormsController::process_bulk_form_actions' );
124
+
125
+ // Forms Model
126
+ add_action('frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2);
127
+
128
+ // Settings Controller
129
+ add_action('admin_menu', 'FrmSettingsController::menu', 45);
130
+ add_action('frm_before_settings', 'FrmSettingsController::license_box');
131
+
132
+ // Stats Controller
133
+ add_action('admin_menu', 'FrmStatisticsController::menu', 24);
134
+ add_action('frm_form_action_reports', 'FrmStatisticsController::list_reports');
135
+
136
+ // Styles Controller
137
+ add_action('admin_menu', 'FrmStylesController::menu', 14);
138
+ add_action('admin_init', 'FrmStylesController::admin_init');
139
+
140
+ // XML Controller
141
+ add_action('admin_menu', 'FrmXMLController::menu', 41);
142
+ }
143
+
144
+ public function load_ajax_hooks() {
145
+ add_action('wp_ajax_frm_install', 'FrmAppController::install' );
146
+ add_action('wp_ajax_frm_uninstall', 'FrmAppController::uninstall' );
147
+ add_action('wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' );
148
+
149
+ add_action('wp_ajax_frmpro_css', 'FrmAppController::load_css' );
150
+ add_action('wp_ajax_nopriv_frmpro_css', 'FrmAppController::load_css' );
151
+
152
+ // Fields Controller
153
+ add_action('wp_ajax_frm_load_field', 'FrmFieldsController::load_field');
154
+ add_action('wp_ajax_frm_insert_field', 'FrmFieldsController::create');
155
+ add_action('wp_ajax_frm_update_field_form_id', 'FrmFieldsController::update_form_id');
156
+ add_action('wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name');
157
+ add_action('wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option');
158
+ add_action('wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate');
159
+ add_action('wp_ajax_frm_delete_field', 'FrmFieldsController::destroy');
160
+ add_action('wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option');
161
+ add_action('wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option');
162
+ add_action('wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option');
163
+ add_action('wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices');
164
+ add_action('wp_ajax_frm_import_options', 'FrmFieldsController::import_options');
165
+ add_action('wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order');
166
+
167
+ // Form Actions Controller
168
+ add_action('wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action');
169
+ add_action('wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action');
170
+
171
+ // Forms Controller
172
+ add_action('wp_ajax_frm_save_form', 'FrmFormsController::route' ); //.0015
173
+ add_action('wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key' ); //.0016
174
+ add_action('wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description' ); //.0015
175
+ add_action('wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' );
176
+ add_action('wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' );
177
+ add_action('wp_ajax_frm_forms_preview', 'FrmFormsController::preview' );
178
+ add_action('wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' );
179
+
180
+ // Styles Controller
181
+ add_action('wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling');
182
+ add_action('wp_ajax_frm_change_styling', 'FrmStylesController::change_styling');
183
+ add_action('wp_ajax_frmpro_load_css', 'FrmStylesController::load_css');
184
+ add_action('wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css');
185
+
186
+ // XML Controller
187
+ add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
188
+ }
189
+
190
+ public function load_form_hooks() {
191
+ // Fields Controller
192
+ add_filter('frm_field_type', 'FrmFieldsController::change_type');
193
+ add_action('frm_field_input_html', 'FrmFieldsController::input_html');
194
+ add_filter('frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3);
195
+ add_filter('frm_field_label_seen', 'FrmFieldsController::check_label');
196
+
197
+ // Styles Controller
198
+ add_filter('frm_use_important_width', 'FrmStylesController::important_style', 10, 2 );
199
+ }
200
+
201
+ public function load_view_hooks() {
202
+ // Hooks go here when a view is loaded
203
+ }
204
+
205
+ public function load_multisite_hooks() {
206
+ // drop tables when mu site is deleted
207
+ add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' );
208
+ }
209
+ }
classes/controllers/FrmSettingsController.php CHANGED
@@ -1,59 +1,42 @@
1
  <?php
2
- /**
3
- * @package Formidable
4
- */
5
-
6
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
7
-
8
- if(class_exists('FrmSettingsController'))
9
- return;
10
 
11
  class FrmSettingsController{
12
- public static function load_hooks(){
13
- add_action('admin_menu', 'FrmSettingsController::menu', 45);
14
- add_action('frm_before_settings', 'FrmSettingsController::license_box');
15
- }
16
 
17
  public static function menu(){
18
  add_submenu_page('formidable', 'Formidable | '. __('Global Settings', 'formidable'), __('Global Settings', 'formidable'), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route');
19
  }
20
-
21
  public static function license_box(){
22
  $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
23
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/license_box.php');
24
  }
25
 
26
  public static function display_form($errors=array(), $message=''){
27
- global $frm_settings, $frm_vars;
28
-
 
29
  $frm_roles = FrmAppHelper::frm_capabilities();
30
-
31
  $uploads = wp_upload_dir();
32
  $target_path = $uploads['basedir'] . '/formidable/css';
33
- $sections = apply_filters('frm_add_settings_section', array(
34
- 'styling' => array('name' => __('Form Styling', 'formidable'), 'class' => 'FrmSettingsController', 'function' => 'styling_tab')
35
- ));
36
-
37
- $recaptcha_themes = array(
38
- 'red' => __('Red', 'formidable'),
39
- 'white' => __('White', 'formidable'),
40
- 'blackglass' => __('Black Glass', 'formidable'),
41
- 'clean' => __('Clean', 'formidable'),
42
- //'custom' => __('Custom', 'formidable'),
43
- );
44
-
45
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/form.php');
46
  }
47
 
48
- public static function process_form($stop_load=false){
49
- global $frm_settings, $frm_vars;
50
-
 
 
51
  if(!isset($_POST['process_form']) or !wp_verify_nonce($_POST['process_form'], 'process_form_nonce'))
52
  wp_die($frm_settings->admin_permission);
53
-
54
  $errors = array();
55
  $message = '';
56
-
57
  if(!isset($frm_vars['settings_routed']) or !$frm_vars['settings_routed']){
58
  //$errors = $frm_settings->validate($_POST,array());
59
  $frm_settings->update(stripslashes_deep($_POST));
@@ -65,19 +48,15 @@ class FrmSettingsController{
65
  }else{
66
  $message = __('Settings Saved', 'formidable');
67
  }
68
-
69
  if($stop_load == 'stop_load'){
70
  $frm_vars['settings_routed'] = true;
71
  return;
72
  }
73
-
74
  self::display_form($errors, $message);
75
  }
76
-
77
- public static function styling_tab(){
78
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/styling_tab.php');
79
- }
80
-
81
  public static function route($stop_load=false){
82
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
83
  $action = FrmAppHelper::get_param($action);
1
  <?php
 
 
 
 
 
 
 
 
2
 
3
  class FrmSettingsController{
 
 
 
 
4
 
5
  public static function menu(){
6
  add_submenu_page('formidable', 'Formidable | '. __('Global Settings', 'formidable'), __('Global Settings', 'formidable'), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route');
7
  }
8
+
9
  public static function license_box(){
10
  $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
11
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/license_box.php');
12
  }
13
 
14
  public static function display_form($errors=array(), $message=''){
15
+ global $frm_vars;
16
+
17
+ $frm_settings = FrmAppHelper::get_settings();
18
  $frm_roles = FrmAppHelper::frm_capabilities();
19
+
20
  $uploads = wp_upload_dir();
21
  $target_path = $uploads['basedir'] . '/formidable/css';
22
+ $sections = apply_filters('frm_add_settings_section', array());
23
+
24
+ $captcha_lang = FrmAppHelper::locales('captcha');
25
+
 
 
 
 
 
 
 
 
26
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-settings/form.php');
27
  }
28
 
29
+ public static function process_form($stop_load=false){
30
+ global $frm_vars;
31
+
32
+ $frm_settings = FrmAppHelper::get_settings();
33
+
34
  if(!isset($_POST['process_form']) or !wp_verify_nonce($_POST['process_form'], 'process_form_nonce'))
35
  wp_die($frm_settings->admin_permission);
36
+
37
  $errors = array();
38
  $message = '';
39
+
40
  if(!isset($frm_vars['settings_routed']) or !$frm_vars['settings_routed']){
41
  //$errors = $frm_settings->validate($_POST,array());
42
  $frm_settings->update(stripslashes_deep($_POST));
48
  }else{
49
  $message = __('Settings Saved', 'formidable');
50
  }
51
+
52
  if($stop_load == 'stop_load'){
53
  $frm_vars['settings_routed'] = true;
54
  return;
55
  }
56
+
57
  self::display_form($errors, $message);
58
  }
59
+
 
 
 
 
60
  public static function route($stop_load=false){
61
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
62
  $action = FrmAppHelper::get_param($action);
classes/controllers/FrmStatisticsController.php CHANGED
@@ -1,29 +1,17 @@
1
  <?php
2
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
-
4
- if(class_exists('FrmStatisticsController'))
5
- return;
6
 
7
  class FrmStatisticsController{
8
- public static function load_hooks(){
9
- add_action('admin_menu', 'FrmStatisticsController::menu', 24);
10
- }
11
-
12
  public static function menu(){
13
- global $frm_vars;
14
- if($frm_vars['pro_is_installed'])
15
- return;
16
-
17
  add_submenu_page('formidable', 'Formidable | '. __('Views', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Views', 'formidable') .'</span>', 'administrator', 'formidable-entry-templates', 'FrmStatisticsController::list_displays');
18
-
19
- add_submenu_page('formidable', 'Formidable | '. __('Reports', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Reports', 'formidable') .'</span>', 'administrator', 'formidable-reports', 'FrmStatisticsController::list_reports');
20
  }
21
-
22
  public static function list_reports(){
 
23
  $form = FrmAppHelper::get_param('form', false);
24
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list.php');
25
  }
26
-
27
  public static function list_displays(){
28
  $form = FrmAppHelper::get_param('form', false);
29
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list_displays.php');
1
  <?php
 
 
 
 
2
 
3
  class FrmStatisticsController{
4
+
 
 
 
5
  public static function menu(){
 
 
 
 
6
  add_submenu_page('formidable', 'Formidable | '. __('Views', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Views', 'formidable') .'</span>', 'administrator', 'formidable-entry-templates', 'FrmStatisticsController::list_displays');
 
 
7
  }
8
+
9
  public static function list_reports(){
10
+ add_filter('frm_form_stop_action_reports', '__return_true');
11
  $form = FrmAppHelper::get_param('form', false);
12
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list.php');
13
  }
14
+
15
  public static function list_displays(){
16
  $form = FrmAppHelper::get_param('form', false);
17
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-statistics/list_displays.php');
classes/controllers/FrmStylesController.php ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmStylesController{
4
+ public static $post_type = 'frm_styles';
5
+ public static $screen = 'formidable_page_formidable-styles';
6
+
7
+ public static function load_pro_hooks() {
8
+ if ( FrmAppHelper::pro_is_installed() ) {
9
+ FrmProStylesController::load_pro_hooks();
10
+ }
11
+ }
12
+
13
+ public static function register_post_types() {
14
+ register_post_type(self::$post_type, array(
15
+ 'label' => __('Styles', 'formidable'),
16
+ 'public' => false,
17
+ 'show_ui' => false,
18
+ 'capability_type' => 'page',
19
+ 'supports' => array(
20
+ 'title',
21
+ ),
22
+ 'has_archive' => false,
23
+ 'labels' => array(
24
+ 'name' => __('Styles', 'formidable'),
25
+ 'singular_name' => __('Style', 'formidable'),
26
+ 'menu_name' => __('Style', 'formidable'),
27
+ 'edit' => __('Edit'),
28
+ 'add_new_item' => __('Create a New Style', 'formidable'),
29
+ 'edit_item' => __('Edit Style', 'formidable')
30
+ )
31
+ ) );
32
+ }
33
+
34
+ public static function menu(){
35
+ add_submenu_page('formidable', 'Formidable | '. __('Styles', 'formidable'), __('Styles', 'formidable'), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route');
36
+ }
37
+
38
+ public static function admin_init() {
39
+ if ( ! FrmAppHelper::is_admin_page('formidable-styles') ) {
40
+ return;
41
+ }
42
+
43
+ self::load_pro_hooks();
44
+ wp_enqueue_script('jquery-ui-datepicker');
45
+ add_action('admin_head', 'FrmStylesController::head');
46
+ }
47
+
48
+ public static function head() {
49
+ wp_enqueue_script('jquery-frm-themepicker');
50
+
51
+ $style = apply_filters('frm_style_head', false);
52
+ ?>
53
+ <link type="text/css" rel="stylesheet" href="<?php echo FrmAppHelper::jquery_ui_base_url() ?>/themes/base/ui.all.css" />
54
+ <link href="<?php echo admin_url('admin-ajax.php') ?>?action=frmpro_css" type="text/css" rel="Stylesheet" class="frm-custom-theme"/>
55
+ <?php if ($style) { ?>
56
+ <link href="<?php echo admin_url('admin-ajax.php') ?>?action=frmpro_load_css&flat=1&<?php echo http_build_query($style->post_content); ?>" type="text/css" rel="Stylesheet" class="frm-single-custom-theme"/>
57
+ <?php }
58
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/head.php');
59
+ }
60
+
61
+ public static function new_style($return = '') {
62
+ FrmAppHelper::update_message( __('create multiple styling templates', 'formidable'), 'wrap' );
63
+ self::load_styler('default');
64
+ }
65
+
66
+ public static function edit($style_id = false, $message = '') {
67
+ if ( ! $style_id ) {
68
+ $style_id = FrmAppHelper::get_param('id');
69
+ if ( empty($style_id) ) {
70
+ $style_id = 'default';
71
+ }
72
+ }
73
+
74
+ if ( 'default' == $style_id ) {
75
+ $style = 'default';
76
+ } else {
77
+ $frm_style = new FrmStyle($style_id);
78
+ $style = $frm_style->get_one();
79
+ $style = $style->ID;
80
+ }
81
+
82
+ self::load_styler($style, $message);
83
+ }
84
+
85
+ public static function save() {
86
+ $frm_style = new FrmStyle();
87
+ $message = '';
88
+ $post_id = ( $_POST && isset($_POST['ID']) ) ? $_POST['ID'] : false;
89
+ if ( $post_id !== false && isset($_POST['frm_style']) && wp_verify_nonce($_POST['frm_style'], 'frm_style_nonce') ) {
90
+ $id = $frm_style->update($post_id);
91
+ if ( empty($post_id) && ! empty($id) ) {
92
+ // set the post id to the new style so it will be loaded for editing
93
+ $post_id = reset($id);
94
+ }
95
+ $message = __('Your styling settings have been saved.', 'formidable');
96
+ }
97
+
98
+ return self::edit($post_id, $message);
99
+ }
100
+
101
+ public static function load_styler($style, $message = '') {
102
+ global $frm_settings;
103
+
104
+ $frm_style = new FrmStyle();
105
+ $styles = $frm_style->get_all();
106
+
107
+ if ( is_numeric($style) ) {
108
+ $style = $styles[$style];
109
+ } else if ( 'default' == $style ) {
110
+ $style = $frm_style->get_default_style($styles);
111
+ }
112
+
113
+ self::add_meta_boxes();
114
+
115
+ include(FrmAppHelper::plugin_path() .'/classes/views/styles/show.php');
116
+ }
117
+
118
+ private static function manage($message = '', $forms = array()) {
119
+ $frm_style = new FrmStyle();
120
+ $styles = $frm_style->get_all();
121
+ $default_style = $frm_style->get_default_style($styles);
122
+
123
+ if ( empty($forms) ) {
124
+ $forms = FrmForm::getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')");
125
+ }
126
+
127
+ include(FrmAppHelper::plugin_path() .'/classes/views/styles/manage.php');
128
+ }
129
+
130
+ private static function manage_styles() {
131
+ if ( ! $_POST || ! isset($_POST['style']) || ! isset($_POST['frm_manage_style']) || ! wp_verify_nonce($_POST['frm_manage_style'], 'frm_manage_style_nonce') ) {
132
+ return self::manage();
133
+ }
134
+
135
+ global $wpdb;
136
+
137
+ $forms = FrmForm::getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')");
138
+
139
+ foreach ( $forms as $form ) {
140
+ if ( $_POST['style'][$form->id] == $_POST['prev_style'][$form->id] ) {
141
+ continue;
142
+ }
143
+
144
+ $form->options['custom_style'] = $_POST['style'][$form->id];
145
+
146
+ $wpdb->update($wpdb->prefix .'frm_forms', array('options' => maybe_serialize($form->options)), array('id' => $form->id));
147
+ unset($form);
148
+ }
149
+
150
+ $message = __('Your form styles have been saved.', 'formidable');
151
+ return self::manage($message, $forms);
152
+ }
153
+
154
+ public static function custom_css($message = '', $style=null) {
155
+ wp_enqueue_style('codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css');
156
+ wp_enqueue_script('codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7');
157
+ wp_enqueue_script('codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array('codemirror'), '4.7');
158
+
159
+ if ( ! isset($style) ) {
160
+ $frm_style = new FrmStyle();
161
+ $style = $frm_style->get_default_style();
162
+ }
163
+
164
+ include(FrmAppHelper::plugin_path() .'/classes/views/styles/custom_css.php');
165
+ }
166
+
167
+ public static function save_css() {
168
+ $frm_style = new FrmStyle();
169
+
170
+ $message = '';
171
+ $post_id = ( $_POST && isset($_POST['ID']) ) ? $_POST['ID'] : false;
172
+ if ( isset($_POST['frm_custom_css']) && wp_verify_nonce($_POST['frm_custom_css'], 'frm_custom_css_nonce') ) {
173
+ $frm_style->update($post_id);
174
+ $message = __('Your styling settings have been saved.', 'formidable');
175
+ }
176
+
177
+ return self::custom_css($message);
178
+ }
179
+
180
+ public static function route() {
181
+ $action = FrmAppHelper::get_param('frm_action');
182
+
183
+ switch ( $action ) {
184
+ case 'edit':
185
+ case 'save':
186
+ case 'manage':
187
+ case 'manage_styles':
188
+ case 'custom_css':
189
+ case 'save_css':
190
+ return self::$action();
191
+ default:
192
+ do_action('frm_style_action_route', $action);
193
+ if ( apply_filters('frm_style_stop_action_route', false, $action) ) {
194
+ return;
195
+ }
196
+
197
+ if ( 'new_style' == $action ) {
198
+ return self::$action();
199
+ }
200
+
201
+ return self::edit();
202
+ }
203
+ }
204
+
205
+ public static function reset_styling() {
206
+ $frm_style = new FrmStyle();
207
+ $defaults = $frm_style->get_defaults();
208
+
209
+ echo json_encode($defaults);
210
+ die();
211
+ }
212
+
213
+ public static function change_styling() {
214
+ $frm_style = new FrmStyle();
215
+ $defaults = $frm_style->get_defaults();
216
+
217
+ // remove the # from the colors
218
+ foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) {
219
+ if ( ! is_array($v) && strpos($v, '#') === 0 ) {
220
+ $_GET['frm_style_setting']['post_content'][$k] = str_replace('#', '', $v);
221
+ }
222
+ }
223
+
224
+ echo '<style type="text/css">';
225
+ include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php');
226
+ echo '</style>';
227
+ die();
228
+ }
229
+
230
+ private static function add_meta_boxes() {
231
+
232
+ // setup meta boxes
233
+ $meta_boxes = array(
234
+ 'general' => __('General', 'formidable'),
235
+ 'field-labels' => __('Field Labels', 'formidable'),
236
+ 'field-description' => __('Field Description', 'formidable'),
237
+ 'field-colors' => __('Field Colors', 'formidable'),
238
+ 'field-sizes' => __('Field Settings', 'formidable'),
239
+ 'check-box-radio-fields' => __('Check Box & Radio Fields', 'formidable'),
240
+ 'section-fields' => __('Section Fields', 'formidable'),
241
+ 'date-fields' => __('Date Fields', 'formidable'),
242
+ 'buttons' => __('Buttons', 'formidable'),
243
+ 'form-messages' => __('Form Messages', 'formidable'),
244
+ );
245
+
246
+ foreach ( $meta_boxes as $nicename => $name ) {
247
+ add_meta_box( $nicename .'-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename );
248
+ unset($nicename, $name);
249
+ }
250
+ }
251
+
252
+ public static function include_style_section($atts, $sec) {
253
+ extract($atts);
254
+ $current_tab = isset($_GET['page-tab']) ? $_GET['page-tab'] : 'default';
255
+ include(FrmAppHelper::plugin_path() .'/classes/views/styles/_'. $sec['args'] .'.php');
256
+ }
257
+
258
+ public static function load_css(){
259
+ header('Content-type: text/css');
260
+
261
+ $frm_style = new FrmStyle();
262
+ $defaults = $frm_style->get_defaults();
263
+
264
+ include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php');
265
+ die();
266
+ }
267
+
268
+ // Get the stylesheets for the form settings page
269
+ public static function get_style_opts() {
270
+ $frm_style = new FrmStyle();
271
+ $styles = $frm_style->get_all();
272
+
273
+ return $styles;
274
+ }
275
+
276
+ public static function get_form_style($form = 'default') {
277
+ $style = FrmFormsHelper::get_form_style($form);
278
+
279
+ if ( empty($style) || 1 == $style ) {
280
+ $style = 'default';
281
+ }
282
+
283
+ $frm_style = new FrmStyle($style);
284
+ return $frm_style->get_one();
285
+ }
286
+
287
+ public static function get_form_style_class($class, $style) {
288
+ if ( 1 == $style ) {
289
+ $style = 'default';
290
+ }
291
+
292
+ $frm_style = new FrmStyle($style);
293
+ $style = $frm_style->get_one();
294
+
295
+ if ( $style ) {
296
+ $class .= ' frm_style_'. $style->post_name;
297
+ }
298
+
299
+ return $class;
300
+ }
301
+
302
+ public static function get_style_val($val, $form = 'default') {
303
+ $style = self::get_form_style($form);
304
+ if ( $style && isset($style->post_content[$val]) ) {
305
+ return $style->post_content[$val];
306
+ }
307
+ }
308
+
309
+ public static function show_entry_styles($default_styles) {
310
+ $frm_style = new FrmStyle('default');
311
+ $style = $frm_style->get_one();
312
+
313
+ if ( ! $style ) {
314
+ return $default_styles;
315
+ }
316
+
317
+ foreach ( $default_styles as $name => $val ) {
318
+ $setting = $name;
319
+ if ( 'border_width' == $name ) {
320
+ $setting = 'field_border_width';
321
+ } else if ( 'alt_bg_color' == $name ) {
322
+ $setting = 'bg_color_active';
323
+ }
324
+ $default_styles[$name] = $style->post_content[$setting];
325
+ unset($name, $val);
326
+ }
327
+
328
+ return $default_styles;
329
+ }
330
+
331
+ public static function &important_style($important, $field) {
332
+ $important = self::get_style_val('important_style', $field['form_id']);
333
+ return $important;
334
+ }
335
+
336
+ /*
337
+ * Fallback for WP < 3.6
338
+ */
339
+ public static function do_accordion_sections( $screen, $context, $object ) {
340
+ if ( function_exists('do_accordion_sections') ) {
341
+ return do_accordion_sections( $screen, $context, $object );
342
+ }
343
+
344
+ global $wp_meta_boxes;
345
+
346
+ $screen = 'formidable_page_formidable-styles';
347
+ $screen = convert_to_screen( $screen );
348
+
349
+ $page = $screen->id;
350
+
351
+ $hidden = get_hidden_meta_boxes( $screen );
352
+ ?>
353
+ <div id="side-sortables" class="accordion-container">
354
+ <?php
355
+ $i = 0;
356
+ $first_open = false;
357
+ do {
358
+ if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
359
+ break;
360
+
361
+ foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
362
+ if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
363
+ foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
364
+ if ( false == $box || ! $box['title'] )
365
+ continue;
366
+ $i++;
367
+ $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
368
+
369
+
370
+ if ( ! $first_open && empty( $hidden_class ) ) {
371
+ $first_open = true;
372
+ }
373
+
374
+ ?>
375
+ <div class="postbox <?php echo esc_attr( $box['id'] ); ?>" >
376
+ <div class="handlediv" title="Click to toggle"><br /></div>
377
+ <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
378
+ <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
379
+ <div class="inside">
380
+ <?php call_user_func( $box['callback'], $object, $box ); ?>
381
+ </div><!-- .inside -->
382
+ </div><!-- .accordion-section-content -->
383
+ </div><!-- .postbox -->
384
+ <?php
385
+ }
386
+ }
387
+ }
388
+ } while(0);
389
+ ?>
390
+ </div><!-- .accordion-container -->
391
+ <?php
392
+ return $i;
393
+ }
394
+ }
395
+
classes/controllers/FrmXMLController.php CHANGED
@@ -1,44 +1,39 @@
1
  <?php
2
- if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
 
4
  class FrmXMLController{
5
- public static function load_hooks(){
6
- add_action('admin_menu', 'FrmXMLController::menu', 41);
7
- add_action('wp_ajax_frm_export_xml', 'FrmXMLController::export_xml');
8
- }
9
-
10
  public static function menu() {
11
  add_submenu_page('formidable', 'Formidable | Import/Export', 'Import/Export', 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route');
12
  }
13
-
14
  public static function add_default_templates() {
15
  if ( !function_exists( 'libxml_disable_entity_loader' ) ){
16
  // XML import is not enabled on your server
17
  return;
18
  }
19
-
20
- include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
21
-
22
  $set_err = libxml_use_internal_errors(true);
23
  $loader = libxml_disable_entity_loader( true );
24
-
25
  $files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
26
-
27
- foreach ( (array) $files as $file) {
28
- $result = FrmXMLHelper::import_xml($file);
29
  unset($file);
30
  }
 
31
  if(is_wp_error($result))
32
  $errors[] = $result->get_error_message();
33
  else if($result)
34
  $message = $result;
35
-
 
36
  unset($files);
37
-
38
  libxml_use_internal_errors( $set_err );
39
  libxml_disable_entity_loader( $loader );
40
  }
41
-
42
  public static function route() {
43
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
44
  $action = FrmAppHelper::get_param($action);
@@ -52,53 +47,60 @@ class FrmXMLController{
52
  }
53
  }
54
  }
55
-
56
  public static function form($errors = array(), $message = '') {
57
- //wp_enqueue_script('jquery-chosen');
58
- //wp_enqueue_style('formidable');
59
-
60
- $frm_form = new FrmForm();
61
- $forms = $frm_form->getAll("status is NULL OR status = '' OR status = 'published'", ' ORDER BY name');
62
- unset($frm_form);
63
-
64
- $export_types = apply_filters('frm_xml_export_types',
65
  array('forms' => __('Forms', 'formidable'))
66
  );
67
-
68
- $export_format = apply_filters('frm_export_formats', array(
69
  'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
70
  ));
71
-
72
- global $frmpro_settings;
73
- $csv_format = $frmpro_settings ? $frmpro_settings->csv_format : 'UTF-8';
74
-
 
 
 
 
75
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php');
76
  }
77
-
78
  public static function import_xml() {
79
  $errors = array();
80
  $message = '';
81
- if ( !isset($_FILES) || !isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int)$_FILES['frm_import_file']['size'] < 1) {
 
 
 
 
 
 
 
 
82
  $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
83
  self::form($errors);
84
  return;
85
  }
86
-
87
  $file = $_FILES['frm_import_file']['tmp_name'];
88
-
89
  if ( !is_uploaded_file($file) ) {
90
  unset($file);
91
  $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
92
  self::form($errors);
93
  return;
94
  }
95
-
96
  //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
97
-
98
- $export_format = apply_filters('frm_export_formats', array(
99
  'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
100
  ));
101
-
102
  $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
103
  if ( $file_type != 'xml' && isset($export_format[$file_type]) ) {
104
  // allow other file types to be imported
@@ -106,207 +108,179 @@ class FrmXMLController{
106
  return;
107
  }
108
  unset($file_type);
109
-
110
  //$media_id = FrmProAppHelper::upload_file('frm_import_file');
111
  //if(is_numeric($media_id)){
112
-
113
  if ( !function_exists( 'libxml_disable_entity_loader' ) ) {
114
  $errors[] = __('XML import is not enabled on your server.', 'formidable');
115
  self::form($errors);
116
  return;
117
  }
118
-
119
- include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
120
-
121
  $set_err = libxml_use_internal_errors(true);
122
  $loader = libxml_disable_entity_loader( true );
123
-
124
  $result = FrmXMLHelper::import_xml($file);
125
- if ( is_wp_error($result) ) {
126
- $errors[] = $result->get_error_message();
127
- } else if ( $result ) {
128
- if ( is_array($result) ) {
129
- $t_strings = array(
130
- 'imported' => __('Imported', 'formidable'),
131
- 'updated' => __('Updated', 'formidable'),
132
- );
133
-
134
- $message = '<ul>';
135
- foreach ( $result as $type => $results ) {
136
- if ( !isset($t_strings[$type]) ) {
137
- // only print imported and updated
138
- continue;
139
- }
140
-
141
- $s_message = array();
142
- foreach ( $results as $k => $m ) {
143
- if ( $m ) {
144
- $strings = array(
145
- 'forms' => sprintf(_n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
146
- 'fields' => sprintf(_n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m),
147
- 'items' => sprintf(_n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m),
148
- 'views' => sprintf(_n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m),
149
- 'posts' => sprintf(_n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m),
150
- 'terms' => sprintf(_n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m),
151
- );
152
-
153
- $s_message[] = isset($strings[$k]) ? $strings[$k] : $t_strings[$type] .' '. $m .' '. ucfirst($k);
154
- }
155
- unset($k);
156
- unset($m);
157
- }
158
-
159
- if ( !empty($s_message) ) {
160
- $message .= '<li><strong>'. $t_strings[$type] .':</strong> ';
161
- $message .= implode(', ', $s_message);
162
- $message .= '</li>';
163
- }
164
-
165
- }
166
-
167
- if ( $message == '<ul>' ) {
168
- $message = '';
169
- $errors[] = __('Nothing was imported or updated', 'formidable');
170
- } else {
171
- $message .= '</ul>';
172
- }
173
- } else {
174
- $message = $result;
175
- }
176
- }
177
-
178
  unset($file);
179
-
180
  libxml_use_internal_errors( $set_err );
181
  libxml_disable_entity_loader( $loader );
182
  //}else{
183
  // foreach ($media_id->errors as $error)
184
  // echo $error[0];
185
  //}
186
-
187
  self::form($errors, $message);
188
  }
189
-
190
  public static function export_xml() {
191
- if ( !current_user_can('frm_edit_forms') ) {
192
- global $frm_settings;
193
- echo $frm_settings->admin_permission;
194
- die();
195
- }
196
-
197
- if (isset($_POST['frm_export_forms'])) {
198
  $ids = $_POST['frm_export_forms'];
199
- } else {
200
- $ids = array();
201
  }
202
-
203
- if ( isset($_POST['type']) ){
 
204
  $type = $_POST['type'];
205
  }
206
-
207
  $format = isset($_POST['format']) ? $_POST['format'] : 'xml';
208
-
209
- if ( !headers_sent() && (!isset($type) || !$type) ) {
210
  wp_redirect(admin_url('admin.php?page=formidable-import'));
211
  die();
212
  }
213
-
214
  if ( $format == 'xml' ) {
215
  self::generate_xml($type, compact('ids'));
216
  } else {
217
  do_action('frm_export_format_'. $format, compact('ids'));
218
  }
219
-
220
- die();
221
- }
222
-
223
- public static function export_xml_direct($controller = 'forms', $ids = false) {
224
- if ( !current_user_can('frm_edit_forms') ) {
225
- global $frm_settings;
226
- wp_die($frm_settings->admin_permission);
227
- }
228
- $is_template = FrmAppHelper::get_param('is_template', false);
229
- self::generate_xml($controller, compact('ids', 'is_template'));
230
  die();
231
  }
232
-
233
  public static function generate_xml($type, $args = array() ) {
234
  global $wpdb;
235
-
236
- $type = (array)$type;
 
 
 
 
 
 
 
 
 
 
237
  $tables = array(
238
- 'items' => $wpdb->prefix .'frm_items',
239
- 'forms' => $wpdb->prefix .'frm_forms',
240
- 'views' => $wpdb->posts
 
 
241
  );
242
-
243
  $defaults = array('ids' => false);
244
  $args = wp_parse_args( $args, $defaults );
245
-
246
  $sitename = sanitize_key( get_bloginfo( 'name' ) );
247
-
248
  if ( ! empty($sitename) ) $sitename .= '.';
249
  $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
250
 
251
  header( 'Content-Description: File Transfer' );
252
  header( 'Content-Disposition: attachment; filename=' . $filename );
253
  header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
254
-
255
  //make sure ids are numeric
256
- if(is_array($args['ids']) && !empty($args['ids']))
257
  $args['ids'] = implode(',', array_filter( $args['ids'], 'is_numeric' ));
258
-
 
259
  $records = array();
260
-
261
  foreach($type as $tb_type){
262
  $where = $join = '';
263
  $table = $tables[$tb_type];
264
-
265
- $select = "$table.id";
266
-
267
- if($tb_type == 'forms'){
268
- //add forms
269
- $where = $wpdb->prepare( "$table.status != %s" , 'draft' );
270
- if ( $args['ids'] )
271
- $where .= " AND $table.id IN (". $args['ids'] .")";
272
-
273
- } else if($tb_type == 'items') {
274
- //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
275
- if ( $args['ids'] ) {
276
- $where = "$table.form_id IN (". $args['ids'] .")";
277
- }
278
- } else {
279
- $select = "$table.ID";
280
- $join = "INNER JOIN $wpdb->postmeta pm ON (pm.post_id=$table.ID)";
281
- $where = "pm.meta_key='frm_form_id' AND pm.meta_value ";
282
- if ( empty($args['ids']) ) {
283
- $where .= "> 0";
284
- } else {
285
- $where .= "IN (". $args['ids'] .")";
286
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  }
288
 
289
- if(!empty($where))
290
- $where = "WHERE ". $where;
291
-
292
  $records[$tb_type] = $wpdb->get_col( "SELECT $select FROM $table $join $where" );
293
  unset($tb_type);
294
  }
295
-
296
- include_once(FrmAppHelper::plugin_path() .'/classes/helpers/FrmXMLHelper.php');
297
 
298
- $frm_field = new FrmField();
299
-
300
  echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
301
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
302
  }
303
-
304
  function allow_mime($mimes) {
305
  if ( !isset($mimes['csv']) ) {
306
  // allow csv files
307
  $mimes['csv'] = 'text/csv';
308
  }
309
-
310
  if ( !isset($mimes['xml']) ) {
311
  // allow xml
312
  $mimes['xml'] = 'text/xml';
@@ -314,5 +288,5 @@ class FrmXMLController{
314
 
315
  return $mimes;
316
  }
317
-
318
  }
1
  <?php
 
2
 
3
  class FrmXMLController{
4
+
 
 
 
 
5
  public static function menu() {
6
  add_submenu_page('formidable', 'Formidable | Import/Export', 'Import/Export', 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route');
7
  }
8
+
9
  public static function add_default_templates() {
10
  if ( !function_exists( 'libxml_disable_entity_loader' ) ){
11
  // XML import is not enabled on your server
12
  return;
13
  }
14
+
 
 
15
  $set_err = libxml_use_internal_errors(true);
16
  $loader = libxml_disable_entity_loader( true );
17
+
18
  $files = apply_filters('frm_default_templates_files', array(FrmAppHelper::plugin_path() .'/classes/views/xml/default-templates.xml'));
19
+
20
+ foreach ( (array) $files as $file ) {
21
+ FrmXMLHelper::import_xml($file);
22
  unset($file);
23
  }
24
+ /*
25
  if(is_wp_error($result))
26
  $errors[] = $result->get_error_message();
27
  else if($result)
28
  $message = $result;
29
+ */
30
+
31
  unset($files);
32
+
33
  libxml_use_internal_errors( $set_err );
34
  libxml_disable_entity_loader( $loader );
35
  }
36
+
37
  public static function route() {
38
  $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
39
  $action = FrmAppHelper::get_param($action);
47
  }
48
  }
49
  }
50
+
51
  public static function form($errors = array(), $message = '') {
52
+ $forms = FrmForm::getAll("status is NULL OR status = '' OR status = 'published'", 'name');
53
+
54
+ $export_types = apply_filters('frm_xml_export_types',
 
 
 
 
 
55
  array('forms' => __('Forms', 'formidable'))
56
  );
57
+
58
+ $export_format = apply_filters('frm_export_formats', array(
59
  'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
60
  ));
61
+
62
+ if ( FrmAppHelper::pro_is_installed() ) {
63
+ $frmpro_settings = new FrmProSettings();
64
+ $csv_format = $frmpro_settings->csv_format;
65
+ } else {
66
+ $csv_format = 'UTF-8';
67
+ }
68
+
69
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php');
70
  }
71
+
72
  public static function import_xml() {
73
  $errors = array();
74
  $message = '';
75
+
76
+ if ( !current_user_can('frm_edit_forms') || ! isset($_POST['import-xml']) || ! wp_verify_nonce($_POST['import-xml'], 'import-xml-nonce') ) {
77
+ $frm_settings = FrmAppHelper::get_settings();
78
+ $errors[] = $frm_settings->admin_permission;
79
+ self::form($errors);
80
+ return;
81
+ }
82
+
83
+ if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) {
84
  $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
85
  self::form($errors);
86
  return;
87
  }
88
+
89
  $file = $_FILES['frm_import_file']['tmp_name'];
90
+
91
  if ( !is_uploaded_file($file) ) {
92
  unset($file);
93
  $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
94
  self::form($errors);
95
  return;
96
  }
97
+
98
  //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
99
+
100
+ $export_format = apply_filters('frm_export_formats', array(
101
  'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple'),
102
  ));
103
+
104
  $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
105
  if ( $file_type != 'xml' && isset($export_format[$file_type]) ) {
106
  // allow other file types to be imported
108
  return;
109
  }
110
  unset($file_type);
111
+
112
  //$media_id = FrmProAppHelper::upload_file('frm_import_file');
113
  //if(is_numeric($media_id)){
114
+
115
  if ( !function_exists( 'libxml_disable_entity_loader' ) ) {
116
  $errors[] = __('XML import is not enabled on your server.', 'formidable');
117
  self::form($errors);
118
  return;
119
  }
120
+
 
 
121
  $set_err = libxml_use_internal_errors(true);
122
  $loader = libxml_disable_entity_loader( true );
123
+
124
  $result = FrmXMLHelper::import_xml($file);
125
+ FrmXMLHelper::parse_message($result, $message, $errors);
126
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  unset($file);
128
+
129
  libxml_use_internal_errors( $set_err );
130
  libxml_disable_entity_loader( $loader );
131
  //}else{
132
  // foreach ($media_id->errors as $error)
133
  // echo $error[0];
134
  //}
135
+
136
  self::form($errors, $message);
137
  }
138
+
139
  public static function export_xml() {
140
+ FrmAppHelper::ajax_permission_check('frm_edit_forms', 'show');
141
+
142
+ $ids = array();
143
+ if ( isset($_POST['frm_export_forms']) ) {
 
 
 
144
  $ids = $_POST['frm_export_forms'];
 
 
145
  }
146
+
147
+ $type = false;
148
+ if ( isset($_POST['type']) ) {
149
  $type = $_POST['type'];
150
  }
151
+
152
  $format = isset($_POST['format']) ? $_POST['format'] : 'xml';
153
+
154
+ if ( ! headers_sent() && ! $type ) {
155
  wp_redirect(admin_url('admin.php?page=formidable-import'));
156
  die();
157
  }
158
+
159
  if ( $format == 'xml' ) {
160
  self::generate_xml($type, compact('ids'));
161
  } else {
162
  do_action('frm_export_format_'. $format, compact('ids'));
163
  }
164
+
 
 
 
 
 
 
 
 
 
 
165
  die();
166
  }
167
+
168
  public static function generate_xml($type, $args = array() ) {
169
  global $wpdb;
170
+
171
+ $type = (array) $type;
172
+ if ( in_array('items', $type) && ! in_array('forms', $type) ) {
173
+ // make sure the form is included if there are entries
174
+ $type[] = 'forms';
175
+ }
176
+
177
+ if ( in_array('forms', $type) ) {
178
+ // include actions with forms
179
+ $type[] = 'actions';
180
+ }
181
+
182
  $tables = array(
183
+ 'items' => $wpdb->prefix .'frm_items',
184
+ 'forms' => $wpdb->prefix .'frm_forms',
185
+ 'posts' => $wpdb->posts,
186
+ 'styles' => $wpdb->posts,
187
+ 'actions' => $wpdb->posts,
188
  );
189
+
190
  $defaults = array('ids' => false);
191
  $args = wp_parse_args( $args, $defaults );
192
+
193
  $sitename = sanitize_key( get_bloginfo( 'name' ) );
194
+
195
  if ( ! empty($sitename) ) $sitename .= '.';
196
  $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
197
 
198
  header( 'Content-Description: File Transfer' );
199
  header( 'Content-Disposition: attachment; filename=' . $filename );
200
  header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
201
+
202
  //make sure ids are numeric
203
+ if ( is_array($args['ids']) && !empty($args['ids']) ) {
204
  $args['ids'] = implode(',', array_filter( $args['ids'], 'is_numeric' ));
205
+ }
206
+
207
  $records = array();
208
+
209
  foreach($type as $tb_type){
210
  $where = $join = '';
211
  $table = $tables[$tb_type];
212
+
213
+ $select = $table .'.id';
214
+
215
+ switch ( $tb_type ) {
216
+ case 'forms':
217
+ //add forms
218
+ if ( $args['ids'] ){
219
+ $where = ' ('. $table .'.id IN ('. $args['ids'] .') OR '. $table .'.parent_form_id IN ('. $args['ids'] .'))';
220
+ } else {
221
+ $where = $wpdb->prepare( $table .'.status != %s', 'draft' );
222
+ }
223
+ break;
224
+ case 'actions':
225
+ $select = $table .'.ID';
226
+ $where = $wpdb->prepare('post_type=%s', FrmFormActionsController::$action_post_type);
227
+ if ( ! empty($args['ids']) ) {
228
+ $where .= ' AND menu_order IN ('. $args['ids'] .')';
229
+ }
230
+ break;
231
+ case 'items':
232
+ //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
233
+ if ( $args['ids'] ) {
234
+ $where = $table .'.form_id IN ('. $args['ids'] .')';
235
+ }
236
+ break;
237
+ case 'styles':
238
+ // Loop through all exported forms and get their selected style IDs
239
+ $form_ids = explode( ',', $args['ids'] );
240
+ $style_ids = array();
241
+ foreach ( $form_ids as $form_id ) {
242
+ $form_data = FrmForm::getOne( $form_id );
243
+ $style_ids[] = $form_data->options['custom_style'];
244
+ unset( $form_id, $form_data );
245
+ }
246
+ $select = $table .'.ID';
247
+ $where = $wpdb->prepare('post_type=%s', 'frm_styles');
248
+
249
+ // Only export selected styles
250
+ if ( ! empty( $style_ids ) ) {
251
+ $where .= ' AND ID IN ('. implode( ',', $style_ids ) .')';
252
+ }
253
+ break;
254
+ default:
255
+ $select = $table .'.ID';
256
+ $join = "INNER JOIN $wpdb->postmeta pm ON (pm.post_id=$table.ID)";
257
+ $where = "pm.meta_key='frm_form_id' AND pm.meta_value ";
258
+ if ( empty($args['ids']) ) {
259
+ $where .= '> 0';
260
+ } else {
261
+ $where .= 'IN ('. $args['ids'] .')';
262
+ }
263
+ break;
264
+ }
265
+
266
+ if ( ! empty($where) ) {
267
+ $where = 'WHERE '. $where;
268
  }
269
 
 
 
 
270
  $records[$tb_type] = $wpdb->get_col( "SELECT $select FROM $table $join $where" );
271
  unset($tb_type);
272
  }
 
 
273
 
 
 
274
  echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
275
  include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php');
276
  }
277
+
278
  function allow_mime($mimes) {
279
  if ( !isset($mimes['csv']) ) {
280
  // allow csv files
281
  $mimes['csv'] = 'text/csv';
282
  }
283
+
284
  if ( !isset($mimes['xml']) ) {
285
  // allow xml
286
  $mimes['xml'] = 'text/xml';
288
 
289
  return $mimes;
290
  }
291
+
292
  }
classes/helpers/FrmAppHelper.php CHANGED
@@ -1,62 +1,216 @@
1
  <?php
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
- if(class_exists('FrmAppHelper'))
5
- return;
6
-
7
  class FrmAppHelper{
8
- public static $db_version = 11; //version of the database we are moving to (skip 12)
9
- public static $pro_db_version = 25;
10
-
 
 
 
 
 
11
  /*
12
  * @since 1.07.02
13
  *
14
  * @param none
15
  * @return float The version of this plugin
16
  */
17
- public static function plugin_version(){
18
- $plugin_data = get_file_data( WP_PLUGIN_DIR .'/formidable/formidable.php', array('Version' => 'Version'), 'plugin' );
19
- return $plugin_data['Version'];
 
 
 
20
  }
21
-
22
  public static function plugin_path(){
23
  return dirname(dirname(dirname(__FILE__)));
24
  }
25
-
26
  public static function plugin_url($url=''){
27
  //prevously FRM_URL constant
28
- if(empty($url))
29
- $url = plugins_url('', 'formidable/formidable.php');
30
- if(is_ssl() and !preg_match('/^https:\/\/.*\..*$/', $url))
 
 
31
  $url = str_replace('http://', 'https://', $url);
32
-
 
33
  return $url;
34
  }
35
-
 
 
 
36
  public static function site_url(){
37
  $url = self::plugin_url(site_url());
38
  return $url;
39
  }
40
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  public static function get_param($param, $default='', $src='get'){
42
  if(strpos($param, '[')){
43
  $params = explode('[', $param);
44
- $param = $params[0];
45
  }
46
 
47
  if($src == 'get'){
48
  $value = (isset($_POST[$param]) ? stripslashes_deep($_POST[$param]) : (isset($_GET[$param]) ? stripslashes_deep($_GET[$param]) : $default));
49
- if(!isset($_POST[$param]) and isset($_GET[$param]) and !is_array($value))
50
  $value = stripslashes_deep(htmlspecialchars_decode(urldecode($_GET[$param])));
 
51
  }else{
52
  $value = isset($_POST[$param]) ? stripslashes_deep(maybe_unserialize($_POST[$param])) : $default;
53
  }
54
-
55
- if(isset($params) and is_array($value) and !empty($value)){
56
  foreach($params as $k => $p){
57
- if(!$k or !is_array($value))
58
  continue;
59
-
 
60
  $p = trim($p, ']');
61
  $value = (isset($value[$p])) ? $value[$p] : $default;
62
  }
@@ -64,11 +218,147 @@ class FrmAppHelper{
64
 
65
  return $value;
66
  }
67
-
68
  public static function get_post_param($param, $default=''){
69
  return isset($_POST[$param]) ? stripslashes_deep(maybe_unserialize($_POST[$param])) : $default;
70
  }
71
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /*
73
  * Check a value from a shortcode to see if true or false.
74
  * True when value is 1, true, 'true', 'yes'
@@ -81,80 +371,112 @@ class FrmAppHelper{
81
  public static function is_true($value) {
82
  return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
83
  }
84
-
 
 
 
 
 
 
 
85
  public static function load_scripts($scripts){
 
86
  foreach ( (array) $scripts as $s ) {
87
  wp_enqueue_script($s);
88
  }
89
  }
90
-
91
  public static function load_styles($styles){
 
92
  foreach ( (array) $styles as $s ) {
93
  wp_enqueue_style($s);
94
  }
95
  }
96
-
97
  public static function get_pages(){
98
  return get_posts( array('post_type' => 'page', 'post_status' => array('publish', 'private'), 'numberposts' => 999, 'orderby' => 'title', 'order' => 'ASC'));
99
  }
100
-
101
  public static function wp_pages_dropdown($field_name, $page_id, $truncate=false){
102
- $pages = FrmAppHelper::get_pages();
103
  ?>
104
  <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-pages-dropdown">
105
- <option value=""></option>
106
  <?php foreach($pages as $page){ ?>
107
- <option value="<?php echo $page->ID; ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $page->ID) or (!isset($_POST[$field_name]) and $page_id == $page->ID))?' selected="selected"':''); ?>><?php echo ($truncate)? FrmAppHelper::truncate($page->post_title, $truncate) : $page->post_title; ?> </option>
 
 
108
  <?php } ?>
109
  </select>
110
  <?php
111
  }
112
-
113
- public static function wp_roles_dropdown($field_name, $capability){
114
- global $frm_vars;
115
- $field_value = FrmAppHelper::get_param($field_name);
116
- if(!isset($frm_vars['editable_roles']) or !$frm_vars['editable_roles'])
117
- $frm_vars['editable_roles'] = get_editable_roles();
 
 
 
 
 
118
 
119
  ?>
120
- <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-pages-dropdown">
121
- <?php foreach($frm_vars['editable_roles'] as $role => $details){
122
- $name = translate_user_role($details['name'] ); ?>
123
- <option value="<?php echo esc_attr($role) ?>" <?php echo (((isset($_POST[$field_name]) and $_POST[$field_name] == $role) or (!isset($_POST[$field_name]) and $capability == $role))?' selected="selected"':''); ?>><?php echo $name ?> </option>
124
- <?php
125
- unset($role);
126
- unset($details);
127
- } ?>
128
  </select>
129
  <?php
130
  }
131
-
132
- public static function frm_capabilities(){
133
  global $frm_vars;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  $cap = array(
135
  'frm_view_forms' => __('View Forms and Templates', 'formidable'),
136
  'frm_edit_forms' => __('Add/Edit Forms and Templates', 'formidable'),
137
  'frm_delete_forms' => __('Delete Forms and Templates', 'formidable'),
138
- 'frm_change_settings' => __('Access this Settings Page', 'formidable')
 
 
139
  );
140
- if($frm_vars['pro_is_installed']){
141
- $cap['frm_view_entries'] = __('View Entries from Admin Area', 'formidable');
142
- $cap['frm_create_entries'] = __('Add Entries from Admin Area', 'formidable');
143
- $cap['frm_edit_entries'] = __('Edit Entries from Admin Area', 'formidable');
144
- $cap['frm_delete_entries'] = __('Delete Entries from Admin Area', 'formidable');
145
- $cap['frm_view_reports'] = __('View Reports', 'formidable');
146
- $cap['frm_edit_displays'] = __('Add/Edit Views', 'formidable');
147
  }
 
 
 
 
 
 
148
  return $cap;
149
  }
150
-
151
  public static function user_has_permission($needed_role){
152
  if($needed_role == '-1')
153
  return false;
154
-
155
  if($needed_role == '' or current_user_can($needed_role))
156
  return true;
157
-
158
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
159
  foreach ($roles as $role){
160
  if (current_user_can($role))
@@ -164,97 +486,232 @@ class FrmAppHelper{
164
  }
165
  return false;
166
  }
167
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  public static function checked($values, $current){
169
- if(FrmAppHelper::check_selected($values, $current))
170
  echo ' checked="checked"';
171
  }
172
-
173
  public static function check_selected($values, $current){
174
  //if(is_array($current))
175
  // $current = (isset($current['value'])) ? $current['value'] : $current['label'];
176
-
177
- if(is_array($values))
178
- $values = array_map(array('FrmAppHelper', 'recursive_trim'), $values);
179
- else
180
- $values = trim($values);
181
  $current = trim($current);
182
-
183
  /*if(is_array($values))
184
  $values = array_map('htmlentities', $values);
185
  else
186
  $values = htmlentities($values);
187
-
188
  $values = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $values);
189
  $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
190
  */
191
 
192
- if((is_array($values) && in_array($current, $values)) or (!is_array($values) and $values == $current))
193
  return true;
194
- else
195
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  }
197
-
198
  public static function recursive_trim(&$value) {
199
- if (is_array($value))
200
  $value = array_map(array('FrmAppHelper', 'recursive_trim'), $value);
201
- else
202
  $value = trim($value);
203
-
 
204
  return $value;
205
  }
206
-
207
  public static function esc_textarea( $text ) {
208
  $safe_text = str_replace('&quot;', '"', $text);
209
  $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
210
  return apply_filters( 'esc_textarea', $safe_text, $text );
211
  }
212
-
 
 
 
 
 
 
 
 
 
 
 
213
  public static function replace_quotes($val){
214
- $val = str_replace(array('&#8220;', '&#8221;', '&#8216;', '&#8217;'), array('"', '"', "'", "'"), $val);
 
 
 
215
  return $val;
216
  }
217
-
218
- public static function script_version($handle, $list='scripts'){
 
 
 
 
 
 
 
 
 
 
219
  global $wp_scripts;
220
- if(!$wp_scripts)
221
  return false;
222
-
 
223
  $ver = 0;
224
-
225
- if ( isset($wp_scripts->registered[$handle]) )
226
- $query = $wp_scripts->registered[$handle];
227
-
228
- if ( is_object( $query ) )
 
 
229
  $ver = $query->ver;
 
230
 
231
  return $ver;
232
  }
233
-
234
  public static function js_redirect($url){
235
  return '<script type="text/javascript">window.location="'. $url .'"</script>';
236
  }
237
-
238
- public static function get_file_contents($filename){
239
- if (is_file($filename)){
240
- ob_start();
241
- include $filename;
242
- $contents = ob_get_contents();
243
- ob_end_clean();
244
- return $contents;
245
  }
246
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
-
249
  public static function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
250
  global $wpdb;
251
 
252
  $key = '';
253
-
254
  if (!empty($name)){
255
  $key = sanitize_key($name);
256
  }
257
-
258
  if(empty($key)){
259
  $max_slug_value = pow(36, $num_chars);
260
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
@@ -263,10 +720,10 @@ class FrmAppHelper{
263
 
264
  if (is_numeric($key) or in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
265
  $key = $key .'a';
266
-
267
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
268
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
269
-
270
  if ($key_check or is_numeric($key_check)){
271
  $suffix = 2;
272
  do {
@@ -279,330 +736,459 @@ class FrmAppHelper{
279
  return $key;
280
  }
281
 
282
- //Editing a Form or Entry
 
 
 
283
  public static function setup_edit_vars($record, $table, $fields='', $default=false, $post_values=array()){
284
- if(!$record) return false;
285
- global $frm_entry_meta, $frm_settings, $frm_vars;
286
-
287
- if(empty($post_values))
 
 
 
288
  $post_values = stripslashes_deep($_POST);
289
-
 
290
  $values = array('id' => $record->id, 'fields' => array());
291
 
292
  foreach ( array('name', 'description') as $var ) {
293
  $default_val = isset($record->{$var}) ? $record->{$var} : '';
294
- $values[$var] = FrmAppHelper::get_param($var, $default_val);
295
  unset($var, $default_val);
296
  }
297
-
298
- if ( apply_filters('frm_use_wpautop', true) ) {
299
- $values['description'] = wpautop(str_replace( '<br>', '<br />', $values['description']));
300
- }
301
-
302
  foreach ( (array) $fields as $field ) {
 
 
 
 
303
 
304
- if ($default){
305
- $meta_value = $field->default_value;
306
- }else{
307
- if($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']){
308
- if(!isset($field->field_options['custom_field']))
309
- $field->field_options['custom_field'] = '';
310
- $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
311
- }else if(isset($record->metas)){
312
- $meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false;
313
- }else{
314
- $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id);
315
- }
316
- }
317
-
318
- $field_type = isset($post_values['field_options']['type_'.$field->id]) ? $post_values['field_options']['type_'.$field->id] : $field->type;
319
- $new_value = isset($post_values['item_meta'][$field->id]) ? maybe_unserialize($post_values['item_meta'][$field->id]) : $meta_value;
320
-
321
- $field_array = array(
322
- 'id' => $field->id,
323
- 'value' => $new_value,
324
- 'default_value' => $field->default_value,
325
- 'name' => $field->name,
326
- 'description' => $field->description,
327
- 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
328
- 'options' => $field->options,
329
- 'required' => $field->required,
330
- 'field_key' => $field->field_key,
331
- 'field_order' => $field->field_order,
332
- 'form_id' => $field->form_id
333
- );
334
-
335
- /*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){
336
- foreach((array)$field_array['options'] as $opt_key => $opt){
337
- if(!is_array($opt))
338
- $field_array['options'][$opt_key] = array('label' => $opt);
339
- unset($opt);
340
- unset($opt_key);
341
- }
342
- }*/
343
-
344
- $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
345
-
346
- foreach ($opt_defaults as $opt => $default_opt){
347
- $field_array[$opt] = ($post_values && isset($post_values['field_options'][$opt.'_'.$field->id]) ) ? maybe_unserialize($post_values['field_options'][$opt.'_'.$field->id]) : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt);
348
- if($opt == 'blank' and $field_array[$opt] == ''){
349
- $field_array[$opt] = $frm_settings->blank_msg;
350
- }else if($opt == 'invalid' and $field_array[$opt] == ''){
351
- if($field_type == 'captcha')
352
- $field_array[$opt] = $frm_settings->re_msg;
353
- else
354
- $field_array[$opt] = sprintf(__('%s is invalid', 'formidable'), $field_array['name']);
355
- }
356
- }
357
-
358
- unset($opt_defaults);
359
-
360
- if ($field_array['custom_html'] == '')
361
- $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
362
-
363
- if ($field_array['size'] == '')
364
- $field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
365
-
366
- $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
367
-
368
- if(!isset($field_array['unique']) or !$field_array['unique'])
369
- $field_array['unique_msg'] = '';
370
-
371
- foreach((array)$field->field_options as $k => $v){
372
- if(!isset($field_array[$k]))
373
- $field_array[$k] = $v;
374
- unset($k);
375
- unset($v);
376
  }
377
-
378
- $values['fields'][$field->id] = $field_array;
379
-
380
- unset($field);
381
- }
382
-
383
- $frm_form = new FrmForm();
384
- $form = $frm_form->getOne( $table == 'entries' ? $record->form_id : $record->id );
385
- unset($frm_form);
386
-
387
- if ($form){
388
- $values['form_name'] = (isset($record->form_id)) ? $form->name : '';
389
- if (is_array($form->options)){
390
- foreach ($form->options as $opt => $value){
391
- if(in_array($opt, array('email_to', 'reply_to', 'reply_to_name')))
392
- $values['notification'][0][$opt] = isset($post_values["notification[0][$opt]"]) ? maybe_unserialize($post_values["notification[0][$opt]"]) : $value;
393
-
394
- $values[$opt] = isset($post_values[$opt]) ? maybe_unserialize($post_values[$opt]) : $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  }
396
  }
397
  }
398
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  $form_defaults = FrmFormsHelper::get_default_opts();
400
-
401
- //set to posted value or default
402
- foreach ($form_defaults as $opt => $default){
403
- if (!isset($values[$opt]) or $values[$opt] == ''){
404
- if($opt == 'notification'){
405
- $values[$opt] = ($post_values and isset($post_values[$opt])) ? $post_values[$opt] : $default;
406
-
407
- foreach($default as $o => $d){
408
- if($o == 'email_to')
409
  $d = ''; //allow blank email address
410
- $values[$opt][0][$o] = ($post_values and isset($post_values[$opt][0][$o])) ? $post_values[$opt][0][$o] : $d;
411
- unset($o);
412
- unset($d);
413
  }
414
- }else{
415
- $values[$opt] = ($post_values and isset($post_values['options'][$opt])) ? $post_values['options'][$opt] : $default;
416
- }
417
- }else if($values[$opt] == 'notification'){
418
- foreach($values[$opt] as $k => $n){
419
- foreach($default as $o => $d){
420
- if(!isset($n[$o]))
421
- $values[$opt][$k][$o] = ($post_values and isset($post_values[$opt][$k][$o])) ? $post_values[$opt][$k][$o] : $d;
422
- unset($o);
423
- unset($d);
424
  }
425
- unset($k);
426
- unset($n);
427
  }
428
  }
429
-
430
- unset($opt);
431
- unset($defaut);
432
  }
433
-
434
- if (!isset($values['custom_style']))
435
- $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $_POST['options']['custom_style'] : ($frm_settings->load_style != 'none');
436
 
437
- foreach(array('before', 'after', 'submit') as $h){
438
- if (!isset($values[$h.'_html']))
 
 
 
 
 
439
  $values[$h .'_html'] = (isset($post_values['options'][$h .'_html']) ? $post_values['options'][$h .'_html'] : FrmFormsHelper::get_default_html($h));
 
440
  unset($h);
441
  }
442
-
443
- if ($table == 'entries')
444
- $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
445
- else if ($table == 'forms')
446
- $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
447
 
448
- return $values;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  }
450
-
451
- public static function insert_opt_html($args){
452
- extract($args);
453
-
454
  $class = '';
455
-
456
- if ( in_array( $type, array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
457
  $class .= 'show_frm_not_email_to';
458
  }
459
  ?>
460
  <li>
461
- <a class="frmids frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($id) ?>" href="javascript:void(0)">[<?php echo $id ?>]</a>
462
- <a class="frmkeys frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($key) ?>" href="javascript:void(0)">[<?php echo FrmAppHelper::truncate($key, 10) ?>]</a>
463
- <a class="frm_insert_code <?php echo $class ?>" data-code="<?php echo esc_attr($id) ?>" href="javascript:void(0)"><?php echo FrmAppHelper::truncate($name, 60) ?></a>
464
  </li>
465
  <?php
466
  }
467
-
468
  public static function get_us_states(){
469
  return apply_filters('frm_us_states', array(
470
- 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
471
  'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
472
- 'DC' => 'District of Columbia',
473
- 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
474
- 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
475
- 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
476
- 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
477
- 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
478
- 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
479
- 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
480
- 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
481
- 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
482
- 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
483
  'WI' => 'Wisconsin', 'WY' => 'Wyoming'
484
  ));
485
  }
486
-
487
  public static function get_countries(){
488
  return apply_filters('frm_countries', array(
489
- __('Afghanistan', 'formidable'), __('Albania', 'formidable'), __('Algeria', 'formidable'),
490
  __('American Samoa', 'formidable'), __('Andorra', 'formidable'), __('Angola', 'formidable'),
491
- __('Anguilla', 'formidable'), __('Antarctica', 'formidable'), __('Antigua and Barbuda', 'formidable'),
492
  __('Argentina', 'formidable'), __('Armenia', 'formidable'), __('Aruba', 'formidable'),
493
  __('Australia', 'formidable'), __('Austria', 'formidable'), __('Azerbaijan', 'formidable'),
494
- __('Bahamas', 'formidable'), __('Bahrain', 'formidable'), __('Bangladesh', 'formidable'),
495
  __('Barbados', 'formidable'), __('Belarus', 'formidable'), __('Belgium', 'formidable'),
496
- __('Belize', 'formidable'), __('Benin', 'formidable'), __('Bermuda', 'formidable'),
497
  __('Bhutan', 'formidable'), __('Bolivia', 'formidable'), __('Bosnia and Herzegovina', 'formidable'),
498
- __('Botswana', 'formidable'), __('Brazil', 'formidable'), __('Brunei', 'formidable'),
499
  __('Bulgaria', 'formidable'), __('Burkina Faso', 'formidable'), __('Burundi', 'formidable'),
500
- __('Cambodia', 'formidable'), __('Cameroon', 'formidable'), __('Canada', 'formidable'),
501
- __('Cape Verde', 'formidable'), __('Cayman Islands', 'formidable'), __('Central African Republic', 'formidable'),
502
  __('Chad', 'formidable'), __('Chile', 'formidable'), __('China', 'formidable'),
503
  __('Colombia', 'formidable'), __('Comoros', 'formidable'), __('Congo', 'formidable'),
504
  __('Costa Rica', 'formidable'), __('C&ocirc;te d\'Ivoire', 'formidable'), __('Croatia', 'formidable'),
505
- __('Cuba', 'formidable'), __('Cyprus', 'formidable'), __('Czech Republic', 'formidable'),
506
  __('Denmark', 'formidable'), __('Djibouti', 'formidable'), __('Dominica', 'formidable'),
507
- __('Dominican Republic', 'formidable'), __('East Timor', 'formidable'), __('Ecuador', 'formidable'),
508
  __('Egypt', 'formidable'), __('El Salvador', 'formidable'), __('Equatorial Guinea', 'formidable'),
509
- __('Eritrea', 'formidable'), __('Estonia', 'formidable'), __('Ethiopia', 'formidable'),
510
- __('Fiji', 'formidable'), __('Finland', 'formidable'), __('France', 'formidable'),
511
- __('French Guiana', 'formidable'), __('French Polynesia', 'formidable'), __('Gabon', 'formidable'),
512
  __('Gambia', 'formidable'), __('Georgia', 'formidable'), __('Germany', 'formidable'),
513
- __('Ghana', 'formidable'), __('Gibraltar', 'formidable'), __('Greece', 'formidable'),
514
  __('Greenland', 'formidable'), __('Grenada', 'formidable'), __('Guam', 'formidable'),
515
- __('Guatemala', 'formidable'), __('Guinea', 'formidable'), __('Guinea-Bissau', 'formidable'),
516
- __('Guyana', 'formidable'), __('Haiti', 'formidable'), __('Honduras', 'formidable'),
517
- __('Hong Kong', 'formidable'), __('Hungary', 'formidable'), __('Iceland', 'formidable'),
518
- __('India', 'formidable'), __('Indonesia', 'formidable'), __('Iran', 'formidable'),
519
- __('Iraq', 'formidable'), __('Ireland', 'formidable'), __('Israel', 'formidable'),
520
- __('Italy', 'formidable'), __('Jamaica', 'formidable'), __('Japan', 'formidable'),
521
- __('Jordan', 'formidable'), __('Kazakhstan', 'formidable'), __('Kenya', 'formidable'),
522
- __('Kiribati', 'formidable'), __('North Korea', 'formidable'), __('South Korea', 'formidable'),
523
- __('Kuwait', 'formidable'), __('Kyrgyzstan', 'formidable'), __('Laos', 'formidable'),
524
- __('Latvia', 'formidable'), __('Lebanon', 'formidable'), __('Lesotho', 'formidable'),
525
- __('Liberia', 'formidable'), __('Libya', 'formidable'), __('Liechtenstein', 'formidable'),
526
- __('Lithuania', 'formidable'), __('Luxembourg', 'formidable'), __('Macedonia', 'formidable'),
527
- __('Madagascar', 'formidable'), __('Malawi', 'formidable'), __('Malaysia', 'formidable'),
528
- __('Maldives', 'formidable'), __('Mali', 'formidable'), __('Malta', 'formidable'),
529
- __('Marshall Islands', 'formidable'), __('Mauritania', 'formidable'), __('Mauritius', 'formidable'),
530
- __('Mexico', 'formidable'), __('Micronesia', 'formidable'), __('Moldova', 'formidable'),
531
- __('Monaco', 'formidable'), __('Mongolia', 'formidable'), __('Montenegro', 'formidable'),
532
- __('Montserrat', 'formidable'), __('Morocco', 'formidable'), __('Mozambique', 'formidable'),
533
- __('Myanmar', 'formidable'), __('Namibia', 'formidable'), __('Nauru', 'formidable'),
534
  __('Nepal', 'formidable'), __('Netherlands', 'formidable'), __('New Zealand', 'formidable'),
535
- __('Nicaragua', 'formidable'), __('Niger', 'formidable'), __('Nigeria', 'formidable'),
536
- __('Norway', 'formidable'), __('Northern Mariana Islands', 'formidable'), __('Oman', 'formidable'),
537
- __('Pakistan', 'formidable'), __('Palau', 'formidable'), __('Palestine', 'formidable'),
538
- __('Panama', 'formidable'), __('Papua New Guinea', 'formidable'), __('Paraguay', 'formidable'),
539
- __('Peru', 'formidable'), __('Philippines', 'formidable'), __('Poland', 'formidable'),
540
- __('Portugal', 'formidable'), __('Puerto Rico', 'formidable'), __('Qatar', 'formidable'),
541
- __('Romania', 'formidable'), __('Russia', 'formidable'), __('Rwanda', 'formidable'),
542
- __('Saint Kitts and Nevis', 'formidable'), __('Saint Lucia', 'formidable'),
543
- __('Saint Vincent and the Grenadines', 'formidable'), __('Samoa', 'formidable'),
544
  __('San Marino', 'formidable'), __('Sao Tome and Principe', 'formidable'), __('Saudi Arabia', 'formidable'),
545
- __('Senegal', 'formidable'), __('Serbia and Montenegro', 'formidable'), __('Seychelles', 'formidable'),
546
- __('Sierra Leone', 'formidable'), __('Singapore', 'formidable'), __('Slovakia', 'formidable'),
547
- __('Slovenia', 'formidable'), __('Solomon Islands', 'formidable'), __('Somalia', 'formidable'),
548
- __('South Africa', 'formidable'), __('Spain', 'formidable'), __('Sri Lanka', 'formidable'),
549
- __('Sudan', 'formidable'), __('Suriname', 'formidable'), __('Swaziland', 'formidable'),
550
- __('Sweden', 'formidable'), __('Switzerland', 'formidable'), __('Syria', 'formidable'),
551
- __('Taiwan', 'formidable'), __('Tajikistan', 'formidable'), __('Tanzania', 'formidable'),
552
- __('Thailand', 'formidable'), __('Togo', 'formidable'), __('Tonga', 'formidable'),
553
- __('Trinidad and Tobago', 'formidable'), __('Tunisia', 'formidable'), __('Turkey', 'formidable'),
554
- __('Turkmenistan', 'formidable'), __('Tuvalu', 'formidable'), __('Uganda', 'formidable'),
 
555
  __('Ukraine', 'formidable'), __('United Arab Emirates', 'formidable'), __('United Kingdom', 'formidable'),
556
- __('United States', 'formidable'), __('Uruguay', 'formidable'), __('Uzbekistan', 'formidable'),
557
- __('Vanuatu', 'formidable'), __('Vatican City', 'formidable'), __('Venezuela', 'formidable'),
558
- __('Vietnam', 'formidable'), __('Virgin Islands, British', 'formidable'),
559
- __('Virgin Islands, U.S.', 'formidable'), __('Yemen', 'formidable'), __('Zambia', 'formidable'),
560
  __('Zimbabwe', 'formidable')
561
  ));
562
  }
563
-
564
  public static function truncate($str, $length, $minword = 3, $continue = '...'){
565
  if(is_array($str))
566
  return;
567
-
568
- $length = (int)$length;
569
  $str = strip_tags($str);
570
  $original_len = (function_exists('mb_strlen')) ? mb_strlen($str) : strlen($str);
571
-
572
  if($length == 0){
573
  return '';
574
  }else if($length <= 10){
575
  $sub = (function_exists('mb_substr')) ? mb_substr($str, 0, $length) : substr($str, 0, $length);
576
  return $sub . (($length < $original_len) ? $continue : '');
577
  }
578
-
579
  $sub = '';
580
  $len = 0;
581
 
582
  $words = (function_exists('mb_split')) ? mb_split(' ', $str) : explode(' ', $str);
583
-
584
  foreach ($words as $word){
585
  $part = (($sub != '') ? ' ' : '') . $word;
586
  $total_len = (function_exists('mb_strlen')) ? mb_strlen($sub . $part) : strlen($sub. $part);
587
- if ( $total_len > $length ) {
588
  break;
589
  }
590
-
591
  $sub .= $part;
592
  $len += (function_exists('mb_strlen')) ? mb_strlen($part) : strlen($part);
593
-
594
  if ( str_word_count($sub) > $minword && $total_len >= $length ) {
595
  break;
596
  }
597
-
598
  unset($total_len, $word);
599
  }
600
-
601
  return $sub . (($len < $original_len) ? $continue : '');
602
  }
603
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  /*
605
- * Added for < 4.0 compatability
606
  *
607
  * @since 1.07.10
608
  *
@@ -616,26 +1202,102 @@ class FrmAppHelper{
616
  } else {
617
  $term = like_escape( $term );
618
  }
619
-
620
  return $term;
621
  }
622
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
  public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ){
624
  if ( empty($where) ) {
625
  return '';
626
  }
627
-
628
  if(is_array($where)){
629
- global $frmdb, $wpdb;
630
- extract($frmdb->get_where_clause_and_values( $where ));
631
- $where = $wpdb->prepare($where, $values);
632
  }else{
633
  $where = $starts_with . $where;
634
  }
635
-
636
  return $where;
637
  }
638
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639
  // Pagination Methods
640
  public static function getLastRecordNum($r_count,$current_p,$p_size){
641
  return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
@@ -647,13 +1309,16 @@ class FrmAppHelper{
647
  else
648
  return (self::getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
649
  }
650
-
651
- public static function getRecordCount($where="", $table_name){
652
- global $wpdb;
653
- $query = 'SELECT COUNT(*) FROM ' . $table_name . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
654
- return $wpdb->get_var($query);
 
 
 
655
  }
656
-
657
  public static function get_referer_query($query) {
658
  if (strpos($query, "google.")) {
659
  //$pattern = '/^.*\/search.*[\?&]q=(.*)$/';
@@ -671,7 +1336,7 @@ class FrmAppHelper{
671
  $querystr = substr($matches[1], 0, strpos($matches[1], '&'));
672
  return urldecode($querystr);
673
  }
674
-
675
  public static function get_referer_info(){
676
  $referrerinfo = '';
677
  $keywords = array();
@@ -679,16 +1344,16 @@ class FrmAppHelper{
679
  if(isset($_SESSION) and isset($_SESSION['frm_http_referer']) and $_SESSION['frm_http_referer']){
680
  foreach ($_SESSION['frm_http_referer'] as $referer) {
681
  $referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
682
- $keywords_used = FrmAppHelper::get_referer_query($referer);
683
  if ($keywords_used)
684
  $keywords[] = $keywords_used;
685
 
686
  $i++;
687
  }
688
-
689
  $referrerinfo .= "\r\n";
690
  }else{
691
- $referrerinfo = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
692
  }
693
 
694
  $i = 1;
@@ -697,7 +1362,7 @@ class FrmAppHelper{
697
  $referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
698
  $i++;
699
  }
700
-
701
  $referrerinfo .= "\r\n";
702
  }
703
 
@@ -707,55 +1372,131 @@ class FrmAppHelper{
707
  $i++;
708
  }
709
  $referrerinfo .= "\r\n";
710
-
711
  return $referrerinfo;
712
  }
713
-
714
  public static function json_to_array($json_vars){
715
  $vars = array();
716
- foreach($json_vars as $jv){
717
  $jv_name = explode('[', $jv['name']);
718
- $last = count($jv_name)-1;
719
- foreach($jv_name as $p => $n){
720
  $name = trim($n, ']');
721
- $this_val = ($p == $last) ? $jv['value'] : array();
722
-
723
- if(!$p){
724
  $l1 = $name;
725
- if($name == '')
726
- $vars[] = $this_val;
727
- else if(!isset($vars[$l1]))
728
- $vars[$l1] = $this_val;
729
  }
730
-
731
- if($p == 1){
732
  $l2 = $name;
733
- if($name == '')
734
- $vars[$l1][] = $this_val;
735
- else if(!isset($vars[$l1][$l2]))
736
- $vars[$l1][$l2] = $this_val;
737
  }
738
-
739
- if($p == 2){
740
- $l3 = $name;
741
- if($name == '')
742
- $vars[$l1][$l2][] = $this_val;
743
- else if(!isset($vars[$l1][$l2][$l3]))
744
- $vars[$l1][$l2][$l3] = $this_val;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745
  }
746
-
747
- unset($this_val);
748
- unset($n);
749
  }
750
-
751
- unset($last);
752
- unset($jv);
753
  }
754
-
755
  return $vars;
756
  }
757
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758
  public static function maybe_json_decode($string){
 
 
 
 
759
  $new_string = json_decode($string, true);
760
  if ( function_exists('json_last_error') ) { // php 5.3+
761
  if ( json_last_error() == JSON_ERROR_NONE ) {
@@ -766,14 +1507,7 @@ class FrmAppHelper{
766
  }
767
  return $string;
768
  }
769
-
770
- public static function check_mem_use($function='', $start_mem=0) {
771
- $mem = memory_get_usage(true) - $start_mem;
772
-
773
- //error_log($mem .' '. $function);
774
- return $start_mem + $mem;
775
- }
776
-
777
  /*
778
  * @since 1.07.10
779
  *
@@ -786,11 +1520,11 @@ class FrmAppHelper{
786
  if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
787
  return;
788
  }
789
-
790
  if ( is_object($post) && $post->post_type != $post_type ) {
791
  return;
792
  }
793
-
794
  echo <<<HTML
795
  <script type="text/javascript">
796
  jQuery(document).ready(function(){
@@ -800,7 +1534,7 @@ jQuery('#toplevel_page_formidable a.wp-has-submenu').removeClass('wp-not-current
800
  </script>
801
  HTML;
802
  }
803
-
804
  /*
805
  * @since 1.07.10
806
  *
@@ -809,15 +1543,73 @@ HTML;
809
  */
810
  public static function min_version_notice($min_version) {
811
  $frm_version = self::plugin_version();
812
-
813
  // check if Formidable meets minimum requirements
814
  if ( version_compare($frm_version, $min_version, '>=') ) {
815
  return;
816
  }
817
-
818
  $wp_list_table = _get_list_table('WP_Plugins_List_Table');
819
  echo '<tr class="plugin-update-tr active"><th colspan="' . $wp_list_table->get_column_count() . '" class="check-column plugin-update colspanchange"><div class="update-message">'.
820
  __('You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable') .
821
  '</div></td></tr>';
822
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
  }
1
  <?php
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
 
 
 
4
  class FrmAppHelper{
5
+ public static $db_version = 17; //version of the database we are moving to
6
+ public static $pro_db_version = 27;
7
+
8
+ /*
9
+ * @since 2.0
10
+ */
11
+ public static $plug_version = '2.0b7';
12
+
13
  /*
14
  * @since 1.07.02
15
  *
16
  * @param none
17
  * @return float The version of this plugin
18
  */
19
+ public static function plugin_version() {
20
+ return self::$plug_version;
21
+ }
22
+
23
+ public static function plugin_folder() {
24
+ return basename(self::plugin_path());
25
  }
26
+
27
  public static function plugin_path(){
28
  return dirname(dirname(dirname(__FILE__)));
29
  }
30
+
31
  public static function plugin_url($url=''){
32
  //prevously FRM_URL constant
33
+ if ( empty($url) ) {
34
+ $url = plugins_url('', self::plugin_folder() .'/formidable.php');
35
+ }
36
+
37
+ if ( is_ssl() && !preg_match('/^https:\/\/.*\..*$/', $url) ) {
38
  $url = str_replace('http://', 'https://', $url);
39
+ }
40
+
41
  return $url;
42
  }
43
+
44
+ /*
45
+ * @return string Site URL
46
+ */
47
  public static function site_url(){
48
  $url = self::plugin_url(site_url());
49
  return $url;
50
  }
51
+
52
+ /*
53
+ * Get the name of this site
54
+ * Used for [sitename] shortcode
55
+ *
56
+ * @since 2.0
57
+ * @return string
58
+ */
59
+ public static function site_name() {
60
+ return get_option('blogname');
61
+ }
62
+
63
+ /*
64
+ * Get the Formidable settings
65
+ *
66
+ * @since 2.0
67
+ *
68
+ * @param None
69
+ * @return Object $frm_setings
70
+ */
71
+ public static function get_settings() {
72
+ global $frm_settings;
73
+ if ( empty($frm_settings) ) {
74
+ $frm_settings = new FrmSettings();
75
+ }
76
+ return $frm_settings;
77
+ }
78
+
79
+ /*
80
+ * Show a message in place of pro features
81
+ *
82
+ * @since 2.0
83
+ */
84
+ public static function update_message($features, $class = ''){
85
+ if ( ! self::pro_is_installed() ) {
86
+ include(FrmAppHelper::plugin_path() .'/classes/views/shared/update_message.php');
87
+ }
88
+ }
89
+
90
+ public static function pro_is_installed() {
91
+ return apply_filters('frm_pro_installed', false);
92
+ }
93
+
94
+ /*
95
+ * Check for certain page in Formidable settings
96
+ *
97
+ * @since 2.0
98
+ *
99
+ * @param $page string The name of the page to check
100
+ * @return boolean
101
+ */
102
+ public static function is_admin_page($page = 'formidable') {
103
+ global $pagenow;
104
+ if ( $pagenow ) {
105
+ return $pagenow == 'admin.php' && $_GET['page'] == $page;
106
+ }
107
+
108
+ return is_admin() && isset($_GET['page']) && $_GET['page'] == $page;
109
+ }
110
+
111
+ /*
112
+ * Check for the form preview page
113
+ *
114
+ * @since 2.0
115
+ *
116
+ * @param None
117
+ * @return boolean
118
+ */
119
+ public static function is_preview_page() {
120
+ global $pagenow;
121
+ return $pagenow && $pagenow == 'admin-ajax.php' && isset($_GET['action']) && $_GET['action'] == 'frm_forms_preview';
122
+ }
123
+
124
+ /*
125
+ * Check for ajax except the form preview page
126
+ *
127
+ * @since 2.0
128
+ *
129
+ * @param None
130
+ * @return boolean
131
+ */
132
+ public static function doing_ajax() {
133
+ return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
134
+ }
135
+
136
+ /*
137
+ * Check if on an admin page
138
+ *
139
+ * @since 2.0
140
+ *
141
+ * @param None
142
+ * @return boolean
143
+ */
144
+ public static function is_admin() {
145
+ return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
146
+ }
147
+
148
+ /*
149
+ * Check if value contains blank value or empty array
150
+ *
151
+ * @since 2.0
152
+ * @param $value - value to check
153
+ * @return true or false
154
+ */
155
+ public static function is_empty_value( $value, $empty = '' ) {
156
+ return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
157
+ }
158
+
159
+ /*
160
+ * Get any value from the $_SERVER
161
+ * Used by [ip] shortcode
162
+ *
163
+ * @since 2.0
164
+ * @return string
165
+ */
166
+ public static function get_server_value($value) {
167
+ return isset($_SERVER[$value]) ? $_SERVER[$value] : '';
168
+ }
169
+
170
+ /*
171
+ * Check for the IP address in several places
172
+ * @return string The IP address of the current user
173
+ */
174
+ public static function get_ip_address(){
175
+ foreach ( array(
176
+ 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
177
+ 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'
178
+ ) as $key ) {
179
+ if ( ! array_key_exists($key, $_SERVER) ) {
180
+ continue;
181
+ }
182
+
183
+ foreach ( explode(',', $_SERVER[$key]) as $ip ) {
184
+ $ip = trim($ip); // just to be safe
185
+
186
+ if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
187
+ return $ip;
188
+ }
189
+ }
190
+ }
191
+ }
192
+
193
  public static function get_param($param, $default='', $src='get'){
194
  if(strpos($param, '[')){
195
  $params = explode('[', $param);
196
+ $param = $params[0];
197
  }
198
 
199
  if($src == 'get'){
200
  $value = (isset($_POST[$param]) ? stripslashes_deep($_POST[$param]) : (isset($_GET[$param]) ? stripslashes_deep($_GET[$param]) : $default));
201
+ if ( ! isset($_POST[$param]) && isset($_GET[$param]) && ! is_array($value) ) {
202
  $value = stripslashes_deep(htmlspecialchars_decode(urldecode($_GET[$param])));
203
+ }
204
  }else{
205
  $value = isset($_POST[$param]) ? stripslashes_deep(maybe_unserialize($_POST[$param])) : $default;
206
  }
207
+
208
+ if ( isset($params) && is_array($value) && ! empty($value) ) {
209
  foreach($params as $k => $p){
210
+ if ( ! $k || ! is_array($value) ) {
211
  continue;
212
+ }
213
+
214
  $p = trim($p, ']');
215
  $value = (isset($value[$p])) ? $value[$p] : $default;
216
  }
218
 
219
  return $value;
220
  }
221
+
222
  public static function get_post_param($param, $default=''){
223
  return isset($_POST[$param]) ? stripslashes_deep(maybe_unserialize($_POST[$param])) : $default;
224
  }
225
+
226
+ /*
227
+ * @since 2.0
228
+ */
229
+ public static function simple_get($action) {
230
+ if ( $_GET && isset($_GET[$action]) ) {
231
+ return $_GET[$action];
232
+ } else {
233
+ return '';
234
+ }
235
+ }
236
+
237
+ /*
238
+ * Used when switching the action for a bulk action
239
+ * @since 2.0
240
+ */
241
+ public static function remove_get_action() {
242
+ if ( ! isset($_GET) ) {
243
+ return;
244
+ }
245
+
246
+ if ( isset($_GET['action']) ) {
247
+ $_SERVER['REQUEST_URI'] = str_replace('&action='. $_GET['action'], '', $_SERVER['REQUEST_URI']);
248
+ }
249
+
250
+ if ( isset($_GET['action2']) ) {
251
+ $_SERVER['REQUEST_URI'] = str_replace('&action='. $_GET['action2'], '', $_SERVER['REQUEST_URI']);
252
+ }
253
+ }
254
+
255
+ /*
256
+ * Check the WP query for a parameter
257
+ *
258
+ * @since 2.0
259
+ * @return string|array
260
+ */
261
+ public static function get_query_var( $value, $param ) {
262
+ if ( $value != '' ) {
263
+ return $value;
264
+ }
265
+
266
+ global $wp_query;
267
+ if ( isset($wp_query->query_vars[$param]) ) {
268
+ $value = $wp_query->query_vars[$param];
269
+ }
270
+
271
+ return $value;
272
+ }
273
+
274
+ public static function trigger_hook_load( $type, $object = null ) {
275
+ // only load the form hooks once
276
+ $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object);
277
+ if ( ! $hooks_loaded ) {
278
+ do_action('frm_load_'. $type .'_hooks');
279
+ }
280
+ }
281
+
282
+ /*
283
+ * Check cache before fetching values and saving to cache
284
+ *
285
+ * @since 2.0
286
+ *
287
+ * @param string $cache_key The unique name for this cache
288
+ * @param string $group The name of the cache group
289
+ * @param string $query If blank, don't run a db call
290
+ * @param string $type The wpdb function to use with this query
291
+ * @return mixed $results The cache or query results
292
+ */
293
+ public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
294
+ $results = wp_cache_get($cache_key, $group);
295
+ if ( ! self::is_empty_value( $results, false ) || empty($query) ) {
296
+ return $results;
297
+ }
298
+
299
+ if ( 'get_posts' == $type ) {
300
+ $results = get_posts($query);
301
+ } else {
302
+ global $wpdb;
303
+ $results = $wpdb->{$type}($query);
304
+ }
305
+
306
+ wp_cache_set($cache_key, $results, $group, $time);
307
+
308
+ return $results;
309
+ }
310
+
311
+ /*
312
+ * Data that should be stored for a long time can be stored in a transient.
313
+ * First check the cache, then check the transient
314
+ * @since 2.0
315
+ * @return mixed The cached value or false
316
+ */
317
+ public static function check_cache_and_transient($cache_key) {
318
+ // check caching layer first
319
+ $results = self::check_cache( $cache_key );
320
+ if ( $results ) {
321
+ return $results;
322
+ }
323
+
324
+ // then check the transient
325
+ $results = get_transient($cache_key);
326
+ if ( $results ) {
327
+ wp_cache_set($cache_key, $results);
328
+ }
329
+
330
+ return $results;
331
+ }
332
+
333
+ /*
334
+ * @since 2.0
335
+ */
336
+ public static function delete_cache_and_transient($cache_key) {
337
+ delete_transient($cache_key);
338
+ wp_cache_delete($cache_key);
339
+ }
340
+
341
+ /*
342
+ * Delete all caching in a single group
343
+ *
344
+ * @since 2.0
345
+ *
346
+ * @param string $group The name of the cache group
347
+ * @return boolean True or False
348
+ */
349
+ public static function cache_delete_group($group) {
350
+ global $wp_object_cache;
351
+
352
+ if ( isset($wp_object_cache->cache[$group]) ) {
353
+ foreach ( $wp_object_cache->cache[$group] as $k => $v ) {
354
+ wp_cache_delete($k, $group);
355
+ }
356
+ return true;
357
+ }
358
+
359
+ return false;
360
+ }
361
+
362
  /*
363
  * Check a value from a shortcode to see if true or false.
364
  * True when value is 1, true, 'true', 'yes'
371
  public static function is_true($value) {
372
  return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
373
  }
374
+
375
+ /*
376
+ * Used to filter shortcode in text widgets
377
+ */
378
+ public static function widget_text_filter_callback( $matches ) {
379
+ return do_shortcode( $matches[0] );
380
+ }
381
+
382
  public static function load_scripts($scripts){
383
+ _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_script' );
384
  foreach ( (array) $scripts as $s ) {
385
  wp_enqueue_script($s);
386
  }
387
  }
388
+
389
  public static function load_styles($styles){
390
+ _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_style' );
391
  foreach ( (array) $styles as $s ) {
392
  wp_enqueue_style($s);
393
  }
394
  }
395
+
396
  public static function get_pages(){
397
  return get_posts( array('post_type' => 'page', 'post_status' => array('publish', 'private'), 'numberposts' => 999, 'orderby' => 'title', 'order' => 'ASC'));
398
  }
399
+
400
  public static function wp_pages_dropdown($field_name, $page_id, $truncate=false){
401
+ $pages = self::get_pages();
402
  ?>
403
  <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" class="frm-pages-dropdown">
404
+ <option value=""> </option>
405
  <?php foreach($pages as $page){ ?>
406
+ <option value="<?php echo $page->ID; ?>" <?php
407
+ echo ( ( ( isset($_POST[$field_name]) && $_POST[$field_name] == $page->ID ) || ( ! isset($_POST[$field_name]) && $page_id == $page->ID ) ) ? ' selected="selected"' : '' );
408
+ ?>><?php echo $truncate ? self::truncate($page->post_title, $truncate) : $page->post_title; ?> </option>
409
  <?php } ?>
410
  </select>
411
  <?php
412
  }
413
+
414
+ public static function post_edit_link($post_id) {
415
+ $post = get_post($post_id);
416
+ if ( $post ) {
417
+ return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. FrmAppHelper::truncate($post->post_title, 50) .'</a>';
418
+ }
419
+ return '';
420
+ }
421
+
422
+ public static function wp_roles_dropdown($field_name, $capability, $multiple = 'single') {
423
+ $capability = (array) self::get_param($field_name, $capability, 'post');
424
 
425
  ?>
426
+ <select name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" <?php
427
+ echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
428
+ ?> class="frm_multiselect">
429
+ <?php self::roles_options($capability); ?>
 
 
 
 
430
  </select>
431
  <?php
432
  }
433
+
434
+ public static function roles_options($capability) {
435
  global $frm_vars;
436
+ if ( isset($frm_vars['editable_roles']) ) {
437
+ $editable_roles = $frm_vars['editable_roles'];
438
+ } else {
439
+ $editable_roles = get_editable_roles();
440
+ $frm_vars['editable_roles'] = $editable_roles;
441
+ }
442
+
443
+ foreach ( $editable_roles as $role => $details ) {
444
+ $name = translate_user_role($details['name'] ); ?>
445
+ <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo $name ?> </option>
446
+ <?php
447
+ unset($role, $details);
448
+ }
449
+ }
450
+
451
+ public static function frm_capabilities($type = 'auto') {
452
  $cap = array(
453
  'frm_view_forms' => __('View Forms and Templates', 'formidable'),
454
  'frm_edit_forms' => __('Add/Edit Forms and Templates', 'formidable'),
455
  'frm_delete_forms' => __('Delete Forms and Templates', 'formidable'),
456
+ 'frm_change_settings' => __('Access this Settings Page', 'formidable'),
457
+ 'frm_view_entries' => __('View Entries from Admin Area', 'formidable'),
458
+ 'frm_delete_entries' => __('Delete Entries from Admin Area', 'formidable'),
459
  );
460
+
461
+ if ( ! self::pro_is_installed() && 'pro' != $type) {
462
+ return $cap;
 
 
 
 
463
  }
464
+
465
+ $cap['frm_create_entries'] = __('Add Entries from Admin Area', 'formidable');
466
+ $cap['frm_edit_entries'] = __('Edit Entries from Admin Area', 'formidable');
467
+ $cap['frm_view_reports'] = __('View Reports', 'formidable');
468
+ $cap['frm_edit_displays'] = __('Add/Edit Views', 'formidable');
469
+
470
  return $cap;
471
  }
472
+
473
  public static function user_has_permission($needed_role){
474
  if($needed_role == '-1')
475
  return false;
476
+
477
  if($needed_role == '' or current_user_can($needed_role))
478
  return true;
479
+
480
  $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
481
  foreach ($roles as $role){
482
  if (current_user_can($role))
486
  }
487
  return false;
488
  }
489
+
490
+ /*
491
+ * Make sure administrators can see Formidable menu
492
+ *
493
+ * @since 2.0
494
+ */
495
+ public static function maybe_add_permissions() {
496
+ if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
497
+ return;
498
+ }
499
+
500
+ global $current_user;
501
+ $frm_roles = self::frm_capabilities();
502
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
503
+ $current_user->add_cap( $frm_role );
504
+ unset($frm_role, $frm_role_description);
505
+ }
506
+ unset($frm_roles);
507
+ }
508
+
509
+ /*
510
+ * Check if the user has permision for action.
511
+ * Return permission message and stop the action if no permission
512
+ * @since 2.0
513
+ */
514
+ public static function permission_check($permission) {
515
+ if ( ! current_user_can($permission) ) {
516
+ $frm_settings = self::get_settings();
517
+ wp_die($frm_settings->admin_permission);
518
+ }
519
+ }
520
+
521
+ /*
522
+ * Check if the user has permision for action.
523
+ * Return permission message and stop the action if no permission
524
+ * @since 2.0
525
+ */
526
+ public static function ajax_permission_check($permission, $show_message = 'hide') {
527
+ if ( current_user_can($permission) ) {
528
+ return;
529
+ }
530
+
531
+ if ( 'hide' == $show_message ) {
532
+ $message = '';
533
+ } else {
534
+ $frm_settings = self::get_settings();
535
+ $message = $frm_settings->admin_permission;
536
+ }
537
+
538
+ die($message);
539
+ }
540
+
541
  public static function checked($values, $current){
542
+ if(self::check_selected($values, $current))
543
  echo ' checked="checked"';
544
  }
545
+
546
  public static function check_selected($values, $current){
547
  //if(is_array($current))
548
  // $current = (isset($current['value'])) ? $current['value'] : $current['label'];
549
+
550
+ self::recursive_trim($values);
 
 
 
551
  $current = trim($current);
552
+
553
  /*if(is_array($values))
554
  $values = array_map('htmlentities', $values);
555
  else
556
  $values = htmlentities($values);
557
+
558
  $values = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $values);
559
  $current = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $current);
560
  */
561
 
562
+ if ( ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current ) ) {
563
  return true;
564
+ } else {
565
  return false;
566
+ }
567
+ }
568
+
569
+ /*
570
+ * Check if value is equal to any of the field options. If not, set it as the other_val.
571
+ * @return string
572
+ */
573
+ public static function check_other_selected( $value, $field_options, $field_type, $opt_key = '' ){
574
+ if ( !$value ) {
575
+ return;
576
+ }
577
+
578
+ $other_val = '';
579
+ if ( $field_type == 'radio' ) {
580
+ //Check if field value equals any of the options. If not, set it as the other value.
581
+ foreach ( $field_options as $opt_key => $opt_val ) {
582
+ if ( is_array( $opt_val ) ) {
583
+ if ( $opt_val['value'] == $value ) {
584
+ return '';
585
+ }
586
+ } else if ( $opt_val == $value ) {
587
+ return '';
588
+ } else {
589
+ $other_val = $value;
590
+ }
591
+ unset($opt_key, $opt_val);
592
+ }
593
+ } else if ( array_key_exists ( $opt_key , (array) $value ) && $value[$opt_key] ) {
594
+ $other_val = $value[$opt_key];
595
+ }
596
+
597
+ return $other_val;
598
  }
599
+
600
  public static function recursive_trim(&$value) {
601
+ if ( is_array($value) ) {
602
  $value = array_map(array('FrmAppHelper', 'recursive_trim'), $value);
603
+ } else {
604
  $value = trim($value);
605
+ }
606
+
607
  return $value;
608
  }
609
+
610
  public static function esc_textarea( $text ) {
611
  $safe_text = str_replace('&quot;', '"', $text);
612
  $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
613
  return apply_filters( 'esc_textarea', $safe_text, $text );
614
  }
615
+
616
+ /*
617
+ * Add auto paragraphs to text areas
618
+ * @since 2.0
619
+ */
620
+ public static function use_wpautop($content) {
621
+ if ( apply_filters('frm_use_wpautop', true) ) {
622
+ $content = wpautop(str_replace( '<br>', '<br />', $content));
623
+ }
624
+ return $content;
625
+ }
626
+
627
  public static function replace_quotes($val){
628
+ //Replace double quotes
629
+ $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;'), '"', $val);
630
+ //Replace single quotes
631
+ $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
632
  return $val;
633
  }
634
+
635
+ /*
636
+ * @since 2.0
637
+ * @return string The base Google APIS url for the current version of jQuery UI
638
+ */
639
+ public static function jquery_ui_base_url() {
640
+ $url = 'http'. ( is_ssl() ? 's' : '' ) .'://ajax.googleapis.com/ajax/libs/jqueryui/'. self::script_version('jquery-ui-core');
641
+ $url = apply_filters('frm_jquery_ui_base_url', $url);
642
+ return $url;
643
+ }
644
+
645
+ public static function script_version($handle) {
646
  global $wp_scripts;
647
+ if ( ! $wp_scripts ) {
648
  return false;
649
+ }
650
+
651
  $ver = 0;
652
+
653
+ if ( ! isset($wp_scripts->registered[$handle]) ) {
654
+ return $ver;
655
+ }
656
+
657
+ $query = $wp_scripts->registered[$handle];
658
+ if ( is_object( $query ) ) {
659
  $ver = $query->ver;
660
+ }
661
 
662
  return $ver;
663
  }
664
+
665
  public static function js_redirect($url){
666
  return '<script type="text/javascript">window.location="'. $url .'"</script>';
667
  }
668
+
669
+ public static function get_user_id_param($user_id){
670
+ if ( !$user_id || empty($user_id) || is_numeric($user_id) ) {
671
+ return $user_id;
 
 
 
 
672
  }
673
+
674
+ if($user_id == 'current'){
675
+ $user_ID = get_current_user_id();
676
+ $user_id = $user_ID;
677
+ }else{
678
+ if ( is_email($user_id) ) {
679
+ $user = get_user_by('email', $user_id);
680
+ } else {
681
+ $user = get_user_by('login', $user_id);
682
+ }
683
+
684
+ if ( $user ) {
685
+ $user_id = $user->ID;
686
+ }
687
+ unset($user);
688
+ }
689
+
690
+ return $user_id;
691
+ }
692
+
693
+ public static function get_file_contents($filename, $atts = array()) {
694
+ if ( ! is_file($filename) ) {
695
+ return false;
696
+ }
697
+
698
+ extract($atts);
699
+ ob_start();
700
+ include($filename);
701
+ $contents = ob_get_contents();
702
+ ob_end_clean();
703
+ return $contents;
704
  }
705
+
706
  public static function get_unique_key($name='', $table_name, $column, $id = 0, $num_chars = 6){
707
  global $wpdb;
708
 
709
  $key = '';
710
+
711
  if (!empty($name)){
712
  $key = sanitize_key($name);
713
  }
714
+
715
  if(empty($key)){
716
  $max_slug_value = pow(36, $num_chars);
717
  $min_slug_value = 37; // we want to have at least 2 characters in the slug
720
 
721
  if (is_numeric($key) or in_array($key, array('id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd')))
722
  $key = $key .'a';
723
+
724
  $query = "SELECT $column FROM $table_name WHERE $column = %s AND ID != %d LIMIT 1";
725
  $key_check = $wpdb->get_var($wpdb->prepare($query, $key, $id));
726
+
727
  if ($key_check or is_numeric($key_check)){
728
  $suffix = 2;
729
  do {
736
  return $key;
737
  }
738
 
739
+ /*
740
+ * Editing a Form or Entry
741
+ * @return bool|array
742
+ */
743
  public static function setup_edit_vars($record, $table, $fields='', $default=false, $post_values=array()){
744
+ if ( ! $record ) {
745
+ return false;
746
+ }
747
+
748
+ global $frm_vars;
749
+
750
+ if ( empty($post_values) ) {
751
  $post_values = stripslashes_deep($_POST);
752
+ }
753
+
754
  $values = array('id' => $record->id, 'fields' => array());
755
 
756
  foreach ( array('name', 'description') as $var ) {
757
  $default_val = isset($record->{$var}) ? $record->{$var} : '';
758
+ $values[$var] = self::get_param($var, $default_val);
759
  unset($var, $default_val);
760
  }
761
+
762
+ $values['description'] = self::use_wpautop($values['description']);
763
+ $frm_settings = self::get_settings();
764
+
 
765
  foreach ( (array) $fields as $field ) {
766
+ // Make sure to filter default values (for placeholder text)
767
+ $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
768
+ self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
769
+ }
770
 
771
+ self::fill_form_opts($record, $table, $post_values, $values);
772
+
773
+ if ( $table == 'entries' ) {
774
+ $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
775
+ } else if ( $table == 'forms' ) {
776
+ $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
777
+ }
778
+
779
+ return $values;
780
+ }
781
+
782
+ private static function fill_field_defaults($field, $record, array &$values, $args) {
783
+ $post_values = $args['post_values'];
784
+
785
+ if ( $args['default'] ) {
786
+ $meta_value = $field->default_value;
787
+ } else {
788
+ if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
789
+ if ( ! isset($field->field_options['custom_field']) ) {
790
+ $field->field_options['custom_field'] = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
791
  }
792
+ $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));
793
+ } else {
794
+ $meta_value = self::get_meta_value($field->id, $record);
795
+ }
796
+ }
797
+
798
+ $field_type = isset($post_values['field_options']['type_'.$field->id]) ? $post_values['field_options']['type_'.$field->id] : $field->type;
799
+ $new_value = isset($post_values['item_meta'][$field->id]) ? maybe_unserialize($post_values['item_meta'][$field->id]) : $meta_value;
800
+
801
+ $field_array = array(
802
+ 'id' => $field->id,
803
+ 'value' => $new_value,
804
+ 'default_value' => $field->default_value,
805
+ 'name' => $field->name,
806
+ 'description' => $field->description,
807
+ 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value),
808
+ 'options' => $field->options,
809
+ 'required' => $field->required,
810
+ 'field_key' => $field->field_key,
811
+ 'field_order' => $field->field_order,
812
+ 'form_id' => $field->form_id
813
+ );
814
+
815
+ $args['field_type'] = $field_type;
816
+ self::fill_field_opts($field, $field_array, $args);
817
+
818
+ $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
819
+
820
+ if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
821
+ $field_array['unique_msg'] = '';
822
+ }
823
+
824
+ foreach ( (array) $field->field_options as $k => $v ) {
825
+ if ( ! isset($field_array[$k]) ) {
826
+ $field_array[$k] = $v;
827
+ }
828
+ unset($k, $v);
829
+ }
830
+
831
+ $values['fields'][$field->id] = $field_array;
832
+ }
833
+
834
+ private static function fill_field_opts($field, array &$field_array, $args) {
835
+ $post_values = $args['post_values'];
836
+ $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
837
+
838
+ foreach ( $opt_defaults as $opt => $default_opt ) {
839
+ $field_array[$opt] = ( $post_values && isset($post_values['field_options'][$opt .'_'. $field->id]) ) ? maybe_unserialize($post_values['field_options'][$opt .'_'. $field->id]) : ( isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt );
840
+ if ( $opt == 'blank' && $field_array[$opt] == '' ) {
841
+ $field_array[$opt] = $args['frm_settings']->blank_msg;
842
+ } else if ( $opt == 'invalid' && $field_array[$opt] == '' ) {
843
+ if ( $args['field_type'] == 'captcha' ) {
844
+ $field_array[$opt] = $args['frm_settings']->re_msg;
845
+ } else {
846
+ $field_array[$opt] = sprintf(__('%s is invalid', 'formidable'), $field_array['name']);
847
  }
848
  }
849
  }
850
+
851
+ if ( $field_array['custom_html'] == '' ) {
852
+ $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
853
+ }
854
+
855
+ $field_array['size'] = self::get_field_size($field_array);
856
+ }
857
+
858
+ private static function fill_form_opts($record, $table, $post_values, array &$values) {
859
+ if ( $table == 'entries' ) {
860
+ $form = $record->form_id;
861
+ FrmFormsHelper::maybe_get_form( $form );
862
+ } else {
863
+ $form = $record;
864
+ }
865
+
866
+ if ( ! $form ) {
867
+ return;
868
+ }
869
+
870
+ $values['form_name'] = isset($record->form_id) ? $form->name : '';
871
+ if ( ! is_array($form->options) ) {
872
+ return;
873
+ }
874
+
875
+ foreach ( $form->options as $opt => $value ) {
876
+ $values[$opt] = isset($post_values[$opt]) ? maybe_unserialize($post_values[$opt]) : $value;
877
+ }
878
+
879
+ self::fill_form_defaults($post_values, $values);
880
+ }
881
+
882
+ /*
883
+ * Set to POST value or default
884
+ */
885
+ private static function fill_form_defaults($post_values, array &$values) {
886
  $form_defaults = FrmFormsHelper::get_default_opts();
887
+
888
+ foreach ( $form_defaults as $opt => $default ) {
889
+ if ( ! isset($values[$opt]) || $values[$opt] == '' ) {
890
+ if ( $opt == 'notification' ) {
891
+ $values[$opt] = ( $post_values && isset($post_values[$opt]) ) ? $post_values[$opt] : $default;
892
+
893
+ foreach ( $default as $o => $d ) {
894
+ if ( $o == 'email_to' ) {
 
895
  $d = ''; //allow blank email address
896
+ }
897
+ $values[$opt][0][$o] = ( $post_values && isset($post_values[$opt][0][$o]) ) ? $post_values[$opt][0][$o] : $d;
898
+ unset($o, $d);
899
  }
900
+ } else {
901
+ $values[$opt] = ( $post_values && isset($post_values['options'][$opt]) ) ? $post_values['options'][$opt] : $default;
902
+ }
903
+ } else if ( $values[$opt] == 'notification' ) {
904
+ foreach ( $values[$opt] as $k => $n ) {
905
+ foreach ( $default as $o => $d ) {
906
+ if ( ! isset($n[$o]) ) {
907
+ $values[$opt][$k][$o] = ( $post_values && isset($post_values[$opt][$k][$o])) ? $post_values[$opt][$k][$o] : $d;
908
+ }
909
+ unset($o, $d);
910
  }
911
+ unset($k, $n);
 
912
  }
913
  }
914
+
915
+ unset($opt, $defaut);
 
916
  }
 
 
 
917
 
918
+ if ( ! isset($values['custom_style']) ) {
919
+ $frm_settings = self::get_settings();
920
+ $values['custom_style'] = ( $post_values && isset($post_values['options']['custom_style']) ) ? $_POST['options']['custom_style'] : ( $frm_settings->load_style != 'none' );
921
+ }
922
+
923
+ foreach ( array('before', 'after', 'submit') as $h ) {
924
+ if ( ! isset($values[$h .'_html']) ) {
925
  $values[$h .'_html'] = (isset($post_values['options'][$h .'_html']) ? $post_values['options'][$h .'_html'] : FrmFormsHelper::get_default_html($h));
926
+ }
927
  unset($h);
928
  }
929
+ }
 
 
 
 
930
 
931
+ public static function get_meta_value($field_id, $entry) {
932
+ if ( isset($entry->metas) ) {
933
+ return isset($entry->metas[$field_id]) ? $entry->metas[$field_id] : false;
934
+ } else {
935
+ return FrmEntryMeta::get_entry_meta_by_field($entry->id, $field_id);
936
+ }
937
+ }
938
+
939
+ /*
940
+ * @since 2.0
941
+ * @return string
942
+ */
943
+ public static function get_field_size($field) {
944
+ if ( '' == $field['size'] ) {
945
+ global $frm_vars;
946
+ $field['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
947
+ }
948
+ return $field['size'];
949
  }
950
+
951
+ public static function insert_opt_html($args) {
 
 
952
  $class = '';
953
+ if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
 
954
  $class .= 'show_frm_not_email_to';
955
  }
956
  ?>
957
  <li>
958
+ <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo $args['id'] ?>]</a>
959
+ <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo $class ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo self::truncate($args['key'], 10) ?>]</a>
960
+ <a href="javascript:void(0)" class="frm_insert_code <?php echo $class ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo self::truncate($args['name'], 60) ?></a>
961
  </li>
962
  <?php
963
  }
964
+
965
  public static function get_us_states(){
966
  return apply_filters('frm_us_states', array(
967
+ 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona',
968
  'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware',
969
+ 'DC' => 'District of Columbia',
970
+ 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho',
971
+ 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas',
972
+ 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland',
973
+ 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi',
974
+ 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada',
975
+ 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York',
976
+ 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma',
977
+ 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina',
978
+ 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah',
979
+ 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia',
980
  'WI' => 'Wisconsin', 'WY' => 'Wyoming'
981
  ));
982
  }
983
+
984
  public static function get_countries(){
985
  return apply_filters('frm_countries', array(
986
+ __('Afghanistan', 'formidable'), __('Albania', 'formidable'), __('Algeria', 'formidable'),
987
  __('American Samoa', 'formidable'), __('Andorra', 'formidable'), __('Angola', 'formidable'),
988
+ __('Anguilla', 'formidable'), __('Antarctica', 'formidable'), __('Antigua and Barbuda', 'formidable'),
989
  __('Argentina', 'formidable'), __('Armenia', 'formidable'), __('Aruba', 'formidable'),
990
  __('Australia', 'formidable'), __('Austria', 'formidable'), __('Azerbaijan', 'formidable'),
991
+ __('Bahamas', 'formidable'), __('Bahrain', 'formidable'), __('Bangladesh', 'formidable'),
992
  __('Barbados', 'formidable'), __('Belarus', 'formidable'), __('Belgium', 'formidable'),
993
+ __('Belize', 'formidable'), __('Benin', 'formidable'), __('Bermuda', 'formidable'),
994
  __('Bhutan', 'formidable'), __('Bolivia', 'formidable'), __('Bosnia and Herzegovina', 'formidable'),
995
+ __('Botswana', 'formidable'), __('Brazil', 'formidable'), __('Brunei', 'formidable'),
996
  __('Bulgaria', 'formidable'), __('Burkina Faso', 'formidable'), __('Burundi', 'formidable'),
997
+ __('Cambodia', 'formidable'), __('Cameroon', 'formidable'), __('Canada', 'formidable'),
998
+ __('Cape Verde', 'formidable'), __('Cayman Islands', 'formidable'), __('Central African Republic', 'formidable'),
999
  __('Chad', 'formidable'), __('Chile', 'formidable'), __('China', 'formidable'),
1000
  __('Colombia', 'formidable'), __('Comoros', 'formidable'), __('Congo', 'formidable'),
1001
  __('Costa Rica', 'formidable'), __('C&ocirc;te d\'Ivoire', 'formidable'), __('Croatia', 'formidable'),
1002
+ __('Cuba', 'formidable'), __('Cyprus', 'formidable'), __('Czech Republic', 'formidable'),
1003
  __('Denmark', 'formidable'), __('Djibouti', 'formidable'), __('Dominica', 'formidable'),
1004
+ __('Dominican Republic', 'formidable'), __('East Timor', 'formidable'), __('Ecuador', 'formidable'),
1005
  __('Egypt', 'formidable'), __('El Salvador', 'formidable'), __('Equatorial Guinea', 'formidable'),
1006
+ __('Eritrea', 'formidable'), __('Estonia', 'formidable'), __('Ethiopia', 'formidable'),
1007
+ __('Fiji', 'formidable'), __('Finland', 'formidable'), __('France', 'formidable'),
1008
+ __('French Guiana', 'formidable'), __('French Polynesia', 'formidable'), __('Gabon', 'formidable'),
1009
  __('Gambia', 'formidable'), __('Georgia', 'formidable'), __('Germany', 'formidable'),
1010
+ __('Ghana', 'formidable'), __('Gibraltar', 'formidable'), __('Greece', 'formidable'),
1011
  __('Greenland', 'formidable'), __('Grenada', 'formidable'), __('Guam', 'formidable'),
1012
+ __('Guatemala', 'formidable'), __('Guinea', 'formidable'), __('Guinea-Bissau', 'formidable'),
1013
+ __('Guyana', 'formidable'), __('Haiti', 'formidable'), __('Honduras', 'formidable'),
1014
+ __('Hong Kong', 'formidable'), __('Hungary', 'formidable'), __('Iceland', 'formidable'),
1015
+ __('India', 'formidable'), __('Indonesia', 'formidable'), __('Iran', 'formidable'),
1016
+ __('Iraq', 'formidable'), __('Ireland', 'formidable'), __('Israel', 'formidable'),
1017
+ __('Italy', 'formidable'), __('Jamaica', 'formidable'), __('Japan', 'formidable'),
1018
+ __('Jordan', 'formidable'), __('Kazakhstan', 'formidable'), __('Kenya', 'formidable'),
1019
+ __('Kiribati', 'formidable'), __('North Korea', 'formidable'), __('South Korea', 'formidable'),
1020
+ __('Kuwait', 'formidable'), __('Kyrgyzstan', 'formidable'), __('Laos', 'formidable'),
1021
+ __('Latvia', 'formidable'), __('Lebanon', 'formidable'), __('Lesotho', 'formidable'),
1022
+ __('Liberia', 'formidable'), __('Libya', 'formidable'), __('Liechtenstein', 'formidable'),
1023
+ __('Lithuania', 'formidable'), __('Luxembourg', 'formidable'), __('Macedonia', 'formidable'),
1024
+ __('Madagascar', 'formidable'), __('Malawi', 'formidable'), __('Malaysia', 'formidable'),
1025
+ __('Maldives', 'formidable'), __('Mali', 'formidable'), __('Malta', 'formidable'),
1026
+ __('Marshall Islands', 'formidable'), __('Mauritania', 'formidable'), __('Mauritius', 'formidable'),
1027
+ __('Mexico', 'formidable'), __('Micronesia', 'formidable'), __('Moldova', 'formidable'),
1028
+ __('Monaco', 'formidable'), __('Mongolia', 'formidable'), __('Montenegro', 'formidable'),
1029
+ __('Montserrat', 'formidable'), __('Morocco', 'formidable'), __('Mozambique', 'formidable'),
1030
+ __('Myanmar', 'formidable'), __('Namibia', 'formidable'), __('Nauru', 'formidable'),
1031
  __('Nepal', 'formidable'), __('Netherlands', 'formidable'), __('New Zealand', 'formidable'),
1032
+ __('Nicaragua', 'formidable'), __('Niger', 'formidable'), __('Nigeria', 'formidable'),
1033
+ __('Norway', 'formidable'), __('Northern Mariana Islands', 'formidable'), __('Oman', 'formidable'),
1034
+ __('Pakistan', 'formidable'), __('Palau', 'formidable'), __('Palestine', 'formidable'),
1035
+ __('Panama', 'formidable'), __('Papua New Guinea', 'formidable'), __('Paraguay', 'formidable'),
1036
+ __('Peru', 'formidable'), __('Philippines', 'formidable'), __('Poland', 'formidable'),
1037
+ __('Portugal', 'formidable'), __('Puerto Rico', 'formidable'), __('Qatar', 'formidable'),
1038
+ __('Romania', 'formidable'), __('Russia', 'formidable'), __('Rwanda', 'formidable'),
1039
+ __('Saint Kitts and Nevis', 'formidable'), __('Saint Lucia', 'formidable'),
1040
+ __('Saint Vincent and the Grenadines', 'formidable'), __('Samoa', 'formidable'),
1041
  __('San Marino', 'formidable'), __('Sao Tome and Principe', 'formidable'), __('Saudi Arabia', 'formidable'),
1042
+ __('Senegal', 'formidable'), __('Serbia and Montenegro', 'formidable'), __('Seychelles', 'formidable'),
1043
+ __('Sierra Leone', 'formidable'), __('Singapore', 'formidable'), __('Slovakia', 'formidable'),
1044
+ __('Slovenia', 'formidable'), __('Solomon Islands', 'formidable'), __('Somalia', 'formidable'),
1045
+ __('South Africa', 'formidable'), __('South Sudan', 'formidable'),
1046
+ __('Spain', 'formidable'), __('Sri Lanka', 'formidable'),
1047
+ __('Sudan', 'formidable'), __('Suriname', 'formidable'), __('Swaziland', 'formidable'),
1048
+ __('Sweden', 'formidable'), __('Switzerland', 'formidable'), __('Syria', 'formidable'),
1049
+ __('Taiwan', 'formidable'), __('Tajikistan', 'formidable'), __('Tanzania', 'formidable'),
1050
+ __('Thailand', 'formidable'), __('Togo', 'formidable'), __('Tonga', 'formidable'),
1051
+ __('Trinidad and Tobago', 'formidable'), __('Tunisia', 'formidable'), __('Turkey', 'formidable'),
1052
+ __('Turkmenistan', 'formidable'), __('Tuvalu', 'formidable'), __('Uganda', 'formidable'),
1053
  __('Ukraine', 'formidable'), __('United Arab Emirates', 'formidable'), __('United Kingdom', 'formidable'),
1054
+ __('United States', 'formidable'), __('Uruguay', 'formidable'), __('Uzbekistan', 'formidable'),
1055
+ __('Vanuatu', 'formidable'), __('Vatican City', 'formidable'), __('Venezuela', 'formidable'),
1056
+ __('Vietnam', 'formidable'), __('Virgin Islands, British', 'formidable'),
1057
+ __('Virgin Islands, U.S.', 'formidable'), __('Yemen', 'formidable'), __('Zambia', 'formidable'),
1058
  __('Zimbabwe', 'formidable')
1059
  ));
1060
  }
1061
+
1062
  public static function truncate($str, $length, $minword = 3, $continue = '...'){
1063
  if(is_array($str))
1064
  return;
1065
+
1066
+ $length = (int) $length;
1067
  $str = strip_tags($str);
1068
  $original_len = (function_exists('mb_strlen')) ? mb_strlen($str) : strlen($str);
1069
+
1070
  if($length == 0){
1071
  return '';
1072
  }else if($length <= 10){
1073
  $sub = (function_exists('mb_substr')) ? mb_substr($str, 0, $length) : substr($str, 0, $length);
1074
  return $sub . (($length < $original_len) ? $continue : '');
1075
  }
1076
+
1077
  $sub = '';
1078
  $len = 0;
1079
 
1080
  $words = (function_exists('mb_split')) ? mb_split(' ', $str) : explode(' ', $str);
1081
+
1082
  foreach ($words as $word){
1083
  $part = (($sub != '') ? ' ' : '') . $word;
1084
  $total_len = (function_exists('mb_strlen')) ? mb_strlen($sub . $part) : strlen($sub. $part);
1085
+ if ( $total_len > $length && str_word_count($sub) ) {
1086
  break;
1087
  }
1088
+
1089
  $sub .= $part;
1090
  $len += (function_exists('mb_strlen')) ? mb_strlen($part) : strlen($part);
1091
+
1092
  if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1093
  break;
1094
  }
1095
+
1096
  unset($total_len, $word);
1097
  }
1098
+
1099
  return $sub . (($len < $original_len) ? $continue : '');
1100
  }
1101
+
1102
+ public static function get_formatted_time($date, $date_format = '', $time_format = '' ) {
1103
+ if ( empty($date) ) {
1104
+ return $date;
1105
+ }
1106
+
1107
+ if ( empty($date_format) ) {
1108
+ $date_format = get_option('date_format');
1109
+ }
1110
+
1111
+ if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1112
+ $frmpro_settings = new FrmProSettings();
1113
+ $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1114
+ }
1115
+
1116
+ $do_time = ( date('H:i:s', strtotime($date)) == '00:00:00' ) ? false : true;
1117
+
1118
+ $date = get_date_from_gmt($date);
1119
+
1120
+ $formatted = date_i18n($date_format, strtotime($date));
1121
+
1122
+ if ( $do_time ) {
1123
+
1124
+ if ( empty($time_format) ) {
1125
+ $time_format = get_option('time_format');
1126
+ }
1127
+
1128
+ $trimmed_format = trim($time_format);
1129
+ if ( $time_format && ! empty($trimmed_format) ) {
1130
+ $formatted .= ' '. __('at', 'formidable') .' '. date_i18n($time_format, strtotime($date));
1131
+ }
1132
+ }
1133
+
1134
+ return $formatted;
1135
+ }
1136
+
1137
+ /*
1138
+ * @returns string The time ago in words
1139
+ */
1140
+ public static function human_time_diff( $from, $to = '' ) {
1141
+ if ( empty($to) )
1142
+ $to = time();
1143
+
1144
+ // Array of time period chunks
1145
+ $chunks = array(
1146
+ array( 60 * 60 * 24 * 365 , __( 'year', 'formidable' ), __( 'years', 'formidable' ) ),
1147
+ array( 60 * 60 * 24 * 30 , __( 'month', 'formidable' ), __( 'months', 'formidable' ) ),
1148
+ array( 60 * 60 * 24 * 7, __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ),
1149
+ array( 60 * 60 * 24 , __( 'day', 'formidable' ), __( 'days', 'formidable' ) ),
1150
+ array( 60 * 60 , __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ),
1151
+ array( 60 , __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ),
1152
+ array( 1, __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) )
1153
+ );
1154
+
1155
+ // Difference in seconds
1156
+ $diff = (int) ($to - $from);
1157
+
1158
+ // Something went wrong with date calculation and we ended up with a negative date.
1159
+ if ( $diff < 1)
1160
+ return '0 ' . __( 'seconds', 'formidable' );
1161
+
1162
+ /**
1163
+ * We only want to output one chunks of time here, eg:
1164
+ * x years
1165
+ * xx months
1166
+ * so there's only one bit of calculation below:
1167
+ */
1168
+
1169
+ $count = 0;
1170
+
1171
+ //Step one: the first chunk
1172
+ for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
1173
+ $seconds = $chunks[$i][0];
1174
+
1175
+ // Finding the biggest chunk (if the chunk fits, break)
1176
+ if ( ( $count = floor($diff / $seconds) ) != 0 )
1177
+ break;
1178
+ }
1179
+
1180
+ // Set output var
1181
+ $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
1182
+
1183
+
1184
+ if ( !(int)trim($output) )
1185
+ $output = '0 ' . __( 'seconds', 'formidable' );
1186
+
1187
+ return $output;
1188
+ }
1189
+
1190
  /*
1191
+ * Added for < WP 4.0 compatability
1192
  *
1193
  * @since 1.07.10
1194
  *
1202
  } else {
1203
  $term = like_escape( $term );
1204
  }
1205
+
1206
  return $term;
1207
  }
1208
+
1209
+ public static function esc_order($order_query) {
1210
+ if ( empty($order_query) ) {
1211
+ return '';
1212
+ }
1213
+
1214
+ // remove ORDER BY before santizing
1215
+ $order_query = strtolower($order_query);
1216
+ if ( strpos($order_query, 'order by') !== false ) {
1217
+ $order_query = str_replace('order by', '', $order_query);
1218
+ }
1219
+
1220
+ $order_query = explode(' ', trim($order_query));
1221
+
1222
+ $order_fields = array(
1223
+ 'id', 'form_key', 'name', 'description',
1224
+ 'parent_form_id', 'logged_in', 'is_template',
1225
+ 'default_template', 'status', 'created_at',
1226
+ );
1227
+
1228
+ $order = trim(trim(reset($order_query), ','));
1229
+ if ( ! in_array($order, $order_fields) ) {
1230
+ return '';
1231
+ }
1232
+
1233
+ $order_by = '';
1234
+ if ( count($order_query) > 1 ) {
1235
+ $sort_options = array('asc', 'desc');
1236
+ $order_by = end($order_query);
1237
+ if ( ! in_array($order_by, $sort_options) ) {
1238
+ $order_by = 'asc';
1239
+ }
1240
+ }
1241
+
1242
+ return ' ORDER BY '. $order . ' '. $order_by;
1243
+ }
1244
+
1245
+ public static function esc_limit($limit) {
1246
+ if ( empty($limit) ) {
1247
+ return '';
1248
+ }
1249
+
1250
+ $limit = trim(str_replace(' limit', '', strtolower($limit)));
1251
+ if ( is_numeric($limit) ) {
1252
+ return ' LIMIT '. $limit;
1253
+ }
1254
+
1255
+ $limit = explode(',', trim($limit));
1256
+ foreach ( $limit as $k => $l ) {
1257
+ if ( is_numeric($l) ) {
1258
+ $limit[$k] = $l;
1259
+ }
1260
+ }
1261
+
1262
+ $limit = implode(',', $limit);
1263
+ return ' LIMIT '. $limit;
1264
+ }
1265
+
1266
  public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ){
1267
  if ( empty($where) ) {
1268
  return '';
1269
  }
1270
+
1271
  if(is_array($where)){
1272
+ global $wpdb;
1273
+ $where = self::get_where_clause_and_values( $where );
1274
+ $where = $wpdb->prepare($where['where'], $where['values']);
1275
  }else{
1276
  $where = $starts_with . $where;
1277
  }
1278
+
1279
  return $where;
1280
  }
1281
+
1282
+ /*
1283
+ * Change array into format $wpdb->prepare can use
1284
+ */
1285
+ public static function get_where_clause_and_values( $args ) {
1286
+ $where = '';
1287
+ $values = array();
1288
+ if ( is_array($args) ) {
1289
+ foreach ( $args as $key => $value ) {
1290
+ $where .= empty($where) ? ' WHERE' : ' AND';
1291
+ $where .= ' '. $key .'=';
1292
+ $where .= is_numeric($value) ? ( strpos($value, '.') !== false ? '%f' : '%d' ) : '%s';
1293
+
1294
+ $values[] = $value;
1295
+ }
1296
+ }
1297
+
1298
+ return compact('where', 'values');
1299
+ }
1300
+
1301
  // Pagination Methods
1302
  public static function getLastRecordNum($r_count,$current_p,$p_size){
1303
  return (($r_count < ($current_p * $p_size))?$r_count:($current_p * $p_size));
1309
  else
1310
  return (self::getLastRecordNum($r_count,($current_p - 1),$p_size) + 1);
1311
  }
1312
+
1313
+ public static function &getRecordCount($where = '', $table_name) {
1314
+ $cache_key = 'count_'. $table_name .'_'. maybe_serialize($where);
1315
+ $query = 'SELECT COUNT(*) FROM ' . $table_name . self::prepend_and_or_where(' WHERE ', $where);
1316
+
1317
+ $count = self::check_cache($cache_key, 'formidable', $query, 'get_var');
1318
+
1319
+ return $count;
1320
  }
1321
+
1322
  public static function get_referer_query($query) {
1323
  if (strpos($query, "google.")) {
1324
  //$pattern = '/^.*\/search.*[\?&]q=(.*)$/';
1336
  $querystr = substr($matches[1], 0, strpos($matches[1], '&'));
1337
  return urldecode($querystr);
1338
  }
1339
+
1340
  public static function get_referer_info(){
1341
  $referrerinfo = '';
1342
  $keywords = array();
1344
  if(isset($_SESSION) and isset($_SESSION['frm_http_referer']) and $_SESSION['frm_http_referer']){
1345
  foreach ($_SESSION['frm_http_referer'] as $referer) {
1346
  $referrerinfo .= str_pad("Referer $i: ",20) . $referer. "\r\n";
1347
+ $keywords_used = self::get_referer_query($referer);
1348
  if ($keywords_used)
1349
  $keywords[] = $keywords_used;
1350
 
1351
  $i++;
1352
  }
1353
+
1354
  $referrerinfo .= "\r\n";
1355
  }else{
1356
+ $referrerinfo = self::get_server_value('HTTP_REFERER');
1357
  }
1358
 
1359
  $i = 1;
1362
  $referrerinfo .= str_pad("Page visited $i: ",20) . $page. "\r\n";
1363
  $i++;
1364
  }
1365
+
1366
  $referrerinfo .= "\r\n";
1367
  }
1368
 
1372
  $i++;
1373
  }
1374
  $referrerinfo .= "\r\n";
1375
+
1376
  return $referrerinfo;
1377
  }
1378
+
1379
  public static function json_to_array($json_vars){
1380
  $vars = array();
1381
+ foreach ( $json_vars as $jv ) {
1382
  $jv_name = explode('[', $jv['name']);
1383
+ $last = count($jv_name) - 1;
1384
+ foreach ( $jv_name as $p => $n ) {
1385
  $name = trim($n, ']');
1386
+ if ( ! isset($l1) ) {
 
 
1387
  $l1 = $name;
 
 
 
 
1388
  }
1389
+
1390
+ if ( ! isset($l2) ) {
1391
  $l2 = $name;
 
 
 
 
1392
  }
1393
+
1394
+ $this_val = ( $p == $last ) ? $jv['value'] : array();
1395
+
1396
+ switch ( $p ) {
1397
+ case 0:
1398
+ $l1 = $name;
1399
+ if ( $name == '' ) {
1400
+ $vars[] = $this_val;
1401
+ } else if ( ! isset($vars[$l1]) ) {
1402
+ $vars[$l1] = $this_val;
1403
+ }
1404
+ break;
1405
+
1406
+ case 1:
1407
+ $l2 = $name;
1408
+ if ( $name == '' ) {
1409
+ $vars[$l1][] = $this_val;
1410
+ } else if ( ! isset($vars[$l1][$l2]) ) {
1411
+ $vars[$l1][$l2] = $this_val;
1412
+ }
1413
+ break;
1414
+
1415
+ case 2:
1416
+ $l3 = $name;
1417
+ if ( $name == '' ) {
1418
+ $vars[$l1][$l2][] = $this_val;
1419
+ } else if ( ! isset($vars[$l1][$l2][$l3]) ) {
1420
+ $vars[$l1][$l2][$l3] = $this_val;
1421
+ }
1422
+ break;
1423
  }
1424
+
1425
+ unset($this_val, $n);
 
1426
  }
1427
+
1428
+ unset($last, $jv);
 
1429
  }
1430
+
1431
  return $vars;
1432
  }
1433
+
1434
+ public static function maybe_add_tooltip($name, $class = 'closed', $form_name = '') {
1435
+ $tooltips = array(
1436
+ 'action_title' => __('Give this action a label for easy reference.', 'formidable'),
1437
+ 'email_to' => __('Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable'),
1438
+ 'cc' => __('Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable'),
1439
+ 'bcc' => __('Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable'),
1440
+ 'reply_to' => __('If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable'),
1441
+ 'from' => __('Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable'),
1442
+ 'email_subject' => esc_attr( sprintf( __('If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable'), $form_name, self::site_name() ) ),
1443
+ );
1444
+
1445
+ if ( !isset($tooltips[$name]) ) {
1446
+ return;
1447
+ }
1448
+
1449
+ if ( 'open' == $class ) {
1450
+ echo ' frm_help"';
1451
+ } else {
1452
+ echo ' class="frm_help"';
1453
+ }
1454
+
1455
+ echo ' title="'. esc_attr($tooltips[$name]);
1456
+
1457
+ if ( 'open' != $class ) {
1458
+ echo '"';
1459
+ }
1460
+ }
1461
+
1462
+ /* Prepare and json_encode post content
1463
+ *
1464
+ * Since 2.0
1465
+ *
1466
+ * @param $post_content array
1467
+ * @return $post_content string ( json encoded array )
1468
+ */
1469
+ public static function prepare_and_encode( $post_content ) {
1470
+
1471
+ //Loop through array to strip slashes and add only the needed ones
1472
+ foreach( $post_content as $key => $val ) {
1473
+ if ( isset( $post_content[$key] ) && !is_array( $val ) ) {
1474
+ // Strip all slashes so everything is the same, no matter where the value is coming from
1475
+ $val = stripslashes( $val );
1476
+
1477
+ // Add backslashes before double quotes and forward slashes only
1478
+ $post_content[$key] = addcslashes( $val, '"\\/' );
1479
+ }
1480
+ unset( $key, $val );
1481
+ }
1482
+
1483
+ // json_encode the array
1484
+ $post_content = json_encode( $post_content );
1485
+
1486
+ // add extra slashes for \r\n since WP strips them
1487
+ $post_content = str_replace( array('\\r', '\\n', '\\u'), array('\\\\r', '\\\\n', '\\\\u'), $post_content );
1488
+
1489
+ // allow for &quot
1490
+ $post_content = str_replace( '&quot;', '\\"', $post_content );
1491
+
1492
+ return $post_content;
1493
+ }
1494
+
1495
  public static function maybe_json_decode($string){
1496
+ if ( is_array($string) ) {
1497
+ return $string;
1498
+ }
1499
+
1500
  $new_string = json_decode($string, true);
1501
  if ( function_exists('json_last_error') ) { // php 5.3+
1502
  if ( json_last_error() == JSON_ERROR_NONE ) {
1507
  }
1508
  return $string;
1509
  }
1510
+
 
 
 
 
 
 
 
1511
  /*
1512
  * @since 1.07.10
1513
  *
1520
  if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1521
  return;
1522
  }
1523
+
1524
  if ( is_object($post) && $post->post_type != $post_type ) {
1525
  return;
1526
  }
1527
+
1528
  echo <<<HTML
1529
  <script type="text/javascript">
1530
  jQuery(document).ready(function(){
1534
  </script>
1535
  HTML;
1536
  }
1537
+
1538
  /*
1539
  * @since 1.07.10
1540
  *
1543
  */
1544
  public static function min_version_notice($min_version) {
1545
  $frm_version = self::plugin_version();
1546
+
1547
  // check if Formidable meets minimum requirements
1548
  if ( version_compare($frm_version, $min_version, '>=') ) {
1549
  return;
1550
  }
1551
+
1552
  $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1553
  echo '<tr class="plugin-update-tr active"><th colspan="' . $wp_list_table->get_column_count() . '" class="check-column plugin-update colspanchange"><div class="update-message">'.
1554
  __('You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable') .
1555
  '</div></td></tr>';
1556
  }
1557
+
1558
+ public static function locales( $type = 'date' ) {
1559
+ $locales = array(
1560
+ 'en' => __('English', 'formidable'), '' => __('English/Western', 'formidable'),
1561
+ 'af' => __('Afrikaans', 'formidable'), 'sq' => __('Albanian', 'formidable'),
1562
+ 'ar' => __('Arabic', 'formidable'), 'hy' => __('Armenian', 'formidable'),
1563
+ 'az' => __('Azerbaijani', 'formidable'), 'eu' => __('Basque', 'formidable'),
1564
+ 'bs' => __('Bosnian', 'formidable'), 'bg' => __('Bulgarian', 'formidable'),
1565
+ 'ca' => __('Catalan', 'formidable'), 'zh-HK' => __('Chinese Hong Kong', 'formidable'),
1566
+ 'zh-CN' => __('Chinese Simplified', 'formidable'), 'zh-TW' => __('Chinese Traditional', 'formidable'),
1567
+ 'hr' => __('Croatian', 'formidable'), 'cs' => __('Czech', 'formidable'),
1568
+ 'da' => __('Danish', 'formidable'), 'nl' => __('Dutch', 'formidable'),
1569
+ 'en-GB' => __('English/UK', 'formidable'), 'eo' => __('Esperanto', 'formidable'),
1570
+ 'et' => __('Estonian', 'formidable'), 'fo' => __('Faroese', 'formidable'),
1571
+ 'fa' => __('Farsi/Persian', 'formidable'), 'fil' => __('Filipino', 'formidable'),
1572
+ 'fi' => __('Finnish', 'formidable'), 'fr' => __('French', 'formidable'),
1573
+ 'fr-CA' => __('French/Canadian', 'formidable'), 'fr-CH' => __('French/Swiss', 'formidable'),
1574
+ 'de' => __('German', 'formidable'), 'de-AT' => __('German/Austria', 'formidable'),
1575
+ 'de-CH' => __('German/Switzerland', 'formidable'), 'el' => __('Greek', 'formidable'),
1576
+ 'he' => __('Hebrew', 'formidable'), 'iw' => __('Hebrew', 'formidable'),
1577
+ 'hi' => __('Hindi', 'formidable'), 'hu' => __('Hungarian', 'formidable'),
1578
+ 'is' => __('Icelandic', 'formidable'), 'id' => __('Indonesian', 'formidable'),
1579
+ 'it' => __('Italian', 'formidable'), 'ja' => __('Japanese', 'formidable'),
1580
+ 'ko' => __('Korean', 'formidable'), 'lv' => __('Latvian', 'formidable'),
1581
+ 'lt' => __('Lithuanian', 'formidable'), 'ms' => __('Malaysian', 'formidable'),
1582
+ 'no' => __('Norwegian', 'formidable'), 'pl' => __('Polish', 'formidable'),
1583
+ 'pt' => __('Portuguese', 'formidable'), 'pt-BR' => __('Portuguese/Brazilian', 'formidable'),
1584
+ 'pt-PT' => __('Portuguese/Portugal', 'formidable'), 'ro' => __('Romanian', 'formidable'),
1585
+ 'ru' => __('Russian', 'formidable'), 'sr' => __('Serbian', 'formidable'),
1586
+ 'sr-SR' => __('Serbian', 'formidable'), 'sk' => __('Slovak', 'formidable'),
1587
+ 'sl' => __('Slovenian', 'formidable'), 'es' => __('Spanish', 'formidable'),
1588
+ 'es-419' => __('Spanish/Latin America', 'formidable'), 'sv' => __('Swedish', 'formidable'),
1589
+ 'ta' => __('Tamil', 'formidable'), 'th' => __('Thai', 'formidable'),
1590
+ 'tu' => __('Turkish', 'formidable'), 'tr' => __('Turkish', 'formidable'),
1591
+ 'uk' => __('Ukranian', 'formidable'), 'vi' => __('Vietnamese', 'formidable'),
1592
+ );
1593
+
1594
+ if ( $type == 'captcha' ) {
1595
+ // remove the languages unavailable for the captcha
1596
+ $unset = array(
1597
+ '', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1598
+ 'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1599
+ 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1600
+ );
1601
+ } else {
1602
+ // remove the languages unavailable for the datepicker
1603
+ $unset = array(
1604
+ 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1605
+ 'de-CH', 'iw', 'hi', 'id', 'pt', 'pt-PT',
1606
+ 'es-419', 'tr',
1607
+ );
1608
+ }
1609
+
1610
+ $locales = array_diff_key($locales, array_flip($unset));
1611
+ $locales = apply_filters('frm_locales', $locales);
1612
+
1613
+ return $locales;
1614
+ }
1615
  }
classes/helpers/FrmEntriesHelper.php CHANGED
@@ -1,145 +1,132 @@
1
  <?php
2
-
3
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
4
 
5
- if(class_exists('FrmEntriesHelper'))
6
- return;
7
-
8
  class FrmEntriesHelper{
9
 
10
  public static function setup_new_vars($fields, $form='', $reset=false){
11
- global $frm_settings, $frm_vars;
12
  $values = array();
13
- foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default)
14
  $values[$var] = FrmAppHelper::get_post_param($var, $default);
15
-
 
16
  $values['fields'] = array();
17
- if (empty($fields)){
18
  return apply_filters('frm_setup_new_entry', $values);
19
  }
20
-
21
  foreach ( (array) $fields as $field ) {
22
- $field->field_options = maybe_unserialize($field->field_options);
23
  $default = $field->default_value;
24
  $posted_val = false;
25
-
26
- if ( $reset ) {
27
- $new_value = $default;
28
- } else if ( $_POST && isset($_POST['item_meta'][$field->id]) && $_POST['item_meta'][$field->id] != '' ) {
29
  $new_value = stripslashes_deep($_POST['item_meta'][$field->id]);
30
  $posted_val = true;
31
  } else if ( isset($field->field_options['clear_on_focus']) && $field->field_options['clear_on_focus'] ) {
32
  $new_value = '';
33
- } else {
34
- $new_value = $default;
35
  }
36
-
37
  $is_default = ($new_value == $default) ? true : false;
38
-
39
  //If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
40
- if ( $field && ( ( $field->type == 'data' && $field->field_options['data_type'] == 'checkbox' ) || $field->type == 'checkbox' || ( $field->type == 'select' && $field->field_options['multiple'] == 1 ) ) ) {
41
- $return_array = true;
42
- } else {
43
- $return_array = false;
44
- }
45
-
46
  $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
47
-
48
  if ( !is_array($new_value) ) {
49
  if ( $is_default ) {
50
  $new_value = $field->default_value;
51
  } else if ( !$posted_val ) {
52
  $new_value = apply_filters('frm_filter_default_value', $new_value, $field);
53
  }
54
-
55
  $new_value = str_replace('"', '&quot;', $new_value);
56
  }
57
-
58
- unset($is_default);
59
- unset($posted_val);
60
-
61
- $field_array = array(
62
- 'id' => $field->id,
63
- 'value' => $new_value,
64
- 'default_value' => $field->default_value,
65
- 'name' => $field->name,
66
- 'description' => $field->description,
67
- 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
68
- 'options' => $field->options,
69
- 'required' => $field->required,
70
- 'field_key' => $field->field_key,
71
- 'field_order' => $field->field_order,
72
- 'form_id' => $field->form_id
73
- );
74
-
75
- $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
76
- $opt_defaults['required_indicator'] = '';
77
-
78
- foreach ($opt_defaults as $opt => $default_opt){
79
- $field_array[$opt] = (isset($field->field_options[$opt]) && $field->field_options[$opt] != '') ? $field->field_options[$opt] : $default_opt;
80
- unset($opt);
81
- unset($default_opt);
82
- }
83
-
84
- unset($opt_defaults);
85
-
86
- if ($field_array['size'] == '')
87
- $field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
88
-
89
-
90
- if ($field_array['custom_html'] == '')
91
- $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
92
-
93
- $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
94
-
95
- foreach((array)$field->field_options as $k => $v){
96
- if(!isset($field_array[$k]))
97
  $field_array[$k] = $v;
98
- unset($k);
99
- unset($v);
100
- }
101
-
102
- $values['fields'][] = $field_array;
103
-
104
- if (!$form or !isset($form->id)){
105
- $frm_form = new FrmForm();
106
- $form = $frm_form->getOne($field->form_id);
107
  }
 
 
 
 
 
 
 
 
108
  }
109
 
110
- $form->options = maybe_unserialize($form->options);
111
- if (is_array($form->options)){
112
- foreach ($form->options as $opt => $value)
113
- $values[$opt] = FrmAppHelper::get_post_param($opt, $value);
114
  }
115
-
116
- if (!isset($values['custom_style']))
117
- $values['custom_style'] = ($frm_settings->load_style != 'none');
118
-
119
- if (!isset($values['email_to']))
120
- $values['email_to'] = '';
121
 
122
- if (!isset($values['submit_value']))
123
- $values['submit_value'] = $frm_settings->submit_value;
124
 
125
- if (!isset($values['success_msg']))
126
- $values['success_msg'] = $frm_settings->success_msg;
 
 
 
 
 
 
127
 
128
- if (!isset($values['akismet']))
129
- $values['akismet'] = '';
130
 
131
- if (!isset($values['before_html']))
132
- $values['before_html'] = FrmFormsHelper::get_default_html('before');
 
 
 
 
 
 
 
 
 
133
 
134
- if (!isset($values['after_html']))
135
- $values['after_html'] = FrmFormsHelper::get_default_html('after');
136
-
137
- if (!isset($values['submit_html']))
138
- $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
139
-
140
  return apply_filters('frm_setup_new_entry', $values);
141
  }
142
-
143
  public static function setup_edit_vars($values, $record){
144
  //$values['description'] = maybe_unserialize( $record->description );
145
  $values['item_key'] = isset($_POST['item_key']) ? $_POST['item_key'] : $record->item_key;
@@ -147,20 +134,261 @@ class FrmEntriesHelper{
147
  $values['is_draft'] = $record->is_draft;
148
  return apply_filters('frm_setup_edit_entry_vars', $values, $record);
149
  }
150
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  public static function replace_default_message($message, $atts) {
152
- if ( strpos($message, '[default-message') === false &&
153
- strpos($message, '[default_message') === false &&
154
  !empty($message) ) {
155
  return $message;
156
  }
157
-
158
  if ( empty($message) ) {
159
  $message = '[default-message]';
160
  }
161
-
162
  preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
163
-
164
  foreach ( $shortcodes[0] as $short_key => $tag ) {
165
  $add_atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
166
  if ( $add_atts ){
@@ -168,26 +396,245 @@ class FrmEntriesHelper{
168
  } else {
169
  $this_atts = $atts;
170
  }
171
-
172
  $default = FrmEntriesController::show_entry_shortcode($this_atts);
173
-
174
  // Add the default message
175
  $message = str_replace($shortcodes[0][$short_key], $default, $message);
176
  }
177
 
178
  return $message;
179
  }
180
-
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
- public static function entries_dropdown( $form_id, $field_name, $field_value='', $blank=true, $blank_label='', $onchange=false ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  _deprecated_function( __FUNCTION__, '1.07.09');
185
  }
186
-
187
  public static function enqueue_scripts($params){
188
  do_action('frm_enqueue_form_scripts', $params);
189
  }
190
-
191
  // Add submitted values to a string for spam checking
192
  public static function entry_array_to_string($values) {
193
  $content = '';
@@ -195,14 +642,14 @@ class FrmEntriesHelper{
195
  if ( $content != '' ) {
196
  $content .= "\n\n";
197
  }
198
-
199
  if ( is_array($val) ) {
200
  $val = implode(',', $val);
201
  }
202
-
203
  $content .= $val;
204
  }
205
-
206
  return $content;
207
  }
208
  }
1
  <?php
 
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
 
 
 
4
  class FrmEntriesHelper{
5
 
6
  public static function setup_new_vars($fields, $form='', $reset=false){
7
+ global $frm_vars;
8
  $values = array();
9
+ foreach ( array('name' => '', 'description' => '', 'item_key' => '') as $var => $default ) {
10
  $values[$var] = FrmAppHelper::get_post_param($var, $default);
11
+ }
12
+
13
  $values['fields'] = array();
14
+ if ( empty($fields) ) {
15
  return apply_filters('frm_setup_new_entry', $values);
16
  }
17
+
18
  foreach ( (array) $fields as $field ) {
 
19
  $default = $field->default_value;
20
  $posted_val = false;
21
+ $new_value = $default;
22
+
23
+ if ( ! $reset && $_POST && isset($_POST['item_meta'][$field->id]) && $_POST['item_meta'][$field->id] != '' ) {
 
24
  $new_value = stripslashes_deep($_POST['item_meta'][$field->id]);
25
  $posted_val = true;
26
  } else if ( isset($field->field_options['clear_on_focus']) && $field->field_options['clear_on_focus'] ) {
27
  $new_value = '';
 
 
28
  }
29
+
30
  $is_default = ($new_value == $default) ? true : false;
31
+
32
  //If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
33
+ $return_array = FrmFieldsHelper::is_field_with_multiple_values( $field );
34
+
 
 
 
 
35
  $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
36
+
37
  if ( !is_array($new_value) ) {
38
  if ( $is_default ) {
39
  $new_value = $field->default_value;
40
  } else if ( !$posted_val ) {
41
  $new_value = apply_filters('frm_filter_default_value', $new_value, $field);
42
  }
43
+
44
  $new_value = str_replace('"', '&quot;', $new_value);
45
  }
46
+
47
+ unset($is_default, $posted_val);
48
+
49
+ $field_array = array(
50
+ 'id' => $field->id,
51
+ 'value' => $new_value,
52
+ 'default_value' => $field->default_value,
53
+ 'name' => $field->name,
54
+ 'description' => $field->description,
55
+ 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value),
56
+ 'options' => $field->options,
57
+ 'required' => $field->required,
58
+ 'field_key' => $field->field_key,
59
+ 'field_order' => $field->field_order,
60
+ 'form_id' => $field->form_id
61
+ );
62
+
63
+ $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
64
+ $opt_defaults['required_indicator'] = '';
65
+
66
+ foreach ($opt_defaults as $opt => $default_opt){
67
+ $field_array[$opt] = (isset($field->field_options[$opt]) && $field->field_options[$opt] != '') ? $field->field_options[$opt] : $default_opt;
68
+ unset($opt, $default_opt);
69
+ }
70
+
71
+ unset($opt_defaults);
72
+
73
+ $field_array['size'] = FrmAppHelper::get_field_size($field_array);
74
+
75
+ if ( $field_array['custom_html'] == '' ) {
76
+ $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
77
+ }
78
+
79
+ $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
80
+
81
+ foreach ( (array) $field->field_options as $k => $v ) {
82
+ if ( ! isset($field_array[$k]) ) {
 
 
 
83
  $field_array[$k] = $v;
 
 
 
 
 
 
 
 
 
84
  }
85
+ unset($k, $v);
86
+ }
87
+
88
+ $values['fields'][] = $field_array;
89
+
90
+ if ( ! $form || ! isset($form->id) ) {
91
+ $form = FrmForm::getOne($field->form_id);
92
+ }
93
  }
94
 
95
+ $form->options = maybe_unserialize($form->options);
96
+ if ( is_array($form->options) ) {
97
+ foreach ( $form->options as $opt => $value ) {
98
+ $values[$opt] = FrmAppHelper::get_post_param($opt, $value);
99
  }
100
+ }
 
 
 
 
 
101
 
102
+ $frm_settings = FrmAppHelper::get_settings();
 
103
 
104
+ $form_defaults = array(
105
+ 'custom_style' => ($frm_settings->load_style != 'none'),
106
+ 'email_to' => '',
107
+ 'submit_value' => $frm_settings->submit_value,
108
+ 'success_msg' => $frm_settings->success_msg,
109
+ 'akismet' => '',
110
+ 'form_class' => '',
111
+ );
112
 
113
+ $values = array_merge($form_defaults, $values);
 
114
 
115
+ if ( ! isset($values['before_html']) ) {
116
+ $values['before_html'] = FrmFormsHelper::get_default_html('before');
117
+ }
118
+
119
+ if ( ! isset($values['after_html']) ) {
120
+ $values['after_html'] = FrmFormsHelper::get_default_html('after');
121
+ }
122
+
123
+ if ( ! isset($values['submit_html']) ) {
124
+ $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
125
+ }
126
 
 
 
 
 
 
 
127
  return apply_filters('frm_setup_new_entry', $values);
128
  }
129
+
130
  public static function setup_edit_vars($values, $record){
131
  //$values['description'] = maybe_unserialize( $record->description );
132
  $values['item_key'] = isset($_POST['item_key']) ? $_POST['item_key'] : $record->item_key;
134
  $values['is_draft'] = $record->is_draft;
135
  return apply_filters('frm_setup_edit_entry_vars', $values, $record);
136
  }
137
+
138
+ public static function get_admin_params($form=null){
139
+ $form_id = $form;
140
+ if ( $form === null ) {
141
+ $form_id = self::get_current_form_id();
142
+ } else if ( $form && is_object($form) ) {
143
+ $form_id = $form->id;
144
+ }
145
+
146
+ $values = array();
147
+ foreach ( array(
148
+ 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form_id,
149
+ 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
150
+ 'keep_post' => ''
151
+ ) as $var => $default ) {
152
+ $values[$var] = FrmAppHelper::get_param($var, $default);
153
+ }
154
+
155
+ return $values;
156
+ }
157
+
158
+ public static function set_current_form($form_id){
159
+ global $frm_vars, $wpdb;
160
+
161
+ $query = $wpdb->prepare('is_template=%d AND (status is NULL OR status = %s OR status = %s)', '0', '', 'published');
162
+ if ( $form_id ) {
163
+ $query .= $wpdb->prepare(' AND id = %d', $form_id);
164
+ }
165
+ $frm_vars['current_form'] = FrmForm::getAll($query, 'name', 1);
166
+
167
+ return $frm_vars['current_form'];
168
+ }
169
+
170
+ public static function get_current_form($form_id = 0) {
171
+ global $frm_vars, $wpdb;
172
+
173
+ if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
174
+ if ( ! $form_id || $form_id == $frm_vars['current_form']->id ) {
175
+ return $frm_vars['current_form'];
176
+ }
177
+ }
178
+
179
+ $form_id = FrmAppHelper::get_param('form', $form_id);
180
+ return self::set_current_form($form_id);
181
+ }
182
+
183
+ public static function get_current_form_id(){
184
+ $form = self::get_current_form();
185
+ $form_id = $form ? $form->id : 0;
186
+
187
+ return $form_id;
188
+ }
189
+
190
+ /*
191
+ * If $entry is numeric, get the entry object
192
+ */
193
+ public static function maybe_get_entry( &$entry ) {
194
+ if ( $entry && is_numeric($entry) ) {
195
+ $entry = FrmEntry::getOne($entry);
196
+ }
197
+ }
198
+
199
+ public static function fill_entry_values($atts, $f, array &$values) {
200
+ if ( FrmFieldsHelper::is_no_save_field($f->type) ) {
201
+ return;
202
+ }
203
+
204
+ if ( $atts['default_email'] ) {
205
+ $values[$f->id] = array('label' => '['. $f->id .' show=field_label]', 'val' => '['. $f->id .']');
206
+ return;
207
+ }
208
+
209
+ //Remove signature from default-message shortcode
210
+ if ( $f->type == 'signature' ) {
211
+ return;
212
+ }
213
+
214
+ if ( $atts['entry'] && !isset($atts['entry']->metas[$f->id]) ) {
215
+ // In case include_blank is set
216
+ $atts['entry']->metas[$f->id] = '';
217
+
218
+ if ( FrmAppHelper::pro_is_installed() ) {
219
+ // If field is a post field
220
+ if ( $atts['entry']->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
221
+ $p_val = FrmProEntryMetaHelper::get_post_value($atts['entry']->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
222
+ 'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
223
+ 'form_id' => $atts['entry']->form_id, 'field' => $f, 'type' => $f->type,
224
+ 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
225
+ ));
226
+ if ( $p_val != '' ) {
227
+ $atts['entry']->metas[$f->id] = $p_val;
228
+ }
229
+ }
230
+
231
+ // If field is in a repeating section
232
+ if ( $atts['entry']->form_id != $f->form_id ) {
233
+ // get entry ids linked through repeat field or embeded form
234
+ $child_entries = FrmProEntry::get_sub_entries($atts['entry']->id, true);
235
+ $val = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $f);
236
+ if ( !empty( $val ) ) {
237
+ $atts['entry']->metas[$f->id] = $val;
238
+ }
239
+ }
240
+ }
241
+
242
+ // Don't include blank values
243
+ if ( ! $atts['include_blank'] && FrmAppHelper::is_empty_value( $atts['entry']->metas[$f->id] ) ) {
244
+ return;
245
+ }
246
+ }
247
+
248
+ $val = '';
249
+ if ( $atts['entry'] ) {
250
+ $prev_val = maybe_unserialize($atts['entry']->metas[$f->id]);
251
+ $meta = array('item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
252
+
253
+ //This filter applies to the default-message shortcode and frm-show-entry shortcode only
254
+ $val = apply_filters('frm_email_value', $prev_val, (object) $meta, $atts['entry']);
255
+ }
256
+
257
+ self::textarea_display_value( $val, $f->type, $atts['plain_text'] );
258
+
259
+ if ( is_array($val) && $atts['format'] == 'text' ) {
260
+ $val = implode(', ', $val);
261
+ }
262
+
263
+ if ( $atts['format'] != 'text' ) {
264
+ $values[$f->field_key] = $val;
265
+ } else {
266
+ $values[$f->id] = array('label' => $f->name, 'val' => $val);
267
+ }
268
+ }
269
+
270
+ /*
271
+ * Replace returns with HTML line breaks for display
272
+ * @ since 2.0
273
+ */
274
+ public static function textarea_display_value( &$value, $type, $plain_text ) {
275
+ if ( $type == 'textarea' && ! $plain_text ) {
276
+ $value = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $value);
277
+ }
278
+ }
279
+
280
+ public static function fill_entry_user_info($atts, array &$values) {
281
+ if ( ! $atts['user_info'] ) {
282
+ return;
283
+ }
284
+
285
+ if ( isset($atts['entry']->description) ) {
286
+ $data = maybe_unserialize($atts['entry']->description);
287
+ } else if ( $atts['default_email'] ) {
288
+ $atts['entry']->ip = '[ip]';
289
+ $data = array(
290
+ 'browser' => '[browser]',
291
+ 'referrer' => '[referrer]',
292
+ );
293
+ } else {
294
+ $data = array(
295
+ 'browser' => '',
296
+ 'referrer' => '',
297
+ );
298
+ }
299
+
300
+ if ( $atts['format'] != 'text' ) {
301
+ $values['ip'] = $atts['entry']->ip;
302
+ $values['browser'] = $data['browser'];
303
+ $values['referrer'] = $data['referrer'];
304
+ } else {
305
+ //$content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
306
+ $values['ip'] = array('label' => __('IP Address', 'formidable'), 'val' => $atts['entry']->ip);
307
+ $values['browser'] = array('label' => __('User-Agent (Browser/OS)', 'formidable'), 'val' => $data['browser']);
308
+ $values['referrer'] = array('label' => __('Referrer', 'formidable'), 'val' => $data['referrer']);
309
+ }
310
+ }
311
+
312
+ public static function convert_entry_to_content($values, $atts, array &$content) {
313
+
314
+ if ( $atts['plain_text'] ) {
315
+ $bg_color_alt = $row_style = '';
316
+ } else {
317
+ $default_settings = apply_filters('frm_show_entry_styles', array(
318
+ 'border_color' => 'dddddd',
319
+ 'bg_color' => 'f7f7f7',
320
+ 'text_color' => '444444',
321
+ 'font_size' => '12px',
322
+ 'border_width' => '1px',
323
+ 'alt_bg_color' => 'ffffff',
324
+ ) );
325
+
326
+ // merge defaults, global settings, and shortcode options
327
+ foreach ( $default_settings as $key => $setting ) {
328
+ if ( $atts[$key] != '' ) {
329
+ continue;
330
+ }
331
+
332
+ $atts[$key] = $setting;
333
+ unset($key, $setting);
334
+ }
335
+
336
+ unset($default_settings);
337
+
338
+ $content[] = '<table cellspacing="0" style="font-size:'. $atts['font_size'] .';line-height:135%; border-bottom:'. $atts['border_width'] .' solid #'. $atts['border_color'] .';"><tbody>'."\r\n";
339
+ $atts['bg_color'] = ' style="background-color:#'. $atts['bg_color'] .';"';
340
+ $bg_color_alt = ' style="background-color:#'. $atts['alt_bg_color'] .';"';
341
+ $row_style = 'style="text-align:'. ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) .';color:#'. $atts['text_color'] .';padding:7px 9px;border-top:'. $atts['border_width'] .' solid #'. $atts['border_color'] .'"';
342
+ }
343
+
344
+ $odd = true;
345
+ foreach ( $values as $id => $value ) {
346
+ if ( $atts['plain_text'] ) {
347
+ if ( 'rtl' == $atts['direction'] ) {
348
+ $content[] = $value['val'] . ' :'. $value['label'] ."\r\n";
349
+ } else {
350
+ $content[] = $value['label'] . ': '. $value['val'] ."\r\n";
351
+ }
352
+ continue;
353
+ }
354
+
355
+ if ( $atts['default_email'] && is_numeric($id) ) {
356
+ $content[] = '[if '. $id .']<tr style="[frm-alt-color]">';
357
+ } else {
358
+ $content[] = '<tr'. ( $odd ? $atts['bg_color'] : $bg_color_alt ) .'>';
359
+ }
360
+
361
+ if ( 'rtl' == $atts['direction'] ) {
362
+ $content[] = '<td '. $row_style .'>'. $value['val'] .'</td><th '. $row_style .'>'. $value['label'] . '</th>';
363
+ } else {
364
+ $content[] = '<th '. $row_style .'>'. $value['label'] .'</th><td '. $row_style .'>'. $value['val'] .'</td>';
365
+ }
366
+ $content[] = '</tr>'. "\r\n";
367
+
368
+ if ( $atts['default_email'] && is_numeric($id) ) {
369
+ $content[] = '[/if '. $id .']';
370
+ }
371
+ $odd = $odd ? false : true;
372
+ }
373
+
374
+ if ( ! $atts['plain_text'] ) {
375
+ $content[] = '</tbody></table>';
376
+ }
377
+ }
378
+
379
  public static function replace_default_message($message, $atts) {
380
+ if ( strpos($message, '[default-message') === false &&
381
+ strpos($message, '[default_message') === false &&
382
  !empty($message) ) {
383
  return $message;
384
  }
385
+
386
  if ( empty($message) ) {
387
  $message = '[default-message]';
388
  }
389
+
390
  preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER);
391
+
392
  foreach ( $shortcodes[0] as $short_key => $tag ) {
393
  $add_atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
394
  if ( $add_atts ){
396
  } else {
397
  $this_atts = $atts;
398
  }
399
+
400
  $default = FrmEntriesController::show_entry_shortcode($this_atts);
401
+
402
  // Add the default message
403
  $message = str_replace($shortcodes[0][$short_key], $default, $message);
404
  }
405
 
406
  return $message;
407
  }
 
408
 
409
+ public static function prepare_display_value($entry, $field, $atts) {
410
+ $field_value = isset($entry->metas[$field->id]) ? $entry->metas[$field->id] : false;
411
+ if ( FrmAppHelper::pro_is_installed() ) {
412
+ FrmProEntriesHelper::get_dfe_values($field, $entry, $field_value);
413
+ }
414
+
415
+ if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) {
416
+ return self::display_value($field_value, $field, $atts);
417
+ }
418
+
419
+ // this is an embeded form
420
+ $val = '';
421
+
422
+ if ( strpos($atts['embedded_field_id'], 'form') === 0 ) {
423
+ //this is a repeating section
424
+ $child_entries = FrmEntry::getAll( array('it.parent_item_id' => $entry->id) );
425
+ } else {
426
+ // get all values for this field
427
+ $child_values = isset($entry->metas[$atts['embedded_field_id']]) ? $entry->metas[$atts['embedded_field_id']] : false;
428
+
429
+ if ( $child_values ) {
430
+ $child_entries = FrmEntry::getAll('it.id in ('. implode(',', array_filter( (array) $child_values, 'is_numeric') ) .')');
431
+ //$atts['post_id']
432
+ }
433
+ }
434
+
435
+ $field_value = array();
436
+
437
+ if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
438
+ return $val;
439
+ }
440
+
441
+ foreach ( $child_entries as $child_entry ) {
442
+ $atts['item_id'] = $child_entry->id;
443
+ $atts['post_id'] = $child_entry->post_id;
444
+
445
+ // get the value for this field -- check for post values as well
446
+ $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
447
+
448
+ if ( $entry_val ) {
449
+ // foreach entry get display_value
450
+ $field_value[] = self::display_value($entry_val, $field, $atts);
451
+ }
452
+
453
+ unset($child_entry);
454
+ }
455
+
456
+ $val = implode(', ', (array) $field_value );
457
+
458
+ return $val;
459
+ }
460
+
461
+ /*
462
+ * Prepare the saved value for display
463
+ * @return string
464
+ */
465
+ public static function display_value($value, $field, $atts = array()) {
466
+
467
+ $defaults = array(
468
+ 'type' => '', 'html' => false, 'show_filename' => true,
469
+ 'truncate' => false, 'sep' => ', ', 'post_id' => 0,
470
+ 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0,
471
+ );
472
+
473
+ $atts = wp_parse_args( $atts, $defaults );
474
+ $atts = apply_filters('frm_display_value_atts', $atts, $field, $value);
475
+
476
+ if ( ! isset($field->field_options['post_field']) ) {
477
+ $field->field_options['post_field'] = '';
478
+ }
479
+
480
+ if ( ! isset($field->field_options['custom_field']) ) {
481
+ $field->field_options['custom_field'] = '';
482
+ }
483
+
484
+ if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
485
+ $atts['pre_truncate'] = $atts['truncate'];
486
+ $atts['truncate'] = true;
487
+ $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0;
488
+
489
+ $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts);
490
+ $atts['truncate'] = $atts['pre_truncate'];
491
+ }
492
+
493
+ if ( $value == '' ) {
494
+ return $value;
495
+ }
496
+
497
+ $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts);
498
+
499
+ $new_value = '';
500
+
501
+ if ( is_array($value) && $atts['type'] != 'file' ) {
502
+ foreach ( $value as $val ) {
503
+ if ( is_array($val) ) { //TODO: add options for display (li or ,)
504
+ $new_value .= implode($atts['sep'], $val);
505
+ if ( $atts['type'] != 'data' ) {
506
+ $new_value .= '<br/>';
507
+ }
508
+ }
509
+ unset($val);
510
+ }
511
+ }
512
+
513
+ if ( ! empty($new_value) ) {
514
+ $value = $new_value;
515
+ } else if ( is_array($value) && $atts['type'] != 'file' ) {
516
+ $value = implode($atts['sep'], $value);
517
+ }
518
+
519
+ if ( $atts['truncate'] && $atts['type'] != 'image' ) {
520
+ $value = FrmAppHelper::truncate($value, 50);
521
+ }
522
+
523
+ return apply_filters('frm_display_value', $value, $field, $atts);
524
+ }
525
+
526
+ /**
527
+ * Sets radio or checkbox value equal to "other" value if it is set
528
+ * @since 2.0
529
+ *
530
+ * @param $values array of posted values
531
+ * @param $clear_vals boolean. If Other vals are not cleared by JavaScript when selection is changed, this should be set to true. Other vals are not cleared with JavaScript on the back-end.
532
+ * @return array of updated POST values
533
+ */
534
+ public static function set_other_vals( $values, $clear_vals = false ){
535
+ if ( ! isset( $values['item_meta']['other'] ) ) {
536
+ return $values;
537
+ }
538
+
539
+ $other_array = $values['item_meta']['other'];
540
+ foreach ( $other_array as $f_id => $o_val ) {
541
+ //For checkboxes
542
+ if ( is_array( $o_val ) ) {
543
+ foreach ( $o_val as $opt_key => $opt_val ) {
544
+ $_POST['item_meta'][$f_id][$opt_key] = $values['item_meta'][$f_id][$opt_key] = $opt_val;
545
+ unset( $opt_key, $opt_val );
546
+ }
547
+ //For radio buttons
548
+ } else if ( $o_val ) {
549
+ // If Other vals weren't cleared with JS (like on the back-end), check if they need to be cleared now
550
+ if ( $clear_vals && isset( $values['item_meta'][$f_id] ) && !empty( $values['item_meta'][$f_id] ) ) {
551
+ $field = FrmField::getOne( $f_id );
552
+ $array = array_filter( $field->options, 'is_numeric', ARRAY_FILTER_USE_KEY );
553
+ // Check if posted value is NOT equal to other value
554
+ if ( !in_array( $values['item_meta'][$f_id], $array ) ) {
555
+ $_POST['item_meta'][$f_id] = $values['item_meta'][$f_id] = $o_val;
556
+ }
557
+ unset( $array );
558
+ } else {
559
+ $_POST['item_meta'][$f_id] = $values['item_meta'][$f_id] = $o_val;
560
+ }
561
+ }
562
+ }
563
+ unset( $_POST['item_meta']['other'] );
564
+
565
+ return $values;
566
+ }
567
+
568
+ /*
569
+ * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
570
+ * @since 2.0
571
+ * @return array of updated POST values
572
+ */
573
+ public static function set_other_repeating_vals( $values, $field ){
574
+ if ( ( $field->type == 'divider' && $field->field_options['repeat'] ) || $field->type == 'form' ) {
575
+ // do nothing
576
+ } else {
577
+ return $values;
578
+ }
579
+
580
+ foreach ( $values['item_meta'][$field->id] as $k => $val ) {
581
+ if ( ! isset( $val['other'] ) || ! is_array( $val['other'] ) ) {
582
+ continue;
583
+ }
584
+
585
+ foreach ( $val['other'] as $sub_fid => $o_val ) {
586
+
587
+ //For checkboxes
588
+ if ( is_array( $o_val ) ) {
589
+ foreach ( $o_val as $opt_key => $opt_val ) {
590
+ $values['item_meta'][$field->id][$k][$sub_fid][$opt_key] = $opt_val;
591
+ unset( $values['item_meta'][$field->id][$k]['other'][$sub_fid][$opt_key] );
592
+ unset( $opt_key, $opt_val );
593
+ }
594
+
595
+ //For radio buttons
596
+ } else if ( $o_val ) {
597
+ $values['item_meta'][$field->id][$k][$sub_fid] = $o_val;
598
+ unset( $values['item_meta'][$field->id][$k]['other'][$sub_fid] );
599
+ }
600
+ unset( $sub_fid, $o_val);
601
+ }
602
+
603
+ unset( $k, $val );
604
+ }
605
+
606
+ return $values;
607
+ }
608
 
609
+ public static function set_posted_value($field, $value, $args) {
610
+ if ( empty($args['parent_field_id']) ) {
611
+ $_POST['item_meta'][$field->id] = $value;
612
+ } else {
613
+ $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field->id] = $value;
614
+ }
615
+ }
616
+
617
+ public static function get_posted_value($field, &$value, $args) {
618
+ if ( is_object( $field ) ) {
619
+ $field_id = $field->id;
620
+ } else {
621
+ $field_id = $field;
622
+ }
623
+ if ( empty($args['parent_field_id']) ) {
624
+ $value = isset($_POST['item_meta'][$field_id]) ? $_POST['item_meta'][$field_id] : '';
625
+ } else {
626
+ $value = $_POST['item_meta'][$args['parent_field_id']][$args['key_pointer']][$field_id];
627
+ }
628
+ }
629
+
630
+ public static function entries_dropdown() {
631
  _deprecated_function( __FUNCTION__, '1.07.09');
632
  }
633
+
634
  public static function enqueue_scripts($params){
635
  do_action('frm_enqueue_form_scripts', $params);
636
  }
637
+
638
  // Add submitted values to a string for spam checking
639
  public static function entry_array_to_string($values) {
640
  $content = '';
642
  if ( $content != '' ) {
643
  $content .= "\n\n";
644
  }
645
+
646
  if ( is_array($val) ) {
647
  $val = implode(',', $val);
648
  }
649
+
650
  $content .= $val;
651
  }
652
+
653
  return $content;
654
  }
655
  }
classes/helpers/FrmEntriesListHelper.php ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmEntriesListHelper extends FrmListHelper {
4
+
5
+ function prepare_items() {
6
+ global $wpdb, $per_page;
7
+
8
+ $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page');
9
+
10
+ $form_id = $this->params['form'];
11
+ if ( ! $form_id ) {
12
+ $this->items = array();
13
+ $this->set_pagination_args( array(
14
+ 'total_items' => 0,
15
+ 'per_page' => $per_page
16
+ ) );
17
+ return;
18
+ }
19
+
20
+ $default_orderby = 'id';
21
+ $default_order = 'DESC';
22
+
23
+ $s_query = $wpdb->prepare('it.form_id=%d', $form_id);
24
+
25
+ $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
26
+
27
+ if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
28
+ $fid = isset( $_REQUEST['fid'] ) ? $_REQUEST['fid'] : '';
29
+ $s_query = FrmProEntriesHelper::get_search_str($s_query, $s, $form_id, $fid);
30
+ }
31
+
32
+ $orderby = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : $default_orderby;
33
+ if ( strpos($orderby, 'meta') !== false ) {
34
+ $order_field = FrmField::getOne(str_replace('meta_', '', $orderby));
35
+ $orderby .= in_array($order_field->type, array('number', 'scale')) ? ' +0 ' : '';
36
+ }
37
+ $order = isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : $default_order;
38
+ $page = $this->get_pagenum();
39
+ $start = isset( $_REQUEST['start'] ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
40
+
41
+ $this->items = FrmEntry::getAll($s_query, ' ORDER BY '. $orderby .' '. $order, ' LIMIT '. $start .','. $per_page, true, false);
42
+ $total_items = FrmEntry::getRecordCount($s_query);
43
+
44
+ $this->set_pagination_args( array(
45
+ 'total_items' => $total_items,
46
+ 'per_page' => $per_page
47
+ ) );
48
+ }
49
+
50
+ function no_items() {
51
+ $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
52
+ if ( ! empty($s) ) {
53
+ _e('No Entries Found', 'formidable');
54
+ return;
55
+ }
56
+
57
+ $form_id = $form = $this->params['form'];
58
+ if ( $form_id ) {
59
+ $form = FrmForm::getOne($form_id);
60
+ }
61
+ $colspan = $this->get_column_count();
62
+
63
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php');
64
+ }
65
+
66
+ function search_box( $text, $input_id ) {
67
+ if ( !$this->has_items() && !isset( $_REQUEST['s'] ) ) {
68
+ return;
69
+ }
70
+
71
+ if ( isset($this->params['form']) ) {
72
+ $form = FrmForm::getOne($this->params['form']);
73
+ } else {
74
+ $form = FrmForm::getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", 'name', ' LIMIT 1');
75
+ }
76
+
77
+ if ( $form ) {
78
+ $field_list = FrmField::getAll("fi.type not in ('". implode("','", FrmFieldsHelper::no_save_fields() ) ."') and fi.form_id=". $form->id, 'field_order');
79
+ }
80
+
81
+ $fid = isset($_REQUEST['fid']) ? esc_attr( stripslashes( $_REQUEST['fid'] ) ) : '';
82
+ $input_id = $input_id . '-search-input';
83
+ $search_str = isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
84
+
85
+ if ( ! empty( $_REQUEST['orderby'] ) ) {
86
+ echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
87
+ }
88
+
89
+ if ( ! empty( $_REQUEST['order'] ) ) {
90
+ echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
91
+ }
92
+ ?>
93
+ <div class="search-box frm_sidebar">
94
+ <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
95
+ <input type="text" id="<?php echo $input_id ?>" name="s" value="<?php echo $search_str; ?>" />
96
+ <?php if ( isset($field_list) && !empty($field_list) ) { ?>
97
+ <select name="fid" class="hide-if-js">
98
+ <option value="">&mdash; <?php _e('All Fields', 'formidable') ?> &mdash;</option>
99
+ <option value="created_at" <?php selected($fid, 'created_at') ?>><?php _e('Entry creation date', 'formidable') ?></option>
100
+ <option value="id" <?php selected($fid, 'id') ?>><?php _e('Entry ID', 'formidable') ?></option>
101
+ <?php foreach($field_list as $f){ ?>
102
+ <option value="<?php echo ($f->type == 'user_id') ? 'user_id' : $f->id ?>" <?php selected($fid, $f->id) ?>><?php echo FrmAppHelper::truncate($f->name, 30); ?></option>
103
+ <?php } ?>
104
+ </select>
105
+
106
+ <div class="button dropdown hide-if-no-js">
107
+ <a href="#" id="frm-fid-search" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Search', 'formidable') ?> <b class="caret"></b></a>
108
+ <ul class="frm-dropdown-menu pull-right" id="frm-fid-search-menu" role="menu" aria-labelledby="frm-fid-search">
109
+ <li><a href="#" id="fid-">&mdash; <?php _e('All Fields', 'formidable') ?> &mdash;</a></li>
110
+ <li><a href="#" id="fid-created_at"><?php _e('Entry creation date', 'formidable') ?></a></li>
111
+ <li><a href="#" id="fid-id"><?php _e('Entry ID', 'formidable') ?></a></li>
112
+ <?php foreach ( $field_list as $f ) { ?>
113
+ <li><a href="#" id="fid-<?php echo ($f->type == 'user_id') ? 'user_id' : $f->id ?>"><?php echo FrmAppHelper::truncate($f->name, 30); ?></a></li>
114
+ <?php
115
+ unset($f);
116
+ } ?>
117
+ </ul>
118
+ </div>
119
+ <?php submit_button( $text, 'button hide-if-js', false, false, array('id' => 'search-submit') );
120
+ } else {
121
+ submit_button( $text, 'button', false, false, array('id' => 'search-submit') );
122
+ if ( ! empty($search_str) ) { ?>
123
+ <a href="<?php echo admin_url('admin.php?page=formidable-entries&frm_action=list&form='.$form->id) ?>"><?php _e('Reset', 'formidable') ?></a>
124
+ <?php }
125
+ } ?>
126
+
127
+ </div>
128
+ <?php
129
+ }
130
+
131
+ function single_row( $item, $style='') {
132
+ // Set up the hover actions for this user
133
+ $actions = array();
134
+ $view_link = '?page=formidable-entries&frm_action=show&id='. $item->id;
135
+
136
+ $this->get_actions( $actions, $item, $view_link );
137
+
138
+ $action_links = $this->row_actions( $actions );
139
+
140
+ // Set up the checkbox ( because the user is editable, otherwise its empty )
141
+ $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
142
+
143
+ $r = "<tr id='item-action-{$item->id}'$style>";
144
+
145
+ list( $columns, $hidden ) = $this->get_column_info();
146
+ $action_col = false;
147
+
148
+ foreach ( $columns as $column_name => $column_display_name ) {
149
+ $class = 'class="'. $column_name .' column-'. $column_name .'"';
150
+
151
+ $style = '';
152
+ if ( in_array( $column_name, $hidden ) )
153
+ $style = ' style="display:none;"';
154
+ else if(!$action_col and !in_array($column_name, array('cb', 'id', 'form_id', 'post_id')))
155
+ $action_col = $column_name;
156
+
157
+ $attributes = $class . $style;
158
+
159
+ $col_name = preg_replace('/^('. $this->params['form'] .'_)/', '', $column_name);
160
+
161
+ switch ( $col_name ) {
162
+ case 'cb':
163
+ $r .= "<th scope='row' class='check-column'>$checkbox</th>";
164
+ break;
165
+ case 'ip':
166
+ case 'id':
167
+ case 'item_key':
168
+ $val = $item->{$col_name};
169
+ break;
170
+ case 'name':
171
+ case 'description':
172
+ $val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100);
173
+ break;
174
+ case 'created_at':
175
+ case 'updated_at':
176
+ $date = FrmAppHelper::get_formatted_time($item->{$col_name});
177
+ $val = "<abbr title='". FrmAppHelper::get_formatted_time($item->{$col_name}, '', 'g:i:s A') ."'>". $date ."</abbr>";
178
+ break;
179
+ case 'is_draft':
180
+ $val = empty($item->is_draft) ? __('No') : __('Yes');
181
+ break;
182
+ case 'form_id':
183
+ $val = FrmFormsHelper::edit_form_link($item->form_id);
184
+ break;
185
+ case 'post_id':
186
+ $val = FrmAppHelper::post_edit_link($item->post_id);
187
+ break;
188
+ case 'user_id':
189
+ $user = get_userdata($item->user_id);
190
+ $val = $user->user_login;
191
+ break;
192
+ default:
193
+ if ( strpos($col_name, 'frmsep_') === 0 ) {
194
+ $sep_val = true;
195
+ $col_name = str_replace('frmsep_', '', $col_name);
196
+ } else {
197
+ $sep_val = false;
198
+ }
199
+
200
+ if ( strpos($col_name, '-_-') ) {
201
+ list($col_name, $embedded_field_id) = explode('-_-', $col_name);
202
+ }
203
+
204
+ $col = FrmField::getOne($col_name);
205
+
206
+ $atts = array(
207
+ 'type' => $col->type, 'truncate' => true,
208
+ 'post_id' => $item->post_id, 'entry_id' => $item->id,
209
+ 'embedded_field_id' => 0,
210
+ );
211
+
212
+ if ( $sep_val ) {
213
+ $atts['saved_value'] = true;
214
+ }
215
+
216
+ if ( isset($embedded_field_id) ) {
217
+ $atts['embedded_field_id'] = $embedded_field_id;
218
+ unset($embedded_field_id);
219
+ }
220
+
221
+ $val = FrmEntriesHelper::prepare_display_value($item, $col, $atts);
222
+
223
+ break;
224
+ }
225
+
226
+ if(isset($val)){
227
+ $r .= "<td $attributes>";
228
+ if($column_name == $action_col){
229
+ $edit_link = '?page=formidable-entries&frm_action=edit&id='. $item->id;
230
+ $r .= '<a href="'. (isset($actions['edit']) ? $edit_link : $view_link) .'" class="row-title" >'. $val .'</a> ';
231
+ $r .= $action_links;
232
+ }else{
233
+ $r .= $val;
234
+ }
235
+ $r .= '</td>';
236
+ }
237
+ unset($val);
238
+ }
239
+ $r .= '</tr>';
240
+
241
+ return $r;
242
+ }
243
+
244
+ private function get_actions( &$actions, $item, $view_link ) {
245
+ $actions['view'] = '<a href="' . esc_url( $view_link ) . '">'. __('View', 'formidable') .'</a>';
246
+
247
+ if ( current_user_can('frm_delete_entries') ) {
248
+ $delete_link = '?page=formidable-entries&frm_action=destroy&id='. $item->id .'&form='. $this->params['form'];
249
+ $actions['delete'] = '<a href="' . wp_nonce_url( $delete_link ) . '" class="submitdelete" onclick="return confirm(\''. __('Are you sure you want to delete that?', 'formidable') .'\')">' . __( 'Delete' ) . '</a>';
250
+ }
251
+
252
+ $actions = apply_filters('frm_row_actions', $actions, $item);
253
+ }
254
+
255
+ }
classes/helpers/FrmFieldsHelper.php CHANGED
@@ -1,195 +1,301 @@
1
  <?php
2
-
3
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
4
 
5
- if(class_exists('FrmFieldsHelper'))
6
- return;
7
-
8
  class FrmFieldsHelper{
9
-
10
  public static function field_selection(){
11
  $fields = apply_filters('frm_available_fields', array(
12
- 'text' => __('Single Line Text', 'formidable'),
13
- 'textarea' => __('Paragraph Text', 'formidable'),
14
- 'checkbox' => __('Checkboxes', 'formidable'),
15
- 'radio' => __('Radio Buttons', 'formidable'),
16
- 'select' => __('Dropdown', 'formidable'),
17
- 'captcha' => __('reCAPTCHA', 'formidable')
 
 
18
  ));
19
-
20
  return $fields;
21
  }
22
-
23
  public static function pro_field_selection(){
24
  return apply_filters('frm_pro_available_fields', array(
25
- 'email' => __('Email Address', 'formidable'),
26
- 'url' => __('Website/URL', 'formidable'),
27
- 'divider' => __('Section Heading', 'formidable'),
28
- 'break' => __('Page Break', 'formidable'),
29
- 'file' => __('File Upload', 'formidable'),
30
- 'rte' => __('Rich Text', 'formidable'),
31
- 'number' => __('Number', 'formidable'),
32
- 'phone' => __('Phone Number', 'formidable'),
33
- 'date' => __('Date', 'formidable'),
34
- 'time' => __('Time', 'formidable'),
35
- 'image' => __('Image URL', 'formidable'),
36
- 'scale' => __('Scale', 'formidable'),
37
- //'grid' => __('Grid', 'formidable'),
38
- 'data' => __('Data from Entries', 'formidable'),
39
- //'form' => __('SubForm', 'formidable'),
40
- 'hidden' => __('Hidden Field', 'formidable'),
41
- 'user_id' => __('User ID (hidden)', 'formidable'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  'password' => __('Password', 'formidable'),
43
- 'html' => __('HTML', 'formidable'),
44
- 'tag' => __('Tags', 'formidable')
45
- //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
46
- //'city_selector' => 'US State/County/City selector',
47
- //'full_name' => 'First and Last Name',
48
- //'quiz' => 'Question and Answer' // for captcha alternative
49
  ));
50
  }
51
-
52
- public static function setup_new_vars($type='', $form_id=''){
53
- global $frm_settings;
54
-
55
- $defaults = FrmFieldsHelper::get_default_field_opts($type, $form_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  $defaults['field_options']['custom_html'] = FrmFieldsHelper::get_default_html($type);
57
 
58
  $values = array();
59
-
60
- foreach ($defaults as $var => $default){
61
- if($var == 'field_options'){
62
  $values['field_options'] = array();
63
- foreach ($default as $opt_var => $opt_default){
64
  $values['field_options'][$opt_var] = $opt_default;
65
- unset($opt_var);
66
- unset($opt_default);
67
  }
68
- }else{
 
69
  $values[$var] = $default;
70
  }
71
- unset($var);
72
- unset($default);
73
- }
74
-
75
- if ($type == 'radio' || ($type == 'checkbox'))
76
- $values['options'] = serialize(array(__('Option 1', 'formidable'), __('Option 2', 'formidable')));
77
- else if ( $type == 'select')
78
- $values['options'] = serialize(array('', __('Option 1', 'formidable')));
79
- else if ($type == 'textarea')
 
 
 
 
 
 
 
 
 
 
 
 
80
  $values['field_options']['max'] = '5';
81
- else if ($type == 'captcha')
 
82
  $values['invalid'] = $frm_settings->re_msg;
83
-
 
 
 
84
  $fields = self::field_selection();
85
  $fields = array_merge($fields, self::pro_field_selection());
86
 
87
- if(isset($fields[$type]))
88
- $values['name'] = $fields[$type];
 
89
 
90
  unset($fields);
91
-
92
  return $values;
93
  }
94
-
 
 
 
 
95
  public static function setup_edit_vars($record, $doing_ajax=false){
96
- global $frm_entry_meta;
97
-
98
  $values = array('id' => $record->id, 'form_id' => $record->form_id);
99
  $defaults = array('name' => $record->name, 'description' => $record->description);
100
  $default_opts = array(
101
- 'field_key' => $record->field_key, 'type' => $record->type,
102
- 'default_value'=> $record->default_value, 'field_order' => $record->field_order,
103
  'required' => $record->required
104
  );
105
-
106
  if($doing_ajax){
107
  $values = $values + $defaults + $default_opts;
108
  $values['form_name'] = '';
109
  }else{
110
  foreach ($defaults as $var => $default){
111
  $values[$var] = htmlspecialchars(FrmAppHelper::get_param($var, $default));
112
- unset($var);
113
- unset($default);
114
  }
115
-
116
  foreach (array('field_key' => $record->field_key, 'type' => $record->type, 'default_value'=> $record->default_value, 'field_order' => $record->field_order, 'required' => $record->required) as $var => $default){
117
  $values[$var] = FrmAppHelper::get_param($var, $default);
118
- unset($var);
119
- unset($default);
120
  }
121
-
122
- $frm_form = new FrmForm();
123
- $values['form_name'] = ($record->form_id) ? $frm_form->getName( $record->form_id ) : '';
124
- unset($frm_form);
125
- }
126
-
127
- unset($defaults);
128
- unset($default_opts);
129
-
130
  $values['options'] = $record->options;
131
  $values['field_options'] = $record->field_options;
132
-
133
  $defaults = self::get_default_field_opts($values['type'], $record, true);
134
-
135
  if($values['type'] == 'captcha'){
136
- global $frm_settings;
137
  $defaults['invalid'] = $frm_settings->re_msg;
138
  }
139
-
140
  foreach($defaults as $opt => $default){
141
  $values[$opt] = (isset($record->field_options[$opt])) ? $record->field_options[$opt] : $default;
142
- unset($opt);
143
- unset($default);
144
  }
145
 
146
  $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
147
-
148
  return apply_filters('frm_setup_edit_field_vars', $values, array('doing_ajax' => $doing_ajax));
149
  }
150
-
151
  public static function get_default_field_opts($type, $field, $limit=false){
152
  $field_options = array(
153
- 'size' => '', 'max' => '', 'label' => '', 'blank' => '',
154
  'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
155
  'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
156
  'custom_html' => ''
157
  );
158
-
159
  if($limit)
160
  return $field_options;
161
-
162
- global $wpdb, $frm_settings;
163
-
164
  $form_id = (is_numeric($field)) ? $field : $field->form_id;
165
-
166
  $key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_fields', 'field_key') : $field->field_key;
167
- $field_count = FrmAppHelper::getRecordCount(array('form_id' => $form_id), $wpdb->prefix .'frm_fields');
168
-
 
 
 
169
  return array(
170
- 'name' => __('Untitled', 'formidable'), 'description' => '',
171
- 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'',
172
- 'field_order' => $field_count+1, 'required' => false,
173
  'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
174
  'invalid' => __('This field is invalid', 'formidable'), 'form_id' => $form_id,
175
  'field_options' => $field_options
176
  );
177
  }
178
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  public static function get_form_fields($form_id, $error=false){
180
- global $frm_field;
181
- $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
182
- $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error);
183
  return $fields;
184
  }
185
-
186
  public static function get_default_html($type='text'){
187
  if (apply_filters('frm_normal_field_type_html', true, $type)){
188
  $input = (in_array($type, array('radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
189
  $for = '';
190
  if(!in_array($type, array('radio', 'checkbox', 'data', 'scale')))
191
  $for = 'for="field_[key]"';
192
-
193
  $default_html = <<<DEFAULT_HTML
194
  <div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
195
  <label $for class="frm_primary_label">[field_name]
@@ -205,51 +311,86 @@ DEFAULT_HTML;
205
 
206
  return apply_filters('frm_custom_html', $default_html, $type);
207
  }
208
-
209
- public static function replace_shortcodes($html, $field, $errors=array(), $form=false){
210
  $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
211
-
212
- $field_name = 'item_meta['. $field['id'] .']';
213
- if(isset($field['multiple']) and $field['multiple'] and ($field['type'] == 'select' or ($field['type'] == 'data' and isset($field['data_type']) and $field['data_type'] == 'select')))
 
 
 
 
 
 
 
 
 
 
214
  $field_name .= '[]';
215
-
 
216
  //replace [id]
217
- $html = str_replace('[id]', $field['id'], $html);
218
-
219
- //replace [key]
 
 
 
220
  $html = str_replace('[key]', $field['field_key'], $html);
221
-
222
  //replace [description] and [required_label] and [error]
223
  $required = ($field['required'] == '0') ? '' : $field['required_indicator'];
224
  if(!is_array($errors))
225
  $errors = array();
226
- $error = isset($errors['field'. $field['id']]) ? $errors['field'. $field['id']] : false;
 
 
 
 
 
 
 
 
 
 
227
  foreach (array('description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value){
228
  if (!$value or $value == '')
229
  $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
230
  else{
231
- $html = str_replace('[if '.$code.']', '', $html);
232
  $html = str_replace('[/if '.$code.']', '', $html);
233
  }
234
 
235
  $html = str_replace('['.$code.']', $value, $html);
236
- }
237
-
238
  //replace [required_class]
239
- $required_class = ($field['required'] == '0') ? '' : ' frm_required_field';
240
- $html = str_replace('[required_class]', $required_class, $html);
241
-
242
  //replace [label_position]
243
- $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field);
244
  $field['label'] = ($field['label'] and $field['label'] != '') ? $field['label'] : 'top';
245
- $html = str_replace('[label_position]', (($field['type'] == 'divider' or $field['type'] == 'break') ? $field['label'] : ' frm_primary_label'), $html);
246
-
247
  //replace [field_name]
248
  $html = str_replace('[field_name]', $field['name'], $html);
249
-
250
- //replace [error_class]
251
- $error_class = isset($errors['field'. $field['id']]) ? ' frm_blank_field' : '';
252
  $error_class .= ' frm_'. $field['label'] .'_container' ;
 
 
 
 
 
 
 
 
 
 
 
253
  //insert custom CSS classes
254
  if(!empty($field['classes'])){
255
  if(!strpos($html, 'frm_form_field '))
@@ -257,140 +398,194 @@ DEFAULT_HTML;
257
  $error_class .= ' '. $field['classes'];
258
  }
259
  $html = str_replace('[error_class]', $error_class, $html);
260
-
261
  //replace [entry_key]
262
  $entry_key = (isset($_GET) and isset($_GET['entry'])) ? $_GET['entry'] : '';
263
  $html = str_replace('[entry_key]', $entry_key, $html);
264
-
265
  //replace [input]
266
  preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
267
  global $frm_vars;
 
268
 
269
- foreach ($shortcodes[0] as $short_key => $tag){
270
  $atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
 
 
 
 
 
 
 
 
271
 
272
- if(!empty($shortcodes[2][$short_key])){
273
- $tag = str_replace('[', '',$shortcodes[0][$short_key]);
274
- $tag = str_replace(']', '', $tag);
275
- $tags = explode(' ', $tag);
276
- if(is_array($tags))
277
- $tag = $tags[0];
278
- }else
279
- $tag = $shortcodes[1][$short_key];
280
-
281
- $replace_with = '';
282
-
283
- if($tag == 'input'){
284
- if(isset($atts['opt'])) $atts['opt']--;
285
  $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
286
- if(isset($atts['class']))
287
  unset($atts['class']);
 
 
288
  $field['shortcodes'] = $atts;
289
  ob_start();
290
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/input.php');
291
  $replace_with = ob_get_contents();
292
  ob_end_clean();
293
- }else if($tag == 'deletelink' and class_exists('FrmProEntriesController'))
294
  $replace_with = FrmProEntriesController::entry_delete_link($atts);
295
-
 
296
  $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
297
  }
298
-
299
  if($form){
300
- $form = (array)$form;
301
-
302
  //replace [form_key]
303
  $html = str_replace('[form_key]', $form['form_key'], $html);
304
-
305
  //replace [form_name]
306
  $html = str_replace('[form_name]', $form['name'], $html);
307
  }
308
  $html .= "\n";
309
-
310
- $html = apply_filters('frm_replace_shortcodes', $html, $field, array('errors' => $errors, 'form' => $form));
311
-
 
 
 
 
 
 
 
 
 
 
312
  // remove [collapse_this] when running the free version
313
  if (preg_match('/\[(collapse_this)\]/s', $html))
314
  $html = str_replace('[collapse_this]', '', $html);
315
-
316
  return $html;
317
  }
318
-
319
- public static function display_recaptcha($field, $error=null){
320
- global $frm_settings, $frm_vars;
321
-
322
- if(!function_exists('recaptcha_get_html'))
323
- require(FrmAppHelper::plugin_path().'/classes/recaptchalib.php');
324
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
326
-
327
- if(defined('DOING_AJAX') and (!isset($frm_vars['preview']) or !$frm_vars['preview'])){
328
- if(!isset($frm_vars['recaptcha_loaded']) or !$frm_vars['recaptcha_loaded'])
329
- $frm_vars['recaptcha_loaded'] = '';
330
-
331
- $frm_vars['recaptcha_loaded'] .= "Recaptcha.create('". $frm_settings->pubkey ."','field_". $field['field_key'] ."',{theme:'". $frm_settings->re_theme ."',lang:'". $lang ."'". apply_filters('frm_recaptcha_custom', '', $field) ."});";
 
 
 
 
332
  ?>
333
- <div id="field_<?php echo $field['field_key'] ?>"></div>
334
- <?php }else{ ?>
335
- <script type="text/javascript">var RecaptchaOptions={theme:'<?php echo $frm_settings->re_theme ?>',lang:'<?php echo $lang ?>'<?php echo apply_filters('frm_recaptcha_custom', '', $field) ?>};</script>
336
- <?php echo recaptcha_get_html($frm_settings->pubkey .'&hl='. $lang, $error, is_ssl());
 
 
 
 
 
 
 
337
  }
338
  }
339
-
340
  public static function dropdown_categories($args){
341
- global $frm_vars;
342
-
343
  $defaults = array('field' => false, 'name' => false, 'show_option_all' => ' ');
344
- extract(wp_parse_args($args, $defaults));
345
-
346
- if(!$field) return;
347
- if(!$name) $name = "item_meta[$field[id]]";
348
- $id = 'field_'. $field['field_key'];
349
- $class = $field['type'];
350
-
351
- $exclude = (is_array($field['exclude_cat'])) ? implode(',', $field['exclude_cat']) : $field['exclude_cat'];
352
- $exclude = apply_filters('frm_exclude_cats', $exclude, $field);
353
-
354
- if(is_array($field['value'])){
355
- if(!empty($exclude))
356
- $field['value'] = array_diff($field['value'], explode(',', $exclude));
357
- $selected = reset($field['value']);
 
 
 
 
 
 
 
358
  }else{
359
- $selected = $field['value'];
360
  }
361
-
362
- $args = array(
363
- 'show_option_all' => $show_option_all, 'hierarchical' => 1, 'name' => $name,
364
- 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected,
365
  'hide_empty' => false, 'echo' => 0, 'orderby' => 'name',
366
  );
367
-
368
- $args = apply_filters('frm_dropdown_cat', $args, $field);
369
-
370
- if ( class_exists('FrmProFormsHelper') ) {
371
- $post_type = FrmProFormsHelper::post_type($field['form_id']);
372
- $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field);
373
- if ( ! $args['taxonomy'] ) {
374
  return;
375
  }
376
-
377
- if ( is_taxonomy_hierarchical($args['taxonomy']) ) {
378
- $args['exclude_tree'] = $exclude;
 
379
  }
380
  }
381
-
382
- $dropdown = wp_dropdown_categories($args);
383
-
384
- $add_html = FrmFieldsController::input_html($field, false);
385
-
386
- if($frm_vars['pro_is_installed'])
387
- $add_html .= FrmProFieldsController::input_html($field, false);
388
-
389
- $dropdown = str_replace("<select name='$name' id='$id' class='$class'", "<select name='$name' id='$id' ". $add_html, $dropdown);
390
-
391
- if(is_array($field['value'])){
 
392
  $skip = true;
393
- foreach($field['value'] as $v){
394
  if($skip){
395
  $skip = false;
396
  continue;
@@ -399,78 +594,375 @@ DEFAULT_HTML;
399
  unset($v);
400
  }
401
  }
402
-
403
  return $dropdown;
404
  }
405
-
406
  public static function get_term_link($tax_id) {
407
  $tax = get_taxonomy($tax_id);
408
  if ( !$tax ) {
409
  return;
410
  }
411
-
412
  $link = sprintf(
413
  __('Please add options from the WordPress "%1$s" page', 'formidable'),
414
  '<a href="'. esc_url(admin_url('edit-tags.php?taxonomy='. $tax->name)) .'" target="_blank">'. ( empty($tax->labels->name) ? __('Categories') : $tax->labels->name ) .'</a>'
415
  );
416
  unset($tax);
417
-
418
  return $link;
419
  }
420
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  public static function get_field_types($type){
422
- $frm_field_selection = FrmFieldsHelper::field_selection();
423
  $field_types = array();
 
424
  $single_input = array(
425
- 'text', 'textarea', 'rte', 'number', 'email', 'url',
426
- 'image', 'file', 'date', 'phone', 'hidden', 'time',
427
  'user_id', 'tag', 'password'
428
  );
429
  $multiple_input = array('radio', 'checkbox', 'select', 'scale');
430
  $other_type = array('divider', 'html', 'break');
431
- $frm_pro_field_selection = FrmFieldsHelper::pro_field_selection();
432
-
433
- if (in_array($type, $single_input)){
434
- foreach($single_input as $input){
435
- if (isset($frm_pro_field_selection[$input]))
436
- $field_types[$input] = $frm_pro_field_selection[$input];
437
- else
438
- $field_types[$input] = $frm_field_selection[$input];
439
  }
440
- }else if (in_array($type, $multiple_input)){
441
- foreach($multiple_input as $input){
442
- if (isset($frm_pro_field_selection[$input]))
443
- $field_types[$input] = $frm_pro_field_selection[$input];
444
- else
445
- $field_types[$input] = $frm_field_selection[$input];
446
  }
447
- }else if (in_array($type, $other_type)){
448
- foreach($other_type as $input){
449
- if (isset($frm_pro_field_selection[$input]))
450
- $field_types[$input] = $frm_pro_field_selection[$input];
451
- else
452
- $field_types[$input] = $frm_field_selection[$input];
453
  }
 
 
454
  }
455
-
456
  return $field_types;
457
  }
458
-
459
- public static function show_onfocus_js($field_id, $clear_on_focus){ ?>
460
- <a class="frm_bstooltip <?php echo ($clear_on_focus) ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_reload_icon frm_icon_font" id="clear_field_<?php echo $field_id; ?>" title="<?php echo esc_attr($clear_on_focus ? __('Clear default value when typing', 'formidable') : __('Do not clear default value when typing', 'formidable')); ?>"></a>
461
  <?php
462
  }
463
-
464
- public static function show_default_blank_js($field_id, $default_blank){ ?>
465
- <a class="frm_bstooltip <?php echo ($default_blank) ? '' :'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_error_icon frm_icon_font" id="default_blank_<?php echo $field_id; ?>" title="<?php echo $default_blank ? __('Default value will NOT pass form validation', 'formidable') : __('Default value will pass form validation', 'formidable'); ?>"></a>
466
  <?php
467
  }
468
-
469
  public static function switch_field_ids($val){
470
  global $frm_duplicate_ids;
471
  $replace = array();
472
  $replace_with = array();
473
- foreach((array)$frm_duplicate_ids as $old => $new){
474
  $replace[] = '[if '. $old .']';
475
  $replace_with[] = '[if '. $new .']';
476
  $replace[] = '[if '. $old .' ';
@@ -493,7 +985,7 @@ DEFAULT_HTML;
493
  }else{
494
  $val = str_replace($replace, $replace_with, $val);
495
  }
496
-
497
  return $val;
498
  }
499
  }
1
  <?php
 
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
 
 
 
4
  class FrmFieldsHelper{
5
+
6
  public static function field_selection(){
7
  $fields = apply_filters('frm_available_fields', array(
8
+ 'text' => __('Single Line Text', 'formidable'),
9
+ 'textarea' => __('Paragraph Text', 'formidable'),
10
+ 'checkbox' => __('Checkboxes', 'formidable'),
11
+ 'radio' => __('Radio Buttons', 'formidable'),
12
+ 'select' => __('Dropdown', 'formidable'),
13
+ 'email' => __('Email Address', 'formidable'),
14
+ 'url' => __('Website/URL', 'formidable'),
15
+ 'captcha' => __('reCAPTCHA', 'formidable'),
16
  ));
17
+
18
  return $fields;
19
  }
20
+
21
  public static function pro_field_selection(){
22
  return apply_filters('frm_pro_available_fields', array(
23
+ 'end_divider' => array(
24
+ 'name' => __('End Section', 'formidable'),
25
+ 'switch_from' => 'divider',
26
+ ),
27
+ 'divider' => array(
28
+ 'name' => __('Section', 'formidable'),
29
+ 'types' => array(
30
+ '' => __('Heading', 'formidable'),
31
+ 'slide' => __('Collapsible', 'formidable'),
32
+ 'repeat' => __('Repeatable', 'formidable'),
33
+ ),
34
+ ),
35
+ 'break' => __('Page Break', 'formidable'),
36
+ 'file' => __('File Upload', 'formidable'),
37
+ 'rte' => __('Rich Text', 'formidable'),
38
+ 'number' => __('Number', 'formidable'),
39
+ 'phone' => __('Phone Number', 'formidable'),
40
+ 'date' => __('Date', 'formidable'),
41
+ 'time' => __('Time', 'formidable'),
42
+ 'image' => __('Image URL', 'formidable'),
43
+ 'scale' => __('Scale', 'formidable'),
44
+ 'data' => array(
45
+ 'name' => __('Dynamic Field', 'formidable'),
46
+ 'types' => array(
47
+ 'select' => __('Dropdown', 'formidable'),
48
+ 'radio' => __('Radio Buttons', 'formidable'),
49
+ 'checkbox' => __('Checkboxes', 'formidable'),
50
+ 'data' => __('List', 'formidable'),
51
+ ),
52
+ ),
53
+ 'form' => __('Embed Form', 'formidable'),
54
+ 'hidden' => __('Hidden Field', 'formidable'),
55
+ 'user_id' => __('User ID (hidden)', 'formidable'),
56
  'password' => __('Password', 'formidable'),
57
+ 'html' => __('HTML', 'formidable'),
58
+ 'tag' => __('Tags', 'formidable')
59
+ //'address' => 'Address' //Address line 1, Address line 2, City, State/Providence, Postal Code, Select Country
60
+ //'city_selector' => 'US State/County/City selector',
61
+ //'full_name' => 'First and Last Name',
62
+ //'quiz' => 'Question and Answer' // for captcha alternative
63
  ));
64
  }
65
+
66
+ public static function is_no_save_field($type) {
67
+ return in_array($type, self::no_save_fields());
68
+ }
69
+
70
+ public static function no_save_fields() {
71
+ return array('divider', 'end_divider', 'captcha', 'break', 'html');
72
+ }
73
+
74
+ /*
75
+ * Check if this is a multiselect dropdown field
76
+ *
77
+ * @since 2.0
78
+ * @return boolean
79
+ */
80
+ public static function is_multiple_select($field) {
81
+ if ( is_array($field) ) {
82
+ return isset($field['multiple']) && $field['multiple'] && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'select') ) );
83
+ } else {
84
+ return isset($field->field_options['multiple']) && $field->field_options['multiple'] && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type']) && $field->field_options['data_type'] == 'select') ) );
85
+ }
86
+ }
87
+
88
+ /*
89
+ * Check if this field can hold an array of values
90
+ *
91
+ * @since 2.0
92
+ * @return boolean
93
+ */
94
+ public static function is_field_with_multiple_values( $field ) {
95
+ if ( ! $field ) {
96
+ return false;
97
+ }
98
+
99
+ return $field->type == 'checkbox' || ( $field->type == 'data' && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select($field);
100
+ }
101
+
102
+ /*
103
+ * If $field is numeric, get the field object
104
+ */
105
+ public static function maybe_get_field( &$field ) {
106
+ if ( ! is_object($field) ) {
107
+ $field = FrmField::getOne($field);
108
+ }
109
+ }
110
+
111
+ public static function setup_new_vars($type = '', $form_id = '') {
112
+
113
+ if ( strpos($type, '|') ) {
114
+ list($type, $setting) = explode('|', $type);
115
+ }
116
+
117
+ $defaults = self::get_default_field_opts($type, $form_id);
118
  $defaults['field_options']['custom_html'] = FrmFieldsHelper::get_default_html($type);
119
 
120
  $values = array();
121
+
122
+ foreach ( $defaults as $var => $default ) {
123
+ if ( $var == 'field_options' ) {
124
  $values['field_options'] = array();
125
+ foreach ( $default as $opt_var => $opt_default ) {
126
  $values['field_options'][$opt_var] = $opt_default;
127
+ unset($opt_var, $opt_default);
 
128
  }
129
+
130
+ } else {
131
  $values[$var] = $default;
132
  }
133
+ unset($var, $default);
134
+ }
135
+
136
+ if ( isset($setting) && !empty($setting) ) {
137
+ if ( 'data' == $type ) {
138
+ $values['field_options']['data_type'] = $setting;
139
+ }else{
140
+ $values['field_options'][$setting] = 1;
141
+ }
142
+ }
143
+
144
+ if ( $type == 'radio' || $type == 'checkbox' ) {
145
+ $values['options'] = serialize( array(
146
+ __('Option 1', 'formidable'),
147
+ __('Option 2', 'formidable'),
148
+ ) );
149
+ } else if ( $type == 'select' ) {
150
+ $values['options'] = serialize( array(
151
+ '', __('Option 1', 'formidable'),
152
+ ) );
153
+ } else if ( $type == 'textarea' ) {
154
  $values['field_options']['max'] = '5';
155
+ } else if ( $type == 'captcha' ) {
156
+ $frm_settings = FrmAppHelper::get_settings();
157
  $values['invalid'] = $frm_settings->re_msg;
158
+ } else if ( 'url' == $type ) {
159
+ $values['name'] = __('Website', 'formidable');
160
+ }
161
+
162
  $fields = self::field_selection();
163
  $fields = array_merge($fields, self::pro_field_selection());
164
 
165
+ if ( isset($fields[$type]) ) {
166
+ $values['name'] = is_array($fields[$type]) ? $fields[$type]['name'] : $fields[$type];
167
+ }
168
 
169
  unset($fields);
170
+
171
  return $values;
172
  }
173
+
174
+ public static function get_html_id($field, $plus = '') {
175
+ return apply_filters('frm_field_html_id', 'field_'. $field['field_key'] . $plus, $field);
176
+ }
177
+
178
  public static function setup_edit_vars($record, $doing_ajax=false){
 
 
179
  $values = array('id' => $record->id, 'form_id' => $record->form_id);
180
  $defaults = array('name' => $record->name, 'description' => $record->description);
181
  $default_opts = array(
182
+ 'field_key' => $record->field_key, 'type' => $record->type,
183
+ 'default_value'=> $record->default_value, 'field_order' => $record->field_order,
184
  'required' => $record->required
185
  );
186
+
187
  if($doing_ajax){
188
  $values = $values + $defaults + $default_opts;
189
  $values['form_name'] = '';
190
  }else{
191
  foreach ($defaults as $var => $default){
192
  $values[$var] = htmlspecialchars(FrmAppHelper::get_param($var, $default));
193
+ unset($var, $default);
 
194
  }
195
+
196
  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){
197
  $values[$var] = FrmAppHelper::get_param($var, $default);
198
+ unset($var, $default);
 
199
  }
200
+
201
+ $values['form_name'] = ($record->form_id) ? FrmForm::getName( $record->form_id ) : '';
202
+ }
203
+
204
+ unset($defaults, $default_opts);
205
+
 
 
 
206
  $values['options'] = $record->options;
207
  $values['field_options'] = $record->field_options;
208
+
209
  $defaults = self::get_default_field_opts($values['type'], $record, true);
210
+
211
  if($values['type'] == 'captcha'){
212
+ $frm_settings = FrmAppHelper::get_settings();
213
  $defaults['invalid'] = $frm_settings->re_msg;
214
  }
215
+
216
  foreach($defaults as $opt => $default){
217
  $values[$opt] = (isset($record->field_options[$opt])) ? $record->field_options[$opt] : $default;
218
+ unset($opt, $default);
 
219
  }
220
 
221
  $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type);
222
+
223
  return apply_filters('frm_setup_edit_field_vars', $values, array('doing_ajax' => $doing_ajax));
224
  }
225
+
226
  public static function get_default_field_opts($type, $field, $limit=false){
227
  $field_options = array(
228
+ 'size' => '', 'max' => '', 'label' => '', 'blank' => '',
229
  'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0,
230
  'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '',
231
  'custom_html' => ''
232
  );
233
+
234
  if($limit)
235
  return $field_options;
236
+
237
+ global $wpdb;
238
+
239
  $form_id = (is_numeric($field)) ? $field : $field->form_id;
240
+
241
  $key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_fields', 'field_key') : $field->field_key;
242
+
243
+ $query = $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}frm_fields fi LEFT JOIN {$wpdb->prefix}frm_forms fr ON (fi.form_id = fr.id) WHERE fr.id = %d OR fr.parent_form_id = %d", $form_id, $form_id);
244
+ $field_count = $wpdb->get_var($query);
245
+
246
+ $frm_settings = FrmAppHelper::get_settings();
247
  return array(
248
+ 'name' => __('Untitled', 'formidable'), 'description' => '',
249
+ 'field_key' => $key, 'type' => $type, 'options'=>'', 'default_value'=>'',
250
+ 'field_order' => $field_count+1, 'required' => false,
251
  'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg,
252
  'invalid' => __('This field is invalid', 'formidable'), 'form_id' => $form_id,
253
  'field_options' => $field_options
254
  );
255
  }
256
+
257
+ public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
258
+ global $wpdb;
259
+
260
+ $values['field_key'] = FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_fields', 'field_key');
261
+ $values['form_id'] = $form_id;
262
+ $values['options'] = maybe_serialize($field->options);
263
+ $values['default_value'] = maybe_serialize($field->default_value);
264
+
265
+ foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
266
+ $values[$col] = $field->{$col};
267
+ }
268
+ }
269
+
270
+ /*
271
+ * @since 2.0
272
+ */
273
+ public static function get_error_msg($field, $error){
274
+ $frm_settings = FrmAppHelper::get_settings();
275
+ $default_settings = $frm_settings->default_options();
276
+
277
+ $defaults = array(
278
+ 'unique_msg' => array('full' => $default_settings['unique_msg'], 'part' => $field->name.' '. __('must be unique', 'formidable')),
279
+ 'invalid' => array('full' => __('This field is invalid', 'formidable'), 'part' => $field->name.' '. __('is invalid', 'formidable'))
280
+ );
281
+
282
+ $msg = ($field->field_options[$error] == $defaults[$error]['full'] || empty($field->field_options[$error])) ? ($defaults[$error]['part']) : $field->field_options[$error];
283
+ return $msg;
284
+ }
285
+
286
  public static function get_form_fields($form_id, $error=false){
287
+ $fields = FrmField::get_all_for_form($form_id);
288
+ $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error);
 
289
  return $fields;
290
  }
291
+
292
  public static function get_default_html($type='text'){
293
  if (apply_filters('frm_normal_field_type_html', true, $type)){
294
  $input = (in_array($type, array('radio', 'checkbox', 'data'))) ? '<div class="frm_opt_container">[input]</div>' : '[input]';
295
  $for = '';
296
  if(!in_array($type, array('radio', 'checkbox', 'data', 'scale')))
297
  $for = 'for="field_[key]"';
298
+
299
  $default_html = <<<DEFAULT_HTML
300
  <div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
301
  <label $for class="frm_primary_label">[field_name]
311
 
312
  return apply_filters('frm_custom_html', $default_html, $type);
313
  }
314
+
315
+ public static function replace_shortcodes($html, $field, $errors = array(), $form = false, $args = array()) {
316
  $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form);
317
+
318
+ $defaults = array(
319
+ 'field_name' => 'item_meta['. $field['id'] .']',
320
+ 'field_id' => $field['id'],
321
+ 'field_plus_id' => '',
322
+ 'section_id' => '',
323
+ );
324
+ $args = wp_parse_args($args, $defaults);
325
+ $field_name = $args['field_name'];
326
+ $field_id = $args['field_id'];
327
+ $html_id = self::get_html_id($field, $args['field_plus_id']);
328
+
329
+ if ( self::is_multiple_select($field) ) {
330
  $field_name .= '[]';
331
+ }
332
+
333
  //replace [id]
334
+ $html = str_replace('[id]', $field_id, $html);
335
+
336
+ // set the label for
337
+ $html = str_replace('field_[key]', $html_id, $html);
338
+
339
+ //replace [key]
340
  $html = str_replace('[key]', $field['field_key'], $html);
341
+
342
  //replace [description] and [required_label] and [error]
343
  $required = ($field['required'] == '0') ? '' : $field['required_indicator'];
344
  if(!is_array($errors))
345
  $errors = array();
346
+ $error = isset($errors['field'. $field_id]) ? $errors['field'. $field_id] : false;
347
+
348
+ //If field type is section heading, add class so a bottom margin can be added to either the h3 or description
349
+ if ( $field['type'] == 'divider' ) {
350
+ if ( isset( $field['description'] ) && $field['description'] ) {
351
+ $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html );
352
+ } else {
353
+ $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html);
354
+ }
355
+ }
356
+
357
  foreach (array('description' => $field['description'], 'required_label' => $required, 'error' => $error) as $code => $value){
358
  if (!$value or $value == '')
359
  $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
360
  else{
361
+ $html = str_replace('[if '.$code.']', '', $html);
362
  $html = str_replace('[/if '.$code.']', '', $html);
363
  }
364
 
365
  $html = str_replace('['.$code.']', $value, $html);
366
+ }
367
+
368
  //replace [required_class]
369
+ $required_class = ($field['required'] == '0') ? '' : ' frm_required_field';
370
+ $html = str_replace('[required_class]', $required_class, $html);
371
+
372
  //replace [label_position]
373
+ $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form);
374
  $field['label'] = ($field['label'] and $field['label'] != '') ? $field['label'] : 'top';
375
+ $html = str_replace('[label_position]', ( ( in_array( $field['type'], array('divider', 'end_divider', 'break') ) ) ? $field['label'] : ' frm_primary_label'), $html);
376
+
377
  //replace [field_name]
378
  $html = str_replace('[field_name]', $field['name'], $html);
379
+
380
+ //replace [error_class]
381
+ $error_class = isset($errors['field'. $field_id]) ? ' frm_blank_field' : '';
382
  $error_class .= ' frm_'. $field['label'] .'_container' ;
383
+
384
+ //Add classes to inline confirmation field (if it doesn't already have classes set)
385
+ if ( isset($field['conf_field']) && $field['conf_field'] == 'inline' && !$field['classes'] ) {
386
+ $error_class .= ' frm_first_half';
387
+ }
388
+
389
+ //Add class if field includes other option
390
+ if ( isset( $field['other'] ) && true == $field['other'] ) {
391
+ $error_class .= ' frm_other_container';
392
+ }
393
+
394
  //insert custom CSS classes
395
  if(!empty($field['classes'])){
396
  if(!strpos($html, 'frm_form_field '))
398
  $error_class .= ' '. $field['classes'];
399
  }
400
  $html = str_replace('[error_class]', $error_class, $html);
401
+
402
  //replace [entry_key]
403
  $entry_key = (isset($_GET) and isset($_GET['entry'])) ? $_GET['entry'] : '';
404
  $html = str_replace('[entry_key]', $entry_key, $html);
405
+
406
  //replace [input]
407
  preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER);
408
  global $frm_vars;
409
+ $frm_settings = FrmAppHelper::get_settings();
410
 
411
+ foreach ( $shortcodes[0] as $short_key => $tag ) {
412
  $atts = shortcode_parse_atts( $shortcodes[2][$short_key] );
413
+ $tag = self::get_shortcode_tag($shortcodes, $short_key, array('conditional' => false, 'conditional_check' => false));
414
+
415
+ $replace_with = '';
416
+
417
+ if ( $tag == 'input' ) {
418
+ if ( isset($atts['opt']) ) {
419
+ $atts['opt']--;
420
+ }
421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
  $field['input_class'] = isset($atts['class']) ? $atts['class'] : '';
423
+ if ( isset($atts['class']) ) {
424
  unset($atts['class']);
425
+ }
426
+
427
  $field['shortcodes'] = $atts;
428
  ob_start();
429
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/input.php');
430
  $replace_with = ob_get_contents();
431
  ob_end_clean();
432
+ } else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) {
433
  $replace_with = FrmProEntriesController::entry_delete_link($atts);
434
+ }
435
+
436
  $html = str_replace($shortcodes[0][$short_key], $replace_with, $html);
437
  }
438
+
439
  if($form){
440
+ $form = (array) $form;
441
+
442
  //replace [form_key]
443
  $html = str_replace('[form_key]', $form['form_key'], $html);
444
+
445
  //replace [form_name]
446
  $html = str_replace('[form_name]', $form['name'], $html);
447
  }
448
  $html .= "\n";
449
+
450
+ //Return html if conf_field to prevent loop
451
+ if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) {
452
+ return $html;
453
+ }
454
+
455
+ //If field is in repeating section
456
+ if ( $args['section_id'] ) {
457
+ $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] ));
458
+ } else {
459
+ $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ));
460
+ }
461
+
462
  // remove [collapse_this] when running the free version
463
  if (preg_match('/\[(collapse_this)\]/s', $html))
464
  $html = str_replace('[collapse_this]', '', $html);
465
+
466
  return $html;
467
  }
468
+
469
+ public static function get_shortcode_tag($shortcodes, $short_key, $args) {
470
+ $args = wp_parse_args($args, array('conditional' => false, 'conditional_check' => false, 'foreach' => false));
471
+ if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) {
472
+ $args['conditional_check'] = true;
473
+ }
474
+
475
+ $prefix = '';
476
+ if ( $args['conditional_check'] ) {
477
+ if ( $args['conditional'] ) {
478
+ $prefix = 'if ';
479
+ } else if ( $args['foreach'] ) {
480
+ $prefix = 'foreach ';
481
+ }
482
+ }
483
+
484
+ $with_tags = $args['conditional_check'] ? 3 : 2;
485
+ if ( ! empty($shortcodes[$with_tags][$short_key]) ) {
486
+ $tag = str_replace( '[' . $prefix, '', $shortcodes[0][$short_key]);
487
+ $tag = str_replace(']', '', $tag);
488
+ $tags = explode(' ', $tag);
489
+ if ( is_array($tags) ) {
490
+ $tag = $tags[0];
491
+ }
492
+ } else {
493
+ $tag = $shortcodes[$with_tags - 1][$short_key];
494
+ }
495
+
496
+ return $tag;
497
+ }
498
+
499
+ public static function display_recaptcha($field){
500
+ $frm_settings = FrmAppHelper::get_settings();
501
  $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
502
+
503
+ $api_js_url = 'https://www.google.com/recaptcha/api.js';
504
+ if ( $lang != 'en' ) {
505
+ $api_js_url .= '?hl='. $lang;
506
+ }
507
+ $api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url);
508
+
509
+ wp_register_script('recaptcha-api', $api_js_url, '', true);
510
+ wp_enqueue_script('recaptcha-api');
511
+
512
  ?>
513
+ <div id="field_<?php echo $field['field_key'] ?>" class="g-recaptcha" data-sitekey="<?php echo $frm_settings->pubkey ?>"></div>
514
+ <?php
515
+ }
516
+
517
+ public static function show_single_option($field) {
518
+ $field_name = $field['name'];
519
+ $html_id = FrmFieldsHelper::get_html_id($field);
520
+ foreach ( $field['options'] as $opt_key => $opt ) {
521
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
522
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
523
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
524
  }
525
  }
526
+
527
  public static function dropdown_categories($args){
528
+
 
529
  $defaults = array('field' => false, 'name' => false, 'show_option_all' => ' ');
530
+ $args = wp_parse_args($args, $defaults);
531
+
532
+ if ( ! $args['field'] ) {
533
+ return;
534
+ }
535
+
536
+ if ( ! $args['name'] ) {
537
+ $args['name'] = 'item_meta['. $args['field']['id'] .']';
538
+ }
539
+
540
+ $id = self::get_html_id($args['field']);
541
+ $class = $args['field']['type'];
542
+
543
+ $exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat'];
544
+ $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']);
545
+
546
+ if ( is_array($args['field']['value']) ) {
547
+ if ( ! empty($exclude) ) {
548
+ $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude));
549
+ }
550
+ $selected = reset($args['field']['value']);
551
  }else{
552
+ $selected = $args['field']['value'];
553
  }
554
+
555
+ $tax_atts = array(
556
+ 'show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'],
557
+ 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected,
558
  'hide_empty' => false, 'echo' => 0, 'orderby' => 'name',
559
  );
560
+
561
+ $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']);
562
+
563
+ if ( FrmAppHelper::pro_is_installed() ) {
564
+ $post_type = FrmProFormsHelper::post_type($args['field']['form_id']);
565
+ $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']);
566
+ if ( ! $tax_atts['taxonomy'] ) {
567
  return;
568
  }
569
+
570
+ // If field type is dropdown (not Dynamic), exclude children when parent is excluded
571
+ if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) {
572
+ $tax_atts['exclude_tree'] = $exclude;
573
  }
574
  }
575
+
576
+ $dropdown = wp_dropdown_categories($tax_atts);
577
+
578
+ $add_html = FrmFieldsController::input_html($args['field'], false);
579
+
580
+ if ( FrmAppHelper::pro_is_installed() ) {
581
+ $add_html .= FrmProFieldsController::input_html($args['field'], false);
582
+ }
583
+
584
+ $dropdown = str_replace("<select name='". $args['name'] ."' id='$id' class='$class'", "<select name='". $args['name'] ."' id='$id' ". $add_html, $dropdown);
585
+
586
+ if ( is_array($args['field']['value']) ) {
587
  $skip = true;
588
+ foreach ( $args['field']['value'] as $v ) {
589
  if($skip){
590
  $skip = false;
591
  continue;
594
  unset($v);
595
  }
596
  }
597
+
598
  return $dropdown;
599
  }
600
+
601
  public static function get_term_link($tax_id) {
602
  $tax = get_taxonomy($tax_id);
603
  if ( !$tax ) {
604
  return;
605
  }
606
+
607
  $link = sprintf(
608
  __('Please add options from the WordPress "%1$s" page', 'formidable'),
609
  '<a href="'. esc_url(admin_url('edit-tags.php?taxonomy='. $tax->name)) .'" target="_blank">'. ( empty($tax->labels->name) ? __('Categories') : $tax->labels->name ) .'</a>'
610
  );
611
  unset($tax);
612
+
613
  return $link;
614
  }
615
+
616
+ public static function value_meets_condition($observed_value, $cond, $hide_opt) {
617
+ if ( is_array($observed_value) ) {
618
+ return self::array_value_condition($observed_value, $cond, $hide_opt);
619
+ }
620
+
621
+ $m = false;
622
+ if ( $cond == '==' ) {
623
+ $m = $observed_value == $hide_opt;
624
+ } else if ( $cond == '!=' ) {
625
+ $m = $observed_value != $hide_opt;
626
+ } else if ( $cond == '>' ) {
627
+ $m = $observed_value > $hide_opt;
628
+ } else if ( $cond == '<' ) {
629
+ $m = $observed_value < $hide_opt;
630
+ } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
631
+ $m = strpos($observed_value, $hide_opt);
632
+ if ( $cond == 'not LIKE' ) {
633
+ $m = ( $m === false ) ? true : false;
634
+ } else {
635
+ $m = ( $m === false ) ? false : true;
636
+ }
637
+ }
638
+ return $m;
639
+ }
640
+
641
+ public static function array_value_condition($observed_value, $cond, $hide_opt) {
642
+ $m = false;
643
+ if ( $cond == '==' ) {
644
+ if ( is_array($hide_opt) ) {
645
+ $m = array_intersect($hide_opt, $observed_value);
646
+ $m = empty($m) ? false : true;
647
+ } else {
648
+ $m = in_array($hide_opt, $observed_value);
649
+ }
650
+ } else if ( $cond == '!=' ) {
651
+ $m = ! in_array($hide_opt, $observed_value);
652
+ } else if ( $cond == '>' ) {
653
+ $min = min($observed_value);
654
+ $m = $min > $hide_opt;
655
+ } else if ( $cond == '<' ) {
656
+ $max = max($observed_value);
657
+ $m = $max < $hide_opt;
658
+ } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
659
+ foreach ( $observed_value as $ob ) {
660
+ $m = strpos($ob, $hide_opt);
661
+ if ( $m !== false ) {
662
+ $m = true;
663
+ break;
664
+ }
665
+ }
666
+
667
+ if ( $cond == 'not LIKE' ) {
668
+ $m = ( $m === false ) ? true : false;
669
+ }
670
+ }
671
+
672
+ return $m;
673
+ }
674
+
675
+ /*
676
+ * Replace a few basic shortcodes and field ids
677
+ * @since 2.0
678
+ * @return string
679
+ */
680
+ public static function basic_replace_shortcodes($value, $form, $entry) {
681
+ if ( strpos($value, '[sitename]') !== false ) {
682
+ $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
683
+ $value = str_replace('[sitename]', $new_value, $value);
684
+ }
685
+
686
+ $value = apply_filters('frm_content', $value, $form, $entry);
687
+ $value = do_shortcode($value);
688
+
689
+ return $value;
690
+ }
691
+
692
+ public static function get_shortcodes($content, $form_id){
693
+ if ( FrmAppHelper::pro_is_installed() ) {
694
+ return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
695
+ }
696
+
697
+ $fields = FrmField::getAll("fi.type not in ('". implode("','", self::no_save_fields() ) ."') and fi.form_id=". (int) $form_id);
698
+
699
+ $tagregexp = self::allowed_shortcodes($fields);
700
+
701
+ preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER);
702
+
703
+ return $matches;
704
+ }
705
+
706
+ public static function allowed_shortcodes($fields = array()) {
707
+ $tagregexp = array(
708
+ 'editlink', 'id', 'key', 'ip',
709
+ 'siteurl', 'sitename', 'admin_email',
710
+ 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by',
711
+ );
712
+
713
+ foreach ( $fields as $field ) {
714
+ $tagregexp[] = $field->id;
715
+ $tagregexp[] = $field->field_key;
716
+ }
717
+
718
+ $tagregexp = implode('|', $tagregexp);
719
+ return $tagregexp;
720
+ }
721
+
722
+ public static function replace_content_shortcodes($content, $entry, $shortcodes) {
723
+ $shortcode_values = array(
724
+ 'id' => $entry->id,
725
+ 'key' => $entry->item_key,
726
+ 'ip' => $entry->ip,
727
+ );
728
+
729
+ foreach ( $shortcodes[0] as $short_key => $tag ) {
730
+ $atts = shortcode_parse_atts( $shortcodes[3][$short_key] );
731
+
732
+ if ( ! empty($shortcodes[3][$short_key]) ) {
733
+ $tag = str_replace( array('[', ']'), '', $shortcodes[0][$short_key]);
734
+ $tags = explode(' ', $tag);
735
+ if ( is_array($tags) ) {
736
+ $tag = $tags[0];
737
+ }
738
+ } else {
739
+ $tag = $shortcodes[2][$short_key];
740
+ }
741
+
742
+ switch ( $tag ) {
743
+ case 'id':
744
+ case 'key':
745
+ case 'ip':
746
+ $replace_with = $shortcode_values[$tag];
747
+ break;
748
+
749
+ case 'user_agent':
750
+ case 'user-agent':
751
+ $entry->description = maybe_unserialize($entry->description);
752
+ $replace_with = $entry->description['browser'];
753
+ break;
754
+
755
+ case 'created_at':
756
+ case 'created-at':
757
+ case 'updated_at':
758
+ case 'updated-at':
759
+ if ( isset($atts['format']) ) {
760
+ $time_format = ' ';
761
+ } else {
762
+ $atts['format'] = get_option('date_format');
763
+ $time_format = false;
764
+ }
765
+
766
+ $this_tag = str_replace('-', '_', $tag);
767
+ $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
768
+ unset($this_tag);
769
+ break;
770
+
771
+ case 'created_by':
772
+ case 'created-by':
773
+ case 'updated_by':
774
+ case 'updated-by':
775
+ $this_tag = str_replace('-', '_', $tag);
776
+ $replace_with = self::get_display_value($entry->{$this_tag}, (object) array('type' => 'user_id'), $atts);
777
+ unset($this_tag);
778
+ break;
779
+
780
+ case 'admin_email':
781
+ case 'siteurl':
782
+ case 'frmurl':
783
+ case 'sitename':
784
+ case 'get':
785
+ $replace_with = self::dynamic_default_values( $tag, $atts );
786
+ break;
787
+
788
+ default:
789
+ $field = FrmField::getOne( $tag );
790
+ if ( ! $field ) {
791
+ break;
792
+ }
793
+
794
+ $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
795
+
796
+ $replace_with = FrmEntryMeta::get_entry_meta_by_field($entry->id, $field->id);
797
+
798
+ $atts['entry_id'] = $entry->id;
799
+ $atts['entry_key'] = $entry->item_key;
800
+ //$replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
801
+
802
+
803
+ if ( is_array($replace_with) ) {
804
+ $replace_with = implode($sep, $replace_with);
805
+ }
806
+
807
+ if ( isset($atts['show']) && $atts['show'] == 'field_label' ) {
808
+ $replace_with = $field->name;
809
+ } else if ( isset($atts['show']) && $atts['show'] == 'description' ) {
810
+ $replace_with = $field->description;
811
+ } else if ( empty($replace_with) && $replace_with != '0' ) {
812
+ $replace_with = '';
813
+ } else {
814
+ $replace_with = self::get_display_value($replace_with, $field, $atts);
815
+ }
816
+
817
+ unset($field);
818
+ break;
819
+ }
820
+
821
+ if ( isset($replace_with) ) {
822
+ $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
823
+ }
824
+
825
+ unset($atts, $conditional, $replace_with);
826
+ }
827
+
828
+ return $content;
829
+ }
830
+
831
+ /*
832
+ * Get the value to replace a few standard shortcodes
833
+ *
834
+ * @since 2.0
835
+ * @return string
836
+ */
837
+ public static function dynamic_default_values( $tag, $atts = array() ) {
838
+ $new_value = '';
839
+ switch ( $tag ) {
840
+ case 'admin_email':
841
+ $new_value = get_option('admin_email');
842
+ break;
843
+ case 'siteurl':
844
+ $new_value = FrmAppHelper::site_url();
845
+ break;
846
+ case 'frmurl':
847
+ $new_value = FrmAppHelper::plugin_url();
848
+ break;
849
+ case 'sitename':
850
+ $new_value = FrmAppHelper::site_name();
851
+ break;
852
+ case 'get':
853
+ $new_value = self::process_get_shortcode( $atts );
854
+ break;
855
+ }
856
+
857
+ return $new_value;
858
+ }
859
+
860
+ /*
861
+ * Process the [get] shortcode
862
+ *
863
+ * @since 2.0
864
+ * @return string|array
865
+ */
866
+ public static function process_get_shortcode( $atts, $return_array = false ) {
867
+ if ( ! isset($atts['param']) ) {
868
+ return '';
869
+ }
870
+
871
+ if ( strpos($atts['param'], '&#91;') ) {
872
+ $atts['param'] = str_replace('&#91;', '[', $atts['param']);
873
+ $atts['param'] = str_replace('&#93;', ']', $atts['param']);
874
+ }
875
+
876
+ $new_value = FrmAppHelper::get_param($atts['param'], '');
877
+ $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
878
+
879
+ if ( $new_value == '' ) {
880
+ if ( ! isset($atts['prev_val']) ) {
881
+ $atts['prev_val'] = '';
882
+ }
883
+
884
+ $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val'];
885
+ }
886
+
887
+ if ( is_array($new_value) && ! $return_array ) {
888
+ $new_value = implode(', ', $new_value);
889
+ }
890
+
891
+ return $new_value;
892
+ }
893
+
894
+ public static function get_display_value($replace_with, $field, $atts = array()) {
895
+ $sep = (isset($atts['sep'])) ? $atts['sep'] : ', ';
896
+
897
+ $replace_with = apply_filters('frm_get_display_value', $replace_with, $field, $atts);
898
+
899
+ if ( $field->type == 'textarea' || $field->type == 'rte' ) {
900
+ $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
901
+ if ( apply_filters('frm_use_wpautop', $autop) ) {
902
+ if ( is_array($replace_with) ) {
903
+ $replace_with = implode("\n", $replace_with);
904
+ }
905
+ $replace_with = wpautop($replace_with);
906
+ }
907
+ unset($autop);
908
+ } else if ( is_array($replace_with) ) {
909
+ $replace_with = implode($sep, $replace_with);
910
+ }
911
+
912
+ return $replace_with;
913
+ }
914
+
915
  public static function get_field_types($type){
916
+ $frm_field_selection = FrmFieldsHelper::field_selection();
917
  $field_types = array();
918
+
919
  $single_input = array(
920
+ 'text', 'textarea', 'rte', 'number', 'email', 'url',
921
+ 'image', 'file', 'date', 'phone', 'hidden', 'time',
922
  'user_id', 'tag', 'password'
923
  );
924
  $multiple_input = array('radio', 'checkbox', 'select', 'scale');
925
  $other_type = array('divider', 'html', 'break');
926
+
927
+ $pro_field_selection = FrmFieldsHelper::pro_field_selection();
928
+
929
+ if ( in_array($type, $single_input) ) {
930
+ foreach ( $single_input as $input ) {
931
+ $field_types[$input] = ( isset($pro_field_selection[$input]) ) ? $pro_field_selection[$input] : $frm_field_selection[$input];
932
+ unset($input);
 
933
  }
934
+ } else if ( in_array($type, $multiple_input) ) {
935
+ foreach ( $multiple_input as $input ) {
936
+ $field_types[$input] = ( isset($pro_field_selection[$input]) ) ? $pro_field_selection[$input] : $frm_field_selection[$input];
937
+ unset($input);
 
 
938
  }
939
+ } else if ( in_array($type, $other_type) ) {
940
+ foreach ( $other_type as $input ) {
941
+ $field_types[$input] = ( isset($pro_field_selection[$input]) ) ? $pro_field_selection[$input] : $frm_field_selection[$input];
942
+ unset($input);
 
 
943
  }
944
+ } else {
945
+ $field_types[$type] = ( isset($pro_field_selection[$type]) ) ? $pro_field_selection[$type] : $frm_field_selection[$type];
946
  }
947
+
948
  return $field_types;
949
  }
950
+
951
+ public static function show_onfocus_js($clear_on_focus){ ?>
952
+ <a href="javascript:void(0)" class="frm_bstooltip <?php echo ($clear_on_focus) ? '' : 'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_reload_icon frm_icon_font" title="<?php echo esc_attr($clear_on_focus ? __('Clear default value when typing', 'formidable') : __('Do not clear default value when typing', 'formidable')); ?>"></a>
953
  <?php
954
  }
955
+
956
+ public static function show_default_blank_js($default_blank){ ?>
957
+ <a href="javascript:void(0)" class="frm_bstooltip <?php echo ($default_blank) ? '' :'frm_inactive_icon '; ?>frm_default_val_icons frm_action_icon frm_error_icon frm_icon_font" title="<?php echo $default_blank ? __('Default value will NOT pass form validation', 'formidable') : __('Default value will pass form validation', 'formidable'); ?>"></a>
958
  <?php
959
  }
960
+
961
  public static function switch_field_ids($val){
962
  global $frm_duplicate_ids;
963
  $replace = array();
964
  $replace_with = array();
965
+ foreach ( (array) $frm_duplicate_ids as $old => $new ) {
966
  $replace[] = '[if '. $old .']';
967
  $replace_with[] = '[if '. $new .']';
968
  $replace[] = '[if '. $old .' ';
985
  }else{
986
  $val = str_replace($replace, $replace_with, $val);
987
  }
988
+
989
  return $val;
990
  }
991
  }
classes/helpers/FrmFormActionsHelper.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
+
4
+ class FrmFormActionsHelper{
5
+
6
+ public static function get_action_for_form($form_id, $type = 'all', $limit = 99) {
7
+ $action_controls = FrmFormActionsController::get_form_actions( $type );
8
+ if ( empty($action_controls) ) {
9
+ // don't continue if there are no available actions
10
+ return array();
11
+ }
12
+
13
+ if ( 'all' != $type ) {
14
+ return $action_controls->get_all( $form_id, $limit );
15
+ }
16
+
17
+ $args = array(
18
+ 'menu_order' => $form_id,
19
+ 'post_type' => FrmFormsController::$action_post_type,
20
+ 'post_status' => 'publish',
21
+ 'numberposts' => 99,
22
+ 'orderby' => 'title',
23
+ 'order' => 'ASC',
24
+ );
25
+
26
+ $actions = FrmAppHelper::check_cache(serialize($args), 'frm_actions');
27
+ if ( false == $actions ) {
28
+ $actions = get_posts( $args );
29
+ wp_cache_set(serialize($args), $actions, 'frm_actions', 300);
30
+ }
31
+
32
+ if ( ! $actions ) {
33
+ return array();
34
+ }
35
+
36
+ $settings = array();
37
+ foreach ( $actions as $action ) {
38
+ if ( ! isset($action_controls[$action->post_excerpt]) || count($settings) >= $limit ) {
39
+ continue;
40
+ }
41
+
42
+ $action = $action_controls[$action->post_excerpt]->prepare_action($action);
43
+
44
+ $settings[$action->ID] = $action;
45
+ }
46
+
47
+ if ( 1 === $limit ) {
48
+ $settings = reset($settings);
49
+ }
50
+
51
+ return $settings;
52
+ }
53
+
54
+ public static function action_conditions_met($action, $entry) {
55
+ $notification = $action->post_content;
56
+ $stop = false;
57
+ $met = array();
58
+
59
+ if ( !isset($notification['conditions']) || empty($notification['conditions']) ) {
60
+ return $stop;
61
+ }
62
+
63
+ foreach ( $notification['conditions'] as $k => $condition ) {
64
+ if ( !is_numeric($k) ) {
65
+ continue;
66
+ }
67
+
68
+ if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
69
+ continue;
70
+ }
71
+
72
+ if ( is_array($condition['hide_opt']) ) {
73
+ $condition['hide_opt'] = reset($condition['hide_opt']);
74
+ }
75
+
76
+ $observed_value = isset($entry->metas[$condition['hide_field']]) ? $entry->metas[$condition['hide_field']] : '';
77
+ if ( $condition['hide_opt'] == 'current_user' ) {
78
+ $condition['hide_opt'] = get_current_user_id();
79
+ }
80
+
81
+ $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']);
82
+
83
+ if ( $notification['conditions']['send_stop'] == 'send' ) {
84
+ $stop = $stop ? false : true;
85
+ }
86
+
87
+ $met[$stop] = $stop;
88
+ }
89
+
90
+ if ( $notification['conditions']['any_all'] == 'all' && !empty($met) && isset($met[0]) && isset($met[1]) ) {
91
+ $stop = ($notification['conditions']['send_stop'] == 'send') ? true : false;
92
+ } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) {
93
+ $stop = false;
94
+ }
95
+
96
+ return $stop;
97
+ }
98
+
99
+ public static function default_action_opts($class = ''){
100
+ return array(
101
+ 'classes' => 'frm_icon_font '. $class,
102
+ 'active' => false,
103
+ 'limit' => 0,
104
+ );
105
+ }
106
+ }
classes/helpers/FrmFormsHelper.php CHANGED
@@ -1,67 +1,76 @@
1
  <?php
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
- if(class_exists('FrmFormsHelper'))
5
- return;
6
-
7
  class FrmFormsHelper{
 
 
 
 
 
 
 
 
 
8
  public static function get_direct_link($key, $form = false ) {
9
  $target_url = esc_url(admin_url('admin-ajax.php') . '?action=frm_forms_preview&form='. $key);
10
  $target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
11
 
12
  return $target_url;
13
  }
14
-
15
- public static function get_template_dropdown($templates) {
16
- if ( ! current_user_can('frm_edit_forms') ) {
17
- return;
 
 
 
 
 
 
 
 
18
  }
 
 
 
 
 
 
 
 
 
 
19
  ?>
20
- <select id="select_form" name="select_form" onChange="frmAddNewForm(this.value,'duplicate')">
21
- <option value="">&mdash; <?php _e('Create Form from Template', 'formidable') ?> &mdash;</option>
22
- <?php foreach ($templates as $temp){ ?>
23
- <option value="<?php echo $temp->id ?>"><?php echo FrmAppHelper::truncate($temp->name, 40) ?></option>
24
- <?php }?>
25
- </select>
26
- <?php
27
- }
28
-
29
- public static function forms_dropdown( $field_name, $field_value='', $blank=true, $field_id=false, $onchange=false ){
30
- if (!$field_id)
31
- $field_id = $field_name;
32
-
33
- $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", $field_name);
34
- $frm_form = new FrmForm();
35
- $forms = $frm_form->getAll($where, ' ORDER BY name');
36
- ?>
37
- <select name="<?php echo $field_name; ?>" id="<?php echo $field_id ?>" <?php if ($onchange) echo 'onchange="'. $onchange .'"'; ?>>
38
- <?php if ($blank){ ?>
39
- <option value=""><?php echo ($blank == 1) ? '' : '- '. $blank .' -'; ?></option>
40
  <?php } ?>
41
  <?php foreach($forms as $form){ ?>
42
- <option value="<?php echo $form->id; ?>" <?php selected($field_value, $form->id); ?>><?php echo FrmAppHelper::truncate($form->name, 33); ?></option>
43
  <?php } ?>
44
  </select>
45
  <?php
46
  }
47
-
48
  public static function form_switcher(){
49
- $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", '');
50
-
51
- $frm_form = new FrmForm();
52
- $forms = $frm_form->getAll($where, ' ORDER BY name');
53
- unset($frm_form);
54
-
55
  $args = array('id' => 0, 'form' => 0);
56
- if(isset($_GET['id']) and !isset($_GET['form']))
57
  unset($args['form']);
58
- else if(isset($_GET['form']) and !isset($_GET['id']))
59
  unset($args['id']);
60
-
61
- if(isset($_GET['page']) and $_GET['page'] == 'formidable-entries' and isset($_GET['frm_action']) and in_array($_GET['frm_action'], array('edit', 'show', 'destroy_all'))){
 
62
  $args['frm_action'] = 'list';
63
  $args['form'] = 0;
64
- }else if(isset($_GET['page']) and $_GET['page'] == 'formidable' and isset($_GET['frm_action']) and $_GET['frm_action'] == 'new'){
65
  $args['frm_action'] = 'edit';
66
  }else if(isset($_GET['post'])){
67
  $args['form'] = 0;
@@ -86,48 +95,59 @@ class FrmFormsHelper{
86
  </li>
87
  <?php
88
  }
89
-
90
  public static function get_sortable_classes($col, $sort_col, $sort_dir){
91
- echo ($sort_col == $col) ? 'sorted' : 'sortable';
92
  echo ($sort_col == $col and $sort_dir == 'desc') ? ' asc' : ' desc';
93
  }
94
-
 
 
 
95
  public static function setup_new_vars($values=array()){
96
- global $wpdb, $frmdb, $frm_settings;
97
-
98
  if(!empty($values)){
99
  $post_values = $values;
100
  }else{
101
  $values = array();
102
  $post_values = isset($_POST) ? $_POST : array();
103
  }
104
-
105
  foreach (array('name' => '', 'description' => '') as $var => $default){
106
  if(!isset($values[$var]))
107
  $values[$var] = FrmAppHelper::get_param($var, $default);
108
  }
109
-
110
- if(apply_filters('frm_use_wpautop', true))
111
- $values['description'] = wpautop(str_replace( '<br>', '<br />', $values['description']));
112
-
113
- foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default){
114
  if(!isset($values[$var]))
115
  $values[$var] = FrmAppHelper::get_param($var, $default);
116
  }
117
-
118
  if(!isset($values['form_key']))
119
  $values['form_key'] = ($post_values and isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
120
-
121
  $values = self::fill_default_opts($values, false, $post_values);
122
-
123
- $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $post_values['options']['custom_style'] : ($frm_settings->load_style != 'none');
 
 
 
 
 
 
124
  $values['before_html'] = FrmFormsHelper::get_default_html('before');
125
  $values['after_html'] = FrmFormsHelper::get_default_html('after');
126
  $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
127
-
128
  return apply_filters('frm_setup_new_form_vars', $values);
129
  }
130
-
 
 
 
131
  public static function setup_edit_vars($values, $record, $post_values=array()){
132
  if(empty($post_values))
133
  $post_values = stripslashes_deep($_POST);
@@ -135,64 +155,54 @@ class FrmFormsHelper{
135
  $values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
136
  $values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
137
  $values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
138
-
 
139
  $values = self::fill_default_opts($values, $record, $post_values);
140
 
141
  return apply_filters('frm_setup_edit_form_vars', $values);
142
  }
143
-
144
  public static function fill_default_opts($values, $record, $post_values) {
145
-
146
  $defaults = FrmFormsHelper::get_default_opts();
147
  foreach ($defaults as $var => $default){
148
  if ( is_array($default) ) {
149
  if(!isset($values[$var]))
150
  $values[$var] = ($record && isset($record->options[$var])) ? $record->options[$var] : array();
151
-
152
  foreach($default as $k => $v){
153
  $values[$var][$k] = ($post_values && isset($post_values[$var][$k])) ? $post_values[$var][$k] : (($record && isset($record->options[$var]) && isset($record->options[$var][$k])) ? $record->options[$var][$k] : $v);
154
-
155
  if ( is_array($v) ) {
156
  foreach ( $v as $k1 => $v1 ) {
157
  $values[$var][$k][$k1] = ($post_values && isset($post_values[$var][$k][$k1])) ? $post_values[$var][$k][$k1] : (($record && isset($record->options[$var]) && isset($record->options[$var][$k]) && isset($record->options[$var][$k][$k1])) ? $record->options[$var][$k][$k1] : $v1);
158
- unset($k1);
159
- unset($v1);
160
  }
161
  }
162
-
163
- unset($k);
164
- unset($v);
165
  }
166
-
167
  }else{
168
  $values[$var] = ($post_values && isset($post_values['options'][$var])) ? $post_values['options'][$var] : (($record && isset($record->options[$var])) ? $record->options[$var] : $default);
169
  }
170
-
171
- unset($var);
172
- unset($default);
173
  }
174
-
175
  return $values;
176
  }
177
-
178
  public static function get_default_opts(){
179
- global $frm_settings;
180
-
181
  return array(
182
- 'notification' => array(
183
- array(
184
- 'email_to' => $frm_settings->email_to, 'reply_to' => '', 'reply_to_name' => '',
185
- 'cust_reply_to' => '', 'cust_reply_to_name' => '',
186
- 'email_subject' => '', 'email_message' => '[default-message]',
187
- 'inc_user_info' => 0, 'plain_text' => 0,
188
- )
189
- ),
190
  'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
191
  'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
192
- 'no_save' => 0, 'ajax_load' => 0
193
  );
194
  }
195
-
196
  public static function get_default_html($loc){
197
  if($loc == 'submit'){
198
  $sending = __('Sending', 'formidable');
@@ -214,83 +224,318 @@ BEFORE_HTML;
214
  }else{
215
  $default_html = '';
216
  }
217
-
218
  return $default_html;
219
  }
220
-
221
  public static function get_draft_link(){
222
- $link = '[if save_draft]<a class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
223
  return $link;
224
  }
225
-
226
  public static function get_custom_submit($html, $form, $submit, $form_action, $values){
227
  $button = FrmFormsHelper::replace_shortcodes($html, $form, $submit, $form_action, $values);
228
- if(strpos($button, '[button_action]')){
229
- $button_parts = explode('[button_action]', $button);
230
- echo $button_parts[0];
231
- //echo ' id="frm_submit_"';
232
- $classes = apply_filters('frm_submit_button_class', array(), $form);
233
- if(!empty($classes))
234
- echo ' class="'. implode(' ', $classes) .'"';
235
-
236
- do_action('frm_submit_button_action', $form, $form_action);
237
- echo $button_parts[1];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
 
 
 
 
 
 
 
239
  }
240
-
241
  public static function replace_shortcodes($html, $form, $title=false, $description=false, $values=array()){
242
  foreach (array('form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show){
243
- if ($code == 'form_name'){
244
  $replace_with = $form->name;
245
- }else if ($code == 'form_description'){
246
- if(apply_filters('frm_use_wpautop', true))
247
- $replace_with = wpautop(str_replace( '<br>', '<br />', $form->description));
248
- else
249
- $replace_with = $form->description;
250
- }else if($code == 'entry_key' and isset($_GET) and isset($_GET['entry'])){
251
  $replace_with = $_GET['entry'];
 
 
252
  }
253
-
254
  if ( FrmAppHelper::is_true($show) && $replace_with != '' ) {
255
- $html = str_replace('[if '.$code.']', '', $html);
256
  $html = str_replace('[/if '.$code.']', '', $html);
257
- }else{
258
  $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
259
  }
260
- $html = str_replace('['.$code.']', $replace_with, $html);
261
  }
262
-
263
  //replace [form_key]
264
  $html = str_replace('[form_key]', $form->form_key, $html);
265
-
266
  //replace [frmurl]
267
- $html = str_replace('[frmurl]', FrmAppHelper::plugin_url(), $html);
268
-
269
  if(strpos($html, '[button_label]')){
 
270
  $replace_with = apply_filters('frm_submit_button', $title, $form);
271
  $html = str_replace('[button_label]', $replace_with, $html);
272
  }
273
-
274
  $html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
275
-
276
  if(strpos($html, '[if back_button]'))
277
  $html = preg_replace('/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html);
278
-
279
  if(strpos($html, '[if save_draft]'))
280
  $html = preg_replace('/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html);
281
-
282
  return $html;
283
  }
284
-
285
- public static function form_loaded($form) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  global $frm_vars;
287
  $small_form = new stdClass();
288
  foreach ( array('id', 'form_key', 'name' ) as $var ) {
289
  $small_form->{$var} = $form->{$var};
290
  unset($var);
291
  }
292
-
293
  $frm_vars['forms_loaded'][] = $small_form;
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  }
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  }
1
  <?php
2
  if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
 
 
 
4
  class FrmFormsHelper{
5
+ /*
6
+ * If $form is numeric, get the form object
7
+ */
8
+ public static function maybe_get_form( &$form ) {
9
+ if ( ! is_object($form) && ! is_array($form) ) {
10
+ $form = FrmForm::getOne($form);
11
+ }
12
+ }
13
+
14
  public static function get_direct_link($key, $form = false ) {
15
  $target_url = esc_url(admin_url('admin-ajax.php') . '?action=frm_forms_preview&form='. $key);
16
  $target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
17
 
18
  return $target_url;
19
  }
20
+
21
+ public static function forms_dropdown( $field_name, $field_value='', $args = array() ) {
22
+ $defaults = array(
23
+ 'blank' => true,
24
+ 'field_id' => false,
25
+ 'onchange' => false,
26
+ 'exclude' => false,
27
+ );
28
+ $args = wp_parse_args( $args, $defaults );
29
+
30
+ if ( ! $args['field_id'] ) {
31
+ $args['field_id'] = $field_name;
32
  }
33
+
34
+ global $wpdb;
35
+
36
+ $query = "is_template=0 AND (status is NULL OR status = '' OR status = 'published') AND (parent_form_id IS NULL OR parent_form_id < 1)";
37
+ if ( $args['exclude'] ) {
38
+ $query .= $wpdb->prepare(" AND id != %d", $args['exclude']);
39
+ }
40
+
41
+ $where = apply_filters('frm_forms_dropdown', $query, $field_name);
42
+ $forms = FrmForm::getAll($where, 'name');
43
  ?>
44
+ <select name="<?php echo $field_name; ?>" id="<?php echo $args['field_id'] ?>" <?php
45
+ if ( $args['onchange'] ) {
46
+ echo 'onchange="'. $args['onchange'] .'"';
47
+ } ?>>
48
+ <?php if ( $args['blank'] ) { ?>
49
+ <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- '. $args['blank'] .' -'; ?></option>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  <?php } ?>
51
  <?php foreach($forms as $form){ ?>
52
+ <option value="<?php echo $form->id; ?>" <?php selected($field_value, $form->id); ?>><?php echo '' == $form->name ? __('(no title)', 'formidable') : FrmAppHelper::truncate($form->name, 33); ?></option>
53
  <?php } ?>
54
  </select>
55
  <?php
56
  }
57
+
58
  public static function form_switcher(){
59
+ $where = apply_filters('frm_forms_dropdown', "(parent_form_id IS NULL OR parent_form_id < 1) AND is_template=0 AND (status is NULL OR status = '' OR status = 'published')", '');
60
+
61
+ $forms = FrmForm::getAll($where, 'name');
62
+
 
 
63
  $args = array('id' => 0, 'form' => 0);
64
+ if ( isset($_GET['id']) && ! isset($_GET['form']) ) {
65
  unset($args['form']);
66
+ } else if(isset($_GET['form']) && ! isset($_GET['id']) ) {
67
  unset($args['id']);
68
+ }
69
+
70
+ if ( FrmAppHelper::is_admin_page('formidable-entries') && isset($_GET['frm_action']) && in_array($_GET['frm_action'], array('edit', 'show', 'destroy_all')) ) {
71
  $args['frm_action'] = 'list';
72
  $args['form'] = 0;
73
+ }else if ( FrmAppHelper::is_admin_page('formidable') && isset($_GET['frm_action']) && in_array($_GET['frm_action'], array('new', 'duplicate')) ) {
74
  $args['frm_action'] = 'edit';
75
  }else if(isset($_GET['post'])){
76
  $args['form'] = 0;
95
  </li>
96
  <?php
97
  }
98
+
99
  public static function get_sortable_classes($col, $sort_col, $sort_dir){
100
+ echo ($sort_col == $col) ? 'sorted' : 'sortable';
101
  echo ($sort_col == $col and $sort_dir == 'desc') ? ' asc' : ' desc';
102
  }
103
+
104
+ /*
105
+ * Used when a form is created
106
+ */
107
  public static function setup_new_vars($values=array()){
108
+ global $wpdb;
109
+
110
  if(!empty($values)){
111
  $post_values = $values;
112
  }else{
113
  $values = array();
114
  $post_values = isset($_POST) ? $_POST : array();
115
  }
116
+
117
  foreach (array('name' => '', 'description' => '') as $var => $default){
118
  if(!isset($values[$var]))
119
  $values[$var] = FrmAppHelper::get_param($var, $default);
120
  }
121
+
122
+ $values['description'] = FrmAppHelper::use_wpautop($values['description']);
123
+
124
+ foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0, 'status' => 'draft', 'parent_form_id' => 0) as $var => $default){
 
125
  if(!isset($values[$var]))
126
  $values[$var] = FrmAppHelper::get_param($var, $default);
127
  }
128
+
129
  if(!isset($values['form_key']))
130
  $values['form_key'] = ($post_values and isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
131
+
132
  $values = self::fill_default_opts($values, false, $post_values);
133
+
134
+ if ( $post_values && isset($post_values['options']['custom_style']) ) {
135
+ $values['custom_style'] = $post_values['options']['custom_style'];
136
+ } else {
137
+ $frm_settings = FrmAppHelper::get_settings();
138
+ $values['custom_style'] = ( $frm_settings->load_style != 'none' );
139
+ }
140
+
141
  $values['before_html'] = FrmFormsHelper::get_default_html('before');
142
  $values['after_html'] = FrmFormsHelper::get_default_html('after');
143
  $values['submit_html'] = FrmFormsHelper::get_default_html('submit');
144
+
145
  return apply_filters('frm_setup_new_form_vars', $values);
146
  }
147
+
148
+ /*
149
+ * Used when editing a form
150
+ */
151
  public static function setup_edit_vars($values, $record, $post_values=array()){
152
  if(empty($post_values))
153
  $post_values = stripslashes_deep($_POST);
155
  $values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
156
  $values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
157
  $values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
158
+ $values['status'] = $record->status;
159
+
160
  $values = self::fill_default_opts($values, $record, $post_values);
161
 
162
  return apply_filters('frm_setup_edit_form_vars', $values);
163
  }
164
+
165
  public static function fill_default_opts($values, $record, $post_values) {
166
+
167
  $defaults = FrmFormsHelper::get_default_opts();
168
  foreach ($defaults as $var => $default){
169
  if ( is_array($default) ) {
170
  if(!isset($values[$var]))
171
  $values[$var] = ($record && isset($record->options[$var])) ? $record->options[$var] : array();
172
+
173
  foreach($default as $k => $v){
174
  $values[$var][$k] = ($post_values && isset($post_values[$var][$k])) ? $post_values[$var][$k] : (($record && isset($record->options[$var]) && isset($record->options[$var][$k])) ? $record->options[$var][$k] : $v);
175
+
176
  if ( is_array($v) ) {
177
  foreach ( $v as $k1 => $v1 ) {
178
  $values[$var][$k][$k1] = ($post_values && isset($post_values[$var][$k][$k1])) ? $post_values[$var][$k][$k1] : (($record && isset($record->options[$var]) && isset($record->options[$var][$k]) && isset($record->options[$var][$k][$k1])) ? $record->options[$var][$k][$k1] : $v1);
179
+ unset($k1, $v1);
 
180
  }
181
  }
182
+
183
+ unset($k, $v);
 
184
  }
185
+
186
  }else{
187
  $values[$var] = ($post_values && isset($post_values['options'][$var])) ? $post_values['options'][$var] : (($record && isset($record->options[$var])) ? $record->options[$var] : $default);
188
  }
189
+
190
+ unset($var, $default);
 
191
  }
192
+
193
  return $values;
194
  }
195
+
196
  public static function get_default_opts(){
197
+ $frm_settings = FrmAppHelper::get_settings();
198
+
199
  return array(
 
 
 
 
 
 
 
 
200
  'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
201
  'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
202
+ 'no_save' => 0, 'ajax_load' => 0, 'form_class' => '',
203
  );
204
  }
205
+
206
  public static function get_default_html($loc){
207
  if($loc == 'submit'){
208
  $sending = __('Sending', 'formidable');
224
  }else{
225
  $default_html = '';
226
  }
227
+
228
  return $default_html;
229
  }
230
+
231
  public static function get_draft_link(){
232
+ $link = '[if save_draft]<a href="javascript:void(0)" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
233
  return $link;
234
  }
235
+
236
  public static function get_custom_submit($html, $form, $submit, $form_action, $values){
237
  $button = FrmFormsHelper::replace_shortcodes($html, $form, $submit, $form_action, $values);
238
+ if ( ! strpos($button, '[button_action]') ) {
239
+ return;
240
+ }
241
+
242
+ $button_parts = explode('[button_action]', $button);
243
+ echo $button_parts[0];
244
+ //echo ' id="frm_submit_"';
245
+
246
+ $classes = apply_filters('frm_submit_button_class', array(), $form);
247
+ if ( ! empty($classes) ) {
248
+ echo ' class="'. implode(' ', $classes) .'"';
249
+ }
250
+
251
+ do_action('frm_submit_button_action', $form, $form_action);
252
+ echo $button_parts[1];
253
+ }
254
+
255
+ /*
256
+ * Automatically add end section fields if they don't exist (2.0 migration)
257
+ * @since 2.0
258
+ */
259
+ public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
260
+ $end_section_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars('end_divider', $form->id));
261
+ $open = false;
262
+ foreach ( $fields as $field ) {
263
+ switch ( $field->type ) {
264
+ case 'divider':
265
+ // create an end section if open
266
+ FrmFormsHelper::maybe_create_end_section($open, $reset_fields, $end_section_values, ( $field->field_order - 1 ) );
267
+ // mark it open for the next end section
268
+ $open = true;
269
+ break;
270
+ case 'break';
271
+ FrmFormsHelper::maybe_create_end_section($open, $reset_fields, $end_section_values, ( $field->field_order - 1 ) );
272
+ break;
273
+ case 'end_divider':
274
+ // There is already an end section here, so there is no need to create one
275
+ $open = false;
276
+ }
277
+
278
+ unset($field);
279
+ }
280
+
281
+ $last_order = end($fields);
282
+ $last_order = $last_order->field_order;
283
+ FrmFormsHelper::maybe_create_end_section($open, $reset_fields, $end_section_values, ( $last_order + 1 ) );
284
+ }
285
+
286
+ /*
287
+ * Create end section field if it doesn't exist. This is for migration from < 2.0
288
+ */
289
+ public static function maybe_create_end_section( &$open, &$reset_fields, $end_section_values, $order ) {
290
+ if ( ! $open ) {
291
+ return;
292
  }
293
+
294
+ $end_section_values['field_order'] = $order;
295
+
296
+ FrmField::create( $end_section_values );
297
+
298
+ $open = false;
299
+ $reset_fields = true;
300
  }
301
+
302
  public static function replace_shortcodes($html, $form, $title=false, $description=false, $values=array()){
303
  foreach (array('form_name' => $title, 'form_description' => $description, 'entry_key' => true) as $code => $show){
304
+ if ( $code == 'form_name' ) {
305
  $replace_with = $form->name;
306
+ } else if ( $code == 'form_description' ) {
307
+ $replace_with = FrmAppHelper::use_wpautop($form->description);
308
+ } else if ( $code == 'entry_key' && isset($_GET) && isset($_GET['entry']) ) {
 
 
 
309
  $replace_with = $_GET['entry'];
310
+ } else {
311
+ $replace_with = '';
312
  }
313
+
314
  if ( FrmAppHelper::is_true($show) && $replace_with != '' ) {
315
+ $html = str_replace('[if '.$code.']', '', $html);
316
  $html = str_replace('[/if '.$code.']', '', $html);
317
+ } else {
318
  $html = preg_replace('/(\[if\s+'.$code.'\])(.*?)(\[\/if\s+'.$code.'\])/mis', '', $html);
319
  }
320
+ $html = str_replace('['.$code.']', $replace_with, $html);
321
  }
322
+
323
  //replace [form_key]
324
  $html = str_replace('[form_key]', $form->form_key, $html);
325
+
326
  //replace [frmurl]
327
+ $html = str_replace('[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html);
328
+
329
  if(strpos($html, '[button_label]')){
330
+ add_filter('frm_submit_button', 'FrmFormsHelper::submit_button_label');
331
  $replace_with = apply_filters('frm_submit_button', $title, $form);
332
  $html = str_replace('[button_label]', $replace_with, $html);
333
  }
334
+
335
  $html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
336
+
337
  if(strpos($html, '[if back_button]'))
338
  $html = preg_replace('/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html);
339
+
340
  if(strpos($html, '[if save_draft]'))
341
  $html = preg_replace('/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html);
342
+
343
  return $html;
344
  }
345
+
346
+ public static function submit_button_label($submit){
347
+ if ( ! $submit || empty($submit) ) {
348
+ $frm_settings = FrmAppHelper::get_settings();
349
+ $submit = $frm_settings->submit_value;
350
+ }
351
+
352
+ return $submit;
353
+ }
354
+
355
+ public static function get_form_style_class($form = false) {
356
+ $style = self::get_form_style($form);
357
+ $class = ' with_frm_style';
358
+
359
+ if ( empty($style) ) {
360
+ if ( FrmAppHelper::is_admin_page('formidable-entries') ) {
361
+ return $class;
362
+ } else {
363
+ return;
364
+ }
365
+ }
366
+
367
+ //If submit button needs to be inline or centered
368
+ if ( is_object($form) ) {
369
+ if ( isset( $form->options['submit_align'] ) && $form->options['submit_align'] ) {
370
+ if ( $form->options['submit_align'] == 'inline' ) {
371
+ $class .= ' frm_inline_form';
372
+ } else if ( $form->options['submit_align'] == 'center' ) {
373
+ $class .= ' frm_center_submit';
374
+ }
375
+ }
376
+ } else if ( isset($form['submit_align']) && $form['submit_align'] ) {
377
+ if ( $form['submit_align'] == 'inline' ) {
378
+ $class .= ' frm_inline_form';
379
+ } else if ( $form['submit_align'] == 'center' ) {
380
+ $class .= ' frm_center_submit';
381
+ }
382
+ }
383
+ $class = apply_filters('frm_add_form_style_class', $class, $style);
384
+
385
+ return $class;
386
+ }
387
+
388
+ public static function get_form_style( $form ) {
389
+ if ( empty($form) ) {
390
+ $style = 1;
391
+ } else if ( is_object($form) ) {
392
+ $style = isset($form->options['custom_style']) ? $form->options['custom_style'] : 1;
393
+ } else if ( is_array($form) ) {
394
+ $style = isset($form['custom_style']) ? $form['custom_style'] : 1;
395
+ } else if ( 'default' == 'form' ) {
396
+ $style = 1;
397
+ } else {
398
+ $form = FrmForm::getOne($form);
399
+ $style = ( $form && isset($form->options['custom_style']) ) ? $form->options['custom_style'] : 1;
400
+ }
401
+
402
+ return $style;
403
+ }
404
+
405
+ public static function form_loaded($form, $this_load, $global_load) {
406
  global $frm_vars;
407
  $small_form = new stdClass();
408
  foreach ( array('id', 'form_key', 'name' ) as $var ) {
409
  $small_form->{$var} = $form->{$var};
410
  unset($var);
411
  }
412
+
413
  $frm_vars['forms_loaded'][] = $small_form;
414
+
415
+ if ( $this_load && empty($global_load) ) {
416
+ $global_load = $frm_vars['load_css'] = true;
417
+ }
418
+
419
+ if ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ) {
420
+ echo FrmAppController::footer_js('header');
421
+ $frm_vars['css_loaded'] = true;
422
+ }
423
+ }
424
+
425
+ public static function get_scroll_js($form_id) {
426
+ ?><script type="text/javascript">jQuery(document).ready(function($){frmFrontForm.scrollMsg(<?php echo $form_id ?>);})</script><?php
427
  }
428
 
429
+ public static function edit_form_link($form_id) {
430
+ if ( is_object($form_id) ) {
431
+ $form = $form_id;
432
+ $name = $form->name;
433
+ $form_id = $form->id;
434
+ } else {
435
+ $name = FrmForm::getName($form_id);
436
+ }
437
+
438
+ if ( $form_id ) {
439
+ $val = '<a href="'. admin_url('admin.php') .'?page=formidable&frm_action=edit&id='. $form_id .'">'. ( '' == $name ? __('(no title)') : FrmAppHelper::truncate($name, 40) ) .'</a>';
440
+ } else {
441
+ $val = '';
442
+ }
443
+
444
+ return $val;
445
+ }
446
+
447
+ public static function delete_trash_link($id, $status, $length = 'long') {
448
+ $link = '';
449
+ $labels = array(
450
+ 'restore' => array(
451
+ 'long' => __('Restore from Trash', 'formidable'),
452
+ 'short' => __('Restore', 'formidable'),
453
+ ),
454
+ 'trash' => array(
455
+ 'long' => __('Move to Trash', 'formidable'),
456
+ 'short' => __('Trash', 'formidable'),
457
+ ),
458
+ 'delete' => array(
459
+ 'long' => __('Delete Permanently', 'formidable'),
460
+ 'short' => __('Delete', 'formidable'),
461
+ ),
462
+ );
463
+
464
+ $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
465
+ $base_url = '?page=formidable&form_type='. $current_page .'&id='. $id;
466
+ if ( 'trash' == $status ) {
467
+ $link = '<a href="'. esc_url(wp_nonce_url( $base_url .'&frm_action=untrash', 'untrash_form_' . $id )) .'" class="submitdelete deletion">'. $labels['restore'][$length] .'</a>';
468
+ } else if ( current_user_can('frm_delete_forms') ) {
469
+ if ( EMPTY_TRASH_DAYS ) {
470
+ $link = '<a href="'. wp_nonce_url( $base_url .'&frm_action=trash', 'trash_form_' . $id ) .'" class="submitdelete deletion">'. $labels['trash'][$length] .'</a>';
471
+ } else {
472
+ $link = '<a href="'. wp_nonce_url( $base_url .'&frm_action=destroy', 'destroy_form_' . $id ) .'" class="submitdelete deletion" onclick="return confirm(\''. __('Are you sure you want to delete this form and all its entries?', 'formidable') .'\')">'. $labels['delete'][$length] .'</a>';
473
+ }
474
+ }
475
+
476
+ return $link;
477
+ }
478
+
479
+ public static function status_nice_name($status) {
480
+ $nice_names = array(
481
+ 'draft' => __('Draft', 'formidable'),
482
+ 'trash' => __('Trash', 'formidable'),
483
+ 'publish' => __('Published', 'formidable'),
484
+ );
485
+
486
+ if ( ! in_array($status, array_keys($nice_names)) ) {
487
+ $status = 'publish';
488
+ }
489
+
490
+ $name = $nice_names[$status];
491
+
492
+ return $name;
493
+ }
494
+
495
+ public static function get_params() {
496
+ $values = array();
497
+ foreach ( array('template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '') as $var => $default ) {
498
+ $values[$var] = FrmAppHelper::get_param($var, $default);
499
+ }
500
+
501
+ return $values;
502
+ }
503
+
504
+ /*
505
+ *
506
+ * @return int The number of forms changed
507
+ */
508
+ public static function change_form_status( $status ) {
509
+ $available_status = array(
510
+ 'untrash' => array(
511
+ 'permission' => 'frm_edit_forms', 'new_status' => 'published',
512
+ ),
513
+ 'trash' => array(
514
+ 'permission' => 'frm_delete_forms', 'new_status' => 'trash',
515
+ ),
516
+ );
517
+
518
+ if ( ! isset($available_status[$status]) ) {
519
+ return;
520
+ }
521
+
522
+ FrmAppHelper::permission_check($available_status[$status]['permission']);
523
+
524
+ $params = self::get_params();
525
+
526
+ //check nonce url
527
+ check_admin_referer($status .'_form_' . $params['id']);
528
+
529
+ $count = 0;
530
+ if ( FrmForm::set_status( $params['id'], $available_status[$status]['new_status'] ) ) {
531
+ $count++;
532
+ }
533
+
534
+ $available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
535
+ $available_status['trash']['message'] = sprintf(_n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="'. esc_url(wp_nonce_url( '?page=formidable&frm_action=untrash&form_type='. ( isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '' ) .'&id='. $params['id'], 'untrash_form_' . $params['id'] )) .'">', '</a>' );
536
+
537
+ $message = $available_status[$status]['message'];
538
+
539
+ FrmFormsController::display_forms_list($params, $message, 1);
540
+ }
541
  }
classes/helpers/FrmFormsListHelper.php ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
+
4
+ class FrmFormsListHelper extends FrmListHelper {
5
+ var $status = '';
6
+
7
+ function __construct($args) {
8
+ $this->status = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
9
+
10
+ parent::__construct( $args );
11
+ }
12
+
13
+ function prepare_items() {
14
+ global $wpdb, $per_page, $mode;
15
+
16
+ $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
17
+
18
+ $default_orderby = 'name';
19
+ $default_order = 'ASC';
20
+
21
+ $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
22
+ $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
23
+
24
+ $page = $this->get_pagenum();
25
+ $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
26
+
27
+ $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
28
+
29
+ $s_query = ' (parent_form_id IS NULL OR parent_form_id < 1) AND ';
30
+ switch ( $this->status ) {
31
+ case 'template':
32
+ $s_query .= "is_template = 1 AND status != 'trash'";
33
+ break;
34
+ case 'draft':
35
+ $s_query .= "is_template = 0 AND status = 'draft'";
36
+ break;
37
+ case 'trash':
38
+ $s_query .= "status='trash'";
39
+ break;
40
+ default:
41
+ $s_query .= "is_template = 0 AND status != 'trash'";
42
+ break;
43
+ }
44
+
45
+ $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
46
+ if ( $s != '' ) {
47
+ preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
48
+ $search_terms = array_map('trim', $matches[0]);
49
+ foreach ( (array) $search_terms as $term ) {
50
+ if ( !empty($s_query) ) {
51
+ $s_query .= " AND";
52
+ }
53
+
54
+ $term = FrmAppHelper::esc_like($term);
55
+
56
+ $s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%'. $term .'%', '%'. $term .'%', '%'. $term .'%');
57
+
58
+ unset($term);
59
+ }
60
+ }
61
+
62
+ $this->items = FrmForm::getAll($s_query, $orderby .' '. $order, $start .','. $per_page);
63
+ $total_items = FrmAppHelper::getRecordCount($s_query, $wpdb->prefix .'frm_forms');
64
+
65
+
66
+ $this->set_pagination_args( array(
67
+ 'total_items' => $total_items,
68
+ 'per_page' => $per_page
69
+ ) );
70
+ }
71
+
72
+ function no_items() {
73
+ if ( 'template' == $this->status ) {
74
+ _e('No Templates Found', 'formidable') ?>.
75
+ <br/><br/><?php _e('To add a new template','formidable') ?>:
76
+ <ol><li><?php printf(__('Create a new %1$sform%2$s.', 'formidable'), '<a href="?page=formidable&amp;frm_action=new-selection">', '</a>') ?></li>
77
+ <li><?php printf(__('After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable'), '<a href="?page=formidable">', '</a>') ?></li>
78
+ <li><?php _e('Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable') ?></li>
79
+ </ol>
80
+ <?php }else{
81
+ _e('No Forms Found', 'formidable') ?>.
82
+ <a href="?page=formidable&amp;frm_action=new-selection"><?php _e('Add New', 'formidable'); ?></a>
83
+ <?php }
84
+ }
85
+
86
+ function get_bulk_actions(){
87
+ $actions = array();
88
+
89
+ if ( in_array($this->status, array('', 'published')) ) {
90
+ $actions['bulk_create_template'] = __('Create Template', 'formidable');
91
+ }
92
+
93
+ if ( 'trash' == $this->status ) {
94
+ if ( current_user_can('frm_edit_forms') ) {
95
+ $actions['bulk_untrash'] = __('Restore', 'formidable');
96
+ }
97
+
98
+ if ( current_user_can('frm_delete_forms') ) {
99
+ $actions['bulk_delete'] = __('Delete Permanently', 'formidable');
100
+ }
101
+ } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
102
+ $actions['bulk_trash'] = __('Move to Trash', 'formidable');
103
+ } else if ( current_user_can('frm_delete_forms') ) {
104
+ $actions['bulk_delete'] = __('Delete');
105
+ }
106
+
107
+ return $actions;
108
+ }
109
+
110
+ function extra_tablenav( $which ) {
111
+ if ( 'top' != $which || 'template' != $this->status ) {
112
+ return;
113
+ }
114
+
115
+ $where = apply_filters('frm_forms_dropdown', "(parent_form_id IS NULL OR parent_form_id < 1) AND is_template=0 AND (status is NULL OR status = '' OR status = 'published')", '');
116
+
117
+ $forms = FrmForm::getAll($where, 'name');
118
+
119
+ $base = admin_url('admin.php?page=formidable&form_type=template');
120
+ $args = array(
121
+ 'frm_action' => 'duplicate',
122
+ 'template' => true,
123
+ );
124
+
125
+ ?>
126
+ <div class="alignleft actions" style="overflow:visible;">
127
+ <div class="button dropdown" style="margin-top:1px;">
128
+ <a href="#" id="frm-templateDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Create New Template', 'formidable') ?> <b class="caret"></b></a>
129
+ <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-templateDrop">
130
+ <?php foreach ( $forms as $form ) {
131
+ $args['id'] = $form->id; ?>
132
+ <li><a href="<?php echo add_query_arg($args, $base); ?>" tabindex="-1"><?php echo empty($form->name) ? __('(no title)') : FrmAppHelper::truncate($form->name, 33); ?></a></li>
133
+ <?php
134
+ unset($form);
135
+ } ?>
136
+ </ul>
137
+ </div>
138
+ </div>
139
+ <?php
140
+ }
141
+
142
+ function get_views() {
143
+
144
+ $statuses = array(
145
+ 'published' => __('My Forms', 'formidable'),
146
+ 'template' => __('Templates', 'formidable'),
147
+ 'draft' => __('Drafts', 'formidable'),
148
+ 'trash' => __('Trash', 'formidable'),
149
+ );
150
+
151
+ $links = array();
152
+ $counts = FrmForm::get_count();
153
+
154
+ foreach ( $statuses as $status => $name ) {
155
+
156
+ if ( (isset($_REQUEST['form_type']) && $status == $_REQUEST['form_type']) || ( !isset($_REQUEST['form_type']) && 'published' == $status ) ) {
157
+ $class = ' class="current"';
158
+ } else {
159
+ $class = '';
160
+ }
161
+
162
+ if ( $counts->{$status} || 'published' == $status ) {
163
+ $links[$status] = '<a href="?page=formidable&form_type='. $status .'" '. $class .'>'. sprintf( __('%1$s <span class="count">(%2$s)</span>', 'formidable'), $name, number_format_i18n( $counts->{$status} ) ) .'</a>';
164
+ }
165
+
166
+ unset($status, $name);
167
+ }
168
+
169
+ return $links;
170
+ }
171
+
172
+ function pagination( $which ) {
173
+ global $mode;
174
+
175
+ parent::pagination ( $which );
176
+
177
+ if ( 'top' == $which ) {
178
+ $this->view_switcher( $mode );
179
+ }
180
+ }
181
+
182
+ function single_row( $item, $style='') {
183
+ global $frm_vars, $mode;
184
+
185
+ // Set up the hover actions for this user
186
+ $actions = array();
187
+ $edit_link = '?page=formidable&frm_action=edit&id='. $item->id;
188
+ $duplicate_link = '?page=formidable&frm_action=duplicate&id='. $item->id;
189
+
190
+ $this->get_actions($actions, $item, $edit_link, $duplicate_link);
191
+
192
+ $action_links = $this->row_actions( $actions );
193
+
194
+ // Set up the checkbox ( because the user is editable, otherwise its empty )
195
+ $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
196
+
197
+ $r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
198
+
199
+ list( $columns, $hidden ) = $this->get_column_info();
200
+
201
+ $format = 'Y/m/d';
202
+ if ( 'list' != $mode ) {
203
+ $format .= ' \<\b\r \/\> g:i:s a';
204
+ }
205
+
206
+ foreach ( $columns as $column_name => $column_display_name ) {
207
+ $class = 'class="'. $column_name .' column-'. $column_name . ( ('name' == $column_name) ? ' post-title page-title column-title' : '' ) .'"';
208
+
209
+ $style = '';
210
+ if ( in_array( $column_name, $hidden ) ) {
211
+ $style = ' style="display:none;"';
212
+ }
213
+
214
+ $attributes = $class . $style;
215
+
216
+ switch ( $column_name ) {
217
+ case 'cb':
218
+ $r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
219
+ break;
220
+ case 'id':
221
+ case 'form_key':
222
+ $val = $item->{$column_name};
223
+ break;
224
+ case 'name':
225
+ $val = $this->get_form_name( $item, $actions, $edit_link );
226
+ $val .= $action_links;
227
+
228
+ break;
229
+ case 'created_at':
230
+ $date = date($format, strtotime($item->created_at));
231
+ $val = '<abbr title="'. date('Y/m/d g:i:s A', strtotime($item->created_at)) .'">'. $date .'</abbr>';
232
+ break;
233
+ case 'shortcode':
234
+ $val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
235
+ if ( 'excerpt' == $mode ) {
236
+ $val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
237
+ }
238
+ break;
239
+ case 'entries':
240
+ if( isset($item->options['no_save']) && $item->options['no_save'] ) {
241
+ $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="'. esc_attr('Entries are not being saved', 'formidable') .'"></i>';
242
+ } else {
243
+ $text = FrmEntry::getRecordCount($item->id);
244
+ $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
245
+ unset($text);
246
+ }
247
+ break;
248
+ case 'type':
249
+ $val = ( $item->is_template && $item->default_template ) ? __('Default', 'formidable') : __('Custom', 'formidable');
250
+ break;
251
+ }
252
+
253
+ if ( isset($val) ) {
254
+ $r .= "<td $attributes>";
255
+ $r .= $val;
256
+ $r .= '</td>';
257
+ }
258
+ unset($val);
259
+ }
260
+ $r .= '</tr>';
261
+
262
+ return $r;
263
+ }
264
+
265
+ private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
266
+ if ( 'trash' == $this->status ) {
267
+ $actions['restore'] = FrmFormsHelper::delete_trash_link($item->id, $item->status, 'short');
268
+ if ( current_user_can('frm_delete_forms') && ! $item->default_template ) {
269
+ $actions['trash'] = '<a href="' . esc_url(wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id='. $item->id, 'destroy_form_'. $item->id )) .'" class="submitdelete" onclick="return confirm(\''. __('Are you sure you want to permanently delete that?', 'formidable') .'\')">' . __( 'Delete Permanently' ) . '</a>';
270
+ }
271
+ return;
272
+ }
273
+
274
+ if ( current_user_can('frm_edit_forms') ) {
275
+ if ( ! $item->is_template || ! $item->default_template ) {
276
+ $actions['frm_edit'] = '<a href="'. esc_url( $edit_link ) . '">'. __('Edit') .'</a>';
277
+ }
278
+
279
+ if ( $item->is_template ) {
280
+ $actions['frm_duplicate'] = '<a href="'. wp_nonce_url( $duplicate_link ) .'">'. __('Create Form from Template', 'formidable') .'</a>';
281
+ } else {
282
+ $actions['frm_settings'] = '<a href="'. esc_url('?page=formidable&frm_action=settings&id='. $item->id ) . '">'. __('Settings', 'formidable') .'</a>';
283
+
284
+ if ( FrmAppHelper::pro_is_installed() ) {
285
+ $actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __('Duplicate', 'formidable') .'</a>';
286
+ }
287
+ }
288
+ }
289
+
290
+ if ( ! $item->default_template ) {
291
+ $actions['trash'] = FrmFormsHelper::delete_trash_link($item->id, $item->status, 'short');
292
+ }
293
+
294
+ $actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __('Preview') .'</a>';
295
+ }
296
+
297
+ private function get_form_name( $item, $actions, $edit_link ) {
298
+ $form_name = $item->name;
299
+ if ( trim($form_name) == '' ) {
300
+ $form_name = __('(no title)');
301
+ }
302
+ $form_name = FrmAppHelper::truncate(strip_tags($form_name), 50);
303
+
304
+ $val = '<strong>';
305
+ if ( 'trash' == $this->status ) {
306
+ $val .= $form_name;
307
+ } else {
308
+ $val .= '<a href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'" class="row-title">'. $form_name .'</a> ';
309
+ }
310
+
311
+ $this->add_draft_label( $item, $val );
312
+ $val .= '</strong>';
313
+
314
+ $this->add_form_description( $item, $val );
315
+
316
+ return $val;
317
+ }
318
+
319
+ private function add_draft_label( $item, &$val ) {
320
+ if ( 'draft' == $item->status && 'draft' != $this->status ) {
321
+ $val .= ' - <span class="post-state">'. __('Draft', 'formidable') .'</span>';
322
+ }
323
+ }
324
+
325
+ private function add_form_description( $item, &$val ) {
326
+ global $mode;
327
+ if ( 'excerpt' == $mode ) {
328
+ $val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
329
+ }
330
+ }
331
+ }
classes/helpers/FrmListHelper.php CHANGED
@@ -1,26 +1,14 @@
1
  <?php
2
-
3
  if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
4
 
5
- if(class_exists('FrmListHelper'))
6
- return;
7
-
8
  class FrmListHelper extends WP_List_Table {
9
-
10
  function __construct($args) {
11
- global $frm_settings;
12
-
13
  $args = wp_parse_args( $args, array(
14
- 'ajax' => false,
15
- 'table_name' => '',
16
- 'page_name' => '',
17
  'params' => array()
18
  ) );
19
- $this->table_name = $args['table_name'];
20
- $this->page_name = $args['page_name'];
21
  $this->params = $args['params'];
22
-
23
- $screen = get_current_screen();
24
 
25
  parent::__construct( $args );
26
  }
@@ -29,77 +17,6 @@ class FrmListHelper extends WP_List_Table {
29
  return current_user_can( 'administrator' );
30
  }
31
 
32
- function prepare_items() {
33
- global $wpdb, $per_page, $frm_settings;
34
- $paged = $this->get_pagenum();
35
- $default_orderby = 'name';
36
- $default_order = 'ASC';
37
-
38
- $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
39
- $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
40
-
41
- $page = $this->get_pagenum();
42
- $default_count = empty($this->page_name) ? 20 : 10;
43
- $per_page = $this->get_items_per_page( 'formidable_page_formidable'. str_replace('-', '_', $this->page_name) .'_per_page', $default_count);
44
-
45
- $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
46
- $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
47
- $fid = isset( $_REQUEST['fid'] ) ? $_REQUEST['fid'] : '';
48
- if($s != ''){
49
- preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
50
- $search_terms = array_map('trim', $matches[0]);
51
- }
52
-
53
- $s_query = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = ". (int)$this->params['template'];
54
-
55
- if($s != ''){
56
- foreach ( (array) $search_terms as $term ) {
57
- if ( !empty($s_query) ) {
58
- $s_query .= " AND";
59
- }
60
-
61
- $term = FrmAppHelper::esc_like($term);
62
-
63
- $s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%'. $term .'%', '%'. $term .'%', '%'. $term .'%');
64
-
65
- unset($term);
66
- }
67
- }
68
-
69
- $frm_form = new FrmForm();
70
- $this->items = $frm_form->getAll($s_query, " ORDER BY $orderby $order", " LIMIT $start, $per_page", true, false);
71
- $total_items = FrmAppHelper::getRecordCount($s_query, $this->table_name);
72
-
73
-
74
- $this->set_pagination_args( array(
75
- 'total_items' => $total_items,
76
- 'per_page' => $per_page
77
- ) );
78
- }
79
-
80
- function no_items() {
81
- if ($this->params['template']){
82
- _e('No Templates Found', 'formidable') ?>.
83
- <br/><br/><?php _e('To add a new template','formidable') ?>:
84
- <ol><li><?php printf(__('Create a new %1$sform%2$s.', 'formidable'), '<a href="?page=formidable&amp;frm_action=new-selection">', '</a>') ?></li>
85
- <li><?php printf(__('After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable'), '<a href="?page=formidable">', '</a>') ?></li>
86
- <li><?php _e('Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable') ?></li>
87
- </ol>
88
- <?php }else{
89
- _e('No Forms Found', 'formidable') ?>.
90
- <a href="?page=formidable&amp;frm_action=new-selection"><?php _e('Add New', 'formidable'); ?></a>
91
- <?php }
92
- }
93
-
94
- function get_bulk_actions(){
95
- $actions = array();
96
- if ( current_user_can('frm_delete_forms') ) {
97
- $actions['bulk_delete'] = __('Delete');
98
- }
99
-
100
- return $actions;
101
- }
102
-
103
  function display_rows() {
104
  $style = '';
105
  foreach ( $this->items as $item ) {
@@ -107,122 +24,5 @@ class FrmListHelper extends WP_List_Table {
107
  echo "\n\t", $this->single_row( $item, $style );
108
  }
109
  }
110
-
111
- function single_row( $item, $style='') {
112
- global $frm_vars, $frm_entry;
113
- $checkbox = '';
114
-
115
- // Set up the hover actions for this user
116
- $actions = array();
117
- $title = esc_attr(strip_tags($item->name));
118
-
119
- if ( current_user_can('frm_edit_forms') ) {
120
- $edit_link = "?page=formidable&frm_action=edit&id={$item->id}";
121
- $duplicate_link = "?page=formidable&frm_action=duplicate&id={$item->id}";
122
-
123
- $actions['frm_edit'] = "<a href='" . esc_url( $edit_link ) . "'>". __('Edit') ."</a>";
124
-
125
- if ( $this->params['template'] ) {
126
- $actions['frm_duplicate'] = "<a href='" . wp_nonce_url( $duplicate_link ) . "'>". __('Create Form from Template', 'formidable') ."</a>";
127
- } else {
128
- $actions['frm_settings'] = "<a href='" . wp_nonce_url( "?page=formidable&frm_action=settings&id={$item->id}" ) . "'>". __('Settings', 'formidable') ."</a>";
129
-
130
- if ( $frm_vars['pro_is_installed'] ) {
131
- $actions['duplicate'] = '<a href="' . wp_nonce_url( $duplicate_link ) . '">'. __('Duplicate', 'formidable') .'</a>';
132
- }
133
- }
134
- }
135
-
136
- $delete_link = "?page=formidable&frm_action=destroy&id={$item->id}";
137
- if(current_user_can('frm_delete_forms'))
138
- $actions['trash'] = '<a class="submitdelete" href="' . wp_nonce_url( $delete_link ) .'" onclick="return confirm(\''. __('Are you sure you want to delete that?', 'formidable') .'\')">' . __( 'Delete' ) . '</a>';
139
-
140
- $actions['view'] = '<a href="'. FrmFormsHelper::get_direct_link($item->form_key, $item) .'" target="_blank">'. __('Preview') .'</a>';
141
-
142
- $action_links = $this->row_actions( $actions );
143
-
144
- // Set up the checkbox ( because the user is editable, otherwise its empty )
145
- $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-'. $item->id .'" value="'. $item->id .'" />';
146
-
147
- $r = '<tr id="item-action-'. $item->id .'"'. $style .'>';
148
-
149
- list( $columns, $hidden ) = $this->get_column_info();
150
- $action_col = false;
151
-
152
- foreach ( $columns as $column_name => $column_display_name ) {
153
- $class = 'class="'. $column_name .' column-'. $column_name .'"';
154
 
155
- $style = '';
156
- if ( in_array( $column_name, $hidden ) )
157
- $style = ' style="display:none;"';
158
- else if(!$action_col and !in_array($column_name, array('cb', 'id')))
159
- $action_col = $column_name;
160
-
161
- $attributes = "$class$style";
162
-
163
- switch ( $column_name ) {
164
- case 'cb':
165
- $r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
166
- break;
167
- case 'id':
168
- case 'form_key':
169
- $val = $item->{$column_name};
170
- break;
171
- case 'name':
172
- if(trim($item->{$column_name}) == '')
173
- $val = __('(no title)');
174
- else
175
- $val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
176
- break;
177
- case 'description':
178
- $val = FrmAppHelper::truncate(strip_tags($item->{$column_name}), 50);
179
- break;
180
- case 'created_at':
181
- $format = 'Y/m/d'; //get_option('date_format');
182
- $date = date($format, strtotime($item->{$column_name}));
183
- $val = "<abbr title='". date($format .' g:i:s A', strtotime($item->{$column_name})) ."'>". $date ."</abbr>";
184
- break;
185
- case 'shortcode':
186
- $val = '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable id={$item->id}]") .'" /><br/>';
187
- $val .= '<input type="text" readonly="true" class="frm_select_box" value="'. esc_attr("[formidable key={$item->form_key}]") .'" />';
188
- break;
189
- case 'entries':
190
- $text = $frm_entry->getRecordCount($item->id);
191
- //$text = sprintf(_n( '%1$s Entry', '%1$s Entries', $text, 'formidable' ), $text);
192
- $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
193
- unset($text);
194
- break;
195
- case 'link':
196
- $links = array();
197
- if($frm_vars['pro_is_installed'] and current_user_can('frm_create_entries'))
198
- $links[] = '<a href="'. wp_nonce_url( "?page=formidable-entries&frm_action=new&form={$item->id}" ) .'" class="frm_add_entry_icon frm_icon_font frm_bstooltip" title="'. __('Add Entry', 'formidable'). '" data-toggle="tooltip"> </a>';
199
-
200
- if ( current_user_can('frm_edit_forms') ){
201
- $links[] = '<a href="' . wp_nonce_url( "?page=formidable&frm_action=duplicate&id={$item->id}&template=1" ) .'" class="frm_icon_font frm_new_template_icon frm_bstooltip" title="'. __('Create template from form', 'formidable') .'" data-toggle="tooltip"> </a>';
202
- }
203
-
204
- $val = implode(' ', $links);
205
- break;
206
- default:
207
- $val = $column_name;
208
- break;
209
- }
210
-
211
- if(isset($val)){
212
- $r .= "<td $attributes>";
213
- if($column_name == $action_col){
214
- $r .= '<a class="row-title" href="'. ( isset($actions['frm_edit']) ? $edit_link : FrmFormsHelper::get_direct_link($item->form_key, $item) ) .'">'. $val .'</a> ';
215
- $r .= $action_links;
216
- }else{
217
- $r .= $val;
218
- }
219
- $r .= '</td>';
220
- }
221
- unset($val);
222
- }
223
- $r .= '</tr>';
224
-
225
- return $r;
226
- }
227
-
228
  }
1
  <?php
 
2
  if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
 
 
 
 
4
  class FrmListHelper extends WP_List_Table {
5
+
6
  function __construct($args) {
 
 
7
  $args = wp_parse_args( $args, array(
 
 
 
8
  'params' => array()
9
  ) );
10
+
 
11
  $this->params = $args['params'];
 
 
12
 
13
  parent::__construct( $args );
14
  }
17
  return current_user_can( 'administrator' );
18
  }
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  function display_rows() {
21
  $style = '';
22
  foreach ( $this->items as $item ) {
24
  echo "\n\t", $this->single_row( $item, $style );
25
  }
26
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
classes/helpers/FrmStylesHelper.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class FrmStylesHelper{
3
+
4
+ public static function jquery_themes(){
5
+ $themes = array(
6
+ 'ui-lightness' => 'UI Lightness',
7
+ 'ui-darkness' => 'UI Darkness',
8
+ 'smoothness' => 'Smoothness',
9
+ 'start' => 'Start',
10
+ 'redmond' => 'Redmond',
11
+ 'sunny' => 'Sunny',
12
+ 'overcast' => 'Overcast',
13
+ 'le-frog' => 'Le Frog',
14
+ 'flick' => 'Flick',
15
+ 'pepper-grinder'=> 'Pepper Grinder',
16
+ 'eggplant' => 'Eggplant',
17
+ 'dark-hive' => 'Dark Hive',
18
+ 'cupertino' => 'Cupertino',
19
+ 'south-street' => 'South Street',
20
+ 'blitzer' => 'Blitzer',
21
+ 'humanity' => 'Humanity',
22
+ 'hot-sneaks' => 'Hot Sneaks',
23
+ 'excite-bike' => 'Excite Bike',
24
+ 'vader' => 'Vader',
25
+ 'dot-luv' => 'Dot Luv',
26
+ 'mint-choc' => 'Mint Choc',
27
+ 'black-tie' => 'Black Tie',
28
+ 'trontastic' => 'Trontastic',
29
+ 'swanky-purse' => 'Swanky Purse'
30
+ );
31
+
32
+ $themes = apply_filters('frm_jquery_themes', $themes);
33
+ return $themes;
34
+ }
35
+
36
+ public static function jquery_css_url($theme_css){
37
+ if ( $theme_css == -1 ) {
38
+ return;
39
+ }
40
+
41
+ if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42
+ $css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
+ } else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
44
+ $css_file = $theme_css;
45
+ } else {
46
+ $uploads = self::get_upload_base();
47
+ $file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
+ if ( file_exists($uploads['basedir'] . $file_path) ) {
49
+ $css_file = $uploads['baseurl'] . $file_path;
50
+ } else {
51
+ $css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.css';
52
+ }
53
+ }
54
+
55
+ return $css_file;
56
+ }
57
+
58
+ public static function enqueue_jquery_css() {
59
+ $theme_css = FrmStylesController::get_style_val('theme_css');
60
+ if ( $theme_css != -1 ) {
61
+ wp_enqueue_style('jquery-theme', FrmStylesHelper::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
62
+ }
63
+ }
64
+
65
+ public static function get_upload_base() {
66
+ $uploads = wp_upload_dir();
67
+ if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
68
+ $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
69
+ }
70
+
71
+ return $uploads;
72
+ }
73
+
74
+ public static function style_menu($active = '') {
75
+ ?>
76
+ <h2 class="nav-tab-wrapper">
77
+ <a href="<?php echo admin_url('admin.php?page=formidable-styles') ?>" class="nav-tab <?php echo ( '' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e('Edit Styles', 'formidable') ?></a>
78
+ <a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=manage') ?>" class="nav-tab <?php echo ( 'manage' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e('Manage Form Styles', 'formidable') ?></a>
79
+ <a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=custom_css') ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e('Custom CSS', 'formidable') ?></a>
80
+ </h2>
81
+ <?php
82
+ }
83
+
84
+ public static function minus_icons() {
85
+ return array(
86
+ 0 => array('-' => '62e', '+' => '62f'),
87
+ 1 => array('-' => '600', '+' => '602'),
88
+ 2 => array('-' => '604', '+' => '603'),
89
+ 3 => array('-' => '633', '+' => '632'),
90
+ 4 => array('-' => '613', '+' => '60f'),
91
+ );
92
+ }
93
+
94
+ public static function arrow_icons() {
95
+ $minus_icons = self::minus_icons();
96
+
97
+ return array(
98
+ 6 => array('-' => '62d', '+' => '62a'),
99
+ 0 => array('-' => '60d', '+' => '609'),
100
+ 1 => array('-' => '60e', '+' => '60c'),
101
+ 2 => array('-' => '630', '+' => '631'),
102
+ 3 => array('-' => '62b', '+' => '628'),
103
+ 4 => array('-' => '62c', '+' => '629'),
104
+ 5 => array('-' => '635', '+' => '634'),
105
+ 'p0' => $minus_icons[0],
106
+ 'p1' => $minus_icons[1],
107
+ 'p2' => $minus_icons[2],
108
+ 'p3' => $minus_icons[3],
109
+ 'p4' => $minus_icons[4],
110
+ );
111
+ }
112
+
113
+ /*
114
+ * @since 2.0
115
+ * @return The class for this icon
116
+ */
117
+ public static function icon_key_to_class($key, $icon = '+', $type = 'arrow') {
118
+ if ( 'arrow' == $type && is_numeric($key) ) {
119
+ //frm_arrowup6_icon
120
+ $arrow = array('-' => 'down', '+' => 'up');
121
+ $class = 'frm_arrow'. $arrow[$icon];
122
+ } else {
123
+ //frm_minus1_icon
124
+ $key = str_replace('p', '', $key);
125
+ $plus = array('-' => 'minus', '+' => 'plus');
126
+ $class = 'frm_'. $plus[$icon];
127
+ }
128
+
129
+ if ( $key ) {
130
+ $class .= $key;
131
+ }
132
+ $class .= '_icon';
133
+
134
+ return $class;
135
+ }
136
+
137
+ public static function bs_icon_select($style, $frm_style, $type = 'arrow') {
138
+ $function_name = $type .'_icons';
139
+ $icons = self::$function_name();
140
+
141
+ $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
142
+ ?>
143
+ <select name="<?php echo $frm_style->get_field_name($name) ?>" id="frm_<?php echo $name ?>" class="frm_icon_font frm_multiselect hide-if-js">
144
+ <?php foreach ( $icons as $key => $icon ) { ?>
145
+ <option value="<?php echo $key ?>" <?php selected($style->post_content[$name], $key) ?>>
146
+ <?php echo '&#xe'. $icon['+'] .'; &#xe'. $icon['-'] .';'; ?>
147
+ </option>
148
+ <?php } ?>
149
+ </select>
150
+
151
+ <div class="btn-group hide-if-no-js" id="frm_<?php echo $name ?>_select">
152
+ <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
153
+ <i class="frm_icon_font <?php echo FrmStylesHelper::icon_key_to_class($style->post_content[$name], '+', $type) ?>"></i>
154
+ <i class="frm_icon_font <?php echo FrmStylesHelper::icon_key_to_class($style->post_content[$name], '-', $type) ?>"></i>
155
+ <b class="caret"></b>
156
+ </button>
157
+ <ul class="multiselect-container frm-dropdown-menu">
158
+ <?php foreach ( $icons as $key => $icon ) { ?>
159
+ <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : '' ?>>
160
+ <a href="javascript:void(0);">
161
+ <label>
162
+ <input type="radio" value="<?php echo $key ?>"/>
163
+ <span>
164
+ <i class="frm_icon_font <?php echo FrmStylesHelper::icon_key_to_class($key, '+', $type) ?>"></i>
165
+ <i class="frm_icon_font <?php echo FrmStylesHelper::icon_key_to_class($key, '-', $type) ?>"></i>
166
+ </span>
167
+ </label>
168
+ </a>
169
+ </li>
170
+ <?php } ?>
171
+ </ul>
172
+ </div>
173
+ <?php
174
+ }
175
+
176
+ public static function hex2rgb($hex) {
177
+ $hex = str_replace('#', '', $hex);
178
+
179
+ if ( strlen($hex) == 3 ) {
180
+ $r = hexdec( substr($hex,0,1).substr($hex,0,1) );
181
+ $g = hexdec( substr($hex,1,1).substr($hex,1,1) );
182
+ $b = hexdec( substr($hex,2,1).substr($hex,2,1) );
183
+ } else {
184
+ $r = hexdec( substr($hex,0,2) );
185
+ $g = hexdec( substr($hex,2,2) );
186
+ $b = hexdec( substr($hex,4,2) );
187
+ }
188
+ $rgb = array($r, $g, $b);
189
+ return implode(',', $rgb); // returns the rgb values separated by commas
190
+ //return $rgb; // returns an array with the rgb values
191
+ }
192
+ }
classes/helpers/FrmXMLHelper.php CHANGED
@@ -2,7 +2,7 @@
2
  if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
 
4
  class FrmXMLHelper{
5
-
6
  public static function get_xml_values($opt, $padding){
7
  if(is_array($opt)){
8
  foreach($opt as $ok => $ov){
@@ -15,36 +15,38 @@ class FrmXMLHelper{
15
  }
16
  }else{
17
  echo self::cdata($opt);
18
- }
19
  }
20
-
21
  public static function import_xml($file){
22
  $defaults = array(
23
  'forms' => 0, 'fields' => 0, 'terms' => 0,
 
 
24
  );
25
-
26
  $imported = array(
27
  'imported' => $defaults,
28
  'updated' => $defaults,
29
  'forms' => array(),
30
  );
31
-
32
  unset($defaults);
33
-
34
  if ( !defined('WP_IMPORTING') ) {
35
  define('WP_IMPORTING', true);
36
  }
37
-
38
  if ( !class_exists('DOMDocument') ) {
39
  return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
40
  }
41
-
42
  $dom = new DOMDocument;
43
  $success = $dom->loadXML( file_get_contents( $file ) );
44
  if ( !$success ) {
45
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
46
  }
47
-
48
  $xml = simplexml_import_dom( $dom );
49
  unset( $dom );
50
 
@@ -52,87 +54,88 @@ class FrmXMLHelper{
52
  if ( !$xml ) {
53
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
54
  }
55
-
56
  // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
57
-
58
- // grab cats, tags and terms
59
- if ( isset($xml->term) ) {
60
- $imported = self::import_xml_terms($xml->term, $imported);
61
- unset($xml->term);
 
 
62
  }
63
-
64
- if ( isset($xml->form) ) {
65
- $imported = self::import_xml_forms($xml->form, $imported);
66
- unset($xml->form);
67
- }
68
-
69
  $return = apply_filters('frm_importing_xml', $imported, $xml );
70
-
71
  return $return;
72
  }
73
-
74
  public static function import_xml_terms($terms, $imported) {
75
  foreach ( $terms as $t ) {
76
  if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
77
  continue;
78
  }
79
-
80
  $term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
81
  'slug' => (string) $t->term_slug,
82
  'description' => (string) $t->term_description,
83
  'term_parent' => (string) $t->term_parent,
84
  'slug' => (string) $t->term_slug,
85
  ));
86
-
87
  if ( $term_id ) {
88
  $imported['imported']['terms']++;
89
  }
90
-
91
- unset($term_id);
92
- unset($t);
93
  }
94
-
95
  return $imported;
96
  }
97
-
98
  public static function import_xml_forms($forms, $imported) {
99
- $frm_form = new FrmForm();
100
- $frm_field = new FrmField();
101
-
102
  foreach ( $forms as $item ) {
103
- $form = array(
104
- 'id' => (int) $item->id,
105
- 'form_key' => (string) $item->form_key,
106
- 'name' => (string) $item->name,
107
- 'description' => (string) $item->description,
108
- 'options' => (string) $item->options,
109
- 'logged_in' => (int) $item->logged_in,
110
- 'is_template' => (int) $item->is_template,
111
- 'default_template' => (int) $item->default_template,
112
- 'editable' => (int) $item->editable,
113
- 'status' => (string) $item->status,
114
- 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
115
- );
116
-
117
- $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
118
-
119
- // if template, allow to edit if form keys match, otherwise, creation date must also match
120
- $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
 
121
  if ( !$form['is_template'] ) {
122
  $edit_query['created_at'] = $form['created_at'];
123
  }
124
-
125
- $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
126
-
127
- $this_form = $frm_form->getAll($edit_query, '', 1);
 
 
 
 
 
128
  unset($edit_query);
129
-
130
  if ( !empty($this_form) ) {
131
- $form_id = $this_form->id;
132
- $frm_form->update($form_id, $form );
133
  $imported['updated']['forms']++;
134
-
135
- $form_fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
 
 
136
  $old_fields = array();
137
  foreach ( $form_fields as $f ) {
138
  $old_fields[$f->id] = $f;
@@ -142,12 +145,15 @@ class FrmXMLHelper{
142
  $form_fields = $old_fields;
143
  unset($old_fields);
144
  } else {
 
145
  //form does not exist, so create it
146
- if ( $form_id = $frm_form->create( $form ) ) {
147
  $imported['imported']['forms']++;
 
 
148
  }
149
  }
150
-
151
  foreach ( $item->field as $field ) {
152
  $f = array(
153
  'id' => (int) $field->id,
@@ -162,25 +168,29 @@ class FrmXMLHelper{
162
  'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
163
  'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
164
  );
165
-
166
- if ( is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'image', 'hidden', 'password', 'tag')) ) {
 
 
 
 
167
  if ( count($f['default_value']) === 1 ) {
168
  $f['default_value'] = '['. reset($f['default_value']) .']';
169
  } else {
170
  $f['default_value'] = reset($f['default_value']);
171
  }
172
  }
173
-
174
  $f = apply_filters('frm_duplicated_field', $f);
175
-
176
  if ( $this_form ) {
177
  // check for field to edit by field id
178
  if ( isset($form_fields[$f['id']]) ) {
179
- $frm_field->update( $f['id'], $f );
180
  $imported['updated']['fields']++;
181
-
182
  unset($form_fields[$f['id']]);
183
-
184
  //unset old field key
185
  if ( isset($form_fields[$f['field_key']]) ) {
186
  unset($form_fields[$f['field_key']]);
@@ -188,51 +198,338 @@ class FrmXMLHelper{
188
  } else if ( isset($form_fields[$f['field_key']]) ) {
189
  // check for field to edit by field key
190
  unset($f['id']);
191
-
192
- $frm_field->update( $form_fields[$f['field_key']], $f );
193
  $imported['updated']['fields']++;
194
-
195
  unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id
196
  unset($form_fields[$f['field_key']]); //unset old field key
197
- } else if ( $frm_field->create( $f ) ) {
198
  // if no matching field id or key in this form, create the field
199
  $imported['imported']['fields']++;
200
  }
201
- } else if ( $frm_field->create( $f ) ) {
202
  $imported['imported']['fields']++;
203
  }
204
-
205
  unset($field);
206
  }
207
-
208
-
209
  // Delete any fields attached to this form that were not included in the template
210
  if ( isset($form_fields) && !empty($form_fields) ) {
211
  foreach ($form_fields as $field){
212
  if ( is_object($field) ) {
213
- $frm_field->destroy($field->id);
214
  }
215
  unset($field);
216
  }
217
  unset($form_fields);
218
  }
219
-
220
-
221
  // Update field ids/keys to new ones
222
- do_action('frm_after_duplicate_form', $form_id, $form);
223
-
224
  $imported['forms'][ (int) $item->id] = $form_id;
225
-
226
- unset($form);
227
- unset($item);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
-
230
- unset($frm_form);
231
- unset($frm_field);
232
-
233
  return $imported;
234
  }
235
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  public static function cdata( $str ) {
237
  $str = maybe_unserialize($str);
238
  if ( is_array($str) ) {
@@ -240,11 +537,11 @@ class FrmXMLHelper{
240
  } else if (seems_utf8( $str ) == false ) {
241
  $str = utf8_encode( $str );
242
  }
243
-
244
  if ( is_numeric($str) ) {
245
  return $str;
246
  }
247
-
248
  // $str = ent2ncr(esc_html($str));
249
  $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
250
 
2
  if ( !defined('ABSPATH') ) die('You are not allowed to call this page directly.');
3
 
4
  class FrmXMLHelper{
5
+
6
  public static function get_xml_values($opt, $padding){
7
  if(is_array($opt)){
8
  foreach($opt as $ok => $ov){
15
  }
16
  }else{
17
  echo self::cdata($opt);
18
+ }
19
  }
20
+
21
  public static function import_xml($file){
22
  $defaults = array(
23
  'forms' => 0, 'fields' => 0, 'terms' => 0,
24
+ 'posts' => 0, 'views' => 0, 'actions' => 0,
25
+ 'styles' => 0,
26
  );
27
+
28
  $imported = array(
29
  'imported' => $defaults,
30
  'updated' => $defaults,
31
  'forms' => array(),
32
  );
33
+
34
  unset($defaults);
35
+
36
  if ( !defined('WP_IMPORTING') ) {
37
  define('WP_IMPORTING', true);
38
  }
39
+
40
  if ( !class_exists('DOMDocument') ) {
41
  return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
42
  }
43
+
44
  $dom = new DOMDocument;
45
  $success = $dom->loadXML( file_get_contents( $file ) );
46
  if ( !$success ) {
47
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
48
  }
49
+
50
  $xml = simplexml_import_dom( $dom );
51
  unset( $dom );
52
 
54
  if ( !$xml ) {
55
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
56
  }
57
+
58
  // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
59
+ foreach ( array('term', 'form', 'view') as $item_type ) {
60
+ // grab cats, tags, and terms, or forms or posts
61
+ if ( isset($xml->{$item_type} ) ) {
62
+ $function_name = 'import_xml_'. $item_type .'s';
63
+ $imported = self::$function_name($xml->{$item_type}, $imported);
64
+ unset($xml->{$item_type});
65
+ }
66
  }
67
+
 
 
 
 
 
68
  $return = apply_filters('frm_importing_xml', $imported, $xml );
69
+
70
  return $return;
71
  }
72
+
73
  public static function import_xml_terms($terms, $imported) {
74
  foreach ( $terms as $t ) {
75
  if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
76
  continue;
77
  }
78
+
79
  $term_id = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
80
  'slug' => (string) $t->term_slug,
81
  'description' => (string) $t->term_description,
82
  'term_parent' => (string) $t->term_parent,
83
  'slug' => (string) $t->term_slug,
84
  ));
85
+
86
  if ( $term_id ) {
87
  $imported['imported']['terms']++;
88
  }
89
+
90
+ unset($term_id, $t);
 
91
  }
92
+
93
  return $imported;
94
  }
95
+
96
  public static function import_xml_forms($forms, $imported) {
 
 
 
97
  foreach ( $forms as $item ) {
98
+ $form = array(
99
+ 'id' => (int) $item->id,
100
+ 'form_key' => (string) $item->form_key,
101
+ 'name' => (string) $item->name,
102
+ 'description' => (string) $item->description,
103
+ 'options' => (string) $item->options,
104
+ 'logged_in' => (int) $item->logged_in,
105
+ 'is_template' => (int) $item->is_template,
106
+ 'default_template' => (int) $item->default_template,
107
+ 'editable' => (int) $item->editable,
108
+ 'status' => (string) $item->status,
109
+ 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
110
+ 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
111
+ );
112
+
113
+ $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
114
+
115
+ // if template, allow to edit if form keys match, otherwise, creation date must also match
116
+ $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
117
  if ( !$form['is_template'] ) {
118
  $edit_query['created_at'] = $form['created_at'];
119
  }
120
+
121
+ if ( ! empty($form['parent_form_id']) && isset($imported['forms'][$form['parent_form_id']]) ) {
122
+ // replace the old parent id with the new one
123
+ $form['parent_form_id'] = $imported['forms'][$form['parent_form_id']];
124
+ }
125
+
126
+ $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
127
+
128
+ $this_form = FrmForm::getAll($edit_query, '', 1);
129
  unset($edit_query);
130
+
131
  if ( !empty($this_form) ) {
132
+ $old_id = $form_id = $this_form->id;
133
+ FrmForm::update($form_id, $form );
134
  $imported['updated']['forms']++;
135
+ // Keep track of whether this specific form was updated or not
136
+ $imported['form_status'][$form_id] = 'updated';
137
+
138
+ $form_fields = FrmField::get_all_for_form($form_id);
139
  $old_fields = array();
140
  foreach ( $form_fields as $f ) {
141
  $old_fields[$f->id] = $f;
145
  $form_fields = $old_fields;
146
  unset($old_fields);
147
  } else {
148
+ $old_id = false;
149
  //form does not exist, so create it
150
+ if ( $form_id = FrmForm::create( $form ) ) {
151
  $imported['imported']['forms']++;
152
+ // Keep track of whether this specific form was updated or not
153
+ $imported['form_status'][$form_id] = 'imported';
154
  }
155
  }
156
+
157
  foreach ( $item->field as $field ) {
158
  $f = array(
159
  'id' => (int) $field->id,
168
  'options' => FrmAppHelper::maybe_json_decode( (string) $field->options),
169
  'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options)
170
  );
171
+
172
+ if ( is_array($f['default_value']) && in_array($f['type'], array(
173
+ 'text', 'email', 'url', 'textarea',
174
+ 'number','phone', 'date', 'time',
175
+ 'hidden', 'password', 'tag', 'image',
176
+ )) ) {
177
  if ( count($f['default_value']) === 1 ) {
178
  $f['default_value'] = '['. reset($f['default_value']) .']';
179
  } else {
180
  $f['default_value'] = reset($f['default_value']);
181
  }
182
  }
183
+
184
  $f = apply_filters('frm_duplicated_field', $f);
185
+
186
  if ( $this_form ) {
187
  // check for field to edit by field id
188
  if ( isset($form_fields[$f['id']]) ) {
189
+ FrmField::update( $f['id'], $f );
190
  $imported['updated']['fields']++;
191
+
192
  unset($form_fields[$f['id']]);
193
+
194
  //unset old field key
195
  if ( isset($form_fields[$f['field_key']]) ) {
196
  unset($form_fields[$f['field_key']]);
198
  } else if ( isset($form_fields[$f['field_key']]) ) {
199
  // check for field to edit by field key
200
  unset($f['id']);
201
+
202
+ FrmField::update( $form_fields[$f['field_key']], $f );
203
  $imported['updated']['fields']++;
204
+
205
  unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id
206
  unset($form_fields[$f['field_key']]); //unset old field key
207
+ } else if ( FrmField::create( $f ) ) {
208
  // if no matching field id or key in this form, create the field
209
  $imported['imported']['fields']++;
210
  }
211
+ } else if ( FrmField::create( $f ) ) {
212
  $imported['imported']['fields']++;
213
  }
214
+
215
  unset($field);
216
  }
217
+
218
+
219
  // Delete any fields attached to this form that were not included in the template
220
  if ( isset($form_fields) && !empty($form_fields) ) {
221
  foreach ($form_fields as $field){
222
  if ( is_object($field) ) {
223
+ FrmField::destroy($field->id);
224
  }
225
  unset($field);
226
  }
227
  unset($form_fields);
228
  }
229
+
 
230
  // Update field ids/keys to new ones
231
+ do_action('frm_after_duplicate_form', $form_id, $form, array('old_id' => $old_id));
232
+
233
  $imported['forms'][ (int) $item->id] = $form_id;
234
+
235
+ unset($form, $item);
236
+ }
237
+
238
+ return $imported;
239
+ }
240
+
241
+ public static function import_xml_views($views, $imported) {
242
+ $imported['posts'] = array();
243
+ $form_action_type = FrmFormActionsController::$action_post_type;
244
+
245
+ $post_types = array(
246
+ 'frm_display' => 'views',
247
+ $form_action_type => 'actions',
248
+ 'frm_styles' => 'styles',
249
+ );
250
+
251
+ foreach ( $views as $item ) {
252
+ $post = array(
253
+ 'post_title' => (string) $item->title,
254
+ 'post_name' => (string) $item->post_name,
255
+ 'post_type' => (string) $item->post_type,
256
+ 'post_password' => (string) $item->post_password,
257
+ 'guid' => (string) $item->guid,
258
+ 'post_status' => (string) $item->status,
259
+ 'post_author' => FrmAppHelper::get_user_id_param( (string) $item->post_author ),
260
+ 'post_id' => (int) $item->post_id,
261
+ 'post_parent' => (int) $item->post_parent,
262
+ 'menu_order' => (int) $item->menu_order,
263
+ 'post_content' => FrmFieldsHelper::switch_field_ids((string) $item->content),
264
+ 'post_excerpt' => FrmFieldsHelper::switch_field_ids((string) $item->excerpt),
265
+ 'is_sticky' => (string) $item->is_sticky,
266
+ 'comment_status' => (string) $item->comment_status,
267
+ 'post_date' => (string) $item->post_date,
268
+ 'post_date_gmt' => (string) $item->post_date_gmt,
269
+ 'ping_status' => (string) $item->ping_status,
270
+ 'postmeta' => array(),
271
+ 'tax_input' => array(),
272
+ );
273
+
274
+ $old_id = $post['post_id'];
275
+ self::populate_post($post, $item, $imported);
276
+
277
+ unset($item);
278
+
279
+ if ( $post['post_type'] == $form_action_type ) {
280
+ $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
281
+ $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
282
+ unset($action_control);
283
+ } else if ( $post['post_type'] == 'frm_styles' ) {
284
+ // Properly encode post content before inserting the post
285
+ $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
286
+ $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
287
+
288
+ // Create/update post now
289
+ $post_id = wp_insert_post( $post );
290
+ } else {
291
+ // Create/update post now
292
+ $post_id = wp_insert_post( $post );
293
+ }
294
+
295
+ if ( ! is_numeric($post_id) ) {
296
+ continue;
297
+ }
298
+
299
+ self::update_postmeta($post, $post_id);
300
+
301
+ $this_type = 'posts';
302
+ if ( isset($post_types[$post['post_type']]) ) {
303
+ $this_type = $post_types[$post['post_type']];
304
+ }
305
+
306
+ if ( isset($post['ID']) && $post_id == $post['ID'] ) {
307
+ $imported['updated'][ $this_type ]++;
308
+ } else {
309
+ $imported['imported'][ $this_type ]++;
310
+ }
311
+
312
+ unset($post);
313
+
314
+ $imported['posts'][ (int) $old_id] = $post_id;
315
  }
316
+
 
 
 
317
  return $imported;
318
  }
319
+
320
+ private static function populate_post( &$post, $item, $imported ) {
321
+ if ( isset($item->attachment_url) ) {
322
+ $post['attachment_url'] = (string) $item->attachment_url;
323
+ }
324
+
325
+ if ( $post['post_type'] == FrmFormActionsController::$action_post_type ) {
326
+ // update to new form id
327
+ $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
328
+ }
329
+
330
+ foreach ( $item->postmeta as $meta ) {
331
+ self::populate_postmeta($post, $meta, $imported);
332
+ unset($meta);
333
+ }
334
+
335
+ self::populate_taxonomies($post, $item);
336
+
337
+ self::maybe_editing_post($post);
338
+ }
339
+
340
+ private static function populate_postmeta( &$post, $meta, $imported ) {
341
+ global $frm_duplicate_ids;
342
+
343
+ $m = array(
344
+ 'key' => (string) $meta->meta_key,
345
+ 'value' => (string) $meta->meta_value
346
+ );
347
+
348
+ //switch old form and field ids to new ones
349
+ if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
350
+ $m['value'] = $imported['forms'][ (int) $m['value'] ];
351
+ } else {
352
+ $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
353
+
354
+ if ( ! empty($frm_duplicate_ids) ) {
355
+
356
+ if ( $m['key'] == 'frm_dyncontent' ) {
357
+ $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
358
+ } else if ( $m['key'] == 'frm_options' ) {
359
+
360
+ foreach ( array('date_field_id', 'edate_field_id') as $setting_name ) {
361
+ if ( isset($m['value'][$setting_name]) && is_numeric($m['value'][$setting_name]) && isset($frm_duplicate_ids[$m['value'][$setting_name]]) ) {
362
+ $m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]];
363
+ }
364
+ }
365
+
366
+ $check_dup_array = array();
367
+ if ( isset($m['value']['order_by']) && !empty($m['value']['order_by']) ) {
368
+ if ( is_numeric($m['value']['order_by']) && isset($frm_duplicate_ids[$m['value']['order_by']]) ) {
369
+ $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']];
370
+ } else if ( is_array($m['value']['order_by']) ) {
371
+ $check_dup_array[] = 'order_by';
372
+ }
373
+ }
374
+
375
+ if ( isset($m['value']['where']) && !empty($m['value']['where']) ) {
376
+ $check_dup_array[] = 'where';
377
+ }
378
+
379
+ foreach ( $check_dup_array as $check_k ) {
380
+ foreach ( (array) $m['value'][$check_k] as $mk => $mv ) {
381
+ if ( isset($frm_duplicate_ids[$mv]) ) {
382
+ $m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv];
383
+ }
384
+ unset($mk, $mv);
385
+ }
386
+ }
387
+ }
388
+ }
389
+ }
390
+
391
+ if ( ! is_array($m['value']) ) {
392
+ $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
393
+ }
394
+
395
+ $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
396
+ }
397
+
398
+ /*
399
+ * Add terms to post
400
+ */
401
+ private static function populate_taxonomies( &$post, $item ) {
402
+ foreach ( $item->category as $c ) {
403
+ $att = $c->attributes();
404
+ if ( ! isset( $att['nicename'] ) ) {
405
+ continue;
406
+ }
407
+
408
+ $taxonomy = (string) $att['domain'];
409
+ if ( is_taxonomy_hierarchical($taxonomy) ) {
410
+ $name = (string) $att['nicename'];
411
+ $h_term = get_term_by('slug', $name, $taxonomy);
412
+ if ( $h_term ) {
413
+ $name = $h_term->term_id;
414
+ }
415
+ unset($h_term);
416
+ } else {
417
+ $name = (string) $c;
418
+ }
419
+
420
+ if ( ! isset($post['tax_input'][$taxonomy]) ) {
421
+ $post['tax_input'][$taxonomy] = array();
422
+ }
423
+
424
+ $post['tax_input'][$taxonomy][] = $name;
425
+ unset($name);
426
+ }
427
+ }
428
+
429
+ /*
430
+ * Edit post if the key and created time match
431
+ */
432
+ private static function maybe_editing_post( &$post ) {
433
+ $match_by = array(
434
+ 'post_type' => $post['post_type'],
435
+ 'name' => $post['post_name'],
436
+ 'post_status' => $post['post_status'],
437
+ 'posts_per_page' => 1,
438
+ );
439
+
440
+ if ( in_array($post['post_status'], array('trash', 'draft')) ) {
441
+ $match_by['include'] = $post['post_id'];
442
+ unset($match_by['name']);
443
+ }
444
+
445
+ $editing = get_posts($match_by);
446
+
447
+ if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
448
+ // set the id of the post to edit
449
+ $post['ID'] = current($editing)->ID;
450
+ }
451
+ }
452
+
453
+ private static function update_postmeta( &$post, $post_id ) {
454
+ foreach ( $post['postmeta'] as $k => $v ) {
455
+ if ( '_edit_last' == $k ) {
456
+ $v = FrmAppHelper::get_user_id_param($v);
457
+ } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
458
+ //change the attachment ID
459
+ $v = FrmProXMLHelper::get_file_id($v);
460
+ }
461
+
462
+ update_post_meta($post_id, $k, $v);
463
+
464
+ unset($k, $v);
465
+ }
466
+ }
467
+
468
+ public static function parse_message($result, &$message, &$errors) {
469
+ if ( is_wp_error($result) ) {
470
+ $errors[] = $result->get_error_message();
471
+ } else if ( ! $result ) {
472
+ return;
473
+ }
474
+
475
+ if ( ! is_array($result) ) {
476
+ $message = $result;
477
+ return;
478
+ }
479
+
480
+ $t_strings = array(
481
+ 'imported' => __('Imported', 'formidable'),
482
+ 'updated' => __('Updated', 'formidable'),
483
+ );
484
+
485
+ $message = '<ul>';
486
+ foreach ( $result as $type => $results ) {
487
+ if ( ! isset($t_strings[$type]) ) {
488
+ // only print imported and updated
489
+ continue;
490
+ }
491
+
492
+ $s_message = array();
493
+ foreach ( $results as $k => $m ) {
494
+ self::item_count_message($m, $k, $s_message);
495
+ unset($k, $m);
496
+ }
497
+
498
+ if ( ! empty($s_message) ) {
499
+ $message .= '<li><strong>'. $t_strings[$type] .':</strong> ';
500
+ $message .= implode(', ', $s_message);
501
+ $message .= '</li>';
502
+ }
503
+
504
+ }
505
+
506
+ if ( $message == '<ul>' ) {
507
+ $message = '';
508
+ $errors[] = __('Nothing was imported or updated', 'formidable');
509
+ } else {
510
+ $message .= '</ul>';
511
+ }
512
+ }
513
+
514
+ public static function item_count_message($m, $type, &$s_message) {
515
+ if ( ! $m ) {
516
+ return;
517
+ }
518
+
519
+ $strings = array(
520
+ 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
521
+ 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
522
+ 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
523
+ 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
524
+ 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
525
+ 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
526
+ 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
527
+ 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
528
+ );
529
+
530
+ $s_message[] = isset($strings[$type]) ? $strings[$type] : ' '. $m .' '. ucfirst($type);
531
+ }
532
+
533
  public static function cdata( $str ) {
534
  $str = maybe_unserialize($str);
535
  if ( is_array($str) ) {
537
  } else if (seems_utf8( $str ) == false ) {
538
  $str = utf8_encode( $str );
539
  }
540
+
541
  if ( is_numeric($str) ) {
542
  return $str;
543
  }
544
+
545
  // $str = ent2ncr(esc_html($str));
546
  $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
547
 
classes/models/FrmDb.php CHANGED
@@ -1,40 +1,76 @@
1
  <?php
2
- if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
-
4
- if(class_exists('FrmDb'))
5
- return;
6
 
7
  class FrmDb{
8
-
 
 
 
 
9
  function __construct(){
 
 
 
 
10
  global $wpdb;
11
- $this->fields = $wpdb->prefix . "frm_fields";
12
- $this->forms = $wpdb->prefix . "frm_forms";
13
- $this->entries = $wpdb->prefix . "frm_items";
14
- $this->entry_metas = $wpdb->prefix . "frm_item_metas";
15
  }
16
-
17
  function upgrade($old_db_version=false){
18
  global $wpdb;
19
  //$frm_db_version is the version of the database we're moving to
20
  $frm_db_version = FrmAppHelper::$db_version;
21
- $old_db_version = (float)$old_db_version;
22
- if(!$old_db_version)
23
  $old_db_version = get_option('frm_db_version');
 
24
 
25
- if ($frm_db_version != $old_db_version){
26
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
27
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  $charset_collate = '';
29
- if( $wpdb->has_cap( 'collation' ) ){
30
- if( !empty($wpdb->charset) )
31
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
32
- if( !empty($wpdb->collate) )
33
- $charset_collate .= " COLLATE $wpdb->collate";
 
34
  }
35
 
 
 
 
 
 
 
 
36
  /* Create/Upgrade Fields Table */
37
- $sql = "CREATE TABLE {$this->fields} (
38
  id int(11) NOT NULL auto_increment,
39
  field_key varchar(255) default NULL,
40
  name text default NULL,
@@ -50,12 +86,10 @@ class FrmDb{
50
  PRIMARY KEY (id),
51
  KEY form_id (form_id),
52
  UNIQUE KEY field_key (field_key)
53
- ) {$charset_collate};";
54
 
55
- dbDelta($sql);
56
-
57
  /* Create/Upgrade Forms Table */
58
- $sql = "CREATE TABLE {$this->forms} (
59
  id int(11) NOT NULL auto_increment,
60
  form_key varchar(255) default NULL,
61
  name varchar(255) default NULL,
@@ -66,17 +100,14 @@ class FrmDb{
66
  is_template tinyint(1) default 0,
67
  default_template tinyint(1) default 0,
68
  status varchar(255) default NULL,
69
- prli_link_id int(11) default NULL,
70
  options longtext default NULL,
71
  created_at datetime NOT NULL,
72
  PRIMARY KEY (id),
73
  UNIQUE KEY form_key (form_key)
74
- ) {$charset_collate};";
75
-
76
- dbDelta($sql);
77
 
78
  /* Create/Upgrade Items Table */
79
- $sql = "CREATE TABLE {$this->entries} (
80
  id int(11) NOT NULL auto_increment,
81
  item_key varchar(255) default NULL,
82
  name varchar(255) default NULL,
@@ -96,12 +127,10 @@ class FrmDb{
96
  KEY user_id (user_id),
97
  KEY parent_item_id (parent_item_id),
98
  UNIQUE KEY item_key (item_key)
99
- ) {$charset_collate};";
100
-
101
- dbDelta($sql);
102
 
103
  /* Create/Upgrade Meta Table */
104
- $sql = "CREATE TABLE {$this->entry_metas} (
105
  id int(11) NOT NULL auto_increment,
106
  meta_value longtext default NULL,
107
  field_id int(11) NOT NULL,
@@ -110,219 +139,496 @@ class FrmDb{
110
  PRIMARY KEY (id),
111
  KEY field_id (field_id),
112
  KEY item_id (item_id)
113
- ) {$charset_collate};";
114
-
115
- dbDelta($sql);
116
-
117
- /**** MIGRATE DATA ****/
118
- if ($frm_db_version >= 1.03 and $old_db_version < 1.03){
119
- global $frm_entry;
120
- $all_entries = $frm_entry->getAll();
121
- foreach($all_entries as $ent){
122
- $opts = maybe_unserialize($ent->description);
123
- if(is_array($opts) and in_array($opts['ip']))
124
- $wpdb->update( $this->entries, array('ip' => $opts['ip']), array( 'id' => $ent->id ) );
125
- }
126
- }
127
-
128
- if($frm_db_version >= 4 and $old_db_version < 4){
129
- global $frm_entry_meta;
130
- $user_ids = $frm_entry_meta->getAll("fi.type='user_id'");
131
- foreach($user_ids as $user_id)
132
- $wpdb->update( $this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id) );
133
  }
134
-
135
- if($frm_db_version >= 6 and $old_db_version < 6){
136
- $fields = $wpdb->get_results("SELECT id, field_options FROM $this->fields WHERE type not in ('hidden', 'user_id', 'break', 'divider', 'html', 'captcha', 'form')");
137
- $default_html = <<<DEFAULT_HTML
138
- <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
139
- <label class="frm_pos_[label_position]">[field_name]
140
- <span class="frm_required">[required_label]</span>
141
- </label>
142
- [input]
143
- [if description]<div class="frm_description">[description]</div>[/if description]
144
- </div>
145
- DEFAULT_HTML;
146
- $old_default_html = <<<DEFAULT_HTML
147
- <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
148
- <label class="frm_pos_[label_position]">[field_name]
149
- <span class="frm_required">[required_label]</span>
150
- </label>
151
- [input]
152
- [if description]<p class="frm_description">[description]</p>[/if description]
153
- </div>
154
- DEFAULT_HTML;
155
- $new_default_html = FrmFieldsHelper::get_default_html('text');
156
- foreach($fields as $field){
157
- $field->field_options = maybe_unserialize($field->field_options);
158
- if ( !isset($field->field_options['custom_html']) || empty($field->field_options['custom_html']) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
159
- $field->field_options['custom_html'] = $new_default_html;
160
- $wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
161
- }
162
- unset($field);
163
- }
164
- unset($default_html);
165
- unset($old_default_html);
166
- unset($fields);
167
  }
168
-
169
- if($frm_db_version >= 11 and $old_db_version < 11){
170
- $forms = $wpdb->get_results("SELECT id, options FROM $this->forms");
171
- $sending = __('Sending', 'formidable');
172
- $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
173
- $old_default_html = <<<DEFAULT_HTML
174
- <div class="frm_submit">
175
- [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
176
- <input type="submit" value="[button_label]" [button_action] />
177
- <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
178
- </div>
179
- DEFAULT_HTML;
180
- unset($sending);
181
- unset($img);
182
-
183
- $new_default_html = FrmFormsHelper::get_default_html('submit');
184
- $draft_link = FrmFormsHelper::get_draft_link();
185
- foreach($forms as $form){
186
- $form->options = maybe_unserialize($form->options);
187
- if(!isset($form->options['submit_html']) or empty($form->options['submit_html']))
188
- continue;
189
-
190
- if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
191
- $form->options['submit_html'] = $new_default_html;
192
- $wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
193
- }else if(!strpos($form->options['submit_html'], 'save_draft')){
194
- $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
195
- $wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
196
- }
197
- unset($form);
198
- }
199
- unset($forms);
200
  }
201
-
202
-
203
 
204
- /**** ADD/UPDATE DEFAULT TEMPLATES ****/
205
- if ( class_exists('FrmXMLController') ) {
206
- FrmXMLController::add_default_templates();
207
  }
208
 
209
-
210
- /***** SAVE DB VERSION *****/
211
- update_option('frm_db_version', $frm_db_version);
212
  }
213
 
214
- do_action('frm_after_install');
 
 
215
  }
216
-
217
  function get_count($table, $args=array()){
218
  global $wpdb;
219
- extract(FrmDb::get_where_clause_and_values( $args ));
220
 
221
- $query = "SELECT COUNT(*) FROM {$table}{$where}";
222
- $query = $wpdb->prepare($query, $values);
223
  return $wpdb->get_var($query);
224
  }
225
 
226
  function get_where_clause_and_values( $args ){
227
- $where = '';
228
- $values = array();
229
- if(is_array($args)){
230
- foreach($args as $key => $value){
231
- $where .= (!empty($where)) ? ' AND' : ' WHERE';
232
- $where .= " {$key}=";
233
- $where .= is_numeric($value) ? (strpos($value, ".") !== false ? '%f' : '%d') : '%s';
234
-
235
- $values[] = $value;
236
- }
237
- }
238
-
239
- return compact('where', 'values');
240
  }
241
-
242
  function get_var($table, $args=array(), $field='id', $order_by=''){
243
  global $wpdb;
244
 
245
- extract(FrmDb::get_where_clause_and_values( $args ));
246
  if(!empty($order_by))
247
  $order_by = " ORDER BY {$order_by}";
248
 
249
- $query = $wpdb->prepare("SELECT {$field} FROM {$table}{$where}{$order_by} LIMIT 1", $values);
250
  return $wpdb->get_var($query);
251
  }
252
-
253
  function get_col($table, $args=array(), $field='id', $order_by=''){
254
  global $wpdb;
255
 
256
- extract(FrmDb::get_where_clause_and_values( $args ));
257
  if(!empty($order_by))
258
  $order_by = " ORDER BY {$order_by}";
259
 
260
- $query = $wpdb->prepare("SELECT {$field} FROM {$table}{$where}{$order_by}", $values);
261
  return $wpdb->get_col($query);
262
  }
263
 
264
  function get_one_record($table, $args=array(), $fields='*', $order_by=''){
265
  global $wpdb;
266
 
267
- extract(FrmDb::get_where_clause_and_values( $args ));
268
-
269
- if(!empty($order_by))
270
- $order_by = " ORDER BY {$order_by}";
271
 
272
- $query = "SELECT {$fields} FROM {$table}{$where} {$order_by} LIMIT 1";
273
- $query = $wpdb->prepare($query, $values);
 
 
 
 
274
  return $wpdb->get_row($query);
275
  }
276
 
277
  function get_records($table, $args=array(), $order_by='', $limit='', $fields='*'){
278
  global $wpdb;
279
 
280
- extract(FrmDb::get_where_clause_and_values( $args ));
281
 
282
  if ( !empty($order_by) && strpos($order_by, ' ORDER BY ') === false ) {
283
- $order_by = " ORDER BY {$order_by}";
284
  }
285
 
286
  if ( !empty($limit) && strpos($order_by, ' LIMIT ') === false ) {
287
- $limit = " LIMIT {$limit}";
288
  }
289
 
290
- $query = "SELECT {$fields} FROM {$table}{$where}{$order_by}{$limit}";
291
- $query = $wpdb->prepare($query, $values);
292
  return $wpdb->get_results($query);
293
  }
294
-
295
  function uninstall(){
296
  if ( !current_user_can('administrator') ) {
297
- global $frm_settings;
298
  wp_die($frm_settings->admin_permission);
299
  }
300
-
301
  global $wpdb, $wp_roles;
302
-
303
  $wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
304
  $wpdb->query('DROP TABLE IF EXISTS '. $this->forms);
305
  $wpdb->query('DROP TABLE IF EXISTS '. $this->entries);
306
  $wpdb->query('DROP TABLE IF EXISTS '. $this->entry_metas);
307
-
308
  delete_option('frm_options');
309
- delete_option('frm_db_version');
310
-
311
  //delete roles
312
  $frm_roles = FrmAppHelper::frm_capabilities();
313
  $roles = get_editable_roles();
314
- foreach($frm_roles as $frm_role => $frm_role_description){
315
- foreach ($roles as $role => $details){
316
  $wp_roles->remove_cap( $role, $frm_role );
317
- unset($role);
318
- unset($details);
319
  }
320
- unset($frm_role);
321
- unset($frm_role_description);
322
  }
323
- unset($roles);
324
- unset($frm_roles);
325
-
326
  do_action('frm_after_uninstall');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  }
328
  }
1
  <?php
 
 
 
 
2
 
3
  class FrmDb{
4
+ var $fields;
5
+ var $forms;
6
+ var $entries;
7
+ var $entry_metas;
8
+
9
  function __construct(){
10
+ if ( ! defined('ABSPATH') ) {
11
+ die('You are not allowed to call this page directly.');
12
+ }
13
+
14
  global $wpdb;
15
+ $this->fields = $wpdb->prefix . 'frm_fields';
16
+ $this->forms = $wpdb->prefix . 'frm_forms';
17
+ $this->entries = $wpdb->prefix . 'frm_items';
18
+ $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
19
  }
20
+
21
  function upgrade($old_db_version=false){
22
  global $wpdb;
23
  //$frm_db_version is the version of the database we're moving to
24
  $frm_db_version = FrmAppHelper::$db_version;
25
+ $old_db_version = (float) $old_db_version;
26
+ if ( ! $old_db_version ) {
27
  $old_db_version = get_option('frm_db_version');
28
+ }
29
 
30
+ if ( $frm_db_version != $old_db_version ) {
31
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
32
+
33
+ $this->create_tables();
34
+ $this->migrate_data($frm_db_version, $old_db_version);
35
+
36
+ /**** ADD/UPDATE DEFAULT TEMPLATES ****/
37
+ FrmXMLController::add_default_templates();
38
+
39
+ /***** SAVE DB VERSION *****/
40
+ update_option('frm_db_version', $frm_db_version);
41
+ }
42
+
43
+ do_action('frm_after_install');
44
+
45
+ /**** update the styling settings ****/
46
+ $frm_style = new FrmStyle();
47
+ $frm_style->update( 'default' );
48
+ }
49
+
50
+ function collation() {
51
+ global $wpdb;
52
+ if ( ! $wpdb->has_cap( 'collation' ) ) {
53
+ return '';
54
+ }
55
+
56
  $charset_collate = '';
57
+ if ( ! empty($wpdb->charset) ) {
58
+ $charset_collate = ' DEFAULT CHARACTER SET '. $wpdb->charset;
59
+ }
60
+
61
+ if ( ! empty($wpdb->collate) ) {
62
+ $charset_collate .= ' COLLATE '. $wpdb->collate;
63
  }
64
 
65
+ return $charset_collate;
66
+ }
67
+
68
+ private function create_tables() {
69
+ $charset_collate = $this->collation();
70
+ $sql = array();
71
+
72
  /* Create/Upgrade Fields Table */
73
+ $sql[] = 'CREATE TABLE '. $this->fields .' (
74
  id int(11) NOT NULL auto_increment,
75
  field_key varchar(255) default NULL,
76
  name text default NULL,
86
  PRIMARY KEY (id),
87
  KEY form_id (form_id),
88
  UNIQUE KEY field_key (field_key)
89
+ )';
90
 
 
 
91
  /* Create/Upgrade Forms Table */
92
+ $sql[] = 'CREATE TABLE '. $this->forms .' (
93
  id int(11) NOT NULL auto_increment,
94
  form_key varchar(255) default NULL,
95
  name varchar(255) default NULL,
100
  is_template tinyint(1) default 0,
101
  default_template tinyint(1) default 0,
102
  status varchar(255) default NULL,
 
103
  options longtext default NULL,
104
  created_at datetime NOT NULL,
105
  PRIMARY KEY (id),
106
  UNIQUE KEY form_key (form_key)
107
+ )';
 
 
108
 
109
  /* Create/Upgrade Items Table */
110
+ $sql[] = 'CREATE TABLE '. $this->entries .' (
111
  id int(11) NOT NULL auto_increment,
112
  item_key varchar(255) default NULL,
113
  name varchar(255) default NULL,
127
  KEY user_id (user_id),
128
  KEY parent_item_id (parent_item_id),
129
  UNIQUE KEY item_key (item_key)
130
+ )';
 
 
131
 
132
  /* Create/Upgrade Meta Table */
133
+ $sql[] = 'CREATE TABLE '. $this->entry_metas .' (
134
  id int(11) NOT NULL auto_increment,
135
  meta_value longtext default NULL,
136
  field_id int(11) NOT NULL,
139
  PRIMARY KEY (id),
140
  KEY field_id (field_id),
141
  KEY item_id (item_id)
142
+ )';
143
+
144
+ foreach ( $sql as $q ) {
145
+ dbDelta($q . $charset_collate .';');
146
+ unset($q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
+ }
149
+
150
+ private function migrate_data($frm_db_version, $old_db_version) {
151
+ if ( $frm_db_version >= 4 && $old_db_version < 4 ) {
152
+ $this->migrate_to_4();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  }
154
+
155
+ if ( $frm_db_version >= 6 && $old_db_version < 6 ) {
156
+ $this->migrate_to_6();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
 
 
158
 
159
+ if ( $frm_db_version >= 11 && $old_db_version < 11 ) {
160
+ $this->migrate_to_11();
 
161
  }
162
 
163
+ if ( $frm_db_version >= 16 && $old_db_version < 16 ) {
164
+ $this->migrate_to_16();
 
165
  }
166
 
167
+ if ( $frm_db_version >= 17 && $old_db_version < 17 ) {
168
+ $this->migrate_to_17();
169
+ }
170
  }
171
+
172
  function get_count($table, $args=array()){
173
  global $wpdb;
174
+ $args = FrmAppHelper::get_where_clause_and_values( $args );
175
 
176
+ $query = "SELECT COUNT(*) FROM {$table}". $args['where'];
177
+ $query = $wpdb->prepare($query, $args['values']);
178
  return $wpdb->get_var($query);
179
  }
180
 
181
  function get_where_clause_and_values( $args ){
182
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::get_where_clause_and_values');
183
+ return FrmAppHelper::get_where_clause_and_values( $args );
 
 
 
 
 
 
 
 
 
 
 
184
  }
185
+
186
  function get_var($table, $args=array(), $field='id', $order_by=''){
187
  global $wpdb;
188
 
189
+ $args = FrmAppHelper::get_where_clause_and_values( $args );
190
  if(!empty($order_by))
191
  $order_by = " ORDER BY {$order_by}";
192
 
193
+ $query = $wpdb->prepare("SELECT {$field} FROM ". $table . $args['where'] . $order_by ." LIMIT 1", $args['values']);
194
  return $wpdb->get_var($query);
195
  }
196
+
197
  function get_col($table, $args=array(), $field='id', $order_by=''){
198
  global $wpdb;
199
 
200
+ $args = FrmAppHelper::get_where_clause_and_values( $args );
201
  if(!empty($order_by))
202
  $order_by = " ORDER BY {$order_by}";
203
 
204
+ $query = $wpdb->prepare("SELECT {$field} FROM ". $table . $args['where'] . $order_by, $args['values']);
205
  return $wpdb->get_col($query);
206
  }
207
 
208
  function get_one_record($table, $args=array(), $fields='*', $order_by=''){
209
  global $wpdb;
210
 
211
+ $args = FrmAppHelper::get_where_clause_and_values( $args );
 
 
 
212
 
213
+ if ( ! empty($order_by) ) {
214
+ $order_by = ' ORDER BY '. $order_by;
215
+ }
216
+
217
+ $query = 'SELECT '. $fields .' FROM '. $table . $args['where'] . $order_by .' LIMIT 1';
218
+ $query = $wpdb->prepare($query, $args['values']);
219
  return $wpdb->get_row($query);
220
  }
221
 
222
  function get_records($table, $args=array(), $order_by='', $limit='', $fields='*'){
223
  global $wpdb;
224
 
225
+ $args = FrmAppHelper::get_where_clause_and_values( $args );
226
 
227
  if ( !empty($order_by) && strpos($order_by, ' ORDER BY ') === false ) {
228
+ $order_by = ' ORDER BY '. $order_by;
229
  }
230
 
231
  if ( !empty($limit) && strpos($order_by, ' LIMIT ') === false ) {
232
+ $limit = ' LIMIT '. $limit;
233
  }
234
 
235
+ $query = 'SELECT '. $fields .' FROM '. $table . $args['where'] . $order_by . $limit;
236
+ $query = $wpdb->prepare($query, $args['values']);
237
  return $wpdb->get_results($query);
238
  }
239
+
240
  function uninstall(){
241
  if ( !current_user_can('administrator') ) {
242
+ $frm_settings = FrmAppHelper::get_settings();
243
  wp_die($frm_settings->admin_permission);
244
  }
245
+
246
  global $wpdb, $wp_roles;
247
+
248
  $wpdb->query('DROP TABLE IF EXISTS '. $this->fields);
249
  $wpdb->query('DROP TABLE IF EXISTS '. $this->forms);
250
  $wpdb->query('DROP TABLE IF EXISTS '. $this->entries);
251
  $wpdb->query('DROP TABLE IF EXISTS '. $this->entry_metas);
252
+
253
  delete_option('frm_options');
254
+ delete_option('frm_db_version');
255
+
256
  //delete roles
257
  $frm_roles = FrmAppHelper::frm_capabilities();
258
  $roles = get_editable_roles();
259
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
260
+ foreach ( $roles as $role => $details ) {
261
  $wp_roles->remove_cap( $role, $frm_role );
262
+ unset($role, $details);
 
263
  }
264
+ unset($frm_role, $frm_role_description);
 
265
  }
266
+ unset($roles, $frm_roles);
267
+
 
268
  do_action('frm_after_uninstall');
269
+ return true;
270
+ }
271
+
272
+ /*
273
+ * Change field size from character to pixel -- Multiply by 7.08
274
+ */
275
+ private function migrate_to_17() {
276
+ global $wpdb;
277
+
278
+ $fields = $wpdb->get_results("SELECT id, field_options FROM $this->fields WHERE type in ('textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file') AND field_options LIKE '%s:4:\"size\";%' AND field_options NOT LIKE '%s:4:\"size\";s:0:%'");
279
+
280
+ $updated = 0;
281
+ foreach ( $fields as $f ) {
282
+ $f->field_options = maybe_unserialize($f->field_options);
283
+ if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
284
+ continue;
285
+ }
286
+
287
+ $f->field_options['size'] = round(7.08 * (int) $f->field_options['size']);
288
+ $f->field_options['size'] .= 'px';
289
+ $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
290
+ if ( $u ) {
291
+ $updated++;
292
+ }
293
+ unset($f);
294
+ }
295
+ }
296
+
297
+ /*
298
+ * Migrate post and email notification settings into actions
299
+ */
300
+ private function migrate_to_16() {
301
+ global $wpdb;
302
+
303
+ $forms = $wpdb->get_results('SELECT id, options FROM '. $this->forms);
304
+
305
+ /* Old email settings format:
306
+ * email_to: Email or field id
307
+ * also_email_to: array of fields ids
308
+ * reply_to: Email, field id, 'custom'
309
+ * cust_reply_to: string
310
+ * reply_to_name: field id, 'custom'
311
+ * cust_reply_to_name: string
312
+ * plain_text: 0|1
313
+ * email_message: string or ''
314
+ * email_subject: string or ''
315
+ * inc_user_info: 0|1
316
+ * update_email: 0, 1, 2
317
+ *
318
+ * Old autoresponder settings format:
319
+ * auto_responder: 0|1
320
+ * ar_email_message: string or ''
321
+ * ar_email_to: field id
322
+ * ar_plain_text: 0|1
323
+ * ar_reply_to_name: string
324
+ * ar_reply_to: string
325
+ * ar_email_subject: string
326
+ * ar_update_email: 0, 1, 2
327
+ *
328
+ * New email settings:
329
+ * post_content: json settings
330
+ * post_title: form id
331
+ * post_excerpt: message
332
+ *
333
+ */
334
+
335
+ $post_type = FrmFormsController::$action_post_type;
336
+ foreach ( $forms as $form ) {
337
+ $form->options = maybe_unserialize($form->options);
338
+
339
+ self::migrate_to_16_post_to_action($form, $post_type);
340
+
341
+ if ( ! isset($form->options['notification']) && isset($form->options['email_to']) && ! empty($form->options['email_to']) ) {
342
+ // add old settings into notification array
343
+ $form->options['notification'] = array(0 => $form->options);
344
+ } else if ( isset($form->options['notification']['email_to']) ) {
345
+ // make sure it's in the correct format
346
+ $form->options['notification'] = array(0 => $form->options['notification']);
347
+ }
348
+
349
+ $notifications = array();
350
+ if ( isset($form->options['notification']) && is_array($form->options['notification']) ) {
351
+ foreach ( $form->options['notification'] as $email_key => $notification ) {
352
+
353
+ // format the email recipient data
354
+ if ( isset($notification['email_to']) ) {
355
+ $email_to = preg_split( "/ (,|;) /", $notification['email_to']);
356
+ } else {
357
+ $email_to = array();
358
+ }
359
+
360
+ if ( isset($notification['also_email_to']) ) {
361
+ $email_fields = (array) $notification['also_email_to'];
362
+ $email_to = array_merge($email_fields, $email_to);
363
+ unset($email_fields);
364
+ }
365
+
366
+ foreach ( $email_to as $key => $email_field ) {
367
+
368
+ if ( is_numeric($email_field) ) {
369
+ $email_to[$key] = '['. $email_field .']';
370
+ }
371
+
372
+ if ( strpos( $email_field, '|') ) {
373
+ $email_opt = explode('|', $email_field);
374
+ if ( isset($email_opt[0]) ) {
375
+ $email_to[$key] = '['. $email_opt[0] .' show='. $email_opt[1] .']';
376
+ }
377
+ unset($email_opt);
378
+ }
379
+ }
380
+ $email_to = implode(', ', $email_to);
381
+
382
+ // format the reply to email
383
+ if ( isset($notification['reply_to']) ) {
384
+ $reply_to = $notification['reply_to'];
385
+ if ( 'custom' == $notification['reply_to'] ) {
386
+ $reply_to = $notification['cust_reply_to'];
387
+ } else if ( is_numeric($reply_to) && ! empty($reply_to) ) {
388
+ $reply_to = '['. $reply_to .']';
389
+ }
390
+ }
391
+
392
+ // format the reply to name
393
+ if ( isset($notification['reply_to_name']) ) {
394
+ $reply_to_name = $notification['reply_to_name'];
395
+ if ( 'custom' == $notification['reply_to_name'] ) {
396
+ $reply_to_name = $notification['cust_reply_to_name'];
397
+ } else if ( !is_numeric($reply_to_name) && ! empty($reply_to_name) ) {
398
+ $reply_to_name = '['. $reply_to_name .']';
399
+ }
400
+ }
401
+
402
+ $event = array('create');
403
+ if ( isset($notification['update_email']) && 1 == $notification['update_email'] ) {
404
+ $event[] = 'update';
405
+ } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
406
+ $event = array('update');
407
+ }
408
+
409
+ $new_notification = array(
410
+ 'post_content' => array(
411
+ 'email_message' => isset($notification['email_message']) ? $notification['email_message'] : '',
412
+ 'email_subject' => isset($notification['email_subject']) ? $notification['email_subject'] : '',
413
+ 'email_to' => $email_to,
414
+ 'plain_text' => isset($notification['plain_text']) ? $notification['plain_text'] : 0,
415
+ 'inc_user_info' => isset($notification['inc_user_info']) ? $notification['inc_user_info'] : 0,
416
+ 'event' => $event,
417
+ 'conditions' => isset($notification['conditions']) ? $notification['conditions'] : '',
418
+ ),
419
+ 'post_name' => $form->id .'_email_'. $email_key,
420
+ );
421
+
422
+ if ( isset($notification['twilio']) && $notification['twilio'] ) {
423
+ $new_notification['post_content'] = $notification['twilio'];
424
+ }
425
+
426
+ if ( !empty($reply_to) ) {
427
+ $new_notification['post_content']['reply_to'] = $reply_to;
428
+ }
429
+
430
+ if ( !empty($reply_to) || !empty($reply_to_name) ) {
431
+ $new_notification['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
432
+ }
433
+
434
+ $notifications[] = $new_notification;
435
+ }
436
+ }
437
+
438
+ if ( isset($form->options['auto_responder']) && $form->options['auto_responder'] && isset($form->options['ar_email_message']) && $form->options['ar_email_message'] ) {
439
+ // migrate autoresponder
440
+
441
+ $email_field = isset($form->options['ar_email_to']) ? $form->options['ar_email_to'] : 0;
442
+ if ( strpos($email_field, '|') ) {
443
+ // data from entries field
444
+ $email_field = explode('|', $email_field);
445
+ if ( isset($email_field[1]) ) {
446
+ $email_field = $email_field[1];
447
+ }
448
+ }
449
+ if ( is_numeric($email_field) && ! empty($email_field) ) {
450
+ $email_field = '['. $email_field .']';
451
+ }
452
+
453
+ $notification = $form->options;
454
+ $new_notification2 = array(
455
+ 'post_content' => array(
456
+ 'email_message' => $notification['ar_email_message'],
457
+ 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
458
+ 'email_to' => $email_field,
459
+ 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
460
+ 'inc_user_info' => 0,
461
+ ),
462
+ 'post_name' => $form->id .'_email_'. (isset($new_notification) ? '1' : '0'),
463
+ );
464
+
465
+
466
+ $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
467
+ $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
468
+
469
+ if ( !empty($reply_to) ) {
470
+ $new_notification2['post_content']['reply_to'] = $reply_to;
471
+ }
472
+
473
+ if ( !empty($reply_to) || !empty($reply_to_name) ) {
474
+ $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
475
+ }
476
+
477
+ $notifications[] = $new_notification2;
478
+ unset($new_notification2);
479
+ }
480
+
481
+ if ( empty($notifications) ) {
482
+ continue;
483
+ }
484
+
485
+ foreach ( $notifications as $new_notification ) {
486
+ $new_notification['post_type'] = $post_type;
487
+ $new_notification['post_excerpt'] = 'email';
488
+ $new_notification['post_title'] = __('Email Notification', 'formidable');
489
+ $new_notification['menu_order'] = $form->id;
490
+ $new_notification['post_status'] = 'publish';
491
+ $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
492
+
493
+ $exists = get_posts( array(
494
+ 'name' => $new_notification['post_name'],
495
+ 'post_type' => $new_notification['post_type'],
496
+ 'post_status' => $new_notification['post_status'],
497
+ 'numberposts' => 1,
498
+ ) );
499
+
500
+ if ( empty($exists) ) {
501
+ wp_insert_post($new_notification);
502
+ }
503
+ unset($new_notification);
504
+ }
505
+
506
+ unset($form, $new_notification2);
507
+ }
508
+ }
509
+
510
+ /*
511
+ * Migrate post settings to form action
512
+ */
513
+ private function migrate_to_16_post_to_action( $form, $post_type ) {
514
+ if ( ! isset($form->options['create_post']) || ! $form->options['create_post'] ) {
515
+ return;
516
+ }
517
+
518
+ $new_action = array(
519
+ 'post_type' => $post_type,
520
+ 'post_excerpt' => 'wppost',
521
+ 'post_title' => __('Create Posts', 'formidable'),
522
+ 'menu_order' => $form->id,
523
+ 'post_status' => 'publish',
524
+ 'post_content' => array(),
525
+ 'post_name' => $form->id .'_wppost_1',
526
+ );
527
+
528
+ $post_settings = array(
529
+ 'post_type', 'post_category', 'post_content',
530
+ 'post_excerpt', 'post_title', 'post_name', 'post_date',
531
+ 'post_status', 'post_custom_fields', 'post_password'
532
+ );
533
+
534
+ foreach ( $post_settings as $post_setting ) {
535
+ if ( isset($form->options[$post_setting]) ) {
536
+ $new_action['post_content'][$post_setting] = $form->options[$post_setting];
537
+ }
538
+ unset($post_setting);
539
+ }
540
+
541
+ $new_action['event'] = array('create', 'update');
542
+ $new_action['post_content'] = json_encode($new_action['post_content']);
543
+
544
+ $exists = get_posts( array(
545
+ 'name' => $new_action['post_name'],
546
+ 'post_type' => $new_action['post_type'],
547
+ 'post_status' => $new_action['post_status'],
548
+ 'numberposts' => 1,
549
+ ) );
550
+
551
+ if ( ! $exists ) {
552
+ wp_insert_post($new_action);
553
+ }
554
+ }
555
+
556
+ private function migrate_to_11() {
557
+ global $wpdb;
558
+
559
+ $forms = $wpdb->get_results("SELECT id, options FROM $this->forms");
560
+ $sending = __('Sending', 'formidable');
561
+ $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
562
+ $old_default_html = <<<DEFAULT_HTML
563
+ <div class="frm_submit">
564
+ [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
565
+ <input type="submit" value="[button_label]" [button_action] />
566
+ <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
567
+ </div>
568
+ DEFAULT_HTML;
569
+ unset($sending, $img);
570
+
571
+ $new_default_html = FrmFormsHelper::get_default_html('submit');
572
+ $draft_link = FrmFormsHelper::get_draft_link();
573
+ foreach($forms as $form){
574
+ $form->options = maybe_unserialize($form->options);
575
+ if(!isset($form->options['submit_html']) or empty($form->options['submit_html']))
576
+ continue;
577
+
578
+ if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
579
+ $form->options['submit_html'] = $new_default_html;
580
+ $wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
581
+ }else if(!strpos($form->options['submit_html'], 'save_draft')){
582
+ $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
583
+ $wpdb->update($this->forms, array('options' => serialize($form->options)), array( 'id' => $form->id ));
584
+ }
585
+ unset($form);
586
+ }
587
+ unset($forms);
588
+ }
589
+
590
+ private function migrate_to_6() {
591
+ global $wpdb;
592
+
593
+ $fields = $wpdb->get_results("SELECT id, field_options FROM $this->fields WHERE type not in ('form', 'hidden', 'user_id', '". implode("','", FrmFieldsHelper::no_save_fields()) ."')");
594
+
595
+ $default_html = <<<DEFAULT_HTML
596
+ <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
597
+ <label class="frm_pos_[label_position]">[field_name]
598
+ <span class="frm_required">[required_label]</span>
599
+ </label>
600
+ [input]
601
+ [if description]<div class="frm_description">[description]</div>[/if description]
602
+ </div>
603
+ DEFAULT_HTML;
604
+
605
+ $old_default_html = <<<DEFAULT_HTML
606
+ <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
607
+ <label class="frm_pos_[label_position]">[field_name]
608
+ <span class="frm_required">[required_label]</span>
609
+ </label>
610
+ [input]
611
+ [if description]<p class="frm_description">[description]</p>[/if description]
612
+ </div>
613
+ DEFAULT_HTML;
614
+
615
+ $new_default_html = FrmFieldsHelper::get_default_html('text');
616
+ foreach ( $fields as $field ) {
617
+ $field->field_options = maybe_unserialize($field->field_options);
618
+ if ( !isset($field->field_options['custom_html']) || empty($field->field_options['custom_html']) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
619
+ $field->field_options['custom_html'] = $new_default_html;
620
+ $wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array( 'id' => $field->id ));
621
+ }
622
+ unset($field);
623
+ }
624
+ unset($default_html, $old_default_html, $fields);
625
+ }
626
+
627
+ private function migrate_to_4() {
628
+ global $wpdb;
629
+ $user_ids = FrmEntryMeta::getAll(array('fi.type' => 'user_id'));
630
+ foreach ( $user_ids as $user_id ) {
631
+ $wpdb->update( $this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id) );
632
+ }
633
  }
634
  }
classes/models/FrmEntry.php CHANGED
@@ -1,150 +1,189 @@
1
  <?php
2
- if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
-
4
- if(class_exists('FrmEntry'))
5
- return;
6
 
7
  class FrmEntry{
8
 
9
- function create( $values ){
10
- global $wpdb, $frm_entry_meta;
11
-
 
 
 
 
 
 
 
12
  $new_values = array(
13
  'item_key' => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
14
  'name' => isset($values['name']) ? $values['name'] : $values['item_key'],
15
- 'ip' => $_SERVER['REMOTE_ADDR'],
16
  'is_draft' => ( ( isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 ) || ( isset($values['is_draft']) && $values['is_draft'] == 1) ) ? 1 : 0,
17
  'form_id' => isset($values['form_id']) ? (int) $values['form_id']: null,
18
  'post_id' => isset($values['post_id']) ? (int) $values['post_id']: null,
 
19
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
20
  'updated_at' => isset($values['updated_at']) ? $values['updated_at'] : ( isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1) ),
21
  );
22
-
23
- if(is_array($new_values['name']))
24
  $new_values['name'] = reset($new_values['name']);
25
-
26
- if(isset($values['description']) and !empty($values['description'])){
 
27
  $new_values['description'] = maybe_serialize($values['description']);
28
- }else{
29
  $referrerinfo = FrmAppHelper::get_referer_info();
30
-
31
- $new_values['description'] = serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'],
32
- 'referrer' => $referrerinfo));
 
 
33
  }
34
-
35
  //if(isset($values['id']) and is_numeric($values['id']))
36
  // $new_values['id'] = $values['id'];
37
-
38
- if(isset($values['frm_user_id']) and (is_numeric($values['frm_user_id']) or (is_admin() and !defined('DOING_AJAX')))){
39
  $new_values['user_id'] = $values['frm_user_id'];
40
- }else{
41
  $user_ID = get_current_user_id();
42
  $new_values['user_id'] = $user_ID ? $user_ID : 0;
43
  }
44
-
45
  $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
46
-
47
- //check for duplicate entries created in the last 5 minutes
48
- if(!defined('WP_IMPORTING')){
49
- $create_entry = true;
50
-
51
- $check_val = $new_values;
52
- $check_val['created_at >'] = date('Y-m-d H:i:s', (strtotime($new_values['created_at']) - (60*5)));
53
- unset($check_val['created_at']);
54
- unset($check_val['updated_at']);
55
- unset($check_val['is_draft']);
56
- unset($check_val['id']);
57
- unset($check_val['item_key']);
58
- if($new_values['item_key'] == $new_values['name'])
59
- unset($check_val['name']);
60
-
61
- global $frmdb;
62
- $entry_exists = $frmdb->get_records($wpdb->prefix .'frm_items', $check_val, 'created_at DESC', '', 'id');
63
- unset($frmdb);
64
-
65
- if($entry_exists and !empty($entry_exists)){
66
- foreach($entry_exists as $entry_exist){
67
- if($create_entry){
68
- $create_entry = false;
69
- //add more checks here to make sure it's a duplicate
70
- if (isset($values['item_meta'])){
71
- $metas = $frm_entry_meta->get_entry_meta_info($entry_exist->id);
72
- $field_metas = array();
73
- foreach($metas as $meta)
74
- $field_metas[$meta->field_id] = $meta->meta_value;
75
-
76
- $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
77
- foreach($diff as $field_id => $meta_value){
78
- if(!empty($meta_value) and !$create_entry)
79
- $create_entry = true;
80
- }
81
- }
82
- }
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
-
86
- if ( !$create_entry ) {
 
 
87
  return false;
88
  }
89
- }
90
-
91
- $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
92
-
93
- if ( $query_results ) {
94
- $entry_id = $wpdb->insert_id;
95
-
96
- global $frm_vars;
97
- if(!isset($frm_vars['saved_entries']))
98
- $frm_vars['saved_entries'] = array();
99
- $frm_vars['saved_entries'][] = (int)$entry_id;
100
-
101
- if ( isset($values['item_meta']) ) {
102
- $frm_entry_meta->update_entry_metas($entry_id, $values['item_meta']);
103
  }
104
-
105
- do_action('frm_after_create_entry', $entry_id, $new_values['form_id']);
106
- do_action('frm_after_create_entry_'. $new_values['form_id'], $entry_id);
107
- return $entry_id;
108
- } else {
109
- return false;
110
  }
 
 
111
  }
112
-
113
- function duplicate( $id ){
114
- global $wpdb, $frm_entry, $frm_entry_meta;
115
 
116
- $values = $frm_entry->getOne( $id );
 
 
 
117
 
118
  $new_values = array();
119
  $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
120
  $new_values['name'] = $values->name;
121
  $new_values['is_draft'] = $values->is_draft;
122
- $new_values['user_id'] = $new_values['updated_by'] = (int)$values->user_id;
123
- $new_values['form_id'] = $values->form_id ? (int)$values->form_id: null;
124
  $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
125
 
126
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
127
- if($query_results){
128
- $entry_id = $wpdb->insert_id;
129
-
130
- global $frm_vars;
131
- if(!isset($frm_vars['saved_entries']))
132
- $frm_vars['saved_entries'] = array();
133
- $frm_vars['saved_entries'][] = (int)$entry_id;
134
-
135
- $frm_entry_meta->duplicate_entry_metas($id, $entry_id);
136
- return $entry_id;
137
- }else
138
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
- function update( $id, $values ){
142
- global $wpdb, $frm_entry_meta, $frm_field, $frm_vars;
143
- if(isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array((int)$id, (array)$frm_vars['saved_entries']))
144
  return;
 
 
 
145
 
146
  $user_ID = get_current_user_id();
147
-
148
  $new_values = array(
149
  'name' => isset($values['name']) ? $values['name'] : '',
150
  'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null,
@@ -152,7 +191,7 @@ class FrmEntry{
152
  'updated_at' => current_time('mysql', 1),
153
  'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID,
154
  );
155
-
156
  if ( isset($values['post_id']) ) {
157
  $new_values['post_id'] = (int) $values['post_id'];
158
  }
@@ -160,46 +199,57 @@ class FrmEntry{
160
  if ( isset($values['item_key']) ) {
161
  $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
162
  }
163
-
164
- if(isset($values['frm_user_id']) and is_numeric($values['frm_user_id']))
 
 
 
 
165
  $new_values['user_id'] = $values['frm_user_id'];
 
166
 
167
  $new_values = apply_filters('frm_update_entry', $new_values, $id);
168
  $query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
169
- if($query_results)
 
 
170
  wp_cache_delete( $id, 'frm_entry');
171
-
172
- if(!isset($frm_vars['saved_entries']))
 
173
  $frm_vars['saved_entries'] = array();
174
-
175
- $frm_vars['saved_entries'][] = (int)$id;
176
-
177
- if (isset($values['item_meta']))
178
- $frm_entry_meta->update_entry_metas($id, $values['item_meta']);
 
 
179
  do_action('frm_after_update_entry', $id, $new_values['form_id']);
180
  do_action('frm_after_update_entry_'. $new_values['form_id'], $id);
181
  return $query_results;
182
  }
183
 
184
- function &destroy( $id ){
185
  global $wpdb;
186
- $id = (int)$id;
187
-
188
- $entry = $this->getOne($id);
189
  if ( !$entry ) {
190
  $result = false;
191
  return $result;
192
  }
193
-
194
  do_action('frm_before_destroy_entry', $id, $entry);
195
-
 
196
  wp_cache_delete( $id, 'frm_entry');
197
  $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=' . $id);
198
  $result = $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=' . $id);
199
  return $result;
200
  }
201
-
202
- function &update_form( $id, $value, $form_id ){
203
  global $wpdb;
204
  $form_id = isset($value) ? $form_id : NULL;
205
  $result = $wpdb->update( $wpdb->prefix .'frm_items', array('form_id' => $form_id), array( 'id' => $id ) );
@@ -207,238 +257,369 @@ class FrmEntry{
207
  wp_cache_delete( $id, 'frm_entry');
208
  return $result;
209
  }
210
-
211
- function getOne( $id, $meta=false){
212
  global $wpdb;
213
-
214
- $entry = wp_cache_get( $id, 'frm_entry' );
215
- if($entry)
216
- return stripslashes_deep($entry);
217
 
218
- $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
219
  LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
220
-
221
  $query .= $wpdb->prepare( is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s', $id);
222
 
 
 
 
 
 
 
 
 
 
 
223
  $entry = $wpdb->get_row($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
- if($meta and $entry){
226
- $metas = $wpdb->get_results($wpdb->prepare("SELECT field_id, meta_value, field_key FROM {$wpdb->prefix}frm_item_metas m LEFT JOIN {$wpdb->prefix}frm_fields f ON m.field_id=f.id WHERE item_id=%d and field_id != %d", $entry->id, 0));
227
-
228
- $entry_metas = array();
229
-
230
- foreach($metas as $meta_val){
231
- $entry_metas[$meta_val->field_id] = $entry_metas[$meta_val->field_key] = maybe_unserialize($meta_val->meta_value);
232
- unset($meta_val);
233
  }
234
- unset($metas);
235
 
236
- $entry->metas = $entry_metas;
237
 
238
- wp_cache_set( $entry->id, $entry, 'frm_entry');
239
  }
 
240
 
241
- return stripslashes_deep($entry);
 
 
242
  }
243
-
244
- function &exists( $id ){
245
  global $wpdb;
246
-
247
- if(wp_cache_get( $id, 'frm_entry' )){
248
  $exists = true;
249
  return $exists;
250
  }
251
-
252
  $where = (is_numeric($id)) ? 'id=%d' : 'item_key=%s';
253
 
254
  $id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE $where", $id));
255
-
256
  $exists = ($id && $id > 0) ? true : false;
257
  return $exists;
258
  }
259
 
260
- function getAll($where = '', $order_by = '', $limit = '', $meta=false, $inc_form=true){
261
  global $wpdb;
262
-
263
- if(is_numeric($limit))
264
- $limit = " LIMIT {$limit}";
265
-
266
- if($inc_form){
267
- $query = "SELECT it.*, fr.name as form_name,fr.form_key as form_key
268
- FROM {$wpdb->prefix}frm_items it LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id" .
269
- FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
270
- }else{
271
- $query = "SELECT it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.updated_by,
272
- it.created_at, it.updated_at, it.is_draft FROM {$wpdb->prefix}frm_items it" .
273
- FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
274
- }
275
-
276
- if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
277
- // sort by a requested field
278
- $query = str_replace( " FROM {$wpdb->prefix}frm_items ", ", (SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id = {$order_matches[1]} AND item_id = it.id) as meta_{$order_matches[1]} FROM {$wpdb->prefix}frm_items ", $query );
279
- }
280
-
281
- $entries = $wpdb->get_results($query, OBJECT_K);
282
- unset($query);
283
-
284
- if($meta and $entries){
285
- if($limit == '' and !is_array($where) and preg_match('/^it\.form_id=\d+$/', $where)){
286
- $meta_where = $wpdb->prepare('fi.form_id=%d', substr($where, 11));
287
- }else if($limit == '' and is_array($where) and count($where) == 1 and isset($where['it.form_id'])){
288
- $meta_where = $wpdb->prepare('fi.form_id=%d', $where['it.form_id']);
289
- }else{
290
- $meta_where = "item_id in (". implode(',', array_filter(array_keys($entries), 'is_numeric')) .")";
291
  }
292
- $query = "SELECT item_id, meta_value, field_id, field_key FROM {$wpdb->prefix}frm_item_metas it
293
- LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id
294
- WHERE $meta_where and field_id != 0";
295
-
296
- $metas = $wpdb->get_results($query);
 
 
 
 
297
  unset($query);
298
-
299
- if($metas){
300
- foreach($metas as $m_key => $meta_val){
301
- if(!isset($entries[$meta_val->item_id]))
302
- continue;
303
-
304
- if(!isset($entries[$meta_val->item_id]->metas))
305
- $entries[$meta_val->item_id]->metas = array();
306
-
307
- $entries[$meta_val->item_id]->metas[$meta_val->field_id] = $entries[$meta_val->item_id]->metas[$meta_val->field_key] = maybe_unserialize($meta_val->meta_value);
308
- }
309
-
310
- foreach($entries as $entry){
311
- wp_cache_set( $entry->id, $entry, 'frm_entry');
312
- unset($entry);
313
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  }
 
 
 
 
 
 
 
 
315
  }
316
-
 
 
 
 
 
317
  return stripslashes_deep($entries);
318
  }
319
 
320
  // Pagination Methods
321
- function getRecordCount($where=''){
322
  global $wpdb;
323
- if(is_numeric($where)){
324
- $query = "SELECT COUNT(*) FROM {$wpdb->prefix}frm_items WHERE form_id=". $where;
 
 
325
  }else{
326
- $query = "SELECT COUNT(*) FROM {$wpdb->prefix}frm_items it LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id" .
327
  FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
328
  }
329
- return $wpdb->get_var($query);
 
 
 
330
  }
331
 
332
- function getPageCount($p_size, $where=''){
333
- if(is_numeric($where))
334
- return ceil((int)$where / (int)$p_size);
335
- else
336
- return ceil((int)$this->getRecordCount($where) / (int)$p_size);
 
337
  }
338
 
339
- function validate( $values, $exclude=false ){
340
- global $wpdb, $frm_field, $frm_entry_meta, $frm_settings;
341
-
342
  $errors = array();
343
-
344
- if ( is_admin() && is_user_logged_in() && (!isset($values['frm_submit_entry']) || !wp_verify_nonce($values['frm_submit_entry'], 'frm_submit_entry_nonce')) ) {
345
- $errors['form'] = __('You do not have permission to do that', 'formidable');
346
- }
347
-
348
- if ( !isset($values['form_id']) || !isset($values['item_meta']) ) {
349
  $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable');
350
  return $errors;
351
  }
352
-
353
- if( !isset($values['item_key']) or $values['item_key'] == '' ){
 
 
 
 
354
  $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
355
  }
356
-
357
- $where = apply_filters('frm_posted_field_ids', 'fi.form_id='. (int)$values['form_id']);
358
- if($exclude)
359
  $where .= " and fi.type not in ('". implode("','", array_filter($exclude, 'esc_sql')) ."')";
360
-
361
- $posted_fields = $frm_field->getAll($where, 'field_order');
362
-
363
- foreach($posted_fields as $posted_field){
364
- $posted_field->field_options = maybe_unserialize($posted_field->field_options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  $value = '';
366
- if (isset($values['item_meta'][$posted_field->id]))
367
- $value = $values['item_meta'][$posted_field->id];
368
-
369
- if (isset($posted_field->field_options['default_blank']) and $posted_field->field_options['default_blank'] and $value == $posted_field->default_value)
370
- $value = '';
371
-
372
- if(is_array($value) and count($value) === 1)
373
- $value = reset($value);
374
-
375
- if($posted_field->type == 'rte' and !is_array($value) and (trim($value) == '<br>'))
376
- $value = '';
377
-
378
- if ($posted_field->required == '1' and !is_array($value) and trim($value) == ''){
379
- $errors['field'. $posted_field->id] = (!isset($posted_field->field_options['blank']) or $posted_field->field_options['blank'] == '' or $posted_field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
380
- }else if ($posted_field->type == 'text' and !isset($_POST['name'])){
381
- $_POST['name'] = $value;
382
- }
383
-
384
- $_POST['item_meta'][$posted_field->id] = $value;
385
-
386
- if ($posted_field->type == 'captcha' and isset($_POST['recaptcha_challenge_field'])){
387
- global $frm_settings;
388
-
389
- if(!function_exists('recaptcha_check_answer'))
390
- require(FrmAppHelper::plugin_path().'/classes/recaptchalib.php');
391
-
392
- $response = recaptcha_check_answer($frm_settings->privkey,
393
- $_SERVER['REMOTE_ADDR'],
394
- $_POST['recaptcha_challenge_field'],
395
- $_POST['recaptcha_response_field']);
396
-
397
- if (!$response->is_valid) {
398
- // What happens when the CAPTCHA was entered incorrectly
399
- $errors['captcha-'. $response->error] = $errors['field'. $posted_field->id] = (!isset($posted_field->field_options['invalid']) or $posted_field->field_options['invalid'] == '') ? $frm_settings->re_msg : $posted_field->field_options['invalid'];
400
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  }
403
-
404
- $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value);
405
-
406
  }
407
-
408
-
409
- // check for spam
410
- if ( empty($exclude) && isset($values['item_meta']) && !empty($values['item_meta']) && empty($errors) ) {
411
- global $wpcom_api_key;
412
- if ( (function_exists( 'akismet_http_post' ) || is_callable('Akismet::http_post')) && ((get_option('wordpress_api_key') || $wpcom_api_key)) && $this->akismet($values) ) {
413
- $frm_form = new FrmForm();
414
- $form = $frm_form->getOne($values['form_id']);
415
-
416
- if ( isset($form->options['akismet']) && !empty($form->options['akismet']) && ($form->options['akismet'] != 'logged' || !is_user_logged_in()) ) {
417
- $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
418
- }
419
- }
420
-
421
- // check for blacklist keys
422
- if ( $this->blacklist_check($values) ) {
423
- $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
424
- }
425
- }
426
 
427
-
428
- $errors = apply_filters('frm_validate_entry', $errors, $values);
429
- return $errors;
 
 
 
 
 
 
430
  }
431
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  // check the blacklisted words
433
- function blacklist_check( $values ) {
 
 
 
 
434
  $mod_keys = trim( get_option( 'blacklist_keys' ) );
435
 
436
  if ( empty( $mod_keys ) ) {
437
  return false;
438
  }
439
-
440
  $content = FrmEntriesHelper::entry_array_to_string($values);
441
-
442
  if ( empty($content) ) {
443
  return false;
444
  }
@@ -459,35 +640,21 @@ class FrmEntry{
459
 
460
  return false;
461
  }
462
-
463
- //Check entries for spam -- returns true if is spam
464
- function akismet($values) {
 
 
 
 
465
  $content = FrmEntriesHelper::entry_array_to_string($values);
466
-
467
  if ( empty($content) ) {
468
  return false;
469
  }
470
-
471
  $datas = array();
472
- $datas['blog'] = FrmAppHelper::site_url();
473
- $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
474
- $datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
475
- $datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
476
- $datas['comment_type'] = 'formidable';
477
- if ( $permalink = get_permalink() )
478
- $datas['permalink'] = $permalink;
479
-
480
- $datas['comment_content'] = $content;
481
-
482
- foreach ( $_SERVER as $key => $value ) {
483
- if ( !in_array($key, array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value) ) {
484
- $datas["$key"] = $value;
485
- } else {
486
- $datas["$key"] = '';
487
- }
488
-
489
- unset($key, $value);
490
- }
491
 
492
  $query_string = '';
493
  foreach ( $datas as $key => $data ) {
@@ -501,8 +668,34 @@ class FrmEntry{
501
  global $akismet_api_host, $akismet_api_port;
502
  $response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
503
  }
504
-
505
- return ( is_array($response) and $response[1] == 'true' ) ? true : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
  }
507
-
508
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
 
 
 
3
 
4
  class FrmEntry{
5
 
6
+ public static function create( $values ) {
7
+ global $wpdb;
8
+
9
+ $values = apply_filters('frm_pre_create_entry', $values);
10
+
11
+ //Clear leftover "other" data
12
+ if ( isset( $values['item_meta']['other'] ) ) {
13
+ unset( $values['item_meta']['other'] );
14
+ }
15
+
16
  $new_values = array(
17
  'item_key' => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
18
  'name' => isset($values['name']) ? $values['name'] : $values['item_key'],
19
+ 'ip' => FrmAppHelper::get_ip_address(),
20
  'is_draft' => ( ( isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 ) || ( isset($values['is_draft']) && $values['is_draft'] == 1) ) ? 1 : 0,
21
  'form_id' => isset($values['form_id']) ? (int) $values['form_id']: null,
22
  'post_id' => isset($values['post_id']) ? (int) $values['post_id']: null,
23
+ 'parent_item_id' => isset($values['parent_item_id']) ? (int) $values['parent_item_id']: null,
24
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
  'updated_at' => isset($values['updated_at']) ? $values['updated_at'] : ( isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1) ),
26
  );
27
+
28
+ if ( is_array($new_values['name']) ) {
29
  $new_values['name'] = reset($new_values['name']);
30
+ }
31
+
32
+ if ( isset($values['description']) && ! empty($values['description']) ) {
33
  $new_values['description'] = maybe_serialize($values['description']);
34
+ } else {
35
  $referrerinfo = FrmAppHelper::get_referer_info();
36
+
37
+ $new_values['description'] = serialize( array(
38
+ 'browser' => FrmAppHelper::get_server_value('HTTP_USER_AGENT'),
39
+ 'referrer' => $referrerinfo,
40
+ ) );
41
  }
42
+
43
  //if(isset($values['id']) and is_numeric($values['id']))
44
  // $new_values['id'] = $values['id'];
45
+
46
+ if ( isset($values['frm_user_id']) && ( is_numeric($values['frm_user_id']) || FrmAppHelper::is_admin() ) ) {
47
  $new_values['user_id'] = $values['frm_user_id'];
48
+ } else {
49
  $user_ID = get_current_user_id();
50
  $new_values['user_id'] = $user_ID ? $user_ID : 0;
51
  }
52
+
53
  $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
54
+
55
+ // don't create duplicate entry
56
+ if ( self::is_duplicate($new_values, $values) ) {
57
+ return false;
58
+ }
59
+
60
+ $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
61
+
62
+ if ( ! $query_results ) {
63
+ return false;
64
+ }
65
+
66
+ $entry_id = $wpdb->insert_id;
67
+
68
+ global $frm_vars;
69
+ if ( ! isset($frm_vars['saved_entries']) ) {
70
+ $frm_vars['saved_entries'] = array();
71
+ }
72
+ $frm_vars['saved_entries'][] = (int) $entry_id;
73
+
74
+ if ( isset($values['item_meta']) ) {
75
+ FrmEntryMeta::update_entry_metas($entry_id, $values['item_meta']);
76
+ }
77
+
78
+ do_action('frm_after_create_entry', $entry_id, $new_values['form_id']);
79
+ do_action('frm_after_create_entry_'. $new_values['form_id'], $entry_id);
80
+ return $entry_id;
81
+ }
82
+
83
+ /*
84
+ * check for duplicate entries created in the last 5 minutes
85
+ * @return boolean
86
+ */
87
+ public static function is_duplicate($new_values, $values) {
88
+ if ( defined('WP_IMPORTING') ) {
89
+ return false;
90
+ }
91
+
92
+ $check_val = $new_values;
93
+ $check_val['created_at >'] = date('Y-m-d H:i:s', (strtotime($new_values['created_at']) - (60*5)));
94
+
95
+ unset($check_val['created_at'], $check_val['updated_at']);
96
+ unset($check_val['is_draft'], $check_val['id'], $check_val['item_key']);
97
+
98
+ if ( $new_values['item_key'] == $new_values['name'] ) {
99
+ unset($check_val['name']);
100
+ }
101
+
102
+ global $wpdb;
103
+
104
+ $check_val = FrmAppHelper::get_where_clause_and_values( $check_val );
105
+
106
+ $entry_exists = $wpdb->get_results( $wpdb->prepare('SELECT id FROM '. $wpdb->prefix .'frm_items '. $check_val['where'] . ' ORDER BY created_at DESC', $check_val['values']) );
107
+
108
+ if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
109
+ return false;
110
+ }
111
+
112
+ $is_duplicate = false;
113
+ foreach ( $entry_exists as $entry_exist ) {
114
+ $is_duplicate = true;
115
+
116
+ //add more checks here to make sure it's a duplicate
117
+ $metas = FrmEntryMeta::get_entry_meta_info($entry_exist->id);
118
+ $field_metas = array();
119
+ foreach ( $metas as $meta ) {
120
+ $field_metas[$meta->field_id] = $meta->meta_value;
121
  }
122
+
123
+ // If prev entry is empty and current entry is not, they are not duplicates
124
+ $filtered_vals = array_filter( $values['item_meta'] );
125
+ if ( empty( $field_metas ) && !empty( $filtered_vals ) ) {
126
  return false;
127
  }
128
+
129
+ $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
130
+ foreach ( $diff as $field_id => $meta_value ) {
131
+ if ( ! empty($meta_value) ) {
132
+ $is_duplicate = false;
133
+ continue;
134
+ }
135
+ }
136
+
137
+ if ( $is_duplicate ) {
138
+ return $is_duplicate;
 
 
 
139
  }
 
 
 
 
 
 
140
  }
141
+
142
+ return $is_duplicate;
143
  }
 
 
 
144
 
145
+ public static function duplicate( $id ){
146
+ global $wpdb;
147
+
148
+ $values = FrmEntry::getOne( $id );
149
 
150
  $new_values = array();
151
  $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
152
  $new_values['name'] = $values->name;
153
  $new_values['is_draft'] = $values->is_draft;
154
+ $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
155
+ $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
156
  $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
157
 
158
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
159
+ if ( ! $query_results ) {
 
 
 
 
 
 
 
 
 
 
160
  return false;
161
+ }
162
+
163
+ $entry_id = $wpdb->insert_id;
164
+
165
+ global $frm_vars;
166
+ if ( ! isset($frm_vars['saved_entries']) ) {
167
+ $frm_vars['saved_entries'] = array();
168
+ }
169
+ $frm_vars['saved_entries'][] = (int) $entry_id;
170
+
171
+ FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
172
+
173
+ do_action('frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array('old_id' => $id));
174
+ return $entry_id;
175
  }
176
 
177
+ public static function update( $id, $values ){
178
+ global $wpdb, $frm_vars;
179
+ if ( isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
180
  return;
181
+ }
182
+
183
+ $values = apply_filters('frm_pre_update_entry', $values, $id);
184
 
185
  $user_ID = get_current_user_id();
186
+
187
  $new_values = array(
188
  'name' => isset($values['name']) ? $values['name'] : '',
189
  'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null,
191
  'updated_at' => current_time('mysql', 1),
192
  'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID,
193
  );
194
+
195
  if ( isset($values['post_id']) ) {
196
  $new_values['post_id'] = (int) $values['post_id'];
197
  }
199
  if ( isset($values['item_key']) ) {
200
  $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
201
  }
202
+
203
+ if ( isset($values['parent_item_id']) ) {
204
+ $new_values['parent_item_id'] = (int) $values['parent_item_id'];
205
+ }
206
+
207
+ if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
208
  $new_values['user_id'] = $values['frm_user_id'];
209
+ }
210
 
211
  $new_values = apply_filters('frm_update_entry', $new_values, $id);
212
  $query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
213
+
214
+ if ( $query_results ) {
215
+ wp_cache_delete( $id .'_nometa', 'frm_entry');
216
  wp_cache_delete( $id, 'frm_entry');
217
+ }
218
+
219
+ if ( !isset($frm_vars['saved_entries']) ) {
220
  $frm_vars['saved_entries'] = array();
221
+ }
222
+
223
+ $frm_vars['saved_entries'][] = (int) $id;
224
+
225
+ if ( isset($values['item_meta']) ) {
226
+ FrmEntryMeta::update_entry_metas($id, $values['item_meta']);
227
+ }
228
  do_action('frm_after_update_entry', $id, $new_values['form_id']);
229
  do_action('frm_after_update_entry_'. $new_values['form_id'], $id);
230
  return $query_results;
231
  }
232
 
233
+ public static function &destroy( $id ){
234
  global $wpdb;
235
+ $id = (int) $id;
236
+
237
+ $entry = self::getOne($id);
238
  if ( !$entry ) {
239
  $result = false;
240
  return $result;
241
  }
242
+
243
  do_action('frm_before_destroy_entry', $id, $entry);
244
+
245
+ wp_cache_delete( $id .'_nometa', 'frm_entry');
246
  wp_cache_delete( $id, 'frm_entry');
247
  $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=' . $id);
248
  $result = $wpdb->query('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=' . $id);
249
  return $result;
250
  }
251
+
252
+ public static function &update_form( $id, $value, $form_id ){
253
  global $wpdb;
254
  $form_id = isset($value) ? $form_id : NULL;
255
  $result = $wpdb->update( $wpdb->prefix .'frm_items', array('form_id' => $form_id), array( 'id' => $id ) );
257
  wp_cache_delete( $id, 'frm_entry');
258
  return $result;
259
  }
260
+
261
+ public static function getOne( $id, $meta = false){
262
  global $wpdb;
 
 
 
 
263
 
264
+ $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
265
  LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
 
266
  $query .= $wpdb->prepare( is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s', $id);
267
 
268
+ if ( ! $meta ) {
269
+ $entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
270
+ return stripslashes_deep($entry);
271
+ }
272
+
273
+ $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
274
+ if ( $entry !== false ) {
275
+ return stripslashes_deep($entry);
276
+ }
277
+
278
  $entry = $wpdb->get_row($query);
279
+ $entry = self::get_meta($entry);
280
+
281
+ return stripslashes_deep($entry);
282
+ }
283
+
284
+ public static function get_meta($entry) {
285
+ if ( ! $entry ) {
286
+ return $entry;
287
+ }
288
+
289
+ global $wpdb;
290
+ $metas = $wpdb->get_results($wpdb->prepare("SELECT field_id, meta_value, field_key, item_id FROM {$wpdb->prefix}frm_item_metas m LEFT JOIN {$wpdb->prefix}frm_fields f ON m.field_id=f.id WHERE item_id=%d and field_id != %d", $entry->id, 0));
291
+
292
+ $entry->metas = array();
293
+
294
+ foreach ( $metas as $meta_val ) {
295
+ if ( $meta_val->item_id == $entry->id ) {
296
+ $entry->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
297
+ continue;
298
+ }
299
 
300
+ // include sub entries in an array
301
+ if ( ! isset( $entry_metas[$meta_val->field_id]) ) {
302
+ $entry->metas[$meta_val->field_id] = array();
 
 
 
 
 
303
  }
 
304
 
305
+ $entry->metas[$meta_val->field_id][] = maybe_unserialize($meta_val->meta_value);
306
 
307
+ unset($meta_val);
308
  }
309
+ unset($metas);
310
 
311
+ wp_cache_set( $entry->id, $entry, 'frm_entry');
312
+
313
+ return $entry;
314
  }
315
+
316
+ public static function &exists( $id ){
317
  global $wpdb;
318
+
319
+ if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
320
  $exists = true;
321
  return $exists;
322
  }
323
+
324
  $where = (is_numeric($id)) ? 'id=%d' : 'item_key=%s';
325
 
326
  $id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE $where", $id));
327
+
328
  $exists = ($id && $id > 0) ? true : false;
329
  return $exists;
330
  }
331
 
332
+ public static function getAll($where, $order_by = '', $limit = '', $meta=false, $inc_form=true){
333
  global $wpdb;
334
+
335
+ $limit = FrmAppHelper::esc_limit($limit);
336
+
337
+ $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
338
+ $entries = wp_cache_get($cache_key, 'frm_entry');
339
+
340
+ if ( false === $entries ) {
341
+ if ( $inc_form ) {
342
+ $query = "SELECT it.*, fr.name as form_name,fr.form_key as form_key
343
+ FROM {$wpdb->prefix}frm_items it LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id" .
344
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
345
+ } else {
346
+ $query = "SELECT it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id,
347
+ it.updated_by, it.created_at, it.updated_at, it.is_draft FROM {$wpdb->prefix}frm_items it" .
348
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  }
350
+
351
+ if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
352
+ // sort by a requested field
353
+ $new_query = ', (SELECT meta_value FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id = '. $order_matches[1] .' AND item_id = it.id) as meta_'. $order_matches[1] .' FROM '. $wpdb->prefix .'frm_items ';
354
+ $query = str_replace( ' FROM '. $wpdb->prefix .'frm_items ', $new_query, $query );
355
+ unset($order_field);
356
+ }
357
+
358
+ $entries = $wpdb->get_results($query, OBJECT_K);
359
  unset($query);
360
+
361
+ wp_cache_set($cache_key, $entries, 'frm_entry', 300);
362
+ }
363
+
364
+ if ( !$meta || !$entries ) {
365
+ return stripslashes_deep($entries);
366
+ }
367
+ unset($meta);
368
+
369
+ if ( !is_array($where) && preg_match('/^it\.form_id=\d+$/', $where) ) {
370
+ $where = array('it.form_id' => substr($where, 11));
371
+ }
372
+
373
+ if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
374
+ $meta_where = $wpdb->prepare('fi.form_id=%d', $where['it.form_id']);
375
+ } else {
376
+ $meta_where = "item_id in (". implode(',', array_filter(array_keys($entries), 'is_numeric')) .")";
377
+ }
378
+
379
+ $query = "SELECT item_id, meta_value, field_id, field_key, form_id FROM {$wpdb->prefix}frm_item_metas it
380
+ LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id
381
+ WHERE $meta_where and field_id != 0";
382
+
383
+ $cache_key = 'metas_'. sanitize_title_with_dashes($meta_where);
384
+ $metas = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_results');
385
+ unset($query, $cache_key);
386
+
387
+ if ( ! $metas ) {
388
+ return stripslashes_deep($entries);
389
+ }
390
+
391
+ foreach ( $metas as $m_key => $meta_val ) {
392
+ if ( !isset($entries[$meta_val->item_id]) ) {
393
+ continue;
394
  }
395
+
396
+ if ( !isset($entries[$meta_val->item_id]->metas) ) {
397
+ $entries[$meta_val->item_id]->metas = array();
398
+ }
399
+
400
+ $entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
401
+
402
+ unset($m_key, $meta_val);
403
  }
404
+
405
+ foreach ( $entries as $entry ) {
406
+ wp_cache_set( $entry->id, $entry, 'frm_entry');
407
+ unset($entry);
408
+ }
409
+
410
  return stripslashes_deep($entries);
411
  }
412
 
413
  // Pagination Methods
414
+ public static function getRecordCount($where=''){
415
  global $wpdb;
416
+ $cache_key = 'count_'. maybe_serialize($where);
417
+
418
+ if ( is_numeric($where) ) {
419
+ $query = $wpdb->prepare('SELECT COUNT(*) FROM '. $wpdb->prefix .'frm_items WHERE form_id=%d', $where);
420
  }else{
421
+ $query = 'SELECT COUNT(*) FROM '. $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id' .
422
  FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
423
  }
424
+
425
+ $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
426
+
427
+ return $count;
428
  }
429
 
430
+ public static function getPageCount($p_size, $where=''){
431
+ if ( is_numeric($where) ) {
432
+ return ceil( (int) $where / (int) $p_size );
433
+ } else {
434
+ return ceil( (int) self::getRecordCount($where) / (int) $p_size );
435
+ }
436
  }
437
 
438
+ public static function validate( $values, $exclude=false ){
439
+ global $wpdb;
440
+
441
  $errors = array();
442
+
443
+ if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
 
 
 
 
444
  $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable');
445
  return $errors;
446
  }
447
+
448
+ if ( is_admin() && is_user_logged_in() && ( ! isset($values['frm_submit_entry_'. $values['form_id']]) || ! wp_verify_nonce($values['frm_submit_entry_'. $values['form_id']], 'frm_submit_entry_nonce') ) ) {
449
+ $errors['form'] = __('You do not have permission to do that', 'formidable');
450
+ }
451
+
452
+ if ( ! isset($values['item_key']) || $values['item_key'] == '' ) {
453
  $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
454
  }
455
+
456
+ $where = apply_filters('frm_posted_field_ids', $wpdb->prepare('fi.form_id=%d', $values['form_id']));
457
+ if ( $exclude ) {
458
  $where .= " and fi.type not in ('". implode("','", array_filter($exclude, 'esc_sql')) ."')";
459
+ }
460
+
461
+ $posted_fields = FrmField::getAll($where, 'field_order');
462
+
463
+ //Set Radio button and checkbox meta equal to "other" value, if it is set
464
+ $values = FrmEntriesHelper::set_other_vals( $values );
465
+
466
+ foreach ( $posted_fields as $posted_field ) {
467
+ self::validate_field($posted_field, $errors, $values);
468
+ unset($posted_field);
469
+ }
470
+
471
+
472
+ // check for spam
473
+ self::spam_check($exclude, $values, $errors);
474
+
475
+ $errors = apply_filters('frm_validate_entry', $errors, $values, compact('exclude'));
476
+
477
+ return $errors;
478
+ }
479
+
480
+ public static function validate_field($posted_field, &$errors, $values, $args = array()) {
481
+ $defaults = array(
482
+ 'id' => $posted_field->id,
483
+ 'parent_field_id' => '', // the id of the repeat or embed form
484
+ 'key_pointer' => '', // the pointer in the posted array
485
+ );
486
+ $args = wp_parse_args( $args, $defaults );
487
+
488
+ // Set values for "other" option in repeated fields
489
+ $values = FrmEntriesHelper::set_other_repeating_vals( $values, $posted_field );
490
+
491
+ if ( empty($args['parent_field_id']) ) {
492
+ $value = isset($values['item_meta'][$args['id']]) ? $values['item_meta'][$args['id']] : '';
493
+ } else {
494
+ // value is from a nested form
495
+ $value = $values;
496
+ }
497
+
498
+ if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
499
  $value = '';
500
+ }
501
+
502
+ // Check for an array with only one value or no values
503
+ if ( is_array($value) ) {
504
+ // If the field has an "other" option
505
+ if ( isset( $posted_field->field_options['other'] ) && $posted_field->field_options['other'] ) {
506
+ if ( count( array_filter( $value) ) == 0 ) {
507
+ $value = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
508
  }
509
+ } else if ( count( $value ) == 1 ) {
510
+ $value = reset($value);
511
+ }
512
+ }
513
+
514
+ if ( $posted_field->required == '1' && !is_array($value) && trim($value) == '' ) {
515
+ $frm_settings = FrmAppHelper::get_settings();
516
+ $errors['field'. $args['id']] = (!isset($posted_field->field_options['blank']) || $posted_field->field_options['blank'] == '') ? $frm_settings->blank_msg : $posted_field->field_options['blank'];
517
+ } else if ( $posted_field->type == 'text' && !isset($_POST['name']) ) {
518
+ $_POST['name'] = $value;
519
+ }
520
+
521
+ self::validate_url_field($errors, $posted_field, $value, $args);
522
+ self::validate_email_field($errors, $posted_field, $value, $args);
523
+
524
+ FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
525
+
526
+ self::validate_recaptcha($errors, $posted_field, $args);
527
+
528
+ $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
529
+ }
530
+
531
+ public static function validate_url_field(&$errors, $field, &$value, $args) {
532
+ if ( $value == '' || ! in_array($field->type, array('website', 'url', 'image')) ) {
533
+ return;
534
+ }
535
+
536
+ if ( trim($value) == 'http://' ) {
537
+ $value = '';
538
+ } else {
539
+ $value = esc_url_raw( $value );
540
+ $value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://'. $value;
541
+ }
542
 
543
+ //validate the url format
544
+ if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) {
545
+ $errors['field'. $args['id']] = FrmFieldsHelper::get_error_msg($field, 'invalid');
546
+ }
547
+ }
548
+
549
+ public static function validate_email_field(&$errors, $field, $value, $args) {
550
+ if ( $value == '' || $field->type != 'email' ) {
551
+ return;
552
+ }
553
+
554
+ //validate the email format
555
+ if ( ! is_email($value) ) {
556
+ $errors['field'. $args['id']] = FrmFieldsHelper::get_error_msg($field, 'invalid');
557
+ }
558
+ }
559
+
560
+ public static function validate_recaptcha(&$errors, $field, $args) {
561
+ if ( $field->type != 'captcha' || FrmAppHelper::is_admin() ) {
562
+ return;
563
+ }
564
+
565
+ if ( ! isset($_POST['g-recaptcha-response']) ) {
566
+ // If captcha is missing, check if it was already verified
567
+ if ( ! isset($_POST['recaptcha_checked']) || ! wp_verify_nonce($_POST['recaptcha_checked'], 'frm_form')) {
568
+ // There was no captcha submitted
569
+ $errors['field'. $args['id']] = __('The captcha is missing from this form', 'formidable');
570
  }
571
+ return;
 
 
572
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573
 
574
+ $frm_settings = FrmAppHelper::get_settings();
575
+
576
+ $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify?secret='. $frm_settings->privkey .'&response='. $_POST['g-recaptcha-response'] .'&remoteip='. FrmAppHelper::get_ip_address() );
577
+ $response = json_decode(wp_remote_retrieve_body( $resp ), true);
578
+
579
+ if ( ! $response['success'] ) {
580
+ // What happens when the CAPTCHA was entered incorrectly
581
+ $errors['field'. $args['id']] = ( ! isset($field->field_options['invalid']) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid'];
582
+ }
583
  }
584
+
585
+ /*
586
+ * check for spam
587
+ */
588
+ public static function spam_check($exclude, $values, &$errors) {
589
+ if ( ! empty($exclude) || ! isset($values['item_meta']) || empty($values['item_meta']) || ! empty($errors) ) {
590
+ // only check spam if there are no other errors
591
+ return;
592
+ }
593
+
594
+ global $wpcom_api_key;
595
+ if ( ( function_exists( 'akismet_http_post' ) || is_callable('Akismet::http_post') ) && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet($values) ) {
596
+ $form = FrmForm::getOne($values['form_id']);
597
+
598
+ if ( isset($form->options['akismet']) && ! empty($form->options['akismet']) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ) {
599
+ $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
600
+ }
601
+ }
602
+
603
+ // check for blacklist keys
604
+ if ( self::blacklist_check($values) ) {
605
+ $errors['spam'] = __('Your entry appears to be spam!', 'formidable');
606
+ }
607
+ }
608
+
609
  // check the blacklisted words
610
+ public static function blacklist_check( $values ) {
611
+ if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
612
+ return false;
613
+ }
614
+
615
  $mod_keys = trim( get_option( 'blacklist_keys' ) );
616
 
617
  if ( empty( $mod_keys ) ) {
618
  return false;
619
  }
620
+
621
  $content = FrmEntriesHelper::entry_array_to_string($values);
622
+
623
  if ( empty($content) ) {
624
  return false;
625
  }
640
 
641
  return false;
642
  }
643
+
644
+ /*
645
+ * Check entries for spam
646
+ *
647
+ * @return boolean true if is spam
648
+ */
649
+ public static function akismet($values) {
650
  $content = FrmEntriesHelper::entry_array_to_string($values);
651
+
652
  if ( empty($content) ) {
653
  return false;
654
  }
655
+
656
  $datas = array();
657
+ self::parse_akismet_array($datas, $content);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
 
659
  $query_string = '';
660
  foreach ( $datas as $key => $data ) {
668
  global $akismet_api_host, $akismet_api_port;
669
  $response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
670
  }
671
+
672
+ return ( is_array($response) && $response[1] == 'true' ) ? true : false;
673
+ }
674
+
675
+ /*
676
+ * Called by FrmEntry::akismet
677
+ * @since 2.0
678
+ */
679
+ private static function parse_akismet_array( &$datas, $content ) {
680
+ $datas['blog'] = FrmAppHelper::site_url();
681
+ $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
682
+ $datas['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
683
+ $datas['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
684
+ $datas['comment_type'] = 'formidable';
685
+ $datas['comment_content'] = $content;
686
+
687
+ if ( $permalink = get_permalink() ) {
688
+ $datas['permalink'] = $permalink;
689
+ }
690
+
691
+ foreach ( $_SERVER as $key => $value ) {
692
+ if ( ! in_array($key, array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW')) && is_string($value) ) {
693
+ $datas[$key] = $value;
694
+ } else {
695
+ $datas[$key] = '';
696
+ }
697
+
698
+ unset($key, $value);
699
+ }
700
  }
 
701
  }
classes/models/FrmEntryMeta.php CHANGED
@@ -1,256 +1,294 @@
1
  <?php
2
- if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
-
4
- if(class_exists('FrmEntryMeta'))
5
- return;
6
 
7
  class FrmEntryMeta{
8
 
9
- function add_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
10
  global $wpdb;
11
-
12
  if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
13
  // don't save blank fields
14
  return;
15
  }
16
-
17
  $new_values = array(
18
  'meta_value' => is_array($meta_value) ? serialize(array_filter($meta_value)) : trim($meta_value),
19
  'item_id' => $entry_id,
20
  'field_id' => $field_id,
21
  'created_at' => current_time('mysql', 1),
22
  );
23
-
24
  $new_values = apply_filters('frm_add_entry_meta', $new_values);
25
 
26
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values );
27
-
28
  $id = $query_results ? $wpdb->insert_id : 0;
29
-
30
  return $id;
31
  }
32
 
33
- function update_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value){
34
  if ( ! $field_id ) {
35
  return false;
36
  }
37
-
38
  global $wpdb;
39
-
40
  $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
41
  $values['meta_value'] = $meta_value;
42
  $values = apply_filters('frm_update_entry_meta', $values);
43
- if ( is_array($meta_value) ) {
44
- $meta_value = array_filter($meta_value);
45
  }
46
  $meta_value = maybe_serialize($values['meta_value']);
47
-
 
 
48
  return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
49
  }
50
-
51
- function update_entry_metas($entry_id, $values){
52
- global $frm_field, $wpdb;
53
-
54
  $prev_values = $wpdb->get_col($wpdb->prepare("SELECT field_id FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d AND field_id != %d", $entry_id, 0));
55
-
56
  foreach ( $values as $field_id => $meta_value ) {
57
-
58
  if ( $prev_values && in_array($field_id, $prev_values) ) {
59
  if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
60
  // remove blank fields
61
  unset($values[$field_id]);
62
  } else {
63
  // if value exists, then update it
64
- $this->update_entry_meta($entry_id, $field_id, '', $values[$field_id]);
65
  }
66
  } else {
67
  // if value does not exist, then create it
68
- $this->add_entry_meta($entry_id, $field_id, '', $values[$field_id]);
69
  }
70
-
71
  }
72
-
73
  if ( empty($prev_values) ) {
74
  return;
75
  }
76
-
77
  $prev_values = array_diff($prev_values, array_keys($values));
78
-
79
  if ( empty($prev_values) ) {
80
  return;
81
  }
82
-
83
  // Delete any leftovers
84
  $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d AND field_id in", $entry_id) ." (". implode(',', $prev_values) .")");
85
  }
86
-
87
- function duplicate_entry_metas($old_id, $new_id){
88
- $metas = $this->get_entry_meta_info($old_id);
89
  foreach ( $metas as $meta ) {
90
- $this->add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
91
  unset($meta);
92
  }
93
  }
94
 
95
- function delete_entry_meta($entry_id, $field_id){
96
  global $wpdb;
97
  return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
98
  }
99
-
100
- function delete_entry_metas($entry_id, $where=''){
101
- _deprecated_function( __FUNCTION__, '1.07.05', '$frm_entry_meta->delete_entry_meta()' );
102
  }
103
-
104
- function get_entry_meta_by_field($entry_id, $field_id, $return_var=true){
105
  global $wpdb;
106
-
107
- $entry_id = (int)$entry_id;
108
-
109
- $cached = wp_cache_get( $entry_id, 'frm_entry' );
110
- if($cached and isset($cached->metas) and isset($cached->metas[$field_id])){
111
  $result = $cached->metas[$field_id];
112
  return stripslashes_deep($result);
113
  }
114
-
115
- if (is_numeric($field_id))
116
  $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d and item_id=%d", $field_id, $entry_id);
117
- else
118
  $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id WHERE fi.field_key=%s and item_id=%d", $field_id, $entry_id);
119
-
120
- if($return_var){
121
- $result = maybe_unserialize($wpdb->get_var("{$query} LIMIT 1"));
122
- if($cached){
123
- if(!isset($cached->metas))
124
- $cached->metas = array();
125
- $cached->metas[$field_id] = $result;
126
- wp_cache_set($entry_id, $cached, 'frm_entry');
 
 
127
  }
128
- $result = stripslashes_deep($result);
129
- }else{
130
- $result = $wpdb->get_col($query, 0);
131
  }
132
-
 
133
  return $result;
134
  }
135
-
136
- function get_entry_meta($entry_id, $field_id, $return_var=true){
 
 
137
  global $wpdb;
138
-
139
- $entry = wp_cache_get($entry_id, 'frm_entry');
140
- if($return_var and $entry and isset($entry->metas) and isset($entry->metas[$field_id])){
141
- $var = $entry->metas[$field_id];
142
- return stripslashes_deep($var);
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
-
145
- $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d and item_id=%d", $field_id, $entry_id);
146
 
147
- if($return_var){
148
- $var = $wpdb->get_var("{$query} LIMIT 1");
149
- if($var)
150
- $var = stripslashes_deep(maybe_unserialize($var));
151
- }else{
152
- $var = $wpdb->get_col($query, 0);
153
  }
154
- return $var;
155
- }
156
 
157
- function get_entry_metas($entry_id){
158
- global $wpdb;
159
- return $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
160
  }
161
-
162
- function get_entry_metas_for_field($field_id, $order='', $limit='', $args=array()){
163
  global $wpdb;
164
-
165
- $defaults = array('value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false);
166
- extract(wp_parse_args( $args, $defaults ));
167
-
168
- $query = "SELECT ";
169
- $query .= ($unique) ? "DISTINCT(em.meta_value)" : "em.meta_value";
170
- $query .= " FROM {$wpdb->prefix}frm_item_metas em ";
171
-
172
- if(!$is_draft)
173
- $query .= " INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=em.item_id) ";
174
- $query .= (is_numeric($field_id)) ? "WHERE em.field_id='{$field_id}'" : "LEFT JOIN {$wpdb->prefix}frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key='{$field_id}'";
175
-
176
- if(!$is_draft)
177
- $query .= " AND e.is_draft=0";
178
-
179
- if($value)
180
- $query .= " AND meta_value='$value'";
181
- $query .= "{$order}{$limit}";
182
-
183
- $values = $wpdb->get_col($query);
184
- if($stripslashes){
185
- foreach($values as $k => $v){
186
- $values[$k] = maybe_unserialize($v);
187
- unset($k);
188
- unset($v);
189
- }
190
- $values = stripslashes_deep($values);
191
  }
192
 
193
- return $values;
 
 
 
 
 
 
 
194
  }
195
-
196
- function get_entry_meta_info($entry_id){
197
  global $wpdb;
198
- return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
 
 
 
 
 
 
199
  }
200
-
201
- function getAll($where = '', $order_by = '', $limit = '', $stripslashes = false){
202
- global $wpdb, $frm_field;
203
- $query = "SELECT it.*, fi.type as field_type, fi.field_key as field_key,
204
- fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
205
- FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id" .
206
- FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
207
-
208
- $results = ($limit == ' LIMIT 1') ? $wpdb->get_row($query) : $wpdb->get_results($query);
209
-
210
- if($results and $stripslashes){
211
- foreach($results as $k => $result){
212
- $results[$k]->meta_value = stripslashes_deep(maybe_unserialize($result->meta_value));
213
- unset($k);
214
- unset($result);
215
- }
 
 
216
  }
217
-
218
- return $results;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  }
220
-
221
- function getEntryIds($where = '', $order_by = '', $limit = '', $unique=true, $drafts=false){
222
  global $wpdb;
223
- $query = "SELECT ";
224
- $query .= ($unique) ? "DISTINCT(it.item_id)" : "it.item_id";
225
- $query .= " FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id ";
226
-
227
- if ( !$drafts ) {
228
- $query .= "INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=it.item_id) ";
229
- if ( is_array($where) ) {
230
  $where['e.is_draft'] = 0;
231
- } else {
232
- if ( strpos($where, ' GROUP BY ') ) {
233
- // don't inject WHERE filtering after GROUP BY
234
- $parts = explode(' GROUP BY ', $where);
235
- $where = $parts[0];
236
- $where .= ' AND e.is_draft=0';
237
- $where .= ' GROUP BY '. $parts[1];
238
- } else {
239
- $where .= ' AND e.is_draft=0';
240
- }
241
  }
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
- $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
245
- if ($limit == ' LIMIT 1')
246
- $results = $wpdb->get_var($query);
247
- else
248
- $results = $wpdb->get_col($query);
 
 
 
 
 
 
 
 
249
 
250
- return $results;
251
  }
252
-
253
- function search_entry_metas($search, $field_id='', $operator){
 
 
 
 
 
 
254
  global $wpdb;
255
  if (is_array($search)){
256
  $where = '';
@@ -260,7 +298,7 @@ class FrmEntryMeta{
260
  if ($field == 'month' and $value > 0)
261
  $where .= " meta_value {$operator} '{$value}%' and";
262
  if ($field == 'day' and $value > 0)
263
- $where .= " meta_value {$operator} '%/{$value}/%' and";
264
  }
265
  $where .= " field_id='{$field_id}'";
266
  $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
@@ -269,7 +307,11 @@ class FrmEntryMeta{
269
  $search = "%{$search}%";
270
  $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
271
  }
272
- return $wpdb->get_col($query, 0);
 
 
 
 
273
  }
274
 
275
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
 
 
 
3
 
4
  class FrmEntryMeta{
5
 
6
+ public static function add_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value) {
7
  global $wpdb;
8
+
9
  if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
10
  // don't save blank fields
11
  return;
12
  }
13
+
14
  $new_values = array(
15
  'meta_value' => is_array($meta_value) ? serialize(array_filter($meta_value)) : trim($meta_value),
16
  'item_id' => $entry_id,
17
  'field_id' => $field_id,
18
  'created_at' => current_time('mysql', 1),
19
  );
20
+
21
  $new_values = apply_filters('frm_add_entry_meta', $new_values);
22
 
23
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values );
24
+
25
  $id = $query_results ? $wpdb->insert_id : 0;
26
+
27
  return $id;
28
  }
29
 
30
+ public static function update_entry_meta($entry_id, $field_id, $meta_key = null, $meta_value){
31
  if ( ! $field_id ) {
32
  return false;
33
  }
34
+
35
  global $wpdb;
36
+
37
  $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
38
  $values['meta_value'] = $meta_value;
39
  $values = apply_filters('frm_update_entry_meta', $values);
40
+ if ( is_array($values['meta_value']) ) {
41
+ $values['meta_value'] = array_filter($values['meta_value']);
42
  }
43
  $meta_value = maybe_serialize($values['meta_value']);
44
+
45
+ wp_cache_delete( $entry_id, 'frm_entry');
46
+
47
  return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
48
  }
49
+
50
+ public static function update_entry_metas($entry_id, $values){
51
+ global $wpdb;
52
+
53
  $prev_values = $wpdb->get_col($wpdb->prepare("SELECT field_id FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d AND field_id != %d", $entry_id, 0));
54
+
55
  foreach ( $values as $field_id => $meta_value ) {
56
+
57
  if ( $prev_values && in_array($field_id, $prev_values) ) {
58
  if ( (is_array($meta_value) && empty($meta_value) ) || ( !is_array($meta_value) && trim($meta_value) == '' ) ) {
59
  // remove blank fields
60
  unset($values[$field_id]);
61
  } else {
62
  // if value exists, then update it
63
+ self::update_entry_meta($entry_id, $field_id, '', $values[$field_id]);
64
  }
65
  } else {
66
  // if value does not exist, then create it
67
+ self::add_entry_meta($entry_id, $field_id, '', $values[$field_id]);
68
  }
69
+
70
  }
71
+
72
  if ( empty($prev_values) ) {
73
  return;
74
  }
75
+
76
  $prev_values = array_diff($prev_values, array_keys($values));
77
+
78
  if ( empty($prev_values) ) {
79
  return;
80
  }
81
+
82
  // Delete any leftovers
83
  $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d AND field_id in", $entry_id) ." (". implode(',', $prev_values) .")");
84
  }
85
+
86
+ public static function duplicate_entry_metas($old_id, $new_id){
87
+ $metas = self::get_entry_meta_info($old_id);
88
  foreach ( $metas as $meta ) {
89
+ self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
90
  unset($meta);
91
  }
92
  }
93
 
94
+ public static function delete_entry_meta($entry_id, $field_id){
95
  global $wpdb;
96
  return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
97
  }
98
+
99
+ public static function delete_entry_metas() {
100
+ _deprecated_function( __FUNCTION__, '1.07.05', 'FrmEntryMeta::delete_entry_meta()' );
101
  }
102
+
103
+ public static function get_entry_meta_by_field($entry_id, $field_id) {
104
  global $wpdb;
105
+
106
+ $entry_id = (int) $entry_id;
107
+
108
+ $cached = FrmAppHelper::check_cache( $entry_id, 'frm_entry' );
109
+ if ( $cached && isset($cached->metas) && isset($cached->metas[$field_id]) ) {
110
  $result = $cached->metas[$field_id];
111
  return stripslashes_deep($result);
112
  }
113
+
114
+ if ( is_numeric($field_id) ) {
115
  $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d and item_id=%d", $field_id, $entry_id);
116
+ } else {
117
  $query = $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas it LEFT OUTER JOIN {$wpdb->prefix}frm_fields fi ON it.field_id=fi.id WHERE fi.field_key=%s and item_id=%d", $field_id, $entry_id);
118
+ }
119
+ $query .= ' LIMIT 1';
120
+
121
+ $cache_key = 'get_entry_meta_by_field_'. $entry_id .'f'. $field_id;
122
+ $result = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
123
+ $result = maybe_unserialize($result);
124
+
125
+ if ( $cached ) {
126
+ if ( !isset($cached->metas) ) {
127
+ $cached->metas = array();
128
  }
129
+ $cached->metas[$field_id] = $result;
130
+ wp_cache_set($entry_id, $cached, 'frm_entry');
 
131
  }
132
+ $result = stripslashes_deep($result);
133
+
134
  return $result;
135
  }
136
+
137
+ public static function get_entry_metas($entry_id){
138
+ _deprecated_function( __FUNCTION__, '1.07.10');
139
+
140
  global $wpdb;
141
+ return $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas WHERE item_id=%d", $entry_id));
142
+ }
143
+
144
+ public static function get_entry_metas_for_field($field_id, $order='', $limit='', $args=array()){
145
+ $defaults = array('value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false);
146
+ $args = wp_parse_args( $args, $defaults );
147
+
148
+ $query = array();
149
+ self::meta_field_query($field_id, $order, $limit, $args, $query);
150
+ $query = implode(' ', $query);
151
+
152
+ $cache_key = 'entry_metas_for_field_'. $field_id . $order . $limit . maybe_serialize($args);
153
+ $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
154
+
155
+ if ( ! $args['stripslashes'] ) {
156
+ return $values;
157
  }
 
 
158
 
159
+ foreach($values as $k => $v){
160
+ $values[$k] = maybe_unserialize($v);
161
+ unset($k, $v);
 
 
 
162
  }
 
 
163
 
164
+ return stripslashes_deep($values);
 
 
165
  }
166
+
167
+ private static function meta_field_query($field_id, $order, $limit, $args, array &$query) {
168
  global $wpdb;
169
+ $query[] = 'SELECT';
170
+ $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
171
+ $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas em ';
172
+
173
+ if ( ! $args['is_draft'] ) {
174
+ $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=em.item_id)';
175
+ }
176
+
177
+ if ( is_numeric($field_id) ) {
178
+ $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
179
+ } else {
180
+ $query[] = $wpdb->prepare('LEFT JOIN '. $wpdb->prefix .'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
+ if ( ! $args['is_draft'] ) {
184
+ $query[] = 'AND e.is_draft=0';
185
+ }
186
+
187
+ if ( $args['value'] ) {
188
+ $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
189
+ }
190
+ $query[] = $order . $limit;
191
  }
192
+
193
+ public static function get_entry_meta_info($entry_id){
194
  global $wpdb;
195
+
196
+ $cache_key = 'entry_meta_info_'. $entry_id;
197
+ $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $entry_id);
198
+
199
+ $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_results');
200
+
201
+ return $results;
202
  }
203
+
204
+ public static function getAll($where = '', $order_by = '', $limit = '', $stripslashes = false){
205
+ global $wpdb;
206
+ $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
207
+ fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
208
+ FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id' .
209
+ FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
210
+
211
+ $cache_key = 'all_'. maybe_serialize($where) . $order_by . $limit;
212
+ $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
213
+
214
+ if ( ! $results || ! $stripslashes ) {
215
+ return $results;
216
+ }
217
+
218
+ foreach ( $results as $k => $result ) {
219
+ $results[$k]->meta_value = stripslashes_deep(maybe_unserialize($result->meta_value));
220
+ unset($k, $result);
221
  }
222
+
223
+ return $results;
224
+ }
225
+
226
+ public static function getEntryIds($where = '', $order_by = '', $limit = '', $unique=true, $args = array()) {
227
+ $defaults = array('is_draft' => false, 'user_id' => '');
228
+ $args = wp_parse_args($args, $defaults);
229
+
230
+ $query = array();
231
+ self::get_ids_query($where, $order_by, $limit, $unique, $args, $query);
232
+ $query = implode(' ', $query);
233
+
234
+ $cache_key = 'ids_'. maybe_serialize($where) . $order_by . 'l'. $limit . 'u'. $unique . maybe_serialize($args);
235
+ $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
236
+
237
+ return $results;
238
  }
239
+
240
+ private static function get_ids_query($where, $order_by, $limit, $unique, $args, array &$query) {
241
  global $wpdb;
242
+ $query[] = 'SELECT';
243
+ $query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id';
244
+ $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id';
245
+
246
+ $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=it.item_id)';
247
+ if ( is_array($where) ) {
248
+ if ( ! $args['is_draft'] ) {
249
  $where['e.is_draft'] = 0;
250
+ } else if ( $args['is_draft'] == 1 ){
251
+ $where['e.is_draft'] = 1;
252
+ }
253
+
254
+ if ( ! empty($args['user_id']) ) {
255
+ $where['e.user_id'] = $args['user_id'];
 
 
 
 
256
  }
257
+ $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
258
+ return;
259
+ }
260
+
261
+ $draft_where = $user_where = '';
262
+ if ( ! $args['is_draft'] ) {
263
+ $draft_where = ' AND e.is_draft=0';
264
+ } else if ( $args['is_draft'] == 1 ) {
265
+ $draft_where = ' AND e.is_draft=1';
266
  }
267
 
268
+ if ( ! empty($args['user_id']) ) {
269
+ $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
270
+ }
271
+
272
+ if ( strpos($where, ' GROUP BY ') ) {
273
+ // don't inject WHERE filtering after GROUP BY
274
+ $parts = explode(' GROUP BY ', $where);
275
+ $where = $parts[0];
276
+ $where .= $draft_where . $user_where;
277
+ $where .= ' GROUP BY '. $parts[1];
278
+ } else {
279
+ $where .= $draft_where . $user_where;
280
+ }
281
 
282
+ $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
283
  }
284
+
285
+ public static function search_entry_metas($search, $field_id='', $operator){
286
+ $cache_key = 'search_'. maybe_serialize($search) . $field_id . $operator;
287
+ $results = wp_cache_get($cache_key, 'frm_entry');
288
+ if ( false !== $results ) {
289
+ return $results;
290
+ }
291
+
292
  global $wpdb;
293
  if (is_array($search)){
294
  $where = '';
298
  if ($field == 'month' and $value > 0)
299
  $where .= " meta_value {$operator} '{$value}%' and";
300
  if ($field == 'day' and $value > 0)
301
+ $where .= " meta_value {$operator} '%/{$value}/%' and";
302
  }
303
  $where .= " field_id='{$field_id}'";
304
  $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
307
  $search = "%{$search}%";
308
  $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
309
  }
310
+
311
+ $results = $wpdb->get_col($query, 0);
312
+ wp_cache_set($cache_key, $results, 'frm_entry', 300);
313
+
314
+ return $results;
315
  }
316
 
317
  }
classes/models/FrmField.php CHANGED
@@ -1,13 +1,14 @@
1
  <?php
2
- if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
 
4
  if(class_exists('FrmField'))
5
  return;
6
 
7
  class FrmField{
 
8
 
9
- function create( $values, $return=true ){
10
- global $wpdb;
11
 
12
  $new_values = array();
13
  $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
@@ -16,37 +17,38 @@ class FrmField{
16
  foreach ( array('name', 'description', 'type', 'default_value') as $col ) {
17
  $new_values[$col] = $values[$col];
18
  }
19
-
20
  $new_values['options'] = $values['options'];
21
 
22
- $new_values['field_order'] = isset($values['field_order']) ? (int)$values['field_order'] : NULL;
23
- $new_values['required'] = isset($values['required']) ? (int)$values['required'] : 0;
24
- $new_values['form_id'] = isset($values['form_id']) ? (int)$values['form_id'] : NULL;
25
  $new_values['field_options'] = $values['field_options'];
26
  $new_values['created_at'] = current_time('mysql', 1);
 
27
  if(isset($values['id'])){
28
- global $frm_duplicate_ids;
29
  $frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
30
  $new_values = apply_filters('frm_duplicated_field', $new_values);
31
  }
32
-
33
  foreach($new_values as $k => $v){
34
  if(is_array($v))
35
  $new_values[$k] = serialize($v);
36
  unset($k);
37
  unset($v);
38
  }
39
-
40
  //if(isset($values['id']) and is_numeric($values['id']))
41
  // $new_values['id'] = $values['id'];
42
-
43
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
44
  if($return){
45
  if($query_results){
46
- delete_transient('frm_all_form_fields_'. $new_values['form_id']);
47
  $new_id = $wpdb->insert_id;
48
- if(isset($values['id']))
49
  $frm_duplicate_ids[$values['id']] = $new_id;
 
50
  return $new_id;
51
  }else{
52
  return false;
@@ -54,204 +56,326 @@ class FrmField{
54
  }
55
  }
56
 
57
- function duplicate($old_form_id, $form_id, $copy_keys=false, $blog_id=false){
58
- global $frm_duplicate_ids, $wpdb;
59
- $fields = $this->getAll(array('fi.form_id' => $old_form_id), 'field_order', '', $blog_id);
60
- foreach ((array)$fields as $field){
61
- $values = array();
62
  $new_key = ($copy_keys) ? $field->field_key : '';
63
- if($copy_keys and substr($field->field_key, -1) == 2)
64
  $new_key = rtrim($new_key, 2);
65
- $values['field_key'] = FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_fields', 'field_key');
66
- $values['options'] = maybe_serialize($field->options);
67
- $values['form_id'] = $form_id;
68
- foreach (array('name', 'description', 'type', 'default_value', 'field_order', 'required', 'field_options') as $col)
69
- $values[$col] = $field->{$col};
70
  $values = apply_filters('frm_duplicated_field', $values);
71
- $new_id = $this->create($values);
72
  $frm_duplicate_ids[$field->id] = $new_id;
73
  $frm_duplicate_ids[$field->field_key] = $new_id;
74
  unset($field);
75
  }
76
  }
77
 
78
- function update( $id, $values ){
79
  global $wpdb;
80
-
81
  if (isset($values['field_key']))
82
  $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
83
 
84
  if ( isset($values['required']) ) {
85
  $values['required'] = (int) $values['required'];
86
  }
87
-
88
- if (isset($values['default_value']) and is_array($values['default_value']))
89
  $values['default_value'] = serialize($values['default_value']);
90
-
91
- if (isset($values['field_options']) and is_array($values['field_options']))
 
92
  $values['field_options'] = serialize($values['field_options']);
93
-
94
- if (isset($values['options']) and is_array($values['options']))
 
95
  $values['options'] = serialize($values['options']);
96
-
 
97
  $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
98
-
 
99
  if(isset($values['form_id'])){
100
  $form_id = $values['form_id'];
101
  }else{
102
- $field = $this->getOne($id);
103
- if($field)
104
  $form_id = $field->form_id;
 
105
  unset($field);
106
  }
107
  unset($values);
108
-
109
  if($query_results){
110
  wp_cache_delete( $id, 'frm_field' );
111
- delete_transient('frm_all_form_fields_'. $form_id);
 
 
112
  }
113
-
114
  return $query_results;
115
  }
116
 
117
- function destroy( $id ){
118
  global $wpdb;
119
 
120
  do_action('frm_before_destroy_field', $id);
121
- do_action('frm_before_destroy_field_'. $id);
122
-
123
  wp_cache_delete( $id, 'frm_field' );
124
- $field = $this->getOne($id);
125
  if ( !$field ) {
126
  return false;
127
  }
128
-
129
- delete_transient('frm_all_form_fields_'. $field->form_id);
130
-
131
- $wpdb->query("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id='$id'");
132
- return $wpdb->query("DELETE FROM {$wpdb->prefix}frm_fields WHERE id='$id'");
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
 
135
- function getOne( $id ){
136
  global $wpdb;
137
- $results = wp_cache_get( $id, 'frm_field' );
138
- if(!$results){
139
-
140
- $where = (is_numeric($id)) ? 'id=%d' : 'field_key=%s';
141
- $results = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_fields WHERE $where", $id));
142
-
143
- if($results){
144
- wp_cache_set( $results->id, $results, 'frm_field' );
145
- wp_cache_set( $results->field_key, $results, 'frm_field' );
146
- }
147
  }
148
-
149
- if($results){
150
- $results->field_options = maybe_unserialize($results->field_options);
151
- if(isset($results->field_options['format']) and !empty($results->field_options['format']))
152
- $results->field_options['format'] = addslashes($results->field_options['format']);
153
- $results->options = maybe_unserialize($results->options);
154
- $results->default_value = maybe_unserialize($results->default_value);
 
 
 
155
  }
156
-
 
 
157
  return stripslashes_deep($results);
158
  }
159
 
160
- function getAll($where=array(), $order_by = '', $limit = '', $blog_id=false){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  global $wpdb;
162
-
163
- if ($blog_id and is_multisite()){
164
  global $wpmuBaseTablePrefix;
165
  if($wpmuBaseTablePrefix)
166
  $prefix = "{$wpmuBaseTablePrefix}{$blog_id}_";
167
  else
168
  $prefix = $wpdb->get_blog_prefix( $blog_id );
169
-
170
- $table_name = "{$prefix}frm_fields";
171
  $form_table_name = "{$prefix}frm_forms";
172
  }else{
173
  $table_name = $wpdb->prefix .'frm_fields';
174
  $form_table_name = $wpdb->prefix .'frm_forms';
175
  }
176
-
177
- if(!empty($order_by) and !preg_match("/ORDER BY/", $order_by))
178
  $order_by = " ORDER BY {$order_by}";
 
 
 
179
 
180
- if(is_numeric($limit))
181
- $limit = " LIMIT {$limit}";
182
-
183
  $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
184
- $old_where = $where;
185
- if(is_array($where)){
186
- global $frmdb;
187
- extract($frmdb->get_where_clause_and_values( $where ));
188
 
189
- $query .= "{$where}{$order_by}{$limit}";
190
- $query = $wpdb->prepare($query, $values);
 
 
 
 
 
 
 
 
 
 
191
  }else{
192
  $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
193
  }
194
-
195
- if ($limit == ' LIMIT 1' or $limit == 1){
196
  $results = $wpdb->get_row($query);
197
- }else{
198
- $ak = is_array($old_where) ? array_keys($old_where) : $old_where;
199
- if($order_by == ' ORDER BY field_order' and empty($limit) and empty($blog_id) and is_array($old_where) and count($old_where) == 1 and reset($ak) == 'fi.form_id'){
200
- $save_cache = true;
201
- $results = get_transient('frm_all_form_fields_'. reset($old_where));
202
- if($results and (is_array($results) or is_object($results)))
203
- $cached = true;
204
- }
205
- unset($ak);
206
- if(!isset($cached))
207
- $results = $wpdb->get_results($query);
208
  }
209
-
210
- if($results and !isset($cached)){
211
- if(is_array($results)){
212
- foreach($results as $r_key => $result){
213
- wp_cache_set($result->id, $result, 'frm_field');
214
- wp_cache_set($result->field_key, $result, 'frm_field');
215
- $results[$r_key]->field_options = maybe_unserialize($result->field_options);
216
- if(isset($results[$r_key]->field_options['format']) and !empty($results[$r_key]->field_options['format']))
217
- $results[$r_key]->field_options['format'] = addslashes($results[$r_key]->field_options['format']);
218
- $results[$r_key]->options = maybe_unserialize($result->options);
219
- $results[$r_key]->default_value = maybe_unserialize($result->default_value);
220
- $form_id = $result->form_id;
221
-
222
- unset($r_key, $result);
223
  }
224
- if(isset($save_cache))
225
- set_transient('frm_all_form_fields_'. $form_id, $results, 60*60*6);
226
- unset($form_id);
227
- }else{
228
- wp_cache_set($results->id, $results, 'frm_field');
229
- wp_cache_set($results->field_key, $results, 'frm_field');
230
- $results->field_options = maybe_unserialize($results->field_options);
231
- if(isset($results->field_options['format']) and !empty($results->field_options['format']))
232
- $results->field_options['format'] = addslashes($results->field_options['format']);
233
- $results->options = maybe_unserialize($results->options);
234
- $results->default_value = maybe_unserialize($results->default_value);
235
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  }
237
-
 
238
  return stripslashes_deep($results);
239
  }
240
 
241
- function getIds($where = '', $order_by = '', $limit = ''){
242
  global $wpdb;
243
-
244
- if ( !empty($order_by) && !preg_match("/ORDER BY/", $order_by) ){
245
  $order_by = ' ORDER BY '. $order_by;
246
  }
247
-
248
- $query = "SELECT fi.id FROM {$wpdb->prefix}frm_fields fi " .
249
- "LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON fi.form_id=fr.id" .
250
  FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
251
- if ($limit == ' LIMIT 1' or $limit == 1)
252
- $results = $wpdb->get_var($query);
253
- else
254
- $results = $wpdb->get_col($query);
 
255
  return $results;
256
  }
 
257
  }
1
  <?php
2
+ if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');;
3
 
4
  if(class_exists('FrmField'))
5
  return;
6
 
7
  class FrmField{
8
+ static $use_cache = true;
9
 
10
+ public static function create( $values, $return=true ){
11
+ global $wpdb, $frm_duplicate_ids;
12
 
13
  $new_values = array();
14
  $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
17
  foreach ( array('name', 'description', 'type', 'default_value') as $col ) {
18
  $new_values[$col] = $values[$col];
19
  }
20
+
21
  $new_values['options'] = $values['options'];
22
 
23
+ $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : NULL;
24
+ $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
25
+ $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : NULL;
26
  $new_values['field_options'] = $values['field_options'];
27
  $new_values['created_at'] = current_time('mysql', 1);
28
+
29
  if(isset($values['id'])){
 
30
  $frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
31
  $new_values = apply_filters('frm_duplicated_field', $new_values);
32
  }
33
+
34
  foreach($new_values as $k => $v){
35
  if(is_array($v))
36
  $new_values[$k] = serialize($v);
37
  unset($k);
38
  unset($v);
39
  }
40
+
41
  //if(isset($values['id']) and is_numeric($values['id']))
42
  // $new_values['id'] = $values['id'];
43
+
44
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
45
  if($return){
46
  if($query_results){
47
+ self::delete_form_transient($new_values['form_id']);
48
  $new_id = $wpdb->insert_id;
49
+ if ( isset($values['id']) ) {
50
  $frm_duplicate_ids[$values['id']] = $new_id;
51
+ }
52
  return $new_id;
53
  }else{
54
  return false;
56
  }
57
  }
58
 
59
+ public static function duplicate($old_form_id, $form_id, $copy_keys=false, $blog_id=false){
60
+ global $frm_duplicate_ids;
61
+ $fields = self::getAll(array('fi.form_id' => $old_form_id), 'field_order', '', $blog_id);
62
+ foreach ( (array) $fields as $field ) {
 
63
  $new_key = ($copy_keys) ? $field->field_key : '';
64
+ if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
65
  $new_key = rtrim($new_key, 2);
66
+ }
67
+
68
+ $values = array();
69
+ FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
70
+
71
  $values = apply_filters('frm_duplicated_field', $values);
72
+ $new_id = self::create($values);
73
  $frm_duplicate_ids[$field->id] = $new_id;
74
  $frm_duplicate_ids[$field->field_key] = $new_id;
75
  unset($field);
76
  }
77
  }
78
 
79
+ public static function update( $id, $values ){
80
  global $wpdb;
81
+
82
  if (isset($values['field_key']))
83
  $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
84
 
85
  if ( isset($values['required']) ) {
86
  $values['required'] = (int) $values['required'];
87
  }
88
+
89
+ if ( isset($values['default_value']) && is_array($values['default_value']) ) {
90
  $values['default_value'] = serialize($values['default_value']);
91
+ }
92
+
93
+ if ( isset($values['field_options']) && is_array($values['field_options']) ) {
94
  $values['field_options'] = serialize($values['field_options']);
95
+ }
96
+
97
+ if ( isset($values['options']) && is_array($values['options']) ) {
98
  $values['options'] = serialize($values['options']);
99
+ }
100
+
101
  $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
102
+
103
+ $form_id = 0;
104
  if(isset($values['form_id'])){
105
  $form_id = $values['form_id'];
106
  }else{
107
+ $field = self::getOne($id);
108
+ if ( $field ) {
109
  $form_id = $field->form_id;
110
+ }
111
  unset($field);
112
  }
113
  unset($values);
114
+
115
  if($query_results){
116
  wp_cache_delete( $id, 'frm_field' );
117
+ if ( $form_id ) {
118
+ self::delete_form_transient($form_id);
119
+ }
120
  }
121
+
122
  return $query_results;
123
  }
124
 
125
+ public static function destroy( $id ){
126
  global $wpdb;
127
 
128
  do_action('frm_before_destroy_field', $id);
129
+
 
130
  wp_cache_delete( $id, 'frm_field' );
131
+ $field = self::getOne($id);
132
  if ( !$field ) {
133
  return false;
134
  }
135
+
136
+ self::delete_form_transient($field->form_id);
137
+
138
+ $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id=%d', $id));
139
+ return $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_fields WHERE id=%d', $id));
140
+ }
141
+
142
+ public static function delete_form_transient($form_id) {
143
+ delete_transient('frm_all_form_fields_'. $form_id .'exclude');
144
+ delete_transient('frm_all_form_fields_'. $form_id .'include');
145
+
146
+ $cache_key = serialize(array('fi.form_id' => (int) $form_id)) . 'field_orderlb';
147
+ wp_cache_delete($cache_key, 'frm_field');
148
+
149
+ $form = FrmForm::getOne($form_id);
150
+ if ( $form && $form->parent_form_id ) {
151
+ self::delete_form_transient( $form->parent_form_id );
152
+ }
153
  }
154
 
155
+ public static function getOne( $id ){
156
  global $wpdb;
157
+
158
+ $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
159
+ $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
160
+
161
+ $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
162
+
163
+ if ( empty($results) ) {
164
+ return $results;
 
 
165
  }
166
+
167
+ if ( is_numeric($id) ) {
168
+ wp_cache_set( $results->field_key, $results, 'frm_field' );
169
+ } else if ( $results ) {
170
+ wp_cache_set( $results->id, $results, 'frm_field' );
171
+ }
172
+
173
+ $results->field_options = maybe_unserialize($results->field_options);
174
+ if ( isset($results->field_options['format']) && ! empty($results->field_options['format']) ) {
175
+ $results->field_options['format'] = addslashes($results->field_options['format']);
176
  }
177
+ $results->options = maybe_unserialize($results->options);
178
+ $results->default_value = maybe_unserialize($results->default_value);
179
+
180
  return stripslashes_deep($results);
181
  }
182
 
183
+ public static function get_all_types_in_form($form_id, $type, $limit = '') {
184
+ if ( ! $form_id ) {
185
+ return array();
186
+ }
187
+
188
+ $results = get_transient('frm_all_form_fields_'. $form_id .'exclude');
189
+ if ( $results !== false ) {
190
+ $fields = array();
191
+ $count = 0;
192
+ foreach ( $results as $result ) {
193
+ if ( $type != $result->type ) {
194
+ continue;
195
+ }
196
+
197
+ $fields[$result->id] = $result;
198
+ $count++;
199
+ if ( $limit === 1 ) {
200
+ $fields = $result;
201
+ break;
202
+ }
203
+
204
+ if ( ! empty($limit) && $count >= $limit ) {
205
+ break;
206
+ }
207
+
208
+ unset($result);
209
+ }
210
+ return stripslashes_deep($fields);
211
+ }
212
+
213
+ self::$use_cache = false;
214
+ $results = self::getAll(array('fi.form_id' => (int) $form_id, 'fi.type' => $type), 'field_order', $limit);
215
+ self::$use_cache = true;
216
+
217
+ return $results;
218
+ }
219
+
220
+ public static function get_all_for_form($form_id, $limit = '', $inc_sub = 'exclude') {
221
+ if ( ! (int) $form_id ) {
222
+ return array();
223
+ }
224
+
225
+ $results = get_transient('frm_all_form_fields_'. $form_id . $inc_sub);
226
+ if ( $results !== false ) {
227
+ if ( empty($limit) ) {
228
+ return stripslashes_deep($results);
229
+ }
230
+
231
+ $fields = array();
232
+ $count = 0;
233
+ foreach ( $results as $result ) {
234
+ $fields[$result->id] = $result;
235
+ if ( ! empty($limit) && $count >= $limit ) {
236
+ break;
237
+ }
238
+ }
239
+
240
+ return stripslashes_deep($fields);
241
+ }
242
+
243
+ self::$use_cache = false;
244
+ $results = self::getAll(array('fi.form_id' => (int) $form_id), 'field_order', $limit);
245
+ self::$use_cache = true;
246
+
247
+ if ( 'include' == $inc_sub ) {
248
+ $form_fields = $results;
249
+ foreach ( $form_fields as $k => $field ) {
250
+ if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
251
+ continue;
252
+ }
253
+ $sub_fields = self::get_all_for_form($field->field_options['form_select']);
254
+ if ( ! empty($sub_fields) ) {
255
+ array_splice($results, $k, 1, $sub_fields);
256
+ }
257
+ unset($field, $sub_fields);
258
+ }
259
+ unset($form_fields);
260
+ }
261
+
262
+ if ( empty($limit) ) {
263
+ set_transient('frm_all_form_fields_'. $form_id . $inc_sub, $results, 60*60*6);
264
+ }
265
+
266
+ return $results;
267
+ }
268
+
269
+ public static function getAll($where=array(), $order_by = '', $limit = '', $blog_id=false){
270
+ $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
271
+ if ( self::$use_cache ) {
272
+ // make sure old cache doesn't get saved as a transient
273
+ $results = wp_cache_get($cache_key, 'frm_field');
274
+ if ( false !== $results ) {
275
+ return stripslashes_deep($results);
276
+ }
277
+ }
278
+
279
  global $wpdb;
280
+
281
+ if ( $blog_id && is_multisite() ) {
282
  global $wpmuBaseTablePrefix;
283
  if($wpmuBaseTablePrefix)
284
  $prefix = "{$wpmuBaseTablePrefix}{$blog_id}_";
285
  else
286
  $prefix = $wpdb->get_blog_prefix( $blog_id );
287
+
288
+ $table_name = "{$prefix}frm_fields";
289
  $form_table_name = "{$prefix}frm_forms";
290
  }else{
291
  $table_name = $wpdb->prefix .'frm_fields';
292
  $form_table_name = $wpdb->prefix .'frm_forms';
293
  }
294
+
295
+ if ( ! empty($order_by) && ! preg_match("/ORDER BY/", $order_by) ) {
296
  $order_by = " ORDER BY {$order_by}";
297
+ }
298
+
299
+ $limit = FrmAppHelper::esc_limit($limit);
300
 
 
 
 
301
  $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
 
 
 
 
302
 
303
+ $old_where = $where;
304
+ if ( is_array($where) ) {
305
+ $where = FrmAppHelper::get_where_clause_and_values( $where );
306
+
307
+ $query .= $where['where'] . $order_by . $limit;
308
+ $query = $wpdb->prepare($query, $where['values']);
309
+
310
+ if ( count($old_where) == 1 && isset($old_where['fi.form_id']) ) {
311
+ // add sub fields to query
312
+ $form_id = $old_where['fi.form_id'];
313
+ $query = str_replace('fi.form_id='. $form_id, '(fi.form_id='. $form_id .' OR fr.parent_form_id = '. $form_id .')', $query);
314
+ }
315
  }else{
316
  $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
317
  }
318
+
319
+ if ( $limit == ' LIMIT 1' || $limit == 1 ) {
320
  $results = $wpdb->get_row($query);
321
+ } else {
322
+ $results = $wpdb->get_results($query);
 
 
 
 
 
 
 
 
 
323
  }
324
+
325
+ if ( ! $results ) {
326
+ stripslashes_deep($results);
327
+ }
328
+
329
+ if ( is_array($results) ) {
330
+ foreach ( $results as $r_key => $result ) {
331
+ wp_cache_set($result->id, $result, 'frm_field');
332
+ wp_cache_set($result->field_key, $result, 'frm_field');
333
+
334
+ $results[$r_key]->field_options = maybe_unserialize($result->field_options);
335
+ if ( isset($results[$r_key]->field_options['format']) && !empty($results[$r_key]->field_options['format']) ) {
336
+ $results[$r_key]->field_options['format'] = addslashes($results[$r_key]->field_options['format']);
 
337
  }
338
+
339
+ $results[$r_key]->options = maybe_unserialize($result->options);
340
+ $results[$r_key]->default_value = maybe_unserialize($result->default_value);
341
+ $form_id = $result->form_id;
342
+
343
+ unset($r_key, $result);
 
 
 
 
 
344
  }
345
+
346
+ unset($form_id);
347
+ }else{
348
+ wp_cache_set($results->id, $results, 'frm_field');
349
+ wp_cache_set($results->field_key, $results, 'frm_field');
350
+
351
+ $results->field_options = maybe_unserialize($results->field_options);
352
+ if ( isset($results->field_options['format']) && !empty($results->field_options['format']) ) {
353
+ $results->field_options['format'] = addslashes($results->field_options['format']);
354
+ }
355
+
356
+ $results->options = maybe_unserialize($results->options);
357
+ $results->default_value = maybe_unserialize($results->default_value);
358
  }
359
+ wp_cache_set($cache_key, $results, 'frm_field', 300);
360
+
361
  return stripslashes_deep($results);
362
  }
363
 
364
+ public static function getIds($where = '', $order_by = '', $limit = ''){
365
  global $wpdb;
366
+ if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
 
367
  $order_by = ' ORDER BY '. $order_by;
368
  }
369
+
370
+ $query = 'SELECT fi.id FROM '. $wpdb->prefix .'frm_fields fi ' .
371
+ 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
372
  FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
373
+
374
+ $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
375
+ $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
376
+ $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
377
+
378
  return $results;
379
  }
380
+
381
  }
classes/models/FrmForm.php CHANGED
@@ -1,25 +1,29 @@
1
  <?php
2
- if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
-
4
- if(class_exists('FrmForm'))
5
- return;
6
 
7
  class FrmForm{
8
 
9
- function create( $values ) {
10
- global $wpdb, $frm_settings;
 
 
 
11
 
12
  $new_values = array(
13
  'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
14
  'name' => $values['name'],
15
  'description' => $values['description'],
16
  'status' => isset($values['status']) ? $values['status'] : 'draft',
 
17
  'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0,
 
18
  'editable' => isset($values['editable']) ? (int) $values['editable'] : 0,
19
  'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
20
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
21
  );
22
-
23
  $options = array();
24
 
25
  $defaults = FrmFormsHelper::get_default_opts();
@@ -39,27 +43,30 @@ class FrmForm{
39
  //if(isset($values['id']) && is_numeric($values['id']))
40
  // $new_values['id'] = $values['id'];
41
 
42
- $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
43
 
44
- return $wpdb->insert_id;
 
45
  }
46
-
47
- function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
 
 
 
48
  global $wpdb;
49
 
50
- $frm_form = new FrmForm();
51
- $values = $frm_form->getOne( $id, $blog_id );
52
  if ( !$values ) {
53
  return false;
54
  }
55
-
56
  $new_key = $copy_keys ? $values->form_key : '';
57
-
58
  $new_values = array(
59
  'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
60
  'name' => $values->name,
61
  'description' => $values->description,
62
- 'status' => $template ? '' : 'draft',
63
  'logged_in' => $values->logged_in ? $values->logged_in : 0,
64
  'editable' => $values->editable ? $values->editable : 0,
65
  'created_at' => current_time('mysql', 1),
@@ -81,37 +88,39 @@ class FrmForm{
81
  }
82
 
83
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
84
-
85
  if ( $query_results ) {
86
- global $frm_field;
87
  $form_id = $wpdb->insert_id;
88
- $frm_field->duplicate($id, $form_id, $copy_keys, $blog_id);
89
-
90
  // update form settings after fields are created
91
- do_action('frm_after_duplicate_form', $form_id, $new_values);
92
  return $form_id;
93
- } else {
94
- return false;
95
  }
 
 
96
  }
97
-
98
- function after_duplicate($form_id, $values) {
99
  $new_opts = $values['options'] = maybe_unserialize($values['options']);
100
-
101
  if ( isset($new_opts['success_msg']) ) {
102
  $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
103
  }
104
-
105
  $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
106
-
107
  if ( $new_opts != $values['options'] ) {
108
  global $wpdb;
109
  $wpdb->update($wpdb->prefix .'frm_forms', array('options' => maybe_serialize($new_opts)), array('id' => $form_id));
110
  }
111
  }
112
 
113
- function update( $id, $values, $create_link = false ) {
114
- global $wpdb, $frm_field, $frm_settings;
 
 
 
115
 
116
  if ( $create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']) ) {
117
  $values['status'] = 'published';
@@ -121,30 +130,9 @@ class FrmForm{
121
  $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
122
  }
123
 
124
- $form_fields = array( 'form_key', 'name', 'description', 'status', 'prli_link_id' );
125
-
126
- $new_values = array();
127
 
128
- if (isset($values['options'])){
129
- $options = array();
130
-
131
- $defaults = FrmFormsHelper::get_default_opts();
132
- foreach ($defaults as $var => $default) {
133
- if ( $var == 'notification' && !defined('WP_IMPORTING')) {
134
- $options[$var] = isset($values[$var]) ? $values[$var] : $default;
135
- } else {
136
- $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default;
137
- }
138
- }
139
-
140
- $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
141
- $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
142
- $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
143
- $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
144
-
145
- $options = apply_filters('frm_form_options_before_update', $options, $values);
146
- $new_values['options'] = serialize($options);
147
- }
148
 
149
  foreach ( $values as $value_key => $value ) {
150
  if ( in_array($value_key, $form_fields) ) {
@@ -152,6 +140,10 @@ class FrmForm{
152
  }
153
  }
154
 
 
 
 
 
155
  if ( !empty($new_values) ) {
156
  $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
157
  if ( $query_results ) {
@@ -160,120 +152,282 @@ class FrmForm{
160
  } else {
161
  $query_results = true;
162
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
- $all_fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
165
- if ( $all_fields && (isset($values['options']) || isset($values['item_meta']) || isset($values['field_options'])) ) {
166
- if ( !isset($values['item_meta']) ) {
167
- $values['item_meta'] = array();
 
168
  }
169
- $existing_keys = array_keys($values['item_meta']);
 
 
170
 
171
- foreach ( $all_fields as $fid ) {
172
- if ( !in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
173
- $values['item_meta'][$fid->id] = '';
174
- }
 
 
 
 
 
175
  }
176
-
177
- foreach ( $values['item_meta'] as $field_id => $default_value ) {
178
- $field = $frm_field->getOne($field_id);
179
- if (!$field) continue;
180
- $field_options = maybe_unserialize($field->field_options);
181
-
182
- if ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) {
183
- //updating the settings page
184
- if(isset($values['field_options']['custom_html_'.$field_id])){
185
- $field_options['custom_html'] = isset($values['field_options']['custom_html_'.$field_id]) ? $values['field_options']['custom_html_'.$field_id] : (isset($field_options['custom_html']) ? $field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type));
186
- $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values);
187
- $frm_field->update($field_id, array('field_options' => $field_options));
188
- }else if($field->type == 'hidden' || $field->type == 'user_id'){
189
- $prev_opts = $field_options;
190
- $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values);
191
- if($prev_opts != $field_options)
192
- $frm_field->update($field_id, array('field_options' => $field_options));
193
- unset($prev_opts);
194
  }
 
195
  }
196
-
197
- if ( (!isset($values['options']) && !isset($values['field_options']['custom_html_'. $field_id])) || defined('WP_IMPORTING') ) {
198
- //updating the form
199
- foreach ( array('size', 'max', 'label', 'invalid', 'blank', 'classes') as $opt ) {
200
- $field_options[$opt] = isset($values['field_options'][$opt.'_'.$field_id]) ? trim($values['field_options'][$opt.'_'.$field_id]) : '';
201
- }
202
 
203
- $field_options['required_indicator'] = isset($values['field_options']['required_indicator_'. $field_id]) ? trim($values['field_options']['required_indicator_'. $field_id]) : '*';
204
- $field_options['separate_value'] = isset($values['field_options']['separate_value_'.$field_id]) ? trim($values['field_options']['separate_value_'.$field_id]) : 0;
 
205
 
206
- $field_options = apply_filters('frm_update_field_options', $field_options, $field, $values);
207
- $default_value = maybe_serialize($values['item_meta'][$field_id]);
208
- $field_key = (isset($values['field_options']['field_key_'.$field_id])) ? $values['field_options']['field_key_'.$field_id] : $field->field_key;
209
- $required = (isset($values['field_options']['required_'.$field_id])) ? $values['field_options']['required_'.$field_id] : false;
210
- $field_type = (isset($values['field_options']['type_'.$field_id])) ? $values['field_options']['type_'.$field_id] : $field->type;
211
- $field_description = (isset($values['field_options']['description_'.$field_id])) ? $values['field_options']['description_'.$field_id] : $field->description;
212
 
213
- $frm_field->update($field_id, array('field_key' => $field_key, 'type' => $field_type, 'default_value' => $default_value, 'field_options' => $field_options, 'description' => $field_description, 'required' => $required));
214
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  }
216
  }
217
-
218
- do_action('frm_update_form', $id, $values);
219
- do_action('frm_update_form_'. $id, $values);
220
 
221
  return $query_results;
222
  }
223
 
224
- function destroy( $id ){
225
- global $wpdb, $frm_entry;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
- $form = $this->getOne($id);
228
  if ( !$form || $form->default_template ) {
229
  return false;
230
  }
231
 
232
- // Disconnect the items from this form
233
- $entries = $frm_entry->getAll(array('it.form_id' => $id));
234
- foreach ( $entries as $item ) {
235
- $frm_entry->destroy($item->id);
236
- unset($item);
237
  }
 
238
  // Disconnect the fields from this form
239
- $query_results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_fields WHERE form_id=%d", $id));
240
 
241
- $query_results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_forms WHERE id=%d", $id));
242
  if ( $query_results ) {
 
 
 
 
243
  do_action('frm_destroy_form', $id);
244
  do_action('frm_destroy_form_'. $id);
245
  }
 
246
  return $query_results;
247
  }
248
-
249
- function getName( $id ) {
 
 
 
250
  global $wpdb;
251
- $cache = wp_cache_get($id, 'frm_form');
252
- if ( $cache ) {
253
- return stripslashes($cache->name);
 
 
254
  }
255
- $query = "SELECT name FROM {$wpdb->prefix}frm_forms WHERE ";
256
- $query .= (is_numeric($id)) ? "id=%d" : "form_key=%s";
 
257
  $query = $wpdb->prepare($query, $id);
258
-
259
- $r = $wpdb->get_var($query);
260
- return stripslashes($r);
 
 
261
  }
262
-
263
- function getIdByKey( $key ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  global $wpdb;
265
- $query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_forms WHERE form_key=%s LIMIT 1", $key);
266
- return $wpdb->get_var($query);
 
 
267
  }
268
 
269
- function getOne( $id, $blog_id=false ){
270
- global $wpdb, $frmdb;
271
-
 
 
 
272
  if ( $blog_id && is_multisite() ) {
273
  global $wpmuBaseTablePrefix;
274
- $prefix = $wpmuBaseTablePrefix ? "{$wpmuBaseTablePrefix}{$blog_id}_" : $wpdb->get_blog_prefix( $blog_id );
275
-
276
- $table_name = "{$prefix}frm_forms";
277
  } else {
278
  $table_name = $wpdb->prefix .'frm_forms';
279
  $cache = wp_cache_get($id, 'frm_form');
@@ -281,15 +435,15 @@ class FrmForm{
281
  if ( isset($cache->options) ) {
282
  $cache->options = maybe_unserialize($cache->options);
283
  }
284
-
285
  return stripslashes_deep($cache);
286
  }
287
  }
288
-
289
  $where = $wpdb->prepare( is_numeric($id) ? 'id=%d' : 'form_key=%s', $id );
290
-
291
- $results = $wpdb->get_row("SELECT * FROM $table_name WHERE $where");
292
-
293
  if ( isset($results->options) ) {
294
  wp_cache_set($results->id, $results, 'frm_form');
295
  $results->options = maybe_unserialize($results->options);
@@ -297,20 +451,26 @@ class FrmForm{
297
  return stripslashes_deep($results);
298
  }
299
 
300
- function getAll( $where = array(), $order_by = '', $limit = '' ){
301
- global $wpdb, $frmdb;
302
-
303
- if(is_numeric($limit))
304
- $limit = " LIMIT {$limit}";
305
-
306
- $query = 'SELECT * FROM ' . $wpdb->prefix .'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
307
-
 
 
 
 
 
308
  if ($limit == ' LIMIT 1' || $limit == 1){
309
- if(is_array($where))
310
  $results = $frmdb->get_one_record($wpdb->prefix .'frm_forms', $where, '*', $order_by);
311
- else
312
  $results = $wpdb->get_row($query);
313
-
 
314
  if($results){
315
  wp_cache_set($results->id, $results, 'frm_form');
316
  $results->options = maybe_unserialize($results->options);
@@ -321,7 +481,7 @@ class FrmForm{
321
  } else {
322
  $results = $wpdb->get_results($query);
323
  }
324
-
325
  if($results){
326
  foreach($results as $result){
327
  wp_cache_set($result->id, $result, 'frm_form');
@@ -329,20 +489,66 @@ class FrmForm{
329
  }
330
  }
331
  }
332
-
333
  return stripslashes_deep($results);
334
  }
335
 
336
- function validate( $values ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  $errors = array();
338
 
339
  /*if( $values['form_key'] == null || $values['form_key'] == '' ){
340
  if( $values['name'] == null || $values['name'] == '' )
341
  $errors[] = "Key can't be blank";
342
- else
343
  $_POST['form_key'] = $values['name'];
344
  }*/
345
-
346
  return apply_filters('frm_validate_form', $errors, $values);
347
  }
348
 
1
  <?php
2
+ if ( ! defined('ABSPATH') ) {
3
+ die('You are not allowed to call this page directly.');
4
+ }
 
5
 
6
  class FrmForm{
7
 
8
+ /*
9
+ * @return int|boolean id on success or false on failure
10
+ */
11
+ public static function create( $values ) {
12
+ global $wpdb;
13
 
14
  $new_values = array(
15
  'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
16
  'name' => $values['name'],
17
  'description' => $values['description'],
18
  'status' => isset($values['status']) ? $values['status'] : 'draft',
19
+ 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
  'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21
+ 'parent_form_id'=> isset($values['parent_form_id']) ? (int) $values['parent_form_id'] : 0,
22
  'editable' => isset($values['editable']) ? (int) $values['editable'] : 0,
23
  'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
  'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
  );
26
+
27
  $options = array();
28
 
29
  $defaults = FrmFormsHelper::get_default_opts();
43
  //if(isset($values['id']) && is_numeric($values['id']))
44
  // $new_values['id'] = $values['id'];
45
 
46
+ $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
47
 
48
+ $id = $wpdb->insert_id;
49
+ return $id;
50
  }
51
+
52
+ /*
53
+ * @return int|boolean ID on success or false on failure
54
+ */
55
+ public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
56
  global $wpdb;
57
 
58
+ $values = self::getOne( $id, $blog_id );
 
59
  if ( !$values ) {
60
  return false;
61
  }
62
+
63
  $new_key = $copy_keys ? $values->form_key : '';
64
+
65
  $new_values = array(
66
  'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
67
  'name' => $values->name,
68
  'description' => $values->description,
69
+ 'status' => $template ? 'published' : 'draft',
70
  'logged_in' => $values->logged_in ? $values->logged_in : 0,
71
  'editable' => $values->editable ? $values->editable : 0,
72
  'created_at' => current_time('mysql', 1),
88
  }
89
 
90
  $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
91
+
92
  if ( $query_results ) {
 
93
  $form_id = $wpdb->insert_id;
94
+ FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
95
+
96
  // update form settings after fields are created
97
+ do_action('frm_after_duplicate_form', $form_id, $new_values, array('old_id' => $id));
98
  return $form_id;
 
 
99
  }
100
+
101
+ return false;
102
  }
103
+
104
+ public static function after_duplicate($form_id, $values) {
105
  $new_opts = $values['options'] = maybe_unserialize($values['options']);
106
+
107
  if ( isset($new_opts['success_msg']) ) {
108
  $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
109
  }
110
+
111
  $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
112
+
113
  if ( $new_opts != $values['options'] ) {
114
  global $wpdb;
115
  $wpdb->update($wpdb->prefix .'frm_forms', array('options' => maybe_serialize($new_opts)), array('id' => $form_id));
116
  }
117
  }
118
 
119
+ /*
120
+ * @return int|boolean
121
+ */
122
+ public static function update( $id, $values, $create_link = false ) {
123
+ global $wpdb;
124
 
125
  if ( $create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']) ) {
126
  $values['status'] = 'published';
130
  $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
131
  }
132
 
133
+ $form_fields = array( 'form_key', 'name', 'description', 'status' );
 
 
134
 
135
+ $new_values = self::set_update_options(array(), $values);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
  foreach ( $values as $value_key => $value ) {
138
  if ( in_array($value_key, $form_fields) ) {
140
  }
141
  }
142
 
143
+ if ( isset($values['new_status']) && !empty($values['new_status']) ) {
144
+ $new_values['status'] = $values['new_status'];
145
+ }
146
+
147
  if ( !empty($new_values) ) {
148
  $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
149
  if ( $query_results ) {
152
  } else {
153
  $query_results = true;
154
  }
155
+ unset($new_values);
156
+
157
+ $values = self::update_fields($id, $values);
158
+
159
+ do_action('frm_update_form', $id, $values);
160
+ do_action('frm_update_form_'. $id, $values);
161
+
162
+ return $query_results;
163
+ }
164
+
165
+ /*
166
+ * @return array
167
+ */
168
+ public static function set_update_options($new_values, $values) {
169
+ if ( ! isset($values['options']) ) {
170
+ return $new_values;
171
+ }
172
+
173
+ $options = array();
174
+
175
+ $defaults = FrmFormsHelper::get_default_opts();
176
+ foreach ($defaults as $var => $default) {
177
+ $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default;
178
+ }
179
+
180
+ $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
181
+ $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
182
+ $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
183
+ $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
184
+
185
+ $options = apply_filters('frm_form_options_before_update', $options, $values);
186
+ $new_values['options'] = serialize($options);
187
+
188
+ return $new_values;
189
+ }
190
+
191
+
192
+ /*
193
+ * @return array
194
+ */
195
+ public static function update_fields($id, $values) {
196
+
197
+ if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
198
+ return $values;
199
+ }
200
+
201
+ $all_fields = FrmField::get_all_for_form($id);
202
+ if ( empty($all_fields) ) {
203
+ return $values;
204
+ }
205
+
206
+ if ( ! isset($values['item_meta']) ) {
207
+ $values['item_meta'] = array();
208
+ }
209
 
210
+ $field_array = array();
211
+ $existing_keys = array_keys($values['item_meta']);
212
+ foreach ( $all_fields as $fid ) {
213
+ if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
214
+ $values['item_meta'][$fid->id] = '';
215
  }
216
+ $field_array[$fid->id] = $fid;
217
+ }
218
+ unset($all_fields);
219
 
220
+ foreach ( $values['item_meta'] as $field_id => $default_value ) {
221
+ if ( isset($field_array[$field_id]) ) {
222
+ $field = $field_array[$field_id];
223
+ } else {
224
+ $field = FrmField::getOne($field_id);
225
+ }
226
+
227
+ if ( ! $field ) {
228
+ continue;
229
  }
230
+
231
+ if ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) {
232
+ //updating the settings page
233
+ if ( isset($values['field_options']['custom_html_'. $field_id]) ) {
234
+ $field->field_options['custom_html'] = isset($values['field_options']['custom_html_'.$field_id]) ? $values['field_options']['custom_html_'.$field_id] : ( isset($field->field_options['custom_html']) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type));
235
+ $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
236
+ FrmField::update($field_id, array('field_options' => $field->field_options));
237
+ } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
238
+ $prev_opts = $field->field_options;
239
+ $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
240
+ if ( $prev_opts != $field->field_options ) {
241
+ FrmField::update($field_id, array('field_options' => $field->field_options));
 
 
 
 
 
 
242
  }
243
+ unset($prev_opts);
244
  }
245
+ }
 
 
 
 
 
246
 
247
+ if ( ( isset($values['options']) || isset($values['field_options']['custom_html_'. $field_id]) ) && ! defined('WP_IMPORTING') ) {
248
+ continue;
249
+ }
250
 
251
+ //updating the form
252
+ foreach ( array('size', 'max', 'label', 'invalid', 'blank', 'classes') as $opt ) {
253
+ $field->field_options[$opt] = isset($values['field_options'][$opt .'_'. $field_id]) ? trim($values['field_options'][$opt .'_'. $field_id]) : '';
254
+ }
 
 
255
 
256
+ $field->field_options['required_indicator'] = isset($values['field_options']['required_indicator_'. $field_id]) ? trim($values['field_options']['required_indicator_'. $field_id]) : '*';
257
+ $field->field_options['separate_value'] = isset($values['field_options']['separate_value_'. $field_id]) ? trim($values['field_options']['separate_value_'. $field_id]) : 0;
258
+
259
+ $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260
+ $default_value = maybe_serialize($values['item_meta'][$field_id]);
261
+ $field_key = isset($values['field_options']['field_key_'. $field_id]) ? $values['field_options']['field_key_'. $field_id] : $field->field_key;
262
+ $required = isset($values['field_options']['required_'. $field_id]) ? $values['field_options']['required_'. $field_id] : false;
263
+ $field_type = isset($values['field_options']['type_'. $field_id]) ? $values['field_options']['type_'. $field_id] : $field->type;
264
+ $field_description = isset($values['field_options']['description_'. $field_id]) ? $values['field_options']['description_'. $field_id] : $field->description;
265
+
266
+ FrmField::update($field_id, array(
267
+ 'field_key' => $field_key, 'type' => $field_type,
268
+ 'default_value' => $default_value, 'field_options' => $field->field_options,
269
+ 'description' => $field_description, 'required' => $required,
270
+ ) );
271
+
272
+ FrmField::delete_form_transient($field->form_id);
273
+ }
274
+
275
+ return $values;
276
+ }
277
+
278
+ /*
279
+ * @return int|boolean
280
+ */
281
+ public static function set_status($id, $status) {
282
+ if ( 'trash' == $status ) {
283
+ return self::trash($id);
284
+ }
285
+
286
+ $statuses = array('published', 'draft', 'trash');
287
+ if ( !in_array($status, $statuses) ) {
288
+ return false;
289
+ }
290
+
291
+ global $wpdb;
292
+
293
+ if ( is_array($id) ) {
294
+ $query_results = $wpdb->query( 'UPDATE '. $wpdb->prefix .'frm_forms SET status = "'. $status .'" WHERE id in ('. implode(',', $id) .')');
295
+ } else {
296
+ $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', array('status' => $status), array('id' => $id));
297
+ }
298
+
299
+ if ( $query_results ) {
300
+ foreach ( (array) $id as $i ) {
301
+ wp_cache_delete( $i, 'frm_form');
302
  }
303
  }
 
 
 
304
 
305
  return $query_results;
306
  }
307
 
308
+ /*
309
+ * @return int|boolean
310
+ */
311
+ public static function trash($id) {
312
+ if ( !EMPTY_TRASH_DAYS ) {
313
+ return self::destroy( $id );
314
+ }
315
+
316
+ $form = self::getOne($id);
317
+ if ( !$form ) {
318
+ return false;
319
+ }
320
+
321
+ $options = $form->options;
322
+ $options['trash_time'] = time();
323
+
324
+ global $wpdb;
325
+ $query_results = $wpdb->update(
326
+ $wpdb->prefix .'frm_forms',
327
+ array('status' => 'trash', 'options' => serialize($options)),
328
+ array('id' => $id)
329
+ );
330
+
331
+ if ( $query_results ) {
332
+ wp_cache_delete( $id, 'frm_form');
333
+ }
334
+
335
+ return $query_results;
336
+ }
337
+
338
+ /*
339
+ * @return int|boolean
340
+ */
341
+ public static function destroy( $id ){
342
+ global $wpdb;
343
 
344
+ $form = self::getOne($id);
345
  if ( !$form || $form->default_template ) {
346
  return false;
347
  }
348
 
349
+ // Disconnect the entries from this form
350
+ $entries = $wpdb->get_col($wpdb->prepare('SELECT id FROM '. $wpdb->prefix .'frm_items WHERE form_id=%d', $id));
351
+ foreach ( $entries as $entry_id ) {
352
+ FrmEntry::destroy($entry_id);
353
+ unset($entry_id);
354
  }
355
+
356
  // Disconnect the fields from this form
357
+ $wpdb->query($wpdb->prepare('DELETE fi FROM '. $wpdb->prefix .'frm_fields AS fi LEFT JOIN '. $wpdb->prefix .'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id));
358
 
359
+ $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
360
  if ( $query_results ) {
361
+ // Delete all form actions linked to this form
362
+ $action_control = FrmFormActionsController::get_form_actions( 'email' );
363
+ $action_control->destroy($id, 'all');
364
+
365
  do_action('frm_destroy_form', $id);
366
  do_action('frm_destroy_form_'. $id);
367
  }
368
+
369
  return $query_results;
370
  }
371
+
372
+ /*
373
+ * @return string form name
374
+ */
375
+ public static function &getName( $id ) {
376
  global $wpdb;
377
+
378
+ $form = FrmAppHelper::check_cache($id, 'frm_form');
379
+ if ( $form ) {
380
+ $r = stripslashes($form->name);
381
+ return $r;
382
  }
383
+
384
+ $query = 'SELECT name FROM '. $wpdb->prefix .'frm_forms WHERE ';
385
+ $query .= is_numeric($id) ? 'id=%d' : 'form_key=%s';
386
  $query = $wpdb->prepare($query, $id);
387
+
388
+ $r = FrmAppHelper::check_cache($id .'_name', 'frm_form', $query, 'get_var');
389
+ $r = stripslashes($r);
390
+
391
+ return $r;
392
  }
393
+
394
+ /*
395
+ * @return int form id
396
+ */
397
+ public static function &getIdByKey( $key ){
398
+ global $wpdb;
399
+ $query = $wpdb->prepare('SELECT id FROM '. $wpdb->prefix .'frm_forms WHERE form_key=%s LIMIT 1', $key);
400
+ $id = FrmAppHelper::check_cache('form_id_'. $key, 'frm_form', $query, 'get_var');
401
+ return $id;
402
+ }
403
+
404
+ /*
405
+ * @return string form key
406
+ */
407
+ public static function &getKeyById($id){
408
+ $cache = FrmAppHelper::check_cache($id, 'frm_form');
409
+ if ( $cache ) {
410
+ return $cache->form_key;
411
+ }
412
+
413
  global $wpdb;
414
+ $query = $wpdb->prepare('SELECT form_key FROM '. $wpdb->prefix .'frm_forms WHERE id=%d', $id);
415
+ $key = FrmAppHelper::check_cache($id .'_key', 'frm_form', $query, 'get_var');
416
+
417
+ return $key;
418
  }
419
 
420
+ /*
421
+ * @return object form
422
+ */
423
+ public static function getOne( $id, $blog_id=false ){
424
+ global $wpdb;
425
+
426
  if ( $blog_id && is_multisite() ) {
427
  global $wpmuBaseTablePrefix;
428
+ $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
429
+
430
+ $table_name = $prefix .'frm_forms';
431
  } else {
432
  $table_name = $wpdb->prefix .'frm_forms';
433
  $cache = wp_cache_get($id, 'frm_form');
435
  if ( isset($cache->options) ) {
436
  $cache->options = maybe_unserialize($cache->options);
437
  }
438
+
439
  return stripslashes_deep($cache);
440
  }
441
  }
442
+
443
  $where = $wpdb->prepare( is_numeric($id) ? 'id=%d' : 'form_key=%s', $id );
444
+
445
+ $results = $wpdb->get_row('SELECT * FROM '. $table_name .' WHERE '. $where);
446
+
447
  if ( isset($results->options) ) {
448
  wp_cache_set($results->id, $results, 'frm_form');
449
  $results->options = maybe_unserialize($results->options);
451
  return stripslashes_deep($results);
452
  }
453
 
454
+ /*
455
+ * @return array of objects
456
+ */
457
+ public static function getAll( $where = array(), $order_by = '', $limit = '' ){
458
+ global $wpdb;
459
+
460
+ if ( is_numeric($limit) ) {
461
+ $limit = ' LIMIT '. $limit;
462
+ }
463
+
464
+ $query = 'SELECT * FROM ' . $wpdb->prefix .'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . FrmAppHelper::esc_order($order_by) . FrmAppHelper::esc_limit($limit);
465
+
466
+ $frmdb = new FrmDb();
467
  if ($limit == ' LIMIT 1' || $limit == 1){
468
+ if ( is_array($where) && ! empty($where) ) {
469
  $results = $frmdb->get_one_record($wpdb->prefix .'frm_forms', $where, '*', $order_by);
470
+ } else {
471
  $results = $wpdb->get_row($query);
472
+ }
473
+
474
  if($results){
475
  wp_cache_set($results->id, $results, 'frm_form');
476
  $results->options = maybe_unserialize($results->options);
481
  } else {
482
  $results = $wpdb->get_results($query);
483
  }
484
+
485
  if($results){
486
  foreach($results as $result){
487
  wp_cache_set($result->id, $result, 'frm_form');
489
  }
490
  }
491
  }
492
+
493
  return stripslashes_deep($results);
494
  }
495
 
496
+ /*
497
+ * @return int count of forms
498
+ */
499
+ public static function &get_count( ) {
500
+ global $wpdb;
501
+
502
+ $cache_key = 'frm_form_counts';
503
+
504
+ $counts = wp_cache_get( $cache_key, 'counts' );
505
+ if ( false !== $counts ) {
506
+ return $counts;
507
+ }
508
+
509
+ $query = 'SELECT status, is_template FROM '. $wpdb->prefix .'frm_forms WHERE parent_form_id IS NULL OR parent_form_id < 1';
510
+
511
+ $results = (array) $wpdb->get_results( $query );
512
+ $statuses = array('published', 'draft', 'template', 'trash');
513
+ $counts = array_fill_keys( $statuses, 0 );
514
+
515
+ foreach ( $results as $row ) {
516
+ if ( 'trash' != $row->status ) {
517
+ if ( $row->is_template ) {
518
+ $counts[ 'template' ] ++;
519
+ } else {
520
+ $counts[ 'published' ] ++;
521
+ }
522
+ } else {
523
+ $counts[ 'trash' ] ++;
524
+ }
525
+
526
+ if ( 'draft' == $row->status ) {
527
+ $counts[ 'draft' ] ++;
528
+ }
529
+
530
+ unset($row);
531
+ }
532
+
533
+ $counts = (object) $counts;
534
+ wp_cache_set( $cache_key, $counts, 'counts' );
535
+
536
+ return $counts;
537
+ }
538
+
539
+ /*
540
+ * @return array of errors
541
+ */
542
+ public static function validate( $values ){
543
  $errors = array();
544
 
545
  /*if( $values['form_key'] == null || $values['form_key'] == '' ){
546
  if( $values['name'] == null || $values['name'] == '' )
547
  $errors[] = "Key can't be blank";
548
+ else
549
  $_POST['form_key'] = $values['name'];
550
  }*/
551
+
552
  return apply_filters('frm_validate_form', $errors, $values);
553
  }
554
 
classes/models/FrmFormAction.php ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmFormAction {
4
+
5
+ public $id_base; // Root id for all actions of this type.
6
+ public $name; // Name for this action type.
7
+ public $option_name;
8
+ public $action_options; // Option array passed to wp_register_sidebar_widget()
9
+ public $control_options; // Option array passed to wp_register_widget_control()
10
+
11
+ public $form_id; // The ID of the form to evaluate
12
+ public $number = false; // Unique ID number of the current instance.
13
+ public $id = false; // Unique ID string of the current instance (id_base-number)
14
+ public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
15
+
16
+ // Member functions that you must over-ride.
17
+
18
+ /** Update a particular instance.
19
+ *
20
+ * This function should check that $new_instance is set correctly.
21
+ * The newly calculated value of $instance should be returned.
22
+ * If "false" is returned, the instance won't be saved/updated.
23
+ *
24
+ * @param array $new_instance New settings for this instance as input by the user via form()
25
+ * @param array $old_instance Old settings for this instance
26
+ * @return array Settings to save or bool false to cancel saving
27
+ */
28
+ public function update($new_instance, $old_instance) {
29
+ return $new_instance;
30
+ }
31
+
32
+ /** Echo the settings update form
33
+ *
34
+ * @param array $instance Current settings
35
+ */
36
+ public function form($instance, $args = array()) {
37
+ echo '<p class="no-options-widget">' . __('There are no options for this action.', 'formidable') . '</p>';
38
+ return 'noform';
39
+ }
40
+
41
+ /*
42
+ * Return an array of the default options
43
+ */
44
+ public function get_defaults() {
45
+ return array();
46
+ }
47
+
48
+ public function get_switch_fields() {
49
+ return array();
50
+ }
51
+
52
+ public function migrate_values($action, $form) {
53
+ return $action;
54
+ }
55
+
56
+ // Functions you'll need to call.
57
+
58
+ /**
59
+ * PHP5 constructor
60
+ *
61
+ * @param string $id_base Optional Base ID for the widget, lower case,
62
+ * if left empty a portion of the widget's class name will be used. Has to be unique.
63
+ * @param string $name Name for the widget displayed on the configuration page.
64
+ * @param array $action_options Optional Passed to wp_register_sidebar_widget()
65
+ * - description: shown on the configuration page
66
+ * - classname
67
+ * @param array $control_options Optional Passed to wp_register_widget_control()
68
+ * - width: required if more than 250px
69
+ * - height: currently not used but may be needed in the future
70
+ */
71
+ public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
+ if ( ! defined('ABSPATH') ) {
73
+ die('You are not allowed to call this page directly.');
74
+ }
75
+
76
+ $this->id_base = strtolower($id_base);
77
+ $this->name = $name;
78
+ $this->option_name = 'frm_' . $this->id_base .'_action';
79
+
80
+ $default_options = array(
81
+ 'classes' => '',
82
+ 'active' => true,
83
+ 'event' => array('create'),
84
+ 'limit' => 1,
85
+ 'force_event' => false,
86
+ 'priority' => 20,
87
+ 'ajax_load' => true,
88
+ 'tooltip' => $name,
89
+ );
90
+
91
+ $this->action_options = wp_parse_args( $action_options, $default_options );
92
+ $this->control_options = wp_parse_args( $control_options, array('id_base' => $this->id_base) );
93
+ }
94
+
95
+ public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
96
+ FrmFormAction::__construct( $id_base, $name, $action_options, $control_options );
97
+ }
98
+
99
+ /**
100
+ * Constructs name attributes for use in form() fields
101
+ *
102
+ * This function should be used in form() methods to create name attributes for fields to be saved by update()
103
+ *
104
+ * @param string $field_name Field name
105
+ * @return string Name attribute for $field_name
106
+ */
107
+ public function get_field_name($field_name, $post_field = 'post_content') {
108
+ return $this->option_name . '[' . $this->number . ']'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
109
+ }
110
+
111
+ /**
112
+ * Constructs id attributes for use in form() fields
113
+ *
114
+ * This function should be used in form() methods to create id attributes for fields to be saved by update()
115
+ *
116
+ * @param string $field_name Field name
117
+ * @return string ID attribute for $field_name
118
+ */
119
+ public function get_field_id($field_name) {
120
+ return $field_name .'_'. $this->number;
121
+ }
122
+
123
+ // Private Function. Don't worry about this.
124
+
125
+ public function _set($number) {
126
+ $this->number = $number;
127
+ $this->id = $this->id_base . '-' . $number;
128
+ }
129
+
130
+ public function prepare_new($form_id = false) {
131
+ if ( $form_id ) {
132
+ $this->form_id = $form_id;
133
+ }
134
+
135
+ $post_content = array();
136
+ $default_values = $this->get_global_defaults();
137
+
138
+ // fill default values
139
+ $post_content = wp_parse_args( $post_content, $default_values);
140
+
141
+ if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
142
+ $post_content['event'] = array( reset($this->action_options['event']) );
143
+ }
144
+
145
+ $form_action = array(
146
+ 'post_title' => $this->name,
147
+ 'post_content' => $post_content,
148
+ 'post_excerpt' => $this->id_base,
149
+ 'ID' => '',
150
+ 'post_status' => 'publish',
151
+ 'post_type' => FrmFormActionsController::$action_post_type,
152
+ 'post_name' => $this->form_id .'_'. $this->id_base .'_'. $this->number,
153
+ 'menu_order' => $this->form_id,
154
+ );
155
+ unset($post_content);
156
+
157
+ return (object) $form_action;
158
+ }
159
+
160
+ public function create($form_id) {
161
+ $this->form_id = $form_id;
162
+
163
+ $action = $this->prepare_new();
164
+
165
+ return $this->save_settings($action);
166
+ }
167
+
168
+ public function duplicate_form_actions($form_id, $old_id) {
169
+ if ( $form_id == $old_id ) {
170
+ // don't duplicate the actions if this is a template getting updated
171
+ return;
172
+ }
173
+
174
+ $this->form_id = $old_id;
175
+ $actions = $this->get_all();
176
+
177
+ $this->form_id = $form_id;
178
+ foreach ( $actions as $action ) {
179
+ $this->duplicate_one($action, $form_id);
180
+ unset($action);
181
+ }
182
+ }
183
+
184
+ /* Check if imported action should be created or updated
185
+ *
186
+ * Since 2.0
187
+ *
188
+ * @param $action array
189
+ * @return $post_id integer
190
+ */
191
+ public function maybe_create_action( $action, $forms ) {
192
+ if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) {
193
+ // Update action only
194
+ $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
195
+ $post_id = $this->save_settings( $action );
196
+ } else {
197
+ // Create action
198
+ $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
199
+ $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
200
+ }
201
+ return $post_id;
202
+ }
203
+
204
+ public function duplicate_one($action, $form_id) {
205
+ global $frm_duplicate_ids;
206
+
207
+ $action->menu_order = $form_id;
208
+ $switch = $this->get_global_switch_fields();
209
+ foreach ( $action->post_content as $key => $val ) {
210
+ if ( is_numeric($val) && isset($frm_duplicate_ids[$val]) ) {
211
+ $action->post_content[$key] = $frm_duplicate_ids[$val];
212
+ } else if ( !is_array($val) ) {
213
+ $action->post_content[$key] = FrmFieldsHelper::switch_field_ids($val);
214
+ } else if ( isset($switch[$key]) && is_array($switch[$key]) ) {
215
+ // loop through each value if empty
216
+ if ( empty($switch[$key]) ) {
217
+ $switch[$key] = array_keys($val);
218
+ }
219
+
220
+ foreach ( $switch[$key] as $subkey ) {
221
+ $action->post_content[$key] = $this->duplicate_array_walk($action->post_content[$key], $subkey, $val);
222
+ }
223
+ }
224
+
225
+ unset($key, $val);
226
+ }
227
+ unset($action->ID);
228
+
229
+ return $this->save_settings($action);
230
+ }
231
+
232
+ private function duplicate_array_walk($action, $subkey, $val) {
233
+ global $frm_duplicate_ids;
234
+
235
+ if ( is_array($subkey) ) {
236
+ foreach ( $subkey as $subkey2 ) {
237
+ foreach ( (array) $val as $ck => $cv ) {
238
+ if ( is_array($cv) ) {
239
+ $action[$ck] = $this->duplicate_array_walk($action[$ck], $subkey2, $cv);
240
+ } else if ( isset($cv[$subkey]) && is_numeric($cv[$subkey]) && isset($frm_duplicate_ids[$cv[$subkey]]) ) {
241
+ $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]];
242
+ }
243
+ }
244
+ }
245
+ } else {
246
+ foreach ( (array) $val as $ck => $cv ) {
247
+ if ( is_array($cv) ) {
248
+ $action[$ck] = $this->duplicate_array_walk($action[$ck], $subkey, $cv);
249
+ } else if ( $ck == $subkey && isset($frm_duplicate_ids[$cv]) ) {
250
+ $action[$ck] = $frm_duplicate_ids[$cv];
251
+ }
252
+ }
253
+ }
254
+
255
+ return $action;
256
+ }
257
+
258
+ /**
259
+ * Deal with changed settings.
260
+ *
261
+ * Do NOT over-ride this function
262
+ *
263
+ */
264
+ public function update_callback( $form_id ) {
265
+ $this->form_id = $form_id;
266
+
267
+ $all_instances = $this->get_settings();
268
+
269
+ // We need to update the data
270
+ if ( $this->updated ) {
271
+ return;
272
+ }
273
+
274
+ if ( isset($_POST[$this->option_name]) && is_array($_POST[$this->option_name]) ) {
275
+ $settings = $_POST[$this->option_name];
276
+ } else {
277
+ return;
278
+ }
279
+
280
+ $action_ids = array();
281
+
282
+ foreach ( $settings as $number => $new_instance ) {
283
+ $this->_set($number);
284
+
285
+ if ( ! isset($new_instance['post_title']) ) {
286
+ // settings were never opened, so don't update
287
+ $action_ids[] = $new_instance['ID'];
288
+ $this->updated = true;
289
+ continue;
290
+ }
291
+
292
+ $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
293
+
294
+ $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
295
+ $new_instance['post_name'] = $this->form_id .'_'. $this->id_base .'_'. $this->number;
296
+ $new_instance['menu_order'] = $this->form_id;
297
+ $new_instance['post_status'] = 'publish';
298
+ $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
299
+
300
+ $instance = $this->update( $new_instance, $old_instance );
301
+
302
+ /**
303
+ * Filter an action's settings before saving.
304
+ *
305
+ * Returning false will effectively short-circuit the widget's ability
306
+ * to update settings.
307
+ *
308
+ * @since 2.0
309
+ *
310
+ * @param array $instance The current widget instance's settings.
311
+ * @param array $new_instance Array of new widget settings.
312
+ * @param array $old_instance Array of old widget settings.
313
+ * @param WP_Widget $this The current widget instance.
314
+ */
315
+ $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
316
+
317
+ $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
318
+ $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
319
+
320
+ if ( false !== $instance ) {
321
+ $all_instances[$number] = $instance;
322
+ }
323
+
324
+ $action_ids[] = $this->save_settings($instance);
325
+
326
+ $this->updated = true;
327
+ }
328
+
329
+ return $action_ids;
330
+ }
331
+
332
+ public function save_settings($settings) {
333
+ $settings = (array) $settings;
334
+
335
+ $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
336
+
337
+ if ( empty($settings['ID']) ) {
338
+ unset($settings['ID']);
339
+ }
340
+
341
+ // delete all styling caches
342
+ FrmAppHelper::cache_delete_group('frm_actions');
343
+
344
+ return wp_insert_post($settings);
345
+ }
346
+
347
+ public function get_single_action( $id ) {
348
+ $action = get_post($id);
349
+ $action = $this->prepare_action($action);
350
+ $this->_set($id);
351
+ return $action;
352
+ }
353
+
354
+ public function get_one( $form_id ) {
355
+ return $this->get_all($form_id, 1);
356
+ }
357
+
358
+ public function get_all( $form_id = false, $limit = 99 ) {
359
+ if ( $form_id ) {
360
+ $this->form_id = $form_id;
361
+ }
362
+
363
+ $type = $this->id_base;
364
+
365
+ global $frm_vars;
366
+ $frm_vars['action_type'] = $type;
367
+
368
+ add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
369
+ $query = array(
370
+ 'post_type' => FrmFormsController::$action_post_type,
371
+ 'post_status' => 'all',
372
+ 'numberposts' => 99,
373
+ 'order' => 'ASC',
374
+ 'suppress_filters' => false,
375
+ );
376
+
377
+ if ( $form_id != 'all' ) {
378
+ // allow actions for all forms
379
+ $query['menu_order'] = $this->form_id;
380
+ }
381
+
382
+ $actions = get_posts( $query );
383
+ unset($query);
384
+
385
+ remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
386
+
387
+ if ( ! $actions ) {
388
+ return array();
389
+ }
390
+
391
+ $settings = array();
392
+ foreach ( $actions as $action ) {
393
+ if ( count($settings) >= $limit ) {
394
+ continue;
395
+ }
396
+
397
+ $action = $this->prepare_action($action);
398
+
399
+ $settings[$action->ID] = $action;
400
+ }
401
+
402
+ if ( 1 === $limit ) {
403
+ $settings = reset($settings);
404
+ }
405
+
406
+ return $settings;
407
+ }
408
+
409
+ public function prepare_action($action) {
410
+ $action->post_content = FrmAppHelper::maybe_json_decode($action->post_content);
411
+
412
+ $default_values = $this->get_global_defaults();
413
+
414
+ // fill default values
415
+ $action->post_content = wp_parse_args( $action->post_content, $default_values);
416
+
417
+ foreach ( $default_values as $k => $vals ) {
418
+ if ( is_array($vals) && ! empty($vals) ) {
419
+ if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty($action->post_content[$k]) ) {
420
+ continue;
421
+ }
422
+ $action->post_content[$k] = wp_parse_args($action->post_content[$k], $vals);
423
+ }
424
+ }
425
+
426
+ if ( ! is_array($action->post_content['event']) ) {
427
+ $action->post_content['event'] = explode(',', $action->post_content['event']);
428
+ }
429
+
430
+ return $action;
431
+ }
432
+
433
+ public function destroy($form_id = false, $type = 'default') {
434
+ global $wpdb;
435
+
436
+ $this->form_id = $form_id;
437
+
438
+ $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type=%s", FrmFormsController::$action_post_type);
439
+ if ( $form_id ) {
440
+ $query .= $wpdb->prepare(" AND menu_order=%d", $form_id);
441
+ }
442
+
443
+ if ( 'all' != $type ) {
444
+ $query .= $wpdb->prepare(" AND post_excerpt=%s", $this->id_base);
445
+ }
446
+
447
+ $post_ids = $wpdb->get_col($query);
448
+
449
+ foreach ( $post_ids as $id ) {
450
+ wp_delete_post($id);
451
+ }
452
+ }
453
+
454
+ public function get_settings() {
455
+ return FrmFormActionsHelper::get_action_for_form($this->form_id, $this->id_base);
456
+ }
457
+
458
+ public function get_global_defaults() {
459
+ $defaults = $this->get_defaults();
460
+
461
+ if ( ! isset($defaults['event']) ) {
462
+ $defaults['event'] = array('create');
463
+ }
464
+
465
+ if ( ! isset($defaults['conditions']) ) {
466
+ $defaults['conditions'] = array(
467
+ 'send_stop' => '',
468
+ 'any_all' => '',
469
+ );
470
+ }
471
+
472
+ return $defaults;
473
+ }
474
+
475
+ public function get_global_switch_fields() {
476
+ $switch = $this->get_switch_fields();
477
+ $switch['conditions'] = array('hide_field');
478
+ return $switch;
479
+ }
480
+
481
+ /*
482
+ * Migrate settings from form->options into new action.
483
+ */
484
+ public function migrate_to_2($form, $update = 'update') {
485
+ $action = $this->prepare_new($form->id);
486
+
487
+ // fill with existing options
488
+ foreach ( $action->post_content as $name => $val ) {
489
+ if ( isset($form->options[$name]) ) {
490
+ $action->post_content[$name] = $form->options[$name];
491
+ unset($form->options[$name]);
492
+ }
493
+ }
494
+
495
+ $action = $this->migrate_values($action, $form);
496
+
497
+ // check if action already exists
498
+ $post_id = get_posts( array(
499
+ 'name' => $action->post_name,
500
+ 'post_type' => FrmFormsController::$action_post_type,
501
+ 'post_status' => $action->post_status,
502
+ 'numberposts' => 1,
503
+ ) );
504
+
505
+ if ( empty($post_id) ) {
506
+ // create action now
507
+ $post_id = $this->save_settings($action);
508
+ }
509
+
510
+ if ( $post_id && 'update' == $update ) {
511
+ global $wpdb;
512
+ $form->options = maybe_serialize($form->options);
513
+
514
+ // update form options
515
+ $wpdb->update($wpdb->prefix .'frm_forms', array('options' => $form->options), array('id' => $form->id));
516
+ wp_cache_delete( $form->id, 'frm_form');
517
+ }
518
+
519
+ return $post_id;
520
+ }
521
+
522
+ }
classes/models/FrmNotification.php CHANGED
@@ -1,115 +1,299 @@
1
  <?php
2
- if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
3
 
4
  class FrmNotification{
5
  function __construct(){
6
- add_action('frm_after_create_entry', array(&$this, 'entry_created'), 10, 2);
 
 
 
7
  }
8
-
9
- function entry_created($entry_id, $form_id){
10
- if (apply_filters('frm_stop_standard_email', false, $entry_id)) return;
11
- global $frm_entry, $frm_entry_meta;
12
-
13
- $entry = $frm_entry->getOne($entry_id, true);
14
- $frm_form = new FrmForm();
15
- $form = $frm_form->getOne($form_id);
16
- $values = $frm_entry_meta->getAll("it.item_id = $entry_id", " ORDER BY fi.field_order");
17
-
18
-
19
- if(isset($form->options['notification']))
20
- $notification = reset($form->options['notification']);
21
- else
22
- $notification = $form->options;
23
-
24
- // Set the from and to email names and addresses
25
- $to_email = $notification['email_to'];
26
- if ( empty($to_email) ) {
27
- $to_email = '[admin_email]';
28
- }
29
-
30
- $to_emails = explode(',', $to_email);
31
-
32
- $reply_to = $reply_to_name = '';
33
-
34
- foreach ($values as $value) {
35
- $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
36
- if (is_array($val))
37
- $val = implode(', ', $val);
38
-
39
- if(isset($notification['reply_to']) and (int)$notification['reply_to'] == $value->field_id and is_email($val))
40
- $reply_to = $val;
41
-
42
- if(isset($notification['reply_to_name']) and (int)$notification['reply_to_name'] == $value->field_id)
43
- $reply_to_name = $val;
44
- }
45
-
46
-
47
- if ( empty($reply_to) && $notification['reply_to'] == 'custom' ) {
48
- $reply_to = $notification['cust_reply_to'];
49
- }
50
-
51
- if ( empty($reply_to_name) && $notification['reply_to_name'] == 'custom' ){
52
- $reply_to_name = $notification['cust_reply_to_name'];
53
- }
54
-
55
- // Set the email message
56
- $plain_text = (isset($notification['plain_text']) && $notification['plain_text']) ? true : false;
57
- $mail_body = isset($notification['email_message']) ? $notification['email_message'] : '';
58
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
60
  'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
61
  'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
62
  ) );
63
-
64
- // Set the subject
65
- $subject = isset($notification['email_subject']) ? $notification['email_subject'] : '';
66
- if ( empty($subject) ) {
67
- $frm_blogname = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES );
68
- $subject = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), $form->name, $frm_blogname);
 
 
 
 
 
 
 
 
 
 
69
  }
70
-
71
- // Send the emails now
72
- foreach ( (array) $to_emails as $to_email) {
73
- $this->send_notification_email(trim($to_email), $subject, $mail_body, $reply_to, $reply_to_name, $plain_text);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
-
77
- function send_notification_email($to_email, $subject, $message, $reply_to='', $reply_to_name='', $plain_text=true, $attachments=array()){
78
- $content_type = ($plain_text) ? 'text/plain' : 'text/html';
79
- $reply_to_name = ($reply_to_name == '') ? wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ) : $reply_to_name; //senders name
80
- $reply_to = ($reply_to == '' or $reply_to == '[admin_email]') ? get_option('admin_email') : $reply_to; //senders e-mail address
81
-
82
- if($to_email == '[admin_email]')
83
- $to_email = get_option('admin_email');
84
-
85
- $charset = get_option('blog_charset');
86
- $recipient = $to_email; //recipient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  $header = array();
88
- $header[] = 'From: "'. $reply_to_name .'" <'. $reply_to .'>';
89
- $header[] = 'Reply-To: '. $reply_to;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  $header[] = 'Content-Type: '. $content_type .'; charset="'. $charset . '"';
91
- $subject = wp_specialchars_decode(strip_tags(stripslashes($subject)), ENT_QUOTES );
92
-
93
- $message = do_shortcode($message);
94
- $message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars
95
- if($plain_text)
 
96
  $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
 
97
 
98
- $header = apply_filters('frm_email_header', $header, compact('to_email', 'subject'));
99
-
100
- if ( apply_filters('frm_encode_subject', 1, $subject ) ) {
101
- $subject = '=?'. $charset .'?B?'. base64_encode($subject) .'?=';
 
 
102
  }
103
-
104
  remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
105
  remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
106
-
107
- if (!wp_mail($recipient, $subject, $message, $header, $attachments)){
108
- $header = 'From: "'. $reply_to_name .'" <'. $reply_to .'>'. "\r\n";
109
- mail($recipient, $subject, $message, $header);
 
 
110
  }
111
 
112
- do_action('frm_notification', $recipient, $subject, $message);
 
 
 
 
 
 
 
 
 
 
113
  }
114
 
115
  }
1
  <?php
 
2
 
3
  class FrmNotification{
4
  function __construct(){
5
+ if ( ! defined('ABSPATH') ) {
6
+ die('You are not allowed to call this page directly.');
7
+ }
8
+ add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
9
  }
10
+
11
+ public static function trigger_email($action, $entry, $form) {
12
+ if ( defined('WP_IMPORTING') ) {
13
+ return;
14
+ }
15
+
16
+ global $wpdb;
17
+
18
+ $notification = $action->post_content;
19
+ $email_key = $action->ID;
20
+
21
+ // Set the subject
22
+ if ( empty($notification['email_subject']) ) {
23
+ $notification['email_subject'] = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), $form->name, '[sitename]');
24
+ }
25
+
26
+ $plain_text = $notification['plain_text'] ? true : false;
27
+
28
+ //Filter these fields
29
+ $filter_fields = array(
30
+ 'email_to', 'cc', 'bcc',
31
+ 'reply_to', 'from',
32
+ 'email_subject', 'email_message',
33
+ );
34
+
35
+ add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
36
+
37
+ //Get all values in entry in order to get User ID field ID
38
+ $values = FrmEntryMeta::getAll('it.field_id != 0 and it.item_id ='. $entry->id .' ORDER BY fi.field_order');
39
+ $user_id_field = $user_id_key = '';
40
+ foreach ( $values as $value ) {
41
+ if ( $value->field_type == 'user_id' ) {
42
+ $user_id_field = $value->field_id;
43
+ $user_id_key = $value->field_key;
44
+ break;
45
+ }
46
+ unset($value);
47
+ }
48
+
49
+ //Filter and prepare the email fields
50
+ foreach ( $filter_fields as $f ) {
51
+ //Don't allow empty From
52
+ if ( in_array($f, array('from')) && empty($notification[$f]) ) {
53
+ $notification[$f] = '[admin_email]';
54
+ //Remove brackets
55
+ } else if ( in_array($f, array('email_to', 'cc', 'bcc', 'reply_to', 'from')) ) {
56
+ //Add a space in case there isn't one
57
+ $notification[$f] = str_replace('<', ' ', $notification[$f]);
58
+ $notification[$f] = str_replace(array('"', '>'), '', $notification[$f]);
59
+
60
+ //Switch userID shortcode to email address
61
+ if ( strpos($notification[$f], '[' . $user_id_field . ']' ) !== false || strpos($notification[$f], '[' . $user_id_key . ']' ) !== false ) {
62
+ $user_data = get_userdata($entry->metas[$user_id_field]);
63
+ $user_email = $user_data->user_email;
64
+ $notification[$f] = str_replace( array('[' . $user_id_field . ']','[' . $user_id_key . ']') , $user_email , $notification[$f]);
65
+ }
66
+ }
67
+
68
+ $notification[$f] = FrmFieldsHelper::basic_replace_shortcodes($notification[$f], $form, $entry);
69
+ }
70
+
71
+ //Put recipients, cc, and bcc into an array if they aren't empty
72
+ $to_emails = ( ! empty( $notification['email_to'] ) ? preg_split( "/(,|;)/", $notification['email_to'] ) : '' );
73
+ $cc = ( ! empty( $notification['cc'] ) ? preg_split( "/(,|;)/", $notification['cc'] ) : '' );
74
+ $bcc = ( ! empty( $notification['bcc'] ) ? preg_split( "/(,|;)/", $notification['bcc'] ) : '' );
75
+
76
+ $to_emails = apply_filters('frm_to_email', $to_emails, array(), $form->id, compact('email_key', 'entry', 'form'));
77
+
78
+ // Stop now if there aren't any recipients
79
+ if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
80
+ return;
81
+ }
82
+
83
+ $to_emails = array_unique( (array) $to_emails );
84
+
85
+ $prev_mail_body = $mail_body = $notification['email_message'];
86
  $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
87
  'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
88
  'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
89
  ) );
90
+
91
+ // Add the user info if it isn't already included
92
+ if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
93
+ $data = maybe_unserialize($entry->description);
94
+ $mail_body .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
95
+ $mail_body .= __('IP Address', 'formidable') . ": ". $entry->ip ."\r\n";
96
+ $mail_body .= __('User-Agent (Browser/OS)', 'formidable') . ": ". $data['browser']."\r\n";
97
+ $mail_body .= __('Referrer', 'formidable') . ": ". $data['referrer']."\r\n";
98
+ }
99
+ unset($prev_mail_body);
100
+
101
+ // Add attachments
102
+ $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
103
+
104
+ if ( ! empty($notification['email_subject']) ) {
105
+ $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
106
  }
107
+
108
+ // check for a phone number
109
+ foreach ( (array) $to_emails as $email_key => $e ) {
110
+ $e = trim($e);
111
+ if ( $e != '[admin_email]' && ! is_email($e) ) {
112
+ $e = explode(' ', $e);
113
+
114
+ //If to_email has name <test@mail.com> format
115
+ if ( is_email(end($e)) ) {
116
+ continue;
117
+ }
118
+
119
+ do_action('frm_send_to_not_email', array(
120
+ 'e' => $e,
121
+ 'subject' => $notification['email_subject'],
122
+ 'mail_body' => $mail_body,
123
+ 'reply_to' => $notification['reply_to'],
124
+ 'from' => $notification['from'],
125
+ 'plain_text' => $plain_text,
126
+ 'attachments' => $attachments,
127
+ 'form' => $form,
128
+ 'email_key' => $email_key,
129
+ ) );
130
+
131
+ unset($to_emails[$email_key]);
132
+ }
133
  }
134
+
135
+ // Send the email now
136
+ $sent_to = self::send_email( array(
137
+ 'to_email' => $to_emails,
138
+ 'subject' => $notification['email_subject'],
139
+ 'message' => $mail_body,
140
+ 'from' => $notification['from'],
141
+ 'plain_text' => $plain_text,
142
+ 'reply_to' => $notification['reply_to'],
143
+ 'attachments' => $attachments,
144
+ 'cc' => $cc,
145
+ 'bcc' => $bcc,
146
+ ) );
147
+
148
+ return $sent_to;
149
  }
150
+
151
+ function entry_created($entry_id, $form_id) {
152
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", '. $form_id .', '. $entry_id .', "email")');
153
+ FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
154
+ }
155
+
156
+ function send_notification_email($to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '') {
157
+ _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
158
+
159
+ return self::send_email(compact(
160
+ 'to_email', 'subject', 'message',
161
+ 'from', 'from_name', 'plain_text',
162
+ 'attachments', 'reply_to'
163
+ ));
164
+ }
165
+
166
+ static function send_email($atts) {
167
+ $admin_email = get_option('admin_email');
168
+ $defaults = array(
169
+ 'to_email' => $admin_email,
170
+ 'subject' => '',
171
+ 'message' => '',
172
+ 'from' => $admin_email,
173
+ 'from_name' => '',
174
+ 'cc' => '',
175
+ 'bcc' => '',
176
+ 'plain_text' => true,
177
+ 'reply_to' => $admin_email,
178
+ 'attachments' => array(),
179
+ );
180
+ $atts = wp_parse_args($atts, $defaults);
181
+
182
+ //senders e-mail address
183
+ $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
184
+
185
+ //Allow name <test@mail.com> format in To, BCC, CC, Reply To, and From fields
186
+ $filter_fields = array('to_email','bcc','cc','from','reply_to');
187
+ foreach ( $filter_fields as $f ) {
188
+ if ( empty($atts[$f]) ) {
189
+ continue;
190
+ }
191
+ if ( is_array($atts[$f]) ) {//to_email, cc, and bcc can be an array
192
+ foreach ( $atts[$f] as $key => $val ) {
193
+ $val = trim($val);
194
+ if ( is_email($val) ) {
195
+ continue;
196
+ } else {
197
+ $parts = explode(' ', $val);
198
+ $part_2 = end($parts);
199
+ $part_1 = trim(str_replace($part_2, '', $val));
200
+ $atts[$f][$key] = $part_1 . ' <'. $part_2 .'>';
201
+ $atts[$f][$key] = str_replace('"', '', $atts[$f][$key]);
202
+ unset($part_1,$part_2,$val);
203
+ }
204
+ }
205
+ unset($f);
206
+ continue;
207
+ }
208
+ if ( is_email($atts[$f]) ) {
209
+ // add sender's name if not included in $from
210
+ if ( $f == 'from' ) {
211
+ $part_2 = $atts[$f];
212
+ $part_1 = ( '' == $atts['from_name'] ) ? wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ) : $atts['from_name'];
213
+ } else {
214
+ continue;
215
+ }
216
+ } else {
217
+ $parts = explode(' ', $atts[$f]);
218
+ $part_2 = end($parts);
219
+ $part_1 = trim(str_replace($part_2, '', $atts[$f]));
220
+ }
221
+ $atts[$f] = $part_1 . ' <'. $part_2 .'>';
222
+ $atts[$f] = str_replace('"', '', $atts[$f]);
223
+ unset($part_1, $part_2, $f);
224
+ }
225
+
226
+ if ( empty($atts['reply_to']) ) {
227
+ $atts['reply_to'] = $atts['from'];
228
+ }
229
+
230
+ if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
231
+ $atts['to_email'] = $admin_email;
232
+ }
233
+
234
+ $recipient = $atts['to_email']; //recipient
235
  $header = array();
236
+ $header[] = 'From: ' . $atts['from'];
237
+
238
+ //Allow for cc and bcc arrays
239
+ $array_fields = array('CC' => $atts['cc'], 'BCC' => $atts['bcc']);
240
+ foreach ( $array_fields as $key => $a_field ) {
241
+ if ( empty($a_field) ) {
242
+ continue;
243
+ }
244
+ if ( is_array($a_field ) ) {
245
+ foreach ( $a_field as $email ) {
246
+ $header[] = $key . ': ' . $email;
247
+ }
248
+ } else {
249
+ $header[] = $key . ': ' . $a_field;
250
+ }
251
+ unset($key, $a_field);
252
+ }
253
+
254
+ $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html';
255
+ $charset = get_option('blog_charset');
256
+
257
+ $header[] = 'Reply-To: '. $atts['reply_to'];
258
  $header[] = 'Content-Type: '. $content_type .'; charset="'. $charset . '"';
259
+ $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES );
260
+
261
+ $message = do_shortcode($atts['message']);
262
+
263
+ if ( $atts['plain_text'] ) {
264
+ $message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars
265
  $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES );
266
+ }
267
 
268
+ $header = apply_filters('frm_email_header', $header, array(
269
+ 'to_email' => $atts['to_email'], 'subject' => $atts['subject'])
270
+ );
271
+
272
+ if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) {
273
+ $atts['subject'] = '=?'. $charset .'?B?'. base64_encode($atts['subject']) .'?=';
274
  }
275
+
276
  remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
277
  remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');
278
+
279
+ $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']);
280
+ if ( ! $sent ) {
281
+ $header = 'From: '. $atts['from'] ."\r\n";
282
+ $recipient = implode(',', (array) $recipient);
283
+ $sent = mail($recipient, $atts['subject'], $message, $header);
284
  }
285
 
286
+ do_action('frm_notification', $recipient, $atts['subject'], $message);
287
+
288
+ if ( $sent ) {
289
+ $sent_to = array_merge( (array)$atts['to_email'], (array) $atts['cc'], (array) $atts['bcc']);
290
+ $sent_to = array_filter( $sent_to );
291
+ if ( apply_filters('frm_echo_emails', false) ) {
292
+ $temp = str_replace('<', '&lt;', $sent_to);
293
+ echo implode(', ', (array) $temp);
294
+ }
295
+ return $sent_to;
296
+ }
297
  }
298
 
299
  }
classes/models/FrmSettings.php CHANGED
@@ -1,15 +1,79 @@
1
  <?php
2
- if(!defined('ABSPATH')) die(__('You are not allowed to call this page directly.', 'formidable'));
3
-
4
- if(class_exists('FrmSettings'))
5
- return;
6
 
7
  class FrmSettings{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- function __construct(){
10
  $this->set_default_options();
11
  }
12
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  function default_options(){
14
  return array(
15
  'menu' => 'Formidable',
@@ -20,7 +84,7 @@ class FrmSettings{
20
  'use_html' => true,
21
  'jquery_css' => false,
22
  'accordion_js' => false,
23
-
24
  'success_msg' => __('Your responses were successfully submitted. Thank you!', 'formidable'),
25
  'blank_msg' => __('This field cannot be blank.', 'formidable'),
26
  'unique_msg' => __('This value must be unique.', 'formidable'),
@@ -29,60 +93,75 @@ class FrmSettings{
29
  'submit_value' => __('Submit', 'formidable'),
30
  'login_msg' => __('You do not have permission to view this form.', 'formidable'),
31
  'admin_permission' => __('You do not have permission to do that', 'formidable'),
32
-
33
  'email_to' => '[admin_email]',
34
  );
35
  }
36
 
37
  function set_default_options(){
38
- if(!isset($this->pubkey)){
39
- $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); // get the options from the database
40
-
41
- $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
42
- }
43
-
44
- if(!isset($this->privkey))
45
- $this->privkey = (isset($recaptcha_opt) and isset($recaptcha_opt['privkey'])) ? $recaptcha_opt['privkey'] : '';
46
-
47
- if(!isset($this->re_theme))
48
- $this->re_theme = (isset($recaptcha_opt) and isset($recaptcha_opt['re_theme'])) ? $recaptcha_opt['re_theme'] : 'red';
49
-
50
- if(!isset($this->re_lang))
51
- $this->re_lang = (isset($recaptcha_opt) and isset($recaptcha_opt['re_lang'])) ? $recaptcha_opt['re_lang'] : 'en';
52
-
53
- if(!isset($this->re_msg) or empty($this->re_msg))
54
- $this->re_msg = __('The reCAPTCHA was not entered correctly', 'formidable');
55
-
56
- if(!isset($this->load_style)){
57
- if(!isset($this->custom_style))
58
  $this->custom_style = true;
59
- if(!isset($this->custom_stylesheet))
60
- $this->custom_stylesheet = false;
61
-
62
- $this->load_style = ($this->custom_stylesheet) ? 'none' : 'all';
63
- }
64
-
65
- $settings = $this->default_options();
66
-
67
- foreach($settings as $setting => $default){
68
- if(!isset($this->{$setting}))
69
- $this->{$setting} = $default;
70
- unset($setting);
71
- unset($default);
72
  }
73
-
74
- if(is_multisite() and is_admin()){
 
 
75
  $mu_menu = get_site_option('frm_admin_menu_name');
76
- if($mu_menu and !empty($mu_menu)){
77
  $this->menu = $mu_menu;
78
  $this->mu_menu = 1;
79
  }
80
  }
81
-
82
- $frm_roles = FrmAppHelper::frm_capabilities();
83
- foreach($frm_roles as $frm_role => $frm_role_description){
84
- if(!isset($this->$frm_role))
85
  $this->$frm_role = 'administrator';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
  }
88
 
@@ -92,67 +171,82 @@ class FrmSettings{
92
  }
93
 
94
  function update($params){
95
- global $wp_roles;
96
-
97
- $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
98
  if ( $this->mu_menu ) {
99
  update_site_option('frm_admin_menu_name', $this->menu);
100
  } else if ( current_user_can('administrator') ) {
101
  update_site_option('frm_admin_menu_name', false);
102
  }
103
-
 
 
 
 
 
 
 
 
104
  $this->pubkey = trim($params['frm_pubkey']);
105
  $this->privkey = $params['frm_privkey'];
106
- $this->re_theme = $params['frm_re_theme'];
107
  $this->re_lang = $params['frm_re_lang'];
108
-
109
- $settings = $this->default_options();
110
-
111
- foreach($settings as $setting => $default){
112
- if(isset($params['frm_'. $setting]))
113
- $this->{$setting} = $params['frm_'. $setting];
114
-
115
- unset($setting);
116
- unset($default);
117
- }
118
-
119
  $this->load_style = $params['frm_load_style'];
120
- $this->preview_page_id = (int)$params['frm-preview-page-id'];
121
  $this->lock_keys = isset($params['frm_lock_keys']) ? $params['frm_lock_keys'] : 0;
122
  $this->track = isset($params['frm_track']) ? $params['frm_track'] : 0;
123
-
124
  $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
125
  //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
126
- //$this->custom_stylesheet = isset($params['frm_custom_stylesheet']) ? $params['frm_custom_stylesheet'] : 0;
127
  $this->jquery_css = isset($params['frm_jquery_css']) ? $params['frm_jquery_css'] : 0;
128
  $this->accordion_js = isset($params['frm_accordion_js']) ? $params['frm_accordion_js'] : 0;
129
-
 
 
130
  //update roles
 
 
131
  $frm_roles = FrmAppHelper::frm_capabilities();
132
  $roles = get_editable_roles();
133
- foreach($frm_roles as $frm_role => $frm_role_description){
134
- $this->$frm_role = isset($params[$frm_role]) ? $params[$frm_role] : 'administrator';
135
-
136
- foreach ($roles as $role => $details){
137
- if($this->$frm_role == $role or ($this->$frm_role == 'editor' and $role == 'administrator') or ($this->$frm_role == 'author' and in_array($role, array('administrator', 'editor'))) or ($this->$frm_role == 'contributor' and in_array($role, array('administrator', 'editor', 'author'))) or $this->$frm_role == 'subscriber')
138
- $wp_roles->add_cap( $role, $frm_role );
139
- else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  $wp_roles->remove_cap( $role, $frm_role );
141
- }
 
 
142
  }
143
-
144
- do_action( 'frm_update_settings', $params );
145
  }
146
 
147
  function store(){
148
  // Save the posted value in the database
149
 
150
  update_option('frm_options', $this);
151
-
152
  delete_transient('frm_options');
153
  set_transient('frm_options', $this);
154
 
155
  do_action( 'frm_store_settings' );
156
  }
157
-
158
  }
1
  <?php
 
 
 
 
2
 
3
  class FrmSettings{
4
+ public $option_name = 'frm_options';
5
+ public $menu;
6
+ public $mu_menu;
7
+ public $preview_page_id;
8
+ public $lock_keys;
9
+ public $track;
10
+ public $use_html;
11
+ public $jquery_css;
12
+ public $accordion_js;
13
+
14
+ public $success_msg;
15
+ public $blank_msg;
16
+ public $unique_msg;
17
+ public $invalid_msg;
18
+ public $failed_msg;
19
+ public $submit_value;
20
+ public $login_msg;
21
+ public $admin_permission;
22
+
23
+ public $email_to;
24
+ public $load_style;
25
+ public $custom_style;
26
+
27
+ public $pubkey;
28
+ public $re_lang;
29
+ public $re_msg;
30
+
31
+ function __construct() {
32
+ if ( ! defined('ABSPATH') ) {
33
+ die('You are not allowed to call this page directly.');
34
+ }
35
+
36
+ $settings = get_transient($this->option_name);
37
+
38
+ if ( ! is_object($settings) ) {
39
+ $settings = $this->translate_settings($settings);
40
+ }
41
+
42
+ foreach ( $settings as $setting_name => $setting ) {
43
+ $this->{$setting_name} = $setting;
44
+ unset($setting_name, $setting);
45
+ }
46
 
 
47
  $this->set_default_options();
48
  }
49
+
50
+ function translate_settings($settings) {
51
+ if ( $settings ) { //workaround for W3 total cache conflict
52
+ return unserialize(serialize($settings));
53
+ }
54
+
55
+ $settings = get_option($this->option_name);
56
+ if ( is_object($settings) ) {
57
+ set_transient($this->option_name, $settings);
58
+ return $settings;
59
+ }
60
+
61
+ // If unserializing didn't work
62
+ if ( $settings ) { //workaround for W3 total cache conflict
63
+ $settings = unserialize(serialize($settings));
64
+ } else {
65
+ $settings = $this;
66
+ }
67
+
68
+ update_option($this->option_name, $settings);
69
+ set_transient($this->option_name, $settings);
70
+
71
+ return $settings;
72
+ }
73
+
74
+ /*
75
+ * @return array
76
+ */
77
  function default_options(){
78
  return array(
79
  'menu' => 'Formidable',
84
  'use_html' => true,
85
  'jquery_css' => false,
86
  'accordion_js' => false,
87
+
88
  'success_msg' => __('Your responses were successfully submitted. Thank you!', 'formidable'),
89
  'blank_msg' => __('This field cannot be blank.', 'formidable'),
90
  'unique_msg' => __('This value must be unique.', 'formidable'),
93
  'submit_value' => __('Submit', 'formidable'),
94
  'login_msg' => __('You do not have permission to view this form.', 'formidable'),
95
  'admin_permission' => __('You do not have permission to do that', 'formidable'),
96
+
97
  'email_to' => '[admin_email]',
98
  );
99
  }
100
 
101
  function set_default_options(){
102
+ $this->fill_recaptcha_settings();
103
+
104
+ if ( ! isset($this->load_style) ) {
105
+ if ( ! isset($this->custom_style) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  $this->custom_style = true;
107
+ }
108
+
109
+ $this->load_style = 'all';
 
 
 
 
 
 
 
 
 
 
110
  }
111
+
112
+ $this->fill_with_defaults();
113
+
114
+ if ( is_multisite() && is_admin() ) {
115
  $mu_menu = get_site_option('frm_admin_menu_name');
116
+ if ( $mu_menu && ! empty($mu_menu) ) {
117
  $this->menu = $mu_menu;
118
  $this->mu_menu = 1;
119
  }
120
  }
121
+
122
+ $frm_roles = FrmAppHelper::frm_capabilities('pro');
123
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
124
+ if ( ! isset($this->$frm_role) ) {
125
  $this->$frm_role = 'administrator';
126
+ }
127
+ }
128
+ }
129
+
130
+ function fill_with_defaults($params = array()) {
131
+ $settings = $this->default_options();
132
+
133
+ foreach ( $settings as $setting => $default ) {
134
+ if ( isset($params['frm_'. $setting]) ) {
135
+ $this->{$setting} = $params['frm_'. $setting];
136
+ } else if ( ! isset($this->{$setting}) ) {
137
+ $this->{$setting} = $default;
138
+ }
139
+ unset($setting, $default);
140
+ }
141
+ }
142
+
143
+ private function fill_recaptcha_settings() {
144
+ $privkey = '';
145
+ $re_lang = 'en';
146
+
147
+ if ( ! isset($this->pubkey) ) {
148
+ // get the options from the database
149
+ $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha');
150
+ $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : '';
151
+ $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey;
152
+ $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang;
153
+ }
154
+
155
+ if ( ! isset($this->re_msg) || empty($this->re_msg) ) {
156
+ $this->re_msg = __('The reCAPTCHA was not entered correctly', 'formidable');
157
+ }
158
+
159
+ if ( ! isset($this->privkey) ) {
160
+ $this->privkey = $privkey;
161
+ }
162
+
163
+ if ( ! isset($this->re_lang) ) {
164
+ $this->re_lang = $re_lang;
165
  }
166
  }
167
 
171
  }
172
 
173
  function update($params){
174
+ $this->fill_with_defaults($params);
175
+ $this->update_settings($params);
176
+
177
  if ( $this->mu_menu ) {
178
  update_site_option('frm_admin_menu_name', $this->menu);
179
  } else if ( current_user_can('administrator') ) {
180
  update_site_option('frm_admin_menu_name', false);
181
  }
182
+
183
+ $this->update_roles($params);
184
+
185
+ do_action( 'frm_update_settings', $params );
186
+ }
187
+
188
+ private function update_settings($params) {
189
+ $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0;
190
+
191
  $this->pubkey = trim($params['frm_pubkey']);
192
  $this->privkey = $params['frm_privkey'];
 
193
  $this->re_lang = $params['frm_re_lang'];
194
+
 
 
 
 
 
 
 
 
 
 
195
  $this->load_style = $params['frm_load_style'];
196
+ $this->preview_page_id = (int) $params['frm-preview-page-id'];
197
  $this->lock_keys = isset($params['frm_lock_keys']) ? $params['frm_lock_keys'] : 0;
198
  $this->track = isset($params['frm_track']) ? $params['frm_track'] : 0;
199
+
200
  $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0;
201
  //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0;
 
202
  $this->jquery_css = isset($params['frm_jquery_css']) ? $params['frm_jquery_css'] : 0;
203
  $this->accordion_js = isset($params['frm_accordion_js']) ? $params['frm_accordion_js'] : 0;
204
+ }
205
+
206
+ private function update_roles($params) {
207
  //update roles
208
+ global $wp_roles;
209
+
210
  $frm_roles = FrmAppHelper::frm_capabilities();
211
  $roles = get_editable_roles();
212
+ foreach ( $frm_roles as $frm_role => $frm_role_description ) {
213
+ $this->$frm_role = (array) ( isset($params[$frm_role]) ? $params[$frm_role] : 'administrator' );
214
+
215
+ if ( count($this->$frm_role) === 1 ) {
216
+ $set_role = reset($this->$frm_role);
217
+ switch ( $set_role ) {
218
+ case 'subscriber':
219
+ array_push($this->$frm_role, 'contributor');
220
+ case 'contributor':
221
+ array_push($this->$frm_role, 'author');
222
+ case 'author':
223
+ array_push($this->$frm_role, 'editor');
224
+ case 'editor':
225
+ array_push($this->$frm_role, 'administrator');
226
+ }
227
+ unset($set_role);
228
+ }
229
+
230
+ foreach ( $roles as $role => $details ) {
231
+ if ( in_array($role, $this->$frm_role) ) {
232
+ $wp_roles->add_cap( $role, $frm_role );
233
+ } else {
234
  $wp_roles->remove_cap( $role, $frm_role );
235
+ }
236
+ unset($role, $details);
237
+ }
238
  }
 
 
239
  }
240
 
241
  function store(){
242
  // Save the posted value in the database
243
 
244
  update_option('frm_options', $this);
245
+
246
  delete_transient('frm_options');
247
  set_transient('frm_options', $this);
248
 
249
  do_action( 'frm_store_settings' );
250
  }
251
+
252
  }
classes/models/FrmStyle.php ADDED
@@ -0,0 +1,418 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class FrmStyle{
3
+ public $number = false; // Unique ID number of the current instance.
4
+ public $id = false; // the id of the post
5
+
6
+ function __construct($id = false) {
7
+ $this->id = $id;
8
+ }
9
+
10
+ function get_new() {
11
+ $this->id = false;
12
+
13
+ $max_slug_value = pow(36, 6);
14
+ $min_slug_value = 37; // we want to have at least 2 characters in the slug
15
+ $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
16
+
17
+ $style = array(
18
+ 'post_type' => FrmStylesController::$post_type,
19
+ 'ID' => '',
20
+ 'post_title' => __('New Style', 'formidable'),
21
+ 'post_name' => $key,
22
+ 'post_content' => $this->get_defaults(),
23
+ 'menu_order' => '',
24
+ 'post_status' => 'publish',
25
+ );
26
+
27
+ return (object) $style;
28
+ }
29
+
30
+ function save($settings) {
31
+ $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
32
+
33
+ if ( empty($settings['ID']) ) {
34
+ unset($settings['ID']);
35
+ }
36
+
37
+ // delete all styling caches
38
+ FrmAppHelper::cache_delete_group('frm_styles');
39
+
40
+ return wp_insert_post($settings);
41
+ }
42
+
43
+ function duplicate($id) {
44
+ // duplicating is a pro feature
45
+ }
46
+
47
+ public function update( $id = 'default' ) {
48
+ $all_instances = $this->get_all();
49
+
50
+ if ( empty($id) ) {
51
+ $new_style = (array) $this->get_new();
52
+ $all_instances[] = $new_style;
53
+ }
54
+
55
+ $action_ids = array();
56
+
57
+ foreach ( $all_instances as $number => $new_instance ) {
58
+ $new_instance = stripslashes_deep( (array) $new_instance);
59
+ $this->id = $new_instance['ID'];
60
+ if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
61
+ $all_instances[$number] = $new_instance;
62
+
63
+ if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
64
+ // this style was set to default, so remove default setting on previous default style
65
+ $new_instance['menu_order'] = 0;
66
+ $action_ids[] = $this->save($new_instance);
67
+ }
68
+
69
+ // don't continue if not saving this style
70
+ continue;
71
+ }
72
+
73
+ $new_instance['post_title'] = $_POST['frm_style_setting']['post_title'];
74
+ $new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
75
+ $new_instance['post_type'] = FrmStylesController::$post_type;
76
+ $new_instance['post_status'] = 'publish';
77
+ $new_instance['menu_order'] = isset($_POST['frm_style_setting']['menu_order']) ? $_POST['frm_style_setting']['menu_order'] : 0;
78
+
79
+ if ( empty($id) ) {
80
+ $new_instance['post_name'] = $new_instance['post_title'];
81
+ }
82
+
83
+ $default_settings = $this->get_defaults();
84
+
85
+ foreach ( $default_settings as $setting => $default ) {
86
+ if ( strpos($setting, 'color') !== false || in_array($setting, array('error_bg', 'error_border', 'error_text')) ) {
87
+ //if is a color
88
+ $new_instance['post_content'][$setting] = str_replace('#', '', $new_instance['post_content'][$setting]);
89
+ } else if ( in_array($setting, array('submit_style', 'important_style', 'auto_width')) && ! isset($new_instance['post_content'][$setting]) ) {
90
+ $new_instance['post_content'][$setting] = 0;
91
+ }
92
+ }
93
+
94
+ $all_instances[$number] = $new_instance;
95
+
96
+ $action_ids[] = $this->save($new_instance);
97
+
98
+ }
99
+
100
+ $this->save_settings($all_instances);
101
+
102
+ return $action_ids;
103
+ }
104
+
105
+ public function save_settings($styles) {
106
+ $filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php';
107
+
108
+ if ( ! is_file($filename) ) {
109
+ return;
110
+ }
111
+
112
+ $defaults = $this->get_defaults();
113
+ $uploads = wp_upload_dir();
114
+ $target_path = $uploads['basedir'];
115
+
116
+ // create static css file
117
+ wp_mkdir_p($target_path);
118
+
119
+ $target_path .= "/formidable";
120
+ wp_mkdir_p($target_path);
121
+
122
+ if ( ! file_exists($target_path .'/index.php') ) {
123
+ // create index.php in uploads/formidable folder
124
+ if ( $fp = fopen($target_path .'/index.php', 'w') ) {
125
+ $index = "<?php\n// Silence is golden.\n?>";
126
+ fwrite($fp, $index);
127
+ fclose($fp);
128
+ unset($index);
129
+ }
130
+ unset($fp);
131
+ }
132
+
133
+ $target_path .= "/css";
134
+ wp_mkdir_p($target_path);
135
+
136
+ $saving = true;
137
+ $css = '/* '. __('WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable') .' */'. "\n";
138
+
139
+ ob_start();
140
+ $frm_style = $this;
141
+ include($filename);
142
+ $css .= preg_replace('/\/\*(.|\s)*?\*\//', '', str_replace(array("\r\n", "\r", "\n", "\t", " "), '', ob_get_contents()));
143
+ ob_end_clean();
144
+
145
+ $css_file = $target_path .'/formidablepro.css';
146
+ if ( $fp = fopen($css_file, 'w') ) {
147
+ fwrite($fp, $css);
148
+ fclose($fp);
149
+
150
+ $stat = @stat( dirname( $css_file ) );
151
+ $perms = $stat['mode'] & 0007777;
152
+ //$perms = $perms & 0000666;
153
+ @chmod( $css_file, $perms );
154
+ }
155
+
156
+ update_option('frmpro_css', $css);
157
+
158
+ delete_transient('frmpro_css');
159
+ set_transient('frmpro_css', $css);
160
+ }
161
+
162
+ function destroy($id) {
163
+ return wp_delete_post($id);
164
+ }
165
+
166
+ function get_one() {
167
+ if ( 'default' == $this->id ) {
168
+ $style = $this->get_default_style();
169
+ if ( $style ) {
170
+ $this->id = $style->ID;
171
+ } else {
172
+ $this->id = false;
173
+ }
174
+ return $style;
175
+ }
176
+
177
+ $style = get_post($this->id);
178
+
179
+ if ( ! $style ) {
180
+ return $style;
181
+ }
182
+
183
+ $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
184
+
185
+ $default_values = $this->get_defaults();
186
+
187
+ // fill default values
188
+ $style->post_content = $this->override_defaults($style->post_content);
189
+ $style->post_content = wp_parse_args( $style->post_content, $default_values);
190
+
191
+ return $style;
192
+ }
193
+
194
+ function get_all() {
195
+ $post_atts = array(
196
+ 'post_type' => FrmStylesController::$post_type,
197
+ 'post_status' => 'publish',
198
+ 'numberposts' => 99,
199
+ 'order_by' => 'title',
200
+ 'order' => 'ASC',
201
+ );
202
+
203
+ $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts');
204
+
205
+ if ( empty($temp_styles) ) {
206
+ // create a new style if there are none
207
+ $new = $this->get_new();
208
+ $new->post_title = $new->post_name = __('Formidable Style', 'formidable');
209
+ $new->menu_order = 1;
210
+ $new = $this->save( (array) $new);
211
+ $this->update('default');
212
+
213
+ $post_atts['include'] = $new;
214
+
215
+ $temp_styles = get_posts( $post_atts );
216
+ }
217
+
218
+ $default_values = $this->get_defaults();
219
+ $default_style = false;
220
+
221
+ $styles = array();
222
+ foreach ( $temp_styles as $style ) {
223
+ $this->id = $style->ID;
224
+ if ( $style->menu_order ) {
225
+ if ( $default_style ) {
226
+ // only return one default
227
+ $style->menu_order = 0;
228
+ } else {
229
+ // check for a default style
230
+ $default_style = $style->ID;
231
+ }
232
+ }
233
+
234
+ $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
235
+
236
+ // fill default values
237
+ $style->post_content = $this->override_defaults($style->post_content);
238
+ $style->post_content = wp_parse_args( $style->post_content, $default_values);
239
+
240
+ $styles[$style->ID] = $style;
241
+ }
242
+
243
+ if ( ! $default_style ) {
244
+ $default_style = reset($styles);
245
+ $styles[$default_style->ID]->menu_order = 1;
246
+ }
247
+
248
+ return $styles;
249
+ }
250
+
251
+ function get_default_style($styles = null) {
252
+ if ( ! isset($styles) ) {
253
+ $styles = $this->get_all();
254
+ }
255
+
256
+ foreach ( $styles as $style ) {
257
+ if ( $style->menu_order ) {
258
+ return $style;
259
+ }
260
+ }
261
+ }
262
+
263
+ function override_defaults($settings) {
264
+ if ( ! is_array($settings) ) {
265
+ return $settings;
266
+ }
267
+
268
+ $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
269
+
270
+ if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
271
+ $settings['form_desc_size'] = $settings['description_font_size'];
272
+ $settings['form_desc_color'] = $settings['description_color'];
273
+ $settings['title_color'] = $settings['label_color'];
274
+ }
275
+
276
+ if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
277
+ $settings['section_color'] = $settings['label_color'];
278
+ $settings['section_border_color'] = $settings['border_color'];
279
+ }
280
+
281
+ if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
282
+ $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
283
+ $settings['submit_hover_color'] = $settings['submit_text_color'];
284
+ $settings['submit_hover_border_color'] = $settings['submit_border_color'];
285
+
286
+ $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
287
+ $settings['submit_active_color'] = $settings['submit_text_color'];
288
+ $settings['submit_active_border_color'] = $settings['submit_border_color'];
289
+ }
290
+
291
+ return $settings;
292
+ }
293
+
294
+ function get_defaults(){
295
+ return array(
296
+ 'theme_css' => 'ui-lightness',
297
+ 'theme_name' => 'UI Lightness',
298
+
299
+ 'form_width' => '100%',
300
+ 'form_align' => 'left',
301
+ 'direction' => is_rtl() ? 'rtl' : 'ltr',
302
+ 'fieldset' => '0px',
303
+ 'fieldset_color' => '000000',
304
+ 'fieldset_padding' => '0 0 15px 0',
305
+ 'fieldset_bg_color' => '',
306
+
307
+ 'title_size' => '20px',
308
+ 'title_color' => '444444',
309
+ 'form_desc_size' => '14px',
310
+ 'form_desc_color' => '666666',
311
+
312
+ 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
313
+ 'font_size' => '14px',
314
+ 'label_color' => '444444',
315
+ 'weight' => 'bold',
316
+ 'position' => 'none',
317
+ 'align' => 'left',
318
+ 'width' => '150px',
319
+ 'required_color' => 'B94A48',
320
+ 'required_weight' => 'bold',
321
+ 'label_padding' => '0 0 3px 0',
322
+
323
+ 'description_font_size' => '12px',
324
+ 'description_color' => '666666',
325
+ 'description_weight' => 'normal',
326
+ 'description_style' => 'normal',
327
+ 'description_align' => 'left',
328
+
329
+ 'field_font_size' => '14px',
330
+ 'field_height' => '32px',
331
+ 'line_height' => 'normal',
332
+ 'field_width' => '100%',
333
+ 'auto_width' => false,
334
+ 'field_pad' => '6px 10px',
335
+ 'field_margin' => '20px',
336
+ 'text_color' => '555555',
337
+ //'border_color_hv' => 'cccccc',
338
+ 'border_color' => 'cccccc',
339
+ 'field_border_width' => '1px',
340
+ 'field_border_style' => 'solid',
341
+
342
+ 'bg_color' => 'ffffff',
343
+ //'bg_color_hv' => 'ffffff',
344
+ 'bg_color_active' => 'ffffff',
345
+ 'border_color_active'=> '66afe9',
346
+ 'text_color_error' => '444444',
347
+ 'bg_color_error' => 'ffffff',
348
+ 'border_color_error'=> 'B94A48',
349
+ 'border_width_error'=> '1px',
350
+ 'border_style_error'=> 'solid',
351
+ 'bg_color_disabled' => 'ffffff',
352
+ 'border_color_disabled' => 'E5E5E5',
353
+ 'text_color_disabled' => 'A1A1A1',
354
+
355
+ 'radio_align' => 'block',
356
+ 'check_align' => 'block',
357
+ 'check_font_size' => '13px',
358
+ 'check_label_color' => '444444',
359
+ 'check_weight' => 'normal',
360
+
361
+ 'section_font_size' => '18px',
362
+ 'section_color' => '444444',
363
+ 'section_weight' => 'bold',
364
+ 'section_pad' => '15px 0 3px 0',
365
+ 'section_mar_top' => '15px',
366
+ 'section_mar_bottom'=> '12px',
367
+ 'section_bg_color' => '',
368
+ 'section_border_color' => 'e8e8e8',
369
+ 'section_border_width' => '2px',
370
+ 'section_border_style' => 'solid',
371
+ 'section_border_loc' => '-top',
372
+ 'collapse_icon' => '6',
373
+ 'collapse_pos' => 'after',
374
+ 'repeat_icon' => '1',
375
+
376
+ 'submit_style' => false,
377
+ 'submit_font_size' => '14px',
378
+ 'submit_width' => 'auto',
379
+ 'submit_height' => 'auto',
380
+ 'submit_bg_color' => 'ffffff',
381
+ 'submit_border_color' => 'cccccc',
382
+ 'submit_border_width' => '1px',
383
+ 'submit_text_color' => '444444',
384
+ 'submit_weight' => 'normal',
385
+ 'submit_border_radius' => '4px',
386
+ 'submit_bg_img' => '',
387
+ 'submit_margin' => '10px',
388
+ 'submit_padding' => '6px 11px',
389
+ 'submit_shadow_color' => 'eeeeee',
390
+ 'submit_hover_bg_color' => 'efefef',
391
+ 'submit_hover_color' => '444444',
392
+ 'submit_hover_border_color' => 'cccccc',
393
+ 'submit_active_bg_color' => 'efefef',
394
+ 'submit_active_color' => '444444',
395
+ 'submit_active_border_color' => 'cccccc',
396
+
397
+ 'border_radius' => '4px',
398
+ 'error_bg' => 'F2DEDE',
399
+ 'error_border' => 'EBCCD1',
400
+ 'error_text' => 'B94A48',
401
+ 'error_font_size' => '14px',
402
+
403
+ 'success_bg_color' => 'DFF0D8',
404
+ 'success_border_color' => 'D6E9C6',
405
+ 'success_text_color' => '468847',
406
+ 'success_font_size' => '14px',
407
+
408
+ 'important_style' => false,
409
+
410
+ 'custom_css' => '',
411
+ );
412
+ }
413
+
414
+ public function get_field_name($field_name, $post_field = 'post_content') {
415
+ return 'frm_style_setting'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
416
+ }
417
+
418
+ }
classes/recaptchalib.php DELETED
@@ -1,274 +0,0 @@
1
- <?php
2
- /*
3
- * This is a PHP library that handles calling reCAPTCHA.
4
- * - Documentation and latest version
5
- * http://recaptcha.net/plugins/php/
6
- * - Get a reCAPTCHA API Key
7
- * https://www.google.com/recaptcha/admin/create
8
- * - Discussion group
9
- * http://groups.google.com/group/recaptcha
10
- *
11
- * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
12
- * AUTHORS:
13
- * Mike Crawford
14
- * Ben Maurer
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in
24
- * all copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
- * THE SOFTWARE.
33
- */
34
-
35
- /**
36
- * The reCAPTCHA server URL's
37
- */
38
- define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
39
- define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
40
- define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
41
-
42
- /**
43
- * Encodes the given data into a query string format
44
- * @param $data - array of string elements to be encoded
45
- * @return string - encoded request
46
- */
47
- function _recaptcha_qsencode ($data) {
48
- $req = "";
49
- foreach ( $data as $key => $value )
50
- $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
51
-
52
- // Cut the last '&'
53
- $req=substr($req,0,strlen($req)-1);
54
- return $req;
55
- }
56
-
57
-
58
-
59
- /**
60
- * Submits an HTTP POST to a reCAPTCHA server
61
- * @param string $host
62
- * @param string $path
63
- * @param array $data
64
- * @param int port
65
- * @return array response
66
- */
67
- function _recaptcha_http_post($host, $path, $data, $port = 80) {
68
-
69
- $req = _recaptcha_qsencode ($data);
70
-
71
- $http_request = "POST $path HTTP/1.0\r\n";
72
- $http_request .= "Host: $host\r\n";
73
- $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
74
- $http_request .= "Content-Length: " . strlen($req) . "\r\n";
75
- $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
76
- $http_request .= "\r\n";
77
- $http_request .= $req;
78
-
79
- $response = '';
80
- if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
81
- die ('Could not open socket');
82
- }
83
-
84
- fwrite($fs, $http_request);
85
-
86
- while ( !feof($fs) )
87
- $response .= fgets($fs, 1160); // One TCP-IP packet
88
- fclose($fs);
89
- $response = explode("\r\n\r\n", $response, 2);
90
-
91
- return $response;
92
- }
93
-
94
-
95
-
96
- /**
97
- * Gets the challenge HTML (javascript and non-javascript version).
98
- * This is called from the browser, and the resulting reCAPTCHA HTML widget
99
- * is embedded within the HTML form it was called from.
100
- * @param string $pubkey A public key for reCAPTCHA
101
- * @param string $error The error given by reCAPTCHA (optional, default is null)
102
- * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
103
-
104
- * @return string - The HTML to be embedded in the user's form.
105
- */
106
- function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
107
- {
108
- if ($pubkey == null || $pubkey == '') {
109
- die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
110
- }
111
-
112
- if ($use_ssl) {
113
- $server = RECAPTCHA_API_SECURE_SERVER;
114
- } else {
115
- $server = RECAPTCHA_API_SERVER;
116
- }
117
-
118
- $errorpart = "";
119
- if ($error) {
120
- $errorpart = "&amp;error=" . $error;
121
- }
122
- return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
123
-
124
- <noscript>
125
- <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
126
- <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
127
- <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
128
- </noscript>';
129
- }
130
-
131
-
132
-
133
-
134
- /**
135
- * A ReCaptchaResponse is returned from recaptcha_check_answer()
136
- */
137
- class ReCaptchaResponse {
138
- var $is_valid;
139
- var $error;
140
- }
141
-
142
-
143
- /**
144
- * Calls an HTTP POST function to verify if the user's guess was correct
145
- * @param string $privkey
146
- * @param string $remoteip
147
- * @param string $challenge
148
- * @param string $response
149
- * @param array $extra_params an array of extra variables to post to the server
150
- * @return ReCaptchaResponse
151
- */
152
- function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
153
- {
154
- if ($privkey == null || $privkey == '') {
155
- die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
156
- }
157
-
158
- if ($remoteip == null || $remoteip == '') {
159
- die ("For security reasons, you must pass the remote ip to reCAPTCHA");
160
- }
161
-
162
-
163
-
164
- //discard spam submissions
165
- if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
166
- $recaptcha_response = new ReCaptchaResponse();
167
- $recaptcha_response->is_valid = false;
168
- $recaptcha_response->error = 'incorrect-captcha-sol';
169
- return $recaptcha_response;
170
- }
171
-
172
- $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
173
- array (
174
- 'privatekey' => $privkey,
175
- 'remoteip' => $remoteip,
176
- 'challenge' => $challenge,
177
- 'response' => $response
178
- ) + $extra_params
179
- );
180
-
181
- $answers = explode ("\n", $response [1]);
182
- $recaptcha_response = new ReCaptchaResponse();
183
-
184
- if (trim ($answers [0]) == 'true') {
185
- $recaptcha_response->is_valid = true;
186
- }
187
- else {
188
- $recaptcha_response->is_valid = false;
189
- $recaptcha_response->error = $answers [1];
190
- }
191
- return $recaptcha_response;
192
-
193
- }
194
-
195
- /**
196
- * gets a URL where the user can sign up for reCAPTCHA. If your application
197
- * has a configuration page where you enter a key, you should provide a link
198
- * using this function.
199
- * @param string $domain The domain where the page is hosted
200
- * @param string $appname The name of your application
201
- */
202
- function recaptcha_get_signup_url ($domain = null, $appname = null) {
203
- return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
204
- }
205
-
206
- function _recaptcha_aes_pad($val) {
207
- $block_size = 16;
208
- $numpad = $block_size - (strlen ($val) % $block_size);
209
- return str_pad($val, strlen ($val) + $numpad, chr($numpad));
210
- }
211
-
212
- /* Mailhide related code */
213
-
214
- function _recaptcha_aes_encrypt($val,$ky) {
215
- if (! function_exists ("mcrypt_encrypt")) {
216
- die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
217
- }
218
- $mode=MCRYPT_MODE_CBC;
219
- $enc=MCRYPT_RIJNDAEL_128;
220
- $val=_recaptcha_aes_pad($val);
221
- return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
222
- }
223
-
224
-
225
- function _recaptcha_mailhide_urlbase64 ($x) {
226
- return strtr(base64_encode ($x), '+/', '-_');
227
- }
228
-
229
- /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
230
- function recaptcha_mailhide_url($pubkey, $privkey, $email) {
231
- if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
232
- die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
233
- "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
234
- }
235
-
236
-
237
- $ky = pack('H*', $privkey);
238
- $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
239
-
240
- return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
241
- }
242
-
243
- /**
244
- * gets the parts of the email to expose to the user.
245
- * eg, given johndoe@example,com return ["john", "example.com"].
246
- * the email is then displayed as john...@example.com
247
- */
248
- function _recaptcha_mailhide_email_parts ($email) {
249
- $arr = preg_split("/@/", $email );
250
-
251
- if (strlen ($arr[0]) <= 4) {
252
- $arr[0] = substr ($arr[0], 0, 1);
253
- } else if (strlen ($arr[0]) <= 6) {
254
- $arr[0] = substr ($arr[0], 0, 3);
255
- } else {
256
- $arr[0] = substr ($arr[0], 0, 4);
257
- }
258
- return $arr;
259
- }
260
-
261
- /**
262
- * Gets html to display an email address given a public an private key.
263
- * to get a key, go to:
264
- *
265
- * http://www.google.com/recaptcha/mailhide/apikey
266
- */
267
- function recaptcha_mailhide_html($pubkey, $privkey, $email) {
268
- $emailparts = _recaptcha_mailhide_email_parts ($email);
269
- $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
270
-
271
- return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
272
- "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
273
-
274
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-entries/_sidebar-shared-pub.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! isset( $entry) ) {
3
+ $entry = $record;
4
+ } ?>
5
+
6
+ <div class="misc-pub-section curtime misc-pub-curtime">
7
+ <span id="timestamp">
8
+ <?php
9
+ $datef = __( 'M j, Y @ G:i' );
10
+ printf(__('Published on: <b>%1$s</b>'), date_i18n( $datef, strtotime( $entry->created_at ) )); ?>
11
+ </span>
12
+ </div>
13
+ <?php if ( $entry->updated_at && $entry->updated_at != $entry->created_at ) { ?>
14
+ <div class="misc-pub-section curtime misc-pub-curtime">
15
+ <span id="timestamp">
16
+ <?php printf(__('Updated on: <b>%1$s</b>', 'formidable'), date_i18n( $datef, strtotime( $entry->updated_at ) )); ?>
17
+ </span>
18
+ </div>
19
+ <?php } ?>
20
+
21
+ <?php do_action('frm_entry_shared_sidebar', $entry); ?>
classes/views/frm-entries/direct.php CHANGED
@@ -2,16 +2,15 @@
2
  <html <?php language_attributes(); ?>>
3
  <head>
4
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
- <title><?php bloginfo('name'); ?></title>
6
- <?php wp_head();
7
- if(!$frm_vars['pro_is_installed']){ ?>
8
- <style type="text/css">.frm_forms.with_frm_style{max-width:750px;}</style>
9
- <?php } ?>
 
10
  </head>
11
  <body>
12
- <div style="padding:25px;">
13
  <?php echo FrmFormsController::show_form($form->id, '', true, true) ?>
14
- </div>
15
  <?php wp_footer(); ?>
16
  </body>
17
  </html>
2
  <html <?php language_attributes(); ?>>
3
  <head>
4
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
+ <?php wp_head(); ?>
7
+ <style type="text/css">
8
+ body:before{content:normal !important;}
9
+ body{padding:25px;}
10
+ </style>
11
  </head>
12
  <body>
 
13
  <?php echo FrmFormsController::show_form($form->id, '', true, true) ?>
 
14
  <?php wp_footer(); ?>
15
  </body>
16
  </html>
classes/views/frm-entries/errors.php CHANGED
@@ -1,35 +1,39 @@
1
- <?php global $frm_settings;
2
- if (isset($message) && $message != ''){
3
- if(is_admin() and !defined('DOING_AJAX')){
4
- ?><div id="message" class="frm_message updated" style="padding:5px;"><?php echo $message ?></div><?php
5
- }else{
6
- ?><script type="text/javascript">jQuery(document).ready(function($){frmScrollMsg(<?php echo $form->id ?>);})</script><?php
7
- echo $message;
 
 
 
 
8
  }
9
- }
10
 
11
  if( isset($errors) && is_array($errors) && !empty($errors) ){
12
- global $frm_settings;
13
 
14
- if ( isset($form) && is_object($form) ) { ?>
15
- <script type="text/javascript">jQuery(document).ready(function($){frmScrollMsg(<?php echo $form->id ?>);})</script>
16
- <?php } ?>
17
- <div class="frm_error_style">
18
  <?php
19
  $img = '';
20
- if(!is_admin() or defined('DOING_AJAX')){
21
  $img = apply_filters('frm_error_icon', $img);
22
- if($img and !empty($img)){
23
  ?><img src="<?php echo $img ?>" alt="" />
24
- <?php
25
  }
26
- }
27
-
 
28
  if(empty($frm_settings->invalid_msg)){
29
  $show_img = false;
30
  foreach( $errors as $error ){
31
- if($show_img and !empty($img)){
32
- ?><img src="<?php echo $img ?>" alt="" /><?php
33
  }else{
34
  $show_img = true;
35
  }
@@ -40,12 +44,13 @@ if(empty($frm_settings->invalid_msg)){
40
 
41
  $show_img = true;
42
  foreach( $errors as $err_key => $error ){
43
- if(!is_numeric($err_key) and ($err_key == 'cptch_number' or strpos($err_key, 'field') === 0 or strpos($err_key, 'captcha') === 0 ))
44
  continue;
45
-
46
- echo '<br/>';
47
- if($show_img and !empty($img)){
48
- ?><img src="<?php echo $img ?>" alt="" /><?php
 
49
  }else{
50
  $show_img = true;
51
  }
@@ -53,4 +58,10 @@ if(empty($frm_settings->invalid_msg)){
53
  }
54
  } ?>
55
  </div>
56
- <?php } ?>
 
 
 
 
 
 
1
+ <?php
2
+ if ( isset($include_extra_container) ) { ?>
3
+ <div class="<?php echo $include_extra_container ?>" id="frm_form_<?php echo $form->id ?>_container">
4
+ <?php
5
+ }
6
+ if (isset($message) && $message != ''){
7
+ if ( FrmAppHelper::is_admin() ) {
8
+ ?><div id="message" class="frm_message updated" style="padding:5px;"><?php echo $message ?></div><?php
9
+ }else{
10
+ FrmFormsHelper::get_scroll_js($form->id);
11
+ echo $message;
12
  }
13
+ }
14
 
15
  if( isset($errors) && is_array($errors) && !empty($errors) ){
 
16
 
17
+ if ( isset($form) && is_object($form) ) {
18
+ FrmFormsHelper::get_scroll_js($form->id);
19
+ } ?>
20
+ <div class="frm_error_style">
21
  <?php
22
  $img = '';
23
+ if ( ! FrmAppHelper::is_admin() ) {
24
  $img = apply_filters('frm_error_icon', $img);
25
+ if ( $img && ! empty($img) ) {
26
  ?><img src="<?php echo $img ?>" alt="" />
27
+ <?php
28
  }
29
+ }
30
+
31
+ $frm_settings = FrmAppHelper::get_settings();
32
  if(empty($frm_settings->invalid_msg)){
33
  $show_img = false;
34
  foreach( $errors as $error ){
35
+ if ( $show_img && ! empty($img) ) {
36
+ ?><img src="<?php echo $img ?>" alt="" /><?php
37
  }else{
38
  $show_img = true;
39
  }
44
 
45
  $show_img = true;
46
  foreach( $errors as $err_key => $error ){
47
+ if ( ! is_numeric($err_key) && ( $err_key == 'cptch_number' || strpos($err_key, 'field') === 0 ) ) {
48
  continue;
49
+ }
50
+
51
+ echo '<br/>';
52
+ if ( $show_img && ! empty($img) ) {
53
+ ?><img src="<?php echo $img ?>" alt="" /><?php
54
  }else{
55
  $show_img = true;
56
  }
58
  }
59
  } ?>
60
  </div>
61
+ <?php
62
+ }
63
+
64
+ if ( isset($include_extra_container) ) { ?>
65
+ </div>
66
+ <?php
67
+ } ?>
classes/views/frm-entries/form.php CHANGED
@@ -1,21 +1,14 @@
1
- <?php
2
- global $frm_vars, $frm_settings;
3
- FrmFormsHelper::form_loaded($form);
4
- if($values['custom_style']) $frm_vars['load_css'] = true;
5
-
6
- if((!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css']){
7
- echo FrmAppController::footer_js('header');
8
- $frm_vars['css_loaded'] = true;
9
- }
10
 
11
  echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $description); ?>
12
  <div class="frm_form_fields <?php echo apply_filters('frm_form_fields_class', '', $values); ?>">
13
  <fieldset>
14
- <div>
15
  <input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" />
16
  <input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" />
17
  <input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" />
18
- <?php wp_nonce_field('frm_submit_entry_nonce', 'frm_submit_entry'); ?>
19
 
20
  <?php if (isset($id)){ ?><input type="hidden" name="id" value="<?php echo esc_attr($id) ?>" /><?php } ?>
21
  <?php if (isset($controller) && isset($plugin)){ ?>
@@ -25,19 +18,19 @@ echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $
25
 
26
  if($values['fields']){
27
  foreach($values['fields'] as $field){
28
- $field_name = 'item_meta['. $field['id'] .']';
29
  if (apply_filters('frm_show_normal_field_type', true, $field['type']))
30
  echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form);
31
  else
32
  do_action('frm_show_other_field_type', $field, $form, array('action' => $form_action));
33
-
34
  do_action('frm_get_field_scripts', $field, $form);
35
- }
36
  }
37
 
38
- if ((is_admin() and !defined('DOING_AJAX')) and !$frm_settings->lock_keys){ ?>
 
39
  <div class="frm_form_field form-field">
40
- <label class="frm_primary_label"><?php _e('Entry Key', 'formidable') ?></label>
41
  <input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" />
42
  </div>
43
  <?php }else{ ?>
@@ -47,22 +40,24 @@ if ((is_admin() and !defined('DOING_AJAX')) and !$frm_settings->lock_keys){ ?>
47
  do_action('frm_entry_form', $form, $form_action, $errors);
48
 
49
  global $frm_vars;
50
- if(isset($frm_vars['div']) and $frm_vars['div']){
51
  echo "</div>\n";
52
- $frm_vars['div'] = false;
53
- } ?>
54
- </div>
55
- </fieldset>
56
- </div>
57
- <?php echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form);
58
 
59
- global $wp_filter;
60
- if(isset($wp_filter['frm_entries_footer_scripts']) and !empty($wp_filter['frm_entries_footer_scripts'])){ ?>
61
  <script type="text/javascript">
62
  <?php do_action('frm_entries_footer_scripts', $values['fields'], $form); ?>
63
- </script><?php }
 
64
 
65
- if ( !$form->is_template && $form->status == 'published' && (!is_admin() || defined('DOING_AJAX')) ) {
66
  unset($values['fields']);
67
  FrmFormsHelper::get_custom_submit($values['submit_html'], $form, $submit, $form_action, $values);
68
  }
 
 
 
1
+ <?php
2
+ global $frm_vars;
3
+ FrmFormsHelper::form_loaded($form, $values['custom_style'], $frm_vars['load_css']);
 
 
 
 
 
 
4
 
5
  echo FrmFormsHelper::replace_shortcodes($values['before_html'], $form, $title, $description); ?>
6
  <div class="frm_form_fields <?php echo apply_filters('frm_form_fields_class', '', $values); ?>">
7
  <fieldset>
 
8
  <input type="hidden" name="frm_action" value="<?php echo esc_attr($form_action) ?>" />
9
  <input type="hidden" name="form_id" value="<?php echo esc_attr($form->id) ?>" />
10
  <input type="hidden" name="form_key" value="<?php echo esc_attr($form->form_key) ?>" />
11
+ <?php wp_nonce_field('frm_submit_entry_nonce', 'frm_submit_entry_'. $form->id); ?>
12
 
13
  <?php if (isset($id)){ ?><input type="hidden" name="id" value="<?php echo esc_attr($id) ?>" /><?php } ?>
14
  <?php if (isset($controller) && isset($plugin)){ ?>
18
 
19
  if($values['fields']){
20
  foreach($values['fields'] as $field){
 
21
  if (apply_filters('frm_show_normal_field_type', true, $field['type']))
22
  echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form);
23
  else
24
  do_action('frm_show_other_field_type', $field, $form, array('action' => $form_action));
25
+
26
  do_action('frm_get_field_scripts', $field, $form);
27
+ }
28
  }
29
 
30
+ $frm_settings = FrmAppHelper::get_settings();
31
+ if ( FrmAppHelper::is_admin() && ! $frm_settings->lock_keys ) { ?>
32
  <div class="frm_form_field form-field">
33
+ <label class="frm_primary_label"><?php _e('Entry Key', 'formidable') ?></label>
34
  <input type="text" name="item_key" value="<?php echo esc_attr($values['item_key']) ?>" />
35
  </div>
36
  <?php }else{ ?>
40
  do_action('frm_entry_form', $form, $form_action, $errors);
41
 
42
  global $frm_vars;
43
+ if ( isset($frm_vars['div']) && $frm_vars['div'] ) {
44
  echo "</div>\n";
45
+ unset($frm_vars['div']);
46
+ }
47
+
48
+ echo FrmFormsHelper::replace_shortcodes($values['after_html'], $form);
 
 
49
 
50
+
51
+ if ( has_action('frm_entries_footer_scripts') ) { ?>
52
  <script type="text/javascript">
53
  <?php do_action('frm_entries_footer_scripts', $values['fields'], $form); ?>
54
+ </script><?php
55
+ }
56
 
57
+ if ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ) {
58
  unset($values['fields']);
59
  FrmFormsHelper::get_custom_submit($values['submit_html'], $form, $submit, $form_action, $values);
60
  }
61
+ ?>
62
+ </fieldset>
63
+ </div>
classes/views/frm-entries/frm-entry.php DELETED
@@ -1,52 +0,0 @@
1
- <?php
2
-
3
- if ( $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST ) {
4
-
5
- if ( !empty($errors) ) {
6
- $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
7
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
8
- return;
9
- }
10
-
11
- do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
12
- if ( !apply_filters('frm_continue_to_create', true, $form->id) ) {
13
- return;
14
- }
15
-
16
- $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
17
- $created = (isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id])) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
18
- $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
19
-
20
- if ( !$created || !is_numeric($created) || $conf_method == 'message' ) {
21
- $saved_message = apply_filters('frm_content', $saved_message, $form, $created);
22
- $message = ($created && is_numeric($created)) ? '<div class="frm_message" id="message">'. wpautop(do_shortcode($saved_message)) .'</div>' : '<div class="frm_error_style">'. $frm_settings->failed_msg .'</div>';
23
-
24
- if ( !isset($form->options['show_form']) || $form->options['show_form'] ) {
25
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
26
- } else {
27
- global $frm_vars;
28
- FrmFormsHelper::form_loaded($form);
29
- if ( $values['custom_style'] ) {
30
- $frm_vars['load_css'] = true;
31
- }
32
-
33
- if ( (!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css'] ) {
34
- echo FrmAppController::footer_js('header');
35
- $frm_vars['css_loaded'] = true;
36
- }
37
- ?>
38
- <div class="frm_forms<?php echo ($values['custom_style']) ? ' with_frm_style' : ''; ?>" id="frm_form_<?php echo $form->id ?>_container"><?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php') ?></div>
39
- <?php
40
- }
41
- } else {
42
- do_action('frm_success_action', $conf_method, $form, $form->options, $created);
43
- }
44
-
45
- do_action('frm_after_entry_processed', array( 'entry_id' => $created, 'form' => $form));
46
- }else{
47
- do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
48
- if (apply_filters('frm_continue_to_new', true, $form->id, $params['action'])){
49
- $values = FrmEntriesHelper::setup_new_vars($fields, $form);
50
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/new.php');
51
- }
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-entries/list.php CHANGED
@@ -1,31 +1,34 @@
1
  <div id="form_entries_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2>
4
- <?php _e('Entries', 'formidable'); ?>
5
- <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
- </h2>
7
 
8
- <?php if($form) FrmAppController::get_form_nav($form->id, true); ?>
9
-
10
- <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
11
- <?php FrmAppController::update_message('view, search, export, and bulk delete your saved entries'); ?>
12
 
13
- <?php if(!$form or $entry_count){ ?>
14
- <img src="<?php echo FrmAppHelper::plugin_url() ?>/screenshot-5.png" alt="Entries List" style="max-width:100%"/>
15
- <?php }else{ ?>
16
- <table class="wp-list-table widefat post fixed" cellspacing="0">
17
- <thead>
18
- <tr><th class="manage-column" scope="col"> </th></tr>
19
- </thead>
20
- <tbody>
21
- <tr><td>
22
- <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/no_entries.php'); ?>
23
- </td></tr>
24
- </tbody>
25
- <tfoot>
26
- <tr><th class="manage-column" scope="col"> </th></tr>
27
- </tfoot>
28
- </table>
29
- <?php } ?>
30
- </div>
 
 
 
31
 
 
 
 
 
1
  <div id="form_entries_page" class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2><?php _e('Entries', 'formidable'); ?>
4
+ <?php do_action('frm_entry_inside_h2', $form); ?>
5
+ </h2>
 
6
 
7
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
 
 
 
8
 
9
+ <form id="posts-filter" method="get">
10
+ <div id="poststuff">
11
+ <div id="post-body" class="metabox-holder columns-2">
12
+ <div id="post-body-content">
13
+ <?php FrmAppController::get_form_nav($form, true, 'hide'); ?>
14
+ </div>
15
+ <div id="postbox-container-1" class="postbox-container">
16
+ <input type="hidden" name="page" value="formidable-entries" />
17
+ <input type="hidden" name="form" value="<?php echo ($form) ? $form->id : ''; ?>" />
18
+ <input type="hidden" name="frm_action" value="list" />
19
+ <?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' ); ?>
20
+ </div>
21
+ <div class="clear"></div>
22
+ </div>
23
+ <?php if ( $form ) { ?>
24
+ <div id="titlediv">
25
+ <input id="title" type="text" value="<?php echo esc_attr($form->name == '' ? __('(no title)') : $form->name) ?>" readonly="readonly" disabled="disabled" />
26
+ </div>
27
+ <?php } ?>
28
+
29
+ <?php $wp_list_table->display(); ?>
30
 
31
+ </div>
32
+ </form>
33
+
34
+ </div>
classes/views/frm-entries/new.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
- if(empty($values) or !isset($values['fields']) or empty($values['fields'])){ ?>
3
- <div class="frm_forms with_frm_style" id="frm_form_<?php echo $form->id ?>_container">
4
  <div class="frm_error_style"><strong><?php _e('Oops!', 'formidable') ?></strong> <?php printf(__('You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable'), '<a href="'. admin_url('?page=formidable&frm_action=edit&id='. $form->id) .'">', '</a>') ?>
5
  </div>
6
- </div>
7
  <?php
8
  return;
9
  } ?>
10
- <div class="frm_forms<?php echo ($values['custom_style']) ? ' with_frm_style' : ''; ?>" id="frm_form_<?php echo $form->id ?>_container">
11
- <form enctype="<?php echo apply_filters('frm_form_enctype', 'multipart/form-data', $form) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo $form->form_key ?>" <?php echo ($frm_settings->use_html) ? '' : 'action=""'; ?>>
12
- <?php
13
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
14
  $form_action = 'create';
15
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/form.php');
16
  ?>
17
  </form>
18
  </div>
1
  <?php
2
+ if ( empty($values) || ! isset($values['fields']) || empty($values['fields']) ) { ?>
3
+ <div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($form); ?>" id="frm_form_<?php echo $form->id ?>_container">
4
  <div class="frm_error_style"><strong><?php _e('Oops!', 'formidable') ?></strong> <?php printf(__('You did not add any fields to your form. %1$sGo back%2$s and add some.', 'formidable'), '<a href="'. admin_url('?page=formidable&frm_action=edit&id='. $form->id) .'">', '</a>') ?>
5
  </div>
6
+ </div>
7
  <?php
8
  return;
9
  } ?>
10
+ <div class="frm_forms <?php echo FrmFormsHelper::get_form_style_class($values); ?>" id="frm_form_<?php echo $form->id ?>_container">
11
+ <form enctype="<?php echo apply_filters('frm_form_enctype', 'multipart/form-data', $form) ?>" method="post" class="frm-show-form <?php do_action('frm_form_classes', $form) ?>" id="form_<?php echo $form->form_key ?>" <?php echo $frm_settings->use_html ? '' : 'action=""'; ?>>
12
+ <?php
13
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/errors.php');
14
  $form_action = 'create';
15
+ require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/form.php');
16
  ?>
17
  </form>
18
  </div>
classes/views/frm-entries/no_entries.php CHANGED
@@ -1,48 +1,18 @@
1
- <?php
2
- if(!isset($colspan))
3
- $colspan = (isset($form_cols)) ? count($form_cols)+1 : '';
4
-
5
- $form->options = maybe_unserialize($form->options);
6
-
7
- if(isset($form->options['no_save']) and $form->options['no_save']){ ?>
8
  <h3><?php _e('This form is not set to save any entries.', 'formidable') ?></h3>
9
- <p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=settings&id='. $form->id) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p>
10
- <?php
11
- }else{
12
  ?>
13
- <h3><?php _e("You don't have any entries in this form.", 'formidable') ?><br/> <?php _e('How to publish', 'formidable') ?>:</h3>
14
- </td></tr>
15
- <tr class="alternate"><td colspan="<?php echo $colspan ?>">
16
- <h3><?php _e('Option 1: Generate your shortcode', 'formidable') ?></h3>
17
- <ol>
18
- <li><?php _e('Go to your WordPress page or post.', 'formidable') ?></li>
19
- <li>
20
- <?php _e('Click on the "Add Form" button above the content box.', 'formidable') ?><br/>
21
- <img alt="" src="http://static.strategy11.com.s3.amazonaws.com/insert-shortcode-icon.png">
22
- </li>
23
- <li><?php _e('Select your form from the dropdown and check the boxes to show the title and description if desired.', 'formidable') ?></li>
24
- <li><?php _e('Click the "Insert Form" button.', 'formidable') ?></li>
25
- </ol>
26
- </td></tr>
27
- <tr><td colspan="<?php echo $colspan ?>">
28
- <h3><?php _e('Option 2: Add a Widget', 'formidable') ?></h3>
29
- <ol class="alignleft" style="margin-right:30px;">
30
- <li><?php _e('Drag a "Formidable Form" widget into your sidebar.', 'formidable') ?></li>
31
- <li><?php _e('Select a form from the "Form" drop-down.', 'formidable') ?></li>
32
- <li><?php _e('Click the "Save" button', 'formidable') ?></li>
33
- </ol>
34
- <img src="<?php echo FrmAppHelper::plugin_url() ?>/screenshot-6.png" alt="<?php esc_attr_e('Formidable Form Widget', 'formidable') ?>" title="<?php esc_attr_e('Formidable Form Widget', 'formidable') ?>" height="261" width="252" />
35
- </td></tr>
36
- <tr class="alternate"><td colspan="<?php echo $colspan ?>">
37
- <h3><?php _e('Option 3: Insert the shortcode or PHP', 'formidable') ?></h3>
38
- <p><?php _e('Insert the following shortcode in your page, post, or text widget. This will be replaced with your form:', 'formidable') ?><br/>
39
- <input type="text" readonly="true" class="frm_select_box frm_no_items" value="[formidable id=<?php echo $form->id; ?>]" />
40
- </p>
41
- <p><?php _e('Show the form with the title and description:', 'formidable') ?><br/>
42
- <input type="text" readonly="true" class="frm_select_box frm_no_items" value="[formidable id=<?php echo $form->id; ?> title=true description=true]" />
43
- </p>
44
-
45
- <p><?php _e('Insert into a theme template file:', 'formidable') ?><br/>
46
- <input type="text" readonly="true" class="frm_select_box frm_no_items" value="echo FrmFormsController::show_form(<?php echo $form->id; ?>, $key='', $title=true, $description=true);" />
47
- </p>
48
- <?php } ?>
1
+ <div style="text-align:center;padding:60px 0;">
2
+ <?php
3
+ if ( $form && isset($form->options['no_save']) && $form->options['no_save'] ) { ?>
 
 
 
 
4
  <h3><?php _e('This form is not set to save any entries.', 'formidable') ?></h3>
5
+ <p>If you would like entries in this form to be saved, go to the <a href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=settings&id='. $form->id) ?>">form Settings</a> page and uncheck the "Do not store any entries submitted from this form" box.</p>
6
+ <?php
7
+ } else if ( $form ) {
8
  ?>
9
+ <div style="font-size:20px;margin-bottom:10px;"><?php printf(__('No Entries for form: %s', 'formidable'), $form->name); ?></div>
10
+ <p style="line-height:200%;"><?php printf( __('For instructions on publishing your form see %1$sthis page%2$s <br/> or click "%3$sAdd New%4$s" above to add an entry from here (Requires License)', 'formidable'), '<a href="https://formidablepro.com/knowledgebase/publish-your-forms/" target="_blank">', '</a>', '<a href="'. admin_url('admin.php?page=formidable-entries&frm_action=new&form='. $form->id) .'">', '</a>'); ?></p>
11
+ <?php
12
+ } else {
13
+ ?>
14
+ <div style="font-size:20px;margin-bottom:10px;"><?php _e('You have not created any forms yet.', 'formidable'); ?></div>
15
+ <p style="line-height:200%;"><?php printf( __('To view entries, you must first %1$sbuild a form%2$s', 'formidable'), '<a href="'. admin_url('admin.php?page=formidable&frm_action=new-selection') .'">', '</a>'); ?></p>
16
+ <?php
17
+ } ?>
18
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-entries/show.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="form_show_entry_page" class="wrap">
2
+ <div class="frmicon icon32"><br/></div>
3
+ <h2><?php _e('View Entry', 'formidable') ?>
4
+ <?php do_action('frm_entry_inside_h2', $entry->form_id); ?>
5
+ </h2>
6
+
7
+ <div class="frm_forms">
8
+
9
+ <div id="poststuff">
10
+ <div id="post-body" class="metabox-holder columns-2">
11
+ <div id="post-body-content">
12
+ <?php FrmAppController::get_form_nav($entry->form_id, true); ?>
13
+ <div class="postbox">
14
+ <h3 class="hndle"><span><?php _e('Entry', 'formidable') ?></span></h3>
15
+ <div class="inside">
16
+ <table class="form-table"><tbody>
17
+ <?php
18
+ $first_h3 = 'frm_first_h3';
19
+ $embedded_field_id = 0;
20
+ foreach ( $fields as $field ) {
21
+ if ( in_array($field->type, array('divider', 'end_divider')) ) {
22
+ $embedded_field_id = 0;
23
+ }
24
+
25
+ if ( in_array($field->type, array('captcha', 'html', 'end_divider')) ) {
26
+ continue;
27
+ }
28
+
29
+ if ( in_array($field->type, array('form', 'divider')) && isset($field->field_options['form_select']) && ! empty($field->field_options['form_select']) ) {
30
+ $embedded_field_id = $field->type == 'form' ? '' : 'form';
31
+ $embedded_field_id .= $field->field_options['form_select'];
32
+ }
33
+
34
+ if ( in_array($field->type, array('break', 'divider') ) ) {
35
+ ?>
36
+ </tbody></table>
37
+ <br/><h3 class="<?php echo $first_h3 ?>"><?php echo $field->name ?></h3>
38
+ <table class="form-table"><tbody>
39
+ <?php
40
+ $first_h3 = '';
41
+ } else {
42
+ ?>
43
+ <tr>
44
+ <th scope="row"><?php echo $field->name ?>:</th>
45
+ <td>
46
+ <?php
47
+ $atts = array(
48
+ 'type' => $field->type, 'post_id' => $entry->post_id,
49
+ 'show_filename' => true, 'show_icon' => true, 'entry_id' => $entry->id,
50
+ 'embedded_field_id' => $embedded_field_id,
51
+ );
52
+ echo $display_value = FrmEntriesHelper::prepare_display_value($entry, $field, $atts);
53
+
54
+ if ( is_email($display_value) && ! in_array($display_value, $to_emails) ) {
55
+ $to_emails[] = $display_value;
56
+ }
57
+ ?>
58
+ </td>
59
+ </tr>
60
+ <?php }
61
+ }
62
+
63
+ ?>
64
+
65
+ <?php if ( $entry->parent_item_id ) { ?>
66
+ <tr><th><?php _e('Parent Entry ID', 'formidable') ?>:</th>
67
+ <td><?php echo $entry->parent_item_id ?>
68
+ </td></tr>
69
+ <?php } ?>
70
+ </tbody></table>
71
+ <?php do_action('frm_show_entry', $entry); ?>
72
+ </div>
73
+ </div>
74
+
75
+ <?php do_action('frm_after_show_entry', $entry); ?>
76
+
77
+ </div>
78
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-show.php'); ?>
79
+ </div>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ <br/>
classes/views/frm-entries/sidebar-show.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="postbox-container-1" class="postbox-container">
2
+ <div id="submitdiv" class="postbox">
3
+ <h3 class="hndle"><span><?php _e('Entry Actions', 'formidable') ?></span></h3>
4
+ <div class="inside">
5
+ <div class="submitbox">
6
+ <div id="minor-publishing" style="border:none;">
7
+ <div class="misc-pub-section">
8
+ <?php do_action('frm_show_entry_publish_box', $entry); ?>
9
+ <div class="clear"></div>
10
+ </div>
11
+ <div id="misc-publishing-actions">
12
+ <?php include(dirname(__FILE__) .'/_sidebar-shared-pub.php'); ?>
13
+ <div class="misc-pub-section">
14
+ <span class="dashicons dashicons-format-aside wp-media-buttons-icon"></span>
15
+ <a href="#" onclick="window.print();return false;"><?php _e('Print', 'formidable') ?></a>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ <div id="major-publishing-actions">
20
+ <?php if ( current_user_can('frm_delete_entries') ) { ?>
21
+ <div id="delete-action">
22
+ <a href="?page=formidable-entries&amp;frm_action=destroy&amp;id=<?php echo $id; ?>&amp;form=<?php echo $entry->form_id ?>" class="submitdelete deletion" onclick="return confirm('<?php _e('Are you sure you want to delete that entry?', 'formidable') ?>');" title="<?php _e('Delete') ?>"><?php _e('Delete') ?></a>
23
+ <?php if ( ! empty($entry->post_id) ) { ?>
24
+ <a href="?page=formidable-entries&amp;frm_action=destroy&amp;id=<?php echo $id; ?>&amp;form=<?php echo $entry->form_id ?>&amp;keep_post=1" class="submitdelete deletion" style="margin-left:10px;" onclick="return confirm('<?php _e('Are you sure you want to delete this entry?', 'formidable') ?>);" title="<?php _e('Delete entry but leave the post', 'formidable') ?>"><?php _e('Delete without Post', 'formidable') ?></a>
25
+ <?php } ?>
26
+ </div>
27
+ <?php } ?>
28
+
29
+ <?php do_action('frm_entry_major_pub', $entry); ?>
30
+ <div class="clear"></div>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ <?php do_action('frm_show_entry_sidebar', $entry); ?>
36
+ </div>
classes/views/frm-fields/import_choices.php CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
  <title><?php bloginfo('name'); ?></title>
6
- <?php
7
  wp_admin_css( 'global' );
8
  wp_admin_css();
9
  wp_admin_css( 'colors' );
@@ -14,7 +14,7 @@
14
 
15
  do_action('admin_print_styles');
16
  do_action('admin_print_scripts');
17
-
18
  ?>
19
  <style type="text/css">
20
  #wpadminbar{display:none;}
@@ -51,26 +51,33 @@
51
  <p class="howto"><?php _e('Edit or add field options (one per line)', 'formidable') ?></p>
52
  <ul class="prepop">
53
  <?php foreach($prepop as $label => $pop){ ?>
54
- <li><a onclick='frmPrePop(<?php echo str_replace("'", '&#145;', json_encode($pop)) ?>); return false;'><?php echo $label ?></a></li>
55
  <?php } ?>
56
  </ul>
57
  <textarea name="frm_bulk_options" id="frm_bulk_options" style="height:240px;width:335px;float:right;">
58
- <?php foreach($field->options as $fopt){
59
- if(is_array($fopt)){
60
- $label = (isset($fopt['label'])) ? $fopt['label'] : reset($fopt);
61
- $value = (isset($fopt['value'])) ? $fopt['value'] : $label;
62
- if($label != $value and isset($field->field_options['separate_value']) and $field->field_options['separate_value'])
63
- echo "$label|$value\n";
64
- else
65
- echo $label ."\n";
66
- }else{
67
- echo $fopt ."\n";
68
- }
 
 
 
 
 
 
 
69
  } ?>
70
  </textarea>
71
 
72
  <p class="submit clear">
73
- <input type="button" onclick="window.top.frmUpdateOpts(<?php echo $field->id ?>,jQuery('#frm_bulk_options').val()); window.top.tb_remove();" class="button-primary" value="<?php _e('Update Field Choices', 'formidable') ?>" />
74
  </p>
75
  </div>
76
 
3
  <head>
4
  <meta charset="<?php bloginfo( 'charset' ); ?>" />
5
  <title><?php bloginfo('name'); ?></title>
6
+ <?php
7
  wp_admin_css( 'global' );
8
  wp_admin_css();
9
  wp_admin_css( 'colors' );
14
 
15
  do_action('admin_print_styles');
16
  do_action('admin_print_scripts');
17
+
18
  ?>
19
  <style type="text/css">
20
  #wpadminbar{display:none;}
51
  <p class="howto"><?php _e('Edit or add field options (one per line)', 'formidable') ?></p>
52
  <ul class="prepop">
53
  <?php foreach($prepop as $label => $pop){ ?>
54
+ <li><a href="javascript:void(0)" onclick='frmPrePop(<?php echo str_replace("'", '&#145;', json_encode($pop)) ?>); return false;'><?php echo $label ?></a></li>
55
  <?php } ?>
56
  </ul>
57
  <textarea name="frm_bulk_options" id="frm_bulk_options" style="height:240px;width:335px;float:right;">
58
+ <?php
59
+ $other_array = array();
60
+ foreach($field->options as $fkey => $fopt){
61
+ //If it is an other option, don't include it
62
+ if ( $fkey && strpos( $fkey, 'other') !== false ) {
63
+ continue;
64
+ }
65
+ if(is_array($fopt)){
66
+ $label = (isset($fopt['label'])) ? $fopt['label'] : reset($fopt);
67
+ $value = (isset($fopt['value'])) ? $fopt['value'] : $label;
68
+ if ( $label != $value && isset($field->field_options['separate_value']) && $field->field_options['separate_value'] ) {
69
+ echo "$label|$value\n";
70
+ } else{
71
+ echo $label ."\n";
72
+ }
73
+ }else{
74
+ echo $fopt ."\n";
75
+ }
76
  } ?>
77
  </textarea>
78
 
79
  <p class="submit clear">
80
+ <input type="button" onclick="window.top.frmAdminBuild.updateOpts(<?php echo $field->id ?>,document.getElementById('frm_bulk_options').value); window.top.tb_remove();" class="button-primary" value="<?php _e('Update Field Choices', 'formidable') ?>" />
81
  </p>
82
  </div>
83
 
classes/views/frm-fields/input.php CHANGED
@@ -1,48 +1,92 @@
1
- <?php if ($field['type'] == 'text'){ ?>
2
- <input type="text" id="field_<?php echo $field['field_key'] ?>" name="<?php echo $field_name ?>" value="<?php echo esc_attr($field['value']) ?>" <?php do_action('frm_field_input_html', $field) ?>/>
3
  <?php }else if ($field['type'] == 'textarea'){ ?>
4
- <textarea name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>"<?php if($field['size']) echo ' cols="'. $field['size'].'"'; if($field['max']) echo ' rows="'. $field['max'] .'"'; ?> <?php do_action('frm_field_input_html', $field) ?>><?php echo FrmAppHelper::esc_textarea($field['value']) ?></textarea>
5
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- }else if ($field['type'] == 'radio'){
8
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
9
  do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
10
  } else if ( is_array($field['options']) ) {
11
  foreach ( $field['options'] as $opt_key => $opt ) {
12
- if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
13
  continue;
14
  }
15
-
16
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
17
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
18
  ?>
19
  <div class="<?php echo apply_filters('frm_radio_class', 'frm_radio', $field, $field_val)?>"><?php
20
 
21
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
22
- ?><label for="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>"><?php
23
  }
24
-
25
- ?><input type="radio" name="<?php echo $field_name ?>" id="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php echo (FrmAppHelper::check_selected($field['value'], $field_val)) ? 'checked="checked"' : ''; ?> <?php do_action('frm_field_input_html', $field) ?>/><?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
28
  echo ' '. $opt .'</label>';
29
- }
 
 
 
 
 
30
  ?></div>
31
  <?php
32
  }
33
  }
34
 
35
- }else if ($field['type'] == 'select'){
36
- if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
37
  echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
38
- }else{
39
- if ( isset($field['read_only']) && $field['read_only'] && (!isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && (!is_admin() || defined('DOING_AJAX')) ) { ?>
40
- <input type="hidden" value="<?php echo esc_attr($field['value']) ?>" name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" />
41
  <select disabled="disabled" <?php do_action('frm_field_input_html', $field) ?>>
42
- <?php }else{ ?>
43
- <select name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" <?php do_action('frm_field_input_html', $field) ?>>
44
- <?php }
45
- foreach ($field['options'] as $opt_key => $opt){
46
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
47
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?>
48
  <option value="<?php echo esc_attr($field_val) ?>" <?php
@@ -53,53 +97,79 @@ if (FrmAppHelper::check_selected($field['value'], $field_val)) echo ' selected="
53
 
54
  }else if ($field['type'] == 'checkbox'){
55
  $checked_values = $field['value'];
56
-
57
- if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
 
 
 
 
 
 
 
 
 
 
 
 
58
  do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
59
  } else if ( $field['options'] ) {
60
  foreach ( $field['options'] as $opt_key => $opt ) {
61
  if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
62
  continue;
63
  }
64
-
65
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
66
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
67
  $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
68
-
69
  ?>
70
  <div class="<?php echo apply_filters('frm_checkbox_class', 'frm_checkbox', $field, $field_val) ?>" id="frm_checkbox_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php
71
 
72
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
73
- ?><label for="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>"><?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
-
76
- ?><input type="checkbox" name="<?php echo $field_name ?>[]" id="field_<?php echo $field['id'] ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php
77
-
78
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
79
  echo ' '. $opt .'</label>';
80
  }
81
-
 
 
 
 
 
 
82
  ?></div>
83
  <?php
84
  }
85
  }
86
 
87
- } else if ( $field['type'] == 'captcha' && (!is_admin() || defined('DOING_AJAX')) ) {
88
- global $frm_settings;
89
- $error_msg = null;
90
-
91
- if ( !empty($errors) ) {
92
- foreach ( $errors as $error_key => $error ) {
93
- if ( strpos($error_key, 'captcha-') === 0 ) {
94
- $error_msg = preg_replace('/^captcha-/', '', $error_key);
95
- }
96
- unset($error);
97
- }
98
- }
99
-
100
- if ( !empty($frm_settings->pubkey) ) {
101
- FrmFieldsHelper::display_recaptcha($field, $error_msg);
102
  }
103
  } else {
104
- do_action('frm_form_fields', $field, $field_name);
105
  }
1
+ <?php if ( in_array($field['type'], array('email', 'url', 'text')) ) { ?>
2
+ <input type="<?php echo ( $frm_settings->use_html || $field['type'] == 'password' ) ? $field['type'] : 'text'; ?>" id="<?php echo $html_id ?>" name="<?php echo $field_name ?>" value="<?php echo esc_attr($field['value']) ?>" <?php do_action('frm_field_input_html', $field) ?>/>
3
  <?php }else if ($field['type'] == 'textarea'){ ?>
4
+ <textarea name="<?php echo $field_name ?>" id="<?php echo $html_id ?>" <?php
5
+ if ( $field['max'] ) {
6
+ echo 'rows="'. $field['max'] .'" ';
7
+ }
8
+ do_action('frm_field_input_html', $field);
9
+ ?>><?php echo FrmAppHelper::esc_textarea($field['value']) ?></textarea>
10
+ <?php
11
+
12
+ } else if ( $field['type'] == 'radio' ) {
13
+ if ( isset($field['read_only']) && $field['read_only'] && ( ! isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) {
14
+ ?>
15
+ <input type="hidden" value="<?php echo esc_attr($field['value']) ?>" name="<?php echo $field_name ?>" />
16
+ <?php
17
+ }
18
 
 
19
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
20
  do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
21
  } else if ( is_array($field['options']) ) {
22
  foreach ( $field['options'] as $opt_key => $opt ) {
23
+ if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key)) {
24
  continue;
25
  }
26
+
27
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
28
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
29
  ?>
30
  <div class="<?php echo apply_filters('frm_radio_class', 'frm_radio', $field, $field_val)?>"><?php
31
 
32
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
33
+ ?><label for="<?php echo $html_id ?>-<?php echo $opt_key ?>"><?php
34
  }
35
+
36
+ $checked = FrmAppHelper::check_selected($field['value'], $field_val) ? 'checked="checked" ' : ' ';
37
+
38
+ //Check if this is an "Other" option
39
+ if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
40
+ $other_opt = true;
41
+
42
+ //Set field value to blank for radio buttons so this value is not saved
43
+ $field_val = '';
44
+
45
+ //Check if field value equals any of the options. If it does not match any options, put it in the other text field.
46
+ $other_val = FrmAppHelper::check_other_selected( $field['value'], $field['options'], $field['type'] );
47
+ if ( $other_val ) {
48
+ $checked = 'checked="checked" ';
49
+ }
50
+
51
+ //Set up name for other field
52
+ $other_name = preg_replace('/\[' . $field['id'] . '\]$/', '', $field_name);
53
+ $other_name = $other_name . '[other]' . '[' . $field['id'] . ']';
54
+ //Converts item_meta[field_id] => item_meta[other][field_id] and
55
+ //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
56
+ //What if section number and field ID are same
57
+ } else {
58
+ $other_opt = false;
59
+ } ?>
60
+
61
+ <input type="radio" name="<?php echo $field_name ?>" id="<?php echo $html_id ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php
62
+ echo $checked;
63
+ do_action('frm_field_input_html', $field);
64
+ ?>/><?php
65
 
66
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
67
  echo ' '. $opt .'</label>';
68
+ }
69
+
70
+ if ( $other_opt ) { ?>
71
+ <input type="text" class="frm_other_input <?php echo ( $checked != ' ' ? '' : ' frm_pos_none' ); ?>" name="<?php echo $other_name ?>" value="<?php echo esc_attr($other_val); ?>"><?php
72
+ }
73
+ unset($other_opt, $other_val, $other_name);
74
  ?></div>
75
  <?php
76
  }
77
  }
78
 
79
+ }else if ($field['type'] == 'select'){
80
+ if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
81
  echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
82
+ }else{
83
+ if ( isset($field['read_only']) && $field['read_only'] && (!isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) { ?>
84
+ <input type="hidden" value="<?php echo esc_attr($field['value']) ?>" name="<?php echo $field_name ?>" id="<?php echo $html_id ?>" />
85
  <select disabled="disabled" <?php do_action('frm_field_input_html', $field) ?>>
86
+ <?php }else{ ?>
87
+ <select name="<?php echo $field_name ?>" id="<?php echo $html_id ?>" <?php do_action('frm_field_input_html', $field) ?>>
88
+ <?php }
89
+ foreach ($field['options'] as $opt_key => $opt){
90
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
91
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); ?>
92
  <option value="<?php echo esc_attr($field_val) ?>" <?php
97
 
98
  }else if ($field['type'] == 'checkbox'){
99
  $checked_values = $field['value'];
100
+
101
+ if ( isset($field['read_only']) && $field['read_only'] && ( ! isset($frm_vars['readonly']) || $frm_vars['readonly'] != 'disabled') && ! FrmAppHelper::is_admin() ) {
102
+ if ( $checked_values ) {
103
+ foreach ( (array) $checked_values as $checked_value ) { ?>
104
+ <input type="hidden" value="<?php echo esc_attr($checked_value) ?>" name="<?php echo $field_name ?>[]" />
105
+ <?php
106
+ }
107
+ } else { ?>
108
+ <input type="hidden" value="<?php echo esc_attr($checked_values) ?>" name="<?php echo $field_name ?>[]" />
109
+ <?php
110
+ }
111
+ }
112
+
113
+ if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
114
  do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
115
  } else if ( $field['options'] ) {
116
  foreach ( $field['options'] as $opt_key => $opt ) {
117
  if ( isset($atts) && isset($atts['opt']) && ($atts['opt'] != $opt_key) ) {
118
  continue;
119
  }
120
+
121
  $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
122
  $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
123
  $checked = FrmAppHelper::check_selected($checked_values, $field_val) ? ' checked="checked"' : '';
124
+
125
  ?>
126
  <div class="<?php echo apply_filters('frm_checkbox_class', 'frm_checkbox', $field, $field_val) ?>" id="frm_checkbox_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php
127
 
128
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
129
+ ?><label for="<?php echo $html_id ?>-<?php echo $opt_key ?>"><?php
130
+ }
131
+
132
+ //Check if this is an "Other" option
133
+ if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
134
+ $other_opt = true;
135
+
136
+ //Check if current Other option has a value
137
+ $other_val = FrmAppHelper::check_other_selected( $field['value'], $field['options'], $field['type'], $opt_key );
138
+ if ( $other_val ) {
139
+ $checked = ' checked="checked"';
140
+ }
141
+
142
+ //Set up name for other field
143
+ $other_name = preg_replace('/\[' . $field['id'] . '\]$/', '', $field_name);
144
+ $other_name = $other_name . '[other]' . '[' . $field['id'] . '][' . $opt_key . ']';
145
+ //Converts item_meta[field_id][] => item_meta[other][field_id][opt_key] and
146
+ //item_meta[parent][0][field_id][] => item_meta[parent][0][other][field_id][opt_key]
147
+ } else {
148
+ $other_opt = false;
149
  }
150
+
151
+ ?><input type="checkbox" name="<?php echo $field_name ?>[<?php echo ( $other_opt ? $opt_key : '' ) ?>]" id="<?php echo $html_id ?>-<?php echo $opt_key ?>" value="<?php echo esc_attr($field_val) ?>" <?php echo $checked ?> <?php do_action('frm_field_input_html', $field) ?> /><?php
152
+
153
  if ( !isset($atts) || !isset($atts['label']) || $atts['label'] ) {
154
  echo ' '. $opt .'</label>';
155
  }
156
+
157
+ if ( $other_opt ) {?>
158
+ <input type="text" class="frm_other_input <?php echo ( $checked ? '' : 'frm_pos_none' ); ?>" name="<?php echo $other_name ?>" value="<?php echo esc_attr($other_val);?>"><?php
159
+ }
160
+
161
+ unset($other_opt, $other_val, $checked);
162
+
163
  ?></div>
164
  <?php
165
  }
166
  }
167
 
168
+ } else if ( $field['type'] == 'captcha' && ! FrmAppHelper::is_admin() ) {
169
+ $frm_settings = FrmAppHelper::get_settings();
170
+ if ( ! empty($frm_settings->pubkey) ) {
171
+ FrmFieldsHelper::display_recaptcha($field);
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
  } else {
174
+ do_action('frm_form_fields', $field, $field_name, compact('errors', 'html_id'));
175
  }
classes/views/frm-fields/radio.php CHANGED
@@ -1,12 +1,26 @@
1
  <?php
2
- if (is_array($field['options'])){
3
- foreach($field['options'] as $opt_key => $opt){
4
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
5
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
6
- $checked = (isset($field['value']) and ((!is_array($field['value']) && $field['value'] == $field_val ) || (is_array($field['value']) && in_array($field_val, $field['value'])))) ? ' checked="true"':'';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
8
-
9
- unset($checked);
10
- }
11
  }
12
- ?>
1
  <?php
2
+ if ( ! is_array($field['options']) ) {
3
+ return;
4
+ }
5
+
6
+ foreach ( $field['options'] as $opt_key => $opt ) {
7
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
8
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
9
+
10
+ //If option is an "other" option, and there is a value set for this field, check if the value belongs in the current "Other" option text field
11
+ if ( isset( $field['other'] ) && $field['other'] == true && $opt_key && strpos( $opt_key, 'other' ) !== false && isset( $field['value'] ) ) {
12
+ $other_val = FrmAppHelper::check_other_selected( $field['value'], $field['options'], $field['type'], $opt_key );
13
+ } else {
14
+ $other_val = '';
15
+ }
16
+
17
+ $checked = ( ( isset( $other_val ) && $other_val ) || isset($field['value']) && (( ! is_array($field['value']) && $field['value'] == $field_val ) || (is_array($field['value']) && in_array($field_val, $field['value']) ) ) ) ? ' checked="true"':'';
18
+
19
+ if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) {
20
+ include(FrmAppHelper::plugin_path() .'/pro/classes/views/frmpro-fields/other-option.php');
21
+ } else {
22
  include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
23
+ }
24
+
25
+ unset($checked, $other_val);
26
  }
 
classes/views/frm-fields/show-build.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ( in_array($display['type'], array('text', 'website', 'email', 'url') ) ) { ?>
2
+ <input type="text" name="<?php echo $field_name ?>" id="<?php echo $html_id ?>" value="<?php echo esc_attr($field['default_value']); ?>" <?php echo ( isset($field['size']) && $field['size'] ) ? 'style="width:'. $field['size'] . ( is_numeric($field['size']) ? 'px' : '') .';"' : ''; ?> class="dyn_default_value" />
3
+ <?php }else if ($field['type'] == 'textarea'){ ?>
4
+ <textarea name="<?php echo $field_name ?>" <?php
5
+ echo ( isset($field['size']) && $field['size'] ) ? 'style="width:'. $field['size'] . ( is_numeric($field['size']) ? 'px' : '') .';"' : '';
6
+ ?> rows="<?php echo $field['max']; ?>" id="<?php echo $html_id ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea>
7
+
8
+ <?php
9
+
10
+ } else if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) {
11
+ $field['default_value'] = maybe_unserialize($field['default_value']);
12
+ if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
13
+ do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
14
+ } else {
15
+ do_action('frm_add_multiple_opts_labels', $field); ?>
16
+ <ul id="frm_field_<?php echo $field['id'] ?>_opts" class="frm_sortable_field_opts clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>">
17
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php'); ?>
18
+ </ul>
19
+ <?php
20
+ }
21
+
22
+ } else if ( $field['type'] == 'select' ) {
23
+ if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
24
+ echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
25
+ } else { ?>
26
+ <select name="<?php echo $field_name . ( ( isset($field['multiple']) && $field['multiple']) ? '[]' : '' ); ?>" <?php
27
+ echo ( isset($field['size']) && $field['size'] ) ? 'style="width:auto"' : '';
28
+ echo ( isset($field['multiple']) && $field['multiple'] ) ? ' multiple="multiple"' : ''; ?> >
29
+ <?php foreach ($field['options'] as $opt_key => $opt){
30
+ $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
31
+ $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
32
+ $selected = ($field['default_value'] == $field_val)?(' selected="selected"'):(''); ?>
33
+ <option value="<?php echo $field_val ?>"<?php echo $selected ?>><?php echo $opt ?> </option>
34
+ <?php } ?>
35
+ </select>
36
+ <?php }
37
+
38
+ if ( $display['default_blank'] ) { ?>
39
+ <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm_clear_on_focus frm-show-click">
40
+ <?php FrmFieldsHelper::show_default_blank_js($field['default_blank']); ?>
41
+ </span>
42
+ <?php } ?>
43
+ <div class="clear"></div>
44
+ <div class="frm-show-click" style="margin-top:5px;">
45
+ <?php
46
+
47
+ if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
48
+ echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
49
+ } else if ( !isset($field['post_field']) || $field['post_field'] != 'post_status' ) { ?>
50
+ <?php do_action('frm_add_multiple_opts_labels', $field); ?>
51
+ <ul id="frm_field_<?php echo $field['id'] ?>_opts" class="frm_sortable_field_opts<?php echo ( count($field['options']) > 10 ) ? ' frm_field_opts_list' : ''; ?>">
52
+ <?php FrmFieldsHelper::show_single_option($field); ?>
53
+ </ul>
54
+ <?php
55
+ } ?>
56
+ </div>
57
+ <?php
58
+ } else if ($field['type'] == 'captcha' ) {
59
+ ?>
60
+ <?php if ( empty($frm_settings->pubkey) ) { ?>
61
+ <div class="howto" style="font-weight:bold;color:#AA0000;"><?php printf(__('Your captcha will not appear on your form until you %1$sset up%2$s the Site and Private Keys', 'formidable'), '<a href="?page=formidable-settings">', '</a>') ?></div>
62
+ <?php } ?>
63
+ <input type="hidden" name="<?php echo $field_name ?>" value="1"/>
64
+ <?php
65
+ } else {
66
+ do_action('frm_display_added_fields',$field);
67
+ }
classes/views/frm-fields/show.php CHANGED
@@ -1 +1,4 @@
1
- <?php echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form); ?>
 
 
 
1
+ <?php
2
+ _deprecated_file( basename(__FILE__), '1.07.11', 'FrmFieldsHelper::replace_shortcodes' );
3
+
4
+ echo FrmFieldsHelper::replace_shortcodes($field['custom_html'], $field, $errors, $form);
classes/views/frm-fields/single-option.php CHANGED
@@ -1,16 +1,13 @@
1
- <div id="frm_delete_field_<?php echo $field['id']; ?>-<?php echo $opt_key ?>_container" class="frm_single_option">
2
- <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon"> </a>
3
- <?php if ($field['type'] != 'select'){ ?>
4
- <input type="<?php echo $field['type'] ?>" name="<?php echo $field_name ?><?php echo ($field['type'] == 'checkbox')?'[]':''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset($checked)? $checked : ''; ?>/>
5
- <?php } ?>
6
- <label class="frm_ipe_field_option field_<?php echo $field['id']?>_option <?php echo $field['separate_value'] ? 'frm_with_key' : ''; ?>" id="field_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php echo ($opt == '') ? __('(Blank)', 'formidable') : $opt ?></label>
7
- <span class="frm_option_key field_<?php echo $field['id']?>_option_key" <?php echo $field['separate_value'] ? '' : "style='display:none;'"; ?>>
8
- <label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php echo ($field_val == '') ? __('(Blank)', 'formidable') : $field_val ?></label>
9
- </span>
10
- </div>
11
- <div class="clear"></div>
12
  <?php
13
- unset($field_val);
14
- unset($opt);
15
- unset($opt_key);
16
  ?>
1
+ <li id="frm_delete_field_<?php echo $field['id']; ?>-<?php echo $opt_key ?>_container" class="frm_single_option">
2
+ <a href="javascript:void(0)" class="frm_single_visible_hover frm_icon_font frm_delete_icon" data-fid="<?php echo $field['id']; ?>"> </a>
3
+ <?php if ( $field['type'] != 'select' ) { ?>
4
+ <input type="<?php echo $field['type'] ?>" name="<?php echo $field_name ?><?php echo ($field['type'] == 'checkbox')?'[]':''; ?>" value="<?php echo esc_attr($field_val) ?>"<?php echo isset($checked)? $checked : ''; ?>/>
5
+ <?php } ?>
6
+ <label class="frm_ipe_field_option field_<?php echo $field['id']?>_option <?php echo $field['separate_value'] ? 'frm_with_key' : ''; ?>" id="<?php echo $html_id ?>-<?php echo $opt_key ?>"><?php echo ($opt == '') ? __('(Blank)', 'formidable') : $opt ?></label>
7
+ <span class="frm_option_key field_<?php echo $field['id']?>_option_key" <?php echo $field['separate_value'] ? '' : "style='display:none;'"; ?>>
8
+ <label class="frm-show-click frm_ipe_field_option_key" id="field_key_<?php echo $field['id']?>-<?php echo $opt_key ?>"><?php echo ($field_val == '') ? __('(Blank)', 'formidable') : $field_val ?></label>
9
+ </span>
10
+ </li>
 
11
  <?php
12
+ unset($field_val, $opt, $opt_key);
 
 
13
  ?>
classes/views/frm-form-actions/_action_inside.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <input type="hidden" name="<?php echo $action_control->get_field_name('post_excerpt', '') ?>" class="frm_action_name" value="<?php echo esc_attr($form_action->post_excerpt); ?>" />
2
+ <input type="hidden" name="<?php echo $action_control->get_field_name('ID', '') ?>" value="<?php echo esc_attr($form_action->ID); ?>" />
3
+
4
+ <table class="form-table">
5
+ <tr>
6
+ <th>
7
+ <label <?php FrmAppHelper::maybe_add_tooltip('action_title') ?>><?php _e('Label', 'formidable') ?></label>
8
+ </th>
9
+ <td><input type="text" name="<?php echo $action_control->get_field_name('post_title', '') ?>" value="<?php echo esc_attr($form_action->post_title); ?>" class="large-text <?php FrmAppHelper::maybe_add_tooltip('action_title', 'open') ?>" id="<?php echo $action_control->get_field_id('action_post_title') ?>" />
10
+ </td>
11
+ </tr>
12
+ </table>
13
+ <?php $action_control->form($form_action, compact('form', 'action_key', 'values')); ?>
14
+
15
+ <table class="form-table frm-no-margin">
16
+ <tr><td>
17
+ <?php
18
+ if ( ! isset($action_control->action_options['event']) ) {
19
+ $events = 'create';
20
+ }
21
+
22
+ if ( ! is_array($action_control->action_options['event']) ) {
23
+ $action_control->action_options['event'] = explode(',', $action_control->action_options['event']);
24
+ }
25
+
26
+ if ( count($action_control->action_options['event']) == 1 || $action_control->action_options['force_event'] ) {
27
+ foreach ( $action_control->action_options['event'] as $e) { ?>
28
+ <input type="hidden" name="<?php echo $action_control->get_field_name('event') ?>[]" value="<?php echo esc_attr($e) ?>" />
29
+ <?php }
30
+ } else {
31
+ ?>
32
+ <p><label><?php _e('Trigger this action after', 'formidable') ?></label>
33
+ <?php
34
+ $event_labels = array(
35
+ 'create' => __('Create', 'formidable'),
36
+ 'update' => __('Update', 'formidable'),
37
+ 'delete' => __('Delete', 'formidable'),
38
+ );
39
+
40
+ foreach ( $action_control->action_options['event'] as $event ) { ?>
41
+ <label for="frm_action_event_<?php echo $event ?>" class="frm_action_events"><input type="checkbox" name="<?php echo $action_control->get_field_name('event') ?>[]" value="<?php echo $event ?>" id="<?php echo $action_control->get_field_id('frm_action_event_'. $event) ?>" <?php FrmAppHelper::checked($form_action->post_content['event'], $event) ?> />
42
+ <?php echo isset($event_labels[$event]) ? $event_labels[$event] : $event; ?>
43
+ </label>
44
+ <?php
45
+ }
46
+ ?> </p>
47
+ <?php
48
+ }
49
+
50
+ do_action('frm_additional_action_settings', $form_action, compact('form', 'action_control', 'action_key', 'values'));
51
+ ?>
52
+ </td></tr>
53
+ </table>
classes/views/frm-form-actions/_email_settings.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <table class="form-table frm-no-margin">
2
+ <tr>
3
+ <th><label <?php FrmAppHelper::maybe_add_tooltip('email_to') ?>><?php _e('To', 'formidable') ?></label>
4
+ </th>
5
+ <td><input type="text" name="<?php echo $this->get_field_name('email_to') ?>" value="<?php echo esc_attr($form_action->post_content['email_to']); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip('email_to', 'open') ?>" id="<?php echo $this->get_field_id('email_to') ?>" />
6
+ </td>
7
+ <td style="width:96px;">
8
+ <a href="javascript:void(0)" class="button frm_email_buttons frm_bcc_button <?php
9
+ echo ( ! empty($form_action->post_content['bcc']) ? 'frm_hidden' : '' );
10
+ ?>" data-emailrow="bcc"><?php _e('BCC', 'formidable') ?></a>
11
+ <a href="javascript:void(0)" class="button frm_email_buttons frm_cc_button <?php
12
+ echo ( ! empty($form_action->post_content['cc']) ? 'frm_hidden' : '' );
13
+ ?>" data-emailrow="cc"><?php _e('CC', 'formidable') ?></a>
14
+ </td>
15
+ </tr>
16
+ <tr id="frm_cc_row" class="<?php echo ( empty($form_action->post_content['cc']) ? 'frm_hidden' : '' )?>" >
17
+ <th><label <?php FrmAppHelper::maybe_add_tooltip('cc') ?>><?php _e('CC', 'formidable') ?></label>
18
+ </th>
19
+ <td class="frm_right_addon">
20
+ <input type="text" name="<?php echo $this->get_field_name('cc') ?>" value="<?php echo esc_attr($form_action->post_content['cc']); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('cc', 'open') ?>" id="<?php echo $this->get_field_id('cc') ?>" />
21
+ <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="cc"></a>
22
+ </td>
23
+ <td></td>
24
+ </tr>
25
+ <tr id="frm_bcc_row" class="<?php echo ( empty($form_action->post_content['bcc']) ? 'frm_hidden' : '' )?>" >
26
+ <th><label <?php FrmAppHelper::maybe_add_tooltip('bcc') ?>><?php _e('BCC', 'formidable') ?></label>
27
+ </th>
28
+ <td class="frm_right_addon">
29
+ <input type="text" name="<?php echo $this->get_field_name('bcc') ?>" value="<?php echo esc_attr($form_action->post_content['bcc']); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('bcc', 'open') ?>" id="<?php echo $this->get_field_id('bcc') ?>" />
30
+ <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="bcc"></a>
31
+ </td>
32
+ <td></td>
33
+ </tr>
34
+ <tr id="frm_reply_to_row" class="<?php echo ( empty($form_action->post_content['reply_to']) ? 'frm_hidden' : '' )?>">
35
+ <th><label <?php FrmAppHelper::maybe_add_tooltip('reply_to') ?>><?php _e('Reply to', 'formidable') ?></label>
36
+ </th>
37
+ <td class="frm_right_addon">
38
+ <input type="text" name="<?php echo $this->get_field_name('reply_to') ?>" value="<?php echo esc_attr($form_action->post_content['reply_to']); ?>" class="frm_not_email_to large-text <?php FrmAppHelper::maybe_add_tooltip('reply_to', 'open') ?>" id="<?php echo $this->get_field_id('reply_to') ?>" />
39
+ <a href="javascript:void(0)" class="frm_icon_font frm_remove_field frm_cancel1_icon" data-emailrow="reply_to"></a>
40
+ </td>
41
+ <td></td>
42
+ </tr>
43
+ <tr>
44
+ <th><label <?php FrmAppHelper::maybe_add_tooltip('from') ?>><?php _e('From', 'formidable') ?></label></th>
45
+ <td><input type="text" name="<?php echo $this->get_field_name('from') ?>" value="<?php echo esc_attr($form_action->post_content['from']); ?>" class="frm_not_email_to frm_email_blur large-text <?php FrmAppHelper::maybe_add_tooltip('from', 'open') ?>" id="<?php echo $this->get_field_id('from') ?>" />
46
+ </td>
47
+ <td><a href="javascript:void(0)" class="button frm_email_buttons frm_reply_to_button <?php echo ( !empty($form_action->post_content['reply_to']) ? 'frm_hidden' : '' )?>" data-emailrow="reply_to"><?php _e('Reply To', 'formidable') ?></a></td>
48
+ </tr>
49
+ <tr>
50
+ <td colspan="3" style="padding-top:0">
51
+ <p><label <?php FrmAppHelper::maybe_add_tooltip('email_subject', '', $form->name) ?>><?php _e('Subject', 'formidable') ?></label><br/>
52
+ <input type="text" name="<?php echo $this->get_field_name('email_subject') ?>" class="frm_not_email_subject large-text <?php FrmAppHelper::maybe_add_tooltip('email_subject', 'open', $form->name) ?>" id="<?php echo $this->get_field_id('email_subject') ?>" size="55" value="<?php echo esc_attr($form_action->post_content['email_subject']); ?>" /></p>
53
+
54
+ <p><label><?php _e('Message', 'formidable') ?> </label><br/>
55
+ <textarea name="<?php echo $this->get_field_name('email_message') ?>" class="frm_not_email_message large-text" id="<?php echo $this->get_field_id('email_message') ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea($form_action->post_content['email_message']) ?></textarea></p>
56
+
57
+ <h4><?php _e('Options', 'formidable') ?> </h4>
58
+ <label for="<?php echo $this->get_field_id('inc_user_info') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('inc_user_info') ?>" class="frm_not_inc_user_info" id="<?php echo $this->get_field_id('inc_user_info') ?>" value="1" <?php checked($form_action->post_content['inc_user_info'], 1); ?> /> <?php _e('Append IP Address, Browser, and Referring URL to message', 'formidable') ?></label>
59
+
60
+ <p><label for="<?php echo $this->get_field_id('plain_text') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('plain_text') ?>" id="<?php echo $this->get_field_id('plain_text') ?>" value="1" <?php checked($form_action->post_content['plain_text'], 1); ?> /> <?php _e('Send Emails in Plain Text', 'formidable') ?></label></p>
61
+ <?php FrmAppHelper::update_message('conditionally send email notifications'); ?>
62
+ </td>
63
+ </tr>
64
+ </table>
classes/views/frm-form-actions/default_actions.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // add post action
3
+ class FrmDefPostAction extends FrmFormAction {
4
+ function __construct() {
5
+ $action_ops = FrmFormActionsHelper::default_action_opts();
6
+ $action_ops['classes'] = 'ab-icon frm_dashicon_font dashicons-before';
7
+
8
+ $this->FrmFormAction('wppost', __('Create Post', 'formidable'), $action_ops);
9
+ }
10
+ }
11
+
12
+
13
+ // add register action
14
+ class FrmDefRegAction extends FrmFormAction {
15
+ function __construct() {
16
+ $action_ops = FrmFormActionsHelper::default_action_opts('frm_register_icon');
17
+
18
+ $this->FrmFormAction('register', __('Register User', 'formidable'), $action_ops);
19
+ }
20
+ }
21
+
22
+ // add paypal action
23
+ class FrmDefPayPalAction extends FrmFormAction {
24
+ function __construct() {
25
+ $action_ops = FrmFormActionsHelper::default_action_opts('frm_paypal_icon');
26
+
27
+ $this->FrmFormAction('paypal', __('Collect Payment', 'formidable'), $action_ops);
28
+ }
29
+ }
30
+
31
+ // add aweber action
32
+ class FrmDefAweberAction extends FrmFormAction {
33
+ function __construct() {
34
+ $action_ops = FrmFormActionsHelper::default_action_opts('frm_aweber_icon');
35
+
36
+ $this->FrmFormAction('aweber', __('Aweber', 'formidable'), $action_ops);
37
+ }
38
+ }
39
+
40
+ // add mailchimp action
41
+ class FrmDefMlcmpAction extends FrmFormAction {
42
+ function __construct() {
43
+ $action_ops = FrmFormActionsHelper::default_action_opts('frm_mailchimp_icon');
44
+
45
+ $this->FrmFormAction('mailchimp', __('MailChimp', 'formidable'), $action_ops);
46
+ }
47
+ }
48
+
49
+ // add twilio action
50
+ class FrmDefTwilioAction extends FrmFormAction {
51
+ function __construct() {
52
+ $action_ops = FrmFormActionsHelper::default_action_opts('frm_sms_icon');
53
+
54
+ $this->FrmFormAction('twilio', __('Twilio', 'formidable'), $action_ops);
55
+ }
56
+ }
57
+
58
+ // add highrise action
59
+ class FrmDefHrsAction extends FrmFormAction {
60
+ function __construct() {
61
+ $action_ops = FrmFormActionsHelper::default_action_opts('frm_highrise_icon');
62
+
63
+ $this->FrmFormAction('highrise', __('Highrise', 'formidable'), $action_ops);
64
+ }
65
+ }
classes/views/frm-form-actions/email_action.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FrmEmailAction extends FrmFormAction {
4
+
5
+ function __construct() {
6
+ $action_ops = array(
7
+ 'classes' => 'frm_email_icon frm_icon_font',
8
+ 'active' => true,
9
+ 'event' => array('create'),
10
+ 'limit' => 99,
11
+ 'priority' => 10,
12
+ 'ajax_load' => false,
13
+ );
14
+ $action_ops = apply_filters('frm_email_control_settings', $action_ops);
15
+
16
+ $this->FrmFormAction('email', __('Email Notification', 'formidable'), $action_ops);
17
+ }
18
+
19
+ function form( $form_action, $args = array() ) {
20
+ extract($args);
21
+
22
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_email_settings.php');
23
+ }
24
+
25
+ function get_defaults() {
26
+ return array(
27
+ 'email_to' => '[admin_email]',
28
+ 'cc' => '',
29
+ 'bcc' => '',
30
+ 'from' => '[sitename] <[admin_email]>',
31
+ 'reply_to' => '',
32
+ 'email_subject' => '',
33
+ 'email_message' => '[default-message]',
34
+ 'inc_user_info' => 0,
35
+ 'plain_text' => 0,
36
+ 'event' => array('create'),
37
+ );
38
+ }
39
+
40
+ }
classes/views/frm-form-actions/form_action.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings';
3
+
4
+ $form_action = apply_filters('frm_form_action_settings', $form_action, $form_action->post_excerpt);
5
+ $form_action = apply_filters('frm_form_'. $form_action->post_excerpt .'_action_settings', $form_action);
6
+
7
+ ?>
8
+ <div id="frm_form_action_<?php echo $action_key ?>" class="widget frm_form_action_settings frm_single_<?php echo $form_action->post_excerpt ?>_settings" data-actionkey="<?php echo $action_key ?>">
9
+ <div class="widget-top">
10
+ <div class="widget-title-action">
11
+ <a href="javascript:void(0)" class="widget-action hide-if-no-js"></a>
12
+ </div>
13
+ <div class="widget-title">
14
+ <h3><span class="frm_form_action_icon <?php echo $action_control->action_options['classes'] ?>"></span>
15
+ <?php echo $form_action->post_title; ?>
16
+ </h3>
17
+ <span class="frm_email_icons alignright">
18
+ <a href="javascript:void(0)" data-removeid="frm_form_action_<?php echo $action_key ?>" class="frm_icon_font frm_delete_icon frm_remove_form_action"> </a>
19
+ </span>
20
+ </div>
21
+ </div>
22
+ <div class="widget-inside frm_hidden">
23
+ <?php
24
+ if ( defined('DOING_AJAX') || ! $action_control->action_options['ajax_load'] ) {
25
+ // only load settings if they are just added or are open
26
+ include(dirname(__FILE__) .'/_action_inside.php');
27
+ } else {
28
+ // include hidden settings so action won't get lost on update ?>
29
+ <input type="hidden" name="<?php echo $action_control->get_field_name('post_excerpt', '') ?>" class="frm_action_name" value="<?php echo esc_attr($form_action->post_excerpt); ?>" />
30
+ <input type="hidden" name="<?php echo $action_control->get_field_name('ID', '') ?>" value="<?php echo esc_attr($form_action->ID); ?>" />
31
+ <?php
32
+ } ?>
33
+ </div>
34
+ <style type="text/css">
35
+ .frm_no_actions{
36
+ opacity:0;
37
+ *visibility:hidden;
38
+ }
39
+ </style>
40
+ </div>
classes/views/frm-forms/_publish_box.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="submitdiv" class="postbox">
2
+ <div class="inside">
3
+ <div class="submitbox" id="submitpost">
4
+
5
+ <div id="minor-publishing">
6
+ <div id="minor-publishing-actions">
7
+ <?php if ( 'draft' == $values['status'] ) { ?>
8
+ <div id="save-action">
9
+ <input type="button" value="<?php esc_html_e('Save Draft', 'formidable'); ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-secondary button-large" id="save-post" />
10
+ <span class="spinner"></span>
11
+ </div>
12
+ <?php } ?>
13
+ <div id="preview-action">
14
+ <?php
15
+ if ( !isset($hide_preview) || !$hide_preview ) {
16
+
17
+ if ( isset($values['form_key']) ) {
18
+ $frm_settings = FrmAppHelper::get_settings();
19
+ if ( empty($frm_settings->preview_page_id) ) { ?>
20
+ <a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" class="preview button" target="wp-frm-preview-<?php echo $id ?>"><?php _e('Preview', 'formidable') ?></a>
21
+ <?php
22
+ } else {
23
+ ?>
24
+ <div class="preview button dropdown">
25
+ <a href="#" id="frm-previewDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Preview', 'formidable') ?> <b class="caret"></b></a>
26
+
27
+ <ul class="frm-dropdown-menu pull-right" role="menu" aria-labelledby="frm-previewDrop">
28
+ <li><a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" target="_blank"><?php _e('On Blank Page', 'formidable') ?></a></li>
29
+ <li><a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('In Theme', 'formidable') ?></a></li>
30
+ </ul>
31
+ </div>
32
+ <?php }
33
+ }
34
+ } ?>
35
+ </div>
36
+ <?php if ( 'draft' == $values['status'] ) { ?>
37
+ <div class="clear"></div>
38
+ <?php } ?>
39
+ </div><!-- #minor-publishing-actions -->
40
+
41
+ <div id="misc-publishing-actions">
42
+ <div class="misc-pub-section">
43
+
44
+ <?php if ( $values['is_template'] ) { ?>
45
+ <br/>
46
+ <?php } else { ?>
47
+ <span id="frm_shortcode"><span class="frm-buttons-icon wp-media-buttons-icon"></span> <?php _e('Form', 'formidable') ?> <strong><?php _e('Shortcodes', 'formidable') ?></strong></span>
48
+ <a href="#edit_frm_shortcode" class="edit-frm_shortcode hide-if-no-js" tabindex='4'><?php _e('Show', 'formidable') ?></a>
49
+ <div id="frm_shortcodediv" class="hide-if-js">
50
+ <p class="howto"><?php _e('Insert on a page, post, or text widget', 'formidable') ?>:</p>
51
+ <p><input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?>]" />
52
+ <input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?> title=true description=true]" />
53
+ </p>
54
+
55
+ <p class="howto"><?php _e('Insert in a template', 'formidable') ?>:</p>
56
+ <p><input type="text" style="font-size:10px;width:98%;font-weight:normal" readonly="true" class="frm_select_box" value="&lt;?php echo FrmFormsController::get_form_shortcode(array('id' => $id, 'title' => false, 'description' => false)); ?&gt;" /></p>
57
+
58
+ <p><a href="#edit_frm_shortcode" class="cancel-frm_shortcode hide-if-no-js"><?php _e('Hide', 'formidable'); ?></a></p>
59
+ </div>
60
+ <?php } ?>
61
+ </div>
62
+
63
+
64
+ <div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e('Status', 'formidable') ?>:</label>
65
+ <span id="form-status-display"><?php echo FrmFormsHelper::status_nice_name($values['status']); ?></span>
66
+ <?php if ( 'draft' != $values['status'] && ( ! isset($_GET['frm_action']) || 'settings' != $_GET['frm_action'] ) ) { ?>
67
+ <a href="#post_status" class="edit-form-status hide-if-no-js" data-slidedown="form-status-select"><span aria-hidden="true"><?php _e('Edit') ?></span> <span class="screen-reader-text"><?php _e('Edit status') ?></span></a>
68
+
69
+ <div id="form-status-select" class="frm_hidden">
70
+ <select name="frm_change_status" id="form_change_status">
71
+ <option value="published" <?php selected($values['status'], 'published') ?>><?php _e( 'Published' ) ?></option>
72
+ <option value="draft" <?php selected($values['status'], 'draft') ?>><?php _e( 'Draft' ) ?></option>
73
+ </select>
74
+ <a href="#post_status" class="save-form-status hide-if-no-js button"><?php _e('OK') ?></a>
75
+ <a href="#post_status" class="cancel-form-status hide-if-no-js button-cancel" data-slideup="form-status-select"><?php _e('Cancel') ?></a>
76
+ </div>
77
+ <?php } ?>
78
+ </div><!-- .misc-pub-section -->
79
+
80
+ <?php if ( has_action('frm_settings_buttons') ) { ?>
81
+ <div class="misc-pub-section">
82
+ <?php do_action('frm_settings_buttons', $values); ?>
83
+ <div class="clear"></div>
84
+ </div>
85
+ <?php } ?>
86
+
87
+ </div><!-- #misc-publishing-actions -->
88
+ <div class="clear"></div>
89
+ </div><!-- #minor-publishing -->
90
+
91
+ <div id="major-publishing-actions">
92
+ <div id="delete-action">
93
+ <?php echo FrmFormsHelper::delete_trash_link($id, $values['status']); ?>
94
+ </div>
95
+
96
+ <div id="publishing-action">
97
+ <span class="spinner"></span>
98
+ <?php if ( isset($_GET['frm_action']) && 'settings' == $_GET['frm_action'] ) { ?>
99
+ <input type="button" value="<?php _e('Update', 'formidable'); ?>" class="frm_submit_form frm_submit_settings_btn button-primary button-large" id="frm_submit_side_top" />
100
+ <?php } else { ?>
101
+ <input type="button" value="<?php echo isset($button) ? esc_attr($button) : __('Update', 'formidable'); ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary button-large" id="frm_submit_side_top" />
102
+ <?php } ?>
103
+ </div>
104
+
105
+ <div class="clear"></div>
106
+ </div><!-- #major-publishing-actions -->
107
+
108
+ </div><!-- .submitbox -->
109
+ </div><!-- .inside -->
110
+ </div><!-- .submitdiv -->
classes/views/frm-forms/add_field.php CHANGED
@@ -1,6 +1,19 @@
1
  <?php
2
- if(isset($values) and isset($values['ajax_load']) and $values['ajax_load'] and isset($count) and $count > 10){ ?>
3
- <li id="frm_field_id_<?php echo $field['id']; ?>" class="form-field frm_field_box frm_field_loading edit_form_item frm_top_container" data-triggered="0">
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  <img src="<?php echo FrmAppHelper::plugin_url() ?>/images/ajax_loader.gif" alt="<?php _e('Loading', 'formidable') ?>" />
5
  <span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars(json_encode($field)) ?></span>
6
  </li>
@@ -8,179 +21,139 @@ if(isset($values) and isset($values['ajax_load']) and $values['ajax_load'] and i
8
  return;
9
  }
10
 
11
- global $frm_settings;
12
- if(!isset($frm_all_field_selection)){
13
- if(isset($frm_field_selection) and isset($frm_pro_field_selection)){
14
- $frm_all_field_selection = array_merge($frm_field_selection, $frm_pro_field_selection);
15
- }else{
16
- $frm_pro_field_selection = FrmFieldsHelper::pro_field_selection();
17
- $frm_all_field_selection = array_merge(FrmFieldsHelper::field_selection(), $frm_pro_field_selection);
 
18
  }
19
  }
20
 
21
- if(!isset($frm_vars))
22
- global $frm_vars;
23
-
24
- $disabled_fields = ($frm_vars['pro_is_installed']) ? array() : $frm_pro_field_selection;
25
 
26
-
27
- $display = apply_filters('frm_display_field_options', array(
28
- 'type' => $field['type'], 'field_data' => $field,
29
- 'required' => true, 'unique' => false, 'read_only' => false,
30
- 'description' => true, 'options' => true, 'label_position' => true,
31
- 'invalid' => false, 'size' => false, 'clear_on_focus' => false,
32
- 'default_blank' => true, 'css' => true
33
- )); ?>
34
- <?php if(!isset($ajax)){ ?>
35
- <li id="frm_field_id_<?php echo $field['id']; ?>" class="form-field edit_form_item frm_field_box ui-state-default edit_field_type_<?php echo $display['type'] ?> frm_top_container">
36
- <?php } ?>
37
- <a href="javascript:void(0);" class="frm_bstooltip alignright frm-show-hover frm-move frm-hover-icon frm_icon_font frm_move_field" title="<?php esc_attr_e('Move Field', 'formidable') ?>"> </a>
38
- <a href="javascript:frm_delete_field(<?php echo $field['id']; ?>)" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_delete_icon" id="frm_delete_field<?php echo $field['id']; ?>" title="<?php esc_attr_e('Delete Field', 'formidable') ?>"> </a>
39
- <a href="javascript:frm_duplicate_field(<?php echo $field['id']; ?>)" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_duplicate_form" title="<?php esc_attr_e('Duplicate Field', 'formidable') ?>"> </a>
 
 
40
  <input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr($field['id']) ?>" />
41
  <?php do_action('frm_extra_field_actions', $field['id']); ?>
42
- <?php if ($display['required']){ ?>
43
  <span id="require_field_<?php echo $field['id']; ?>">
44
- <a class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int)$field['required'] ?>" id="req_field_<?php echo $field['id']; ?>" title="Click to Mark as <?php echo ($field['required'] == '0') ? '' : 'not '; ?>Required"></a>
45
  </span>
46
- <?php } ?>
47
- <label class="frm_ipe_field_label frm_primary_label <?php echo ($field['type'] == 'break') ? 'button': ''; ?>" id="field_label_<?php echo $field['id']; ?>"><?php echo force_balance_tags($field['name']) ?></label>
48
-
49
- <div class="frm_form_fields" data-ftype="<?php echo $display['type'] ?>">
50
- <?php if ($display['type'] == 'text'){ ?>
51
- <input type="text" name="<?php echo $field_name ?>" id="field_<?php echo $field['field_key'] ?>" value="<?php echo esc_attr($field['default_value']); ?>" <?php echo (isset($field['size']) && $field['size']) ? 'style="width:auto" size="'. $field['size'] .'"' : ''; ?> class="dyn_default_value" />
52
- <?php }else if ($field['type'] == 'textarea'){ ?>
53
- <textarea name="<?php echo $field_name ?>"<?php if ($field['size']) echo ' style="width:auto" cols="'. $field['size'] .'"' ?> rows="<?php echo $field['max']; ?>" id="field_<?php echo $field['field_key'] ?>" class="dyn_default_value"><?php echo FrmAppHelper::esc_textarea(force_balance_tags($field['default_value'])); ?></textarea>
54
-
55
- <?php
56
-
57
- }else if ($field['type'] == 'radio' or $field['type'] == 'checkbox'){
58
- $field['default_value'] = maybe_unserialize($field['default_value']);
59
- if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
60
- do_action('frm_after_checkbox', array('field' => $field, 'field_name' => $field_name, 'type' => $field['type']));
61
- }else{ ?>
62
- <div id="frm_field_<?php echo $field['id'] ?>_opts" class="clear<?php echo (count($field['options']) > 10) ? ' frm_field_opts_list' : ''; ?>">
63
- <?php do_action('frm_add_multiple_opts_labels', $field); ?>
64
- <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/radio.php'); ?>
65
- </div>
66
- <?php
67
- }
68
  ?>
 
69
 
70
- <div class="frm-show-click" style="margin-top:5px;">
 
 
71
  <?php
 
72
 
73
- if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
74
- echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
75
- } else if ( !isset($field['post_field']) || $field['post_field'] != 'post_status' ) {
76
- ?>
77
- <div id="frm_add_field_<?php echo $field['id']; ?>">
78
- <a href="javascript:frm_add_field_option(<?php echo $field['id']; ?>)" class="frm_orange frm_add_opt">+ <?php _e('Add an Option', 'formidable') ?></a>
79
-
80
- <?php _e('or', 'formidable'); ?>
81
- <a title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '&quot;', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Field Choices', 'formidable') ?></a>
82
- </div>
83
  <?php
 
 
84
  }
 
 
85
  ?>
86
- </div>
87
  <?php
88
- }else if ($field['type'] == 'select'){
89
- if(isset($field['post_field']) and $field['post_field'] == 'post_category'){
90
- echo FrmFieldsHelper::dropdown_categories(array('name' => $field_name, 'field' => $field) );
91
- }else{ ?>
92
- <select name="<?php echo $field_name; echo (isset($field['multiple']) and $field['multiple']) ? '[]' : ''; ?>" <?php
93
- echo (isset($field['size']) && $field['size']) ? 'style="width:auto"' : '';
94
- echo (isset($field['multiple']) and $field['multiple']) ? ' multiple="multiple"' : ''; ?> >
95
- <?php foreach ($field['options'] as $opt_key => $opt){
96
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
97
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
98
- $selected = ($field['default_value'] == $field_val)?(' selected="selected"'):(''); ?>
99
- <option value="<?php echo $field_val ?>"<?php echo $selected ?>><?php echo $opt ?></option>
100
- <?php } ?>
101
- </select>
102
- <?php }
103
- if ($display['default_blank']){ ?>
104
- <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm-show-click">
105
- <?php FrmFieldsHelper::show_default_blank_js($field['id'], $field['default_blank']); ?>
106
- </span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  <?php } ?>
108
- <div class="clear"></div>
 
 
 
 
109
  <div class="frm-show-click" style="margin-top:5px;">
110
- <?php
111
-
112
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
113
  echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
114
- } else if ( !isset($field['post_field']) || $field['post_field'] != 'post_status' ) { ?>
115
- <div id="frm_field_<?php echo $field['id'] ?>_opts"<?php echo (count($field['options']) > 10) ? ' class="frm_field_opts_list"' : ''; ?>>
116
- <?php do_action('frm_add_multiple_opts_labels', $field); ?>
117
- <?php
118
-
119
- foreach ( $field['options'] as $opt_key => $opt ) {
120
- $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
121
- $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
122
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/single-option.php');
123
- }
124
- ?>
125
- </div>
126
  <div id="frm_add_field_<?php echo $field['id']; ?>">
127
- <a href="javascript:frm_add_field_option(<?php echo $field['id']; ?>)" class="frm_orange frm_add_opt">+ <?php _e('Add an Option', 'formidable') ?></a>
128
-
129
- <?php if (!isset($field['post_field']) or $field['post_field'] != 'post_category'){ ?>
130
- <?php _e('or', 'formidable'); ?>
131
- <a title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '&quot;', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Field Choices', 'formidable') ?></a>
 
 
 
 
132
  <?php } ?>
133
  </div>
134
- <?php
135
- } ?>
136
- </div>
137
- <?php
138
- }else if ($field['type'] == 'captcha'){
139
- ?>
140
- <img src="<?php echo FrmAppHelper::plugin_url() ?>/images/<?php echo $frm_settings->re_theme ?>-captcha.png" alt="captcha" />
141
- <p class="howto" style="margin-top:0;"><?php printf(__('Hint: Change colors in the %1$sFormidable settings', 'formidable'), '<a href="?page=formidable-settings">') ?></a></p>
142
- <div class="clear"></div>
143
- <?php if (empty($frm_settings->pubkey)){ ?>
144
- <div class="howto" style="font-weight:bold;color:red;"><?php printf(__('Your captcha will not appear on your form until you %1$sset up%2$s the Public and Private Keys', 'formidable'), '<a href="?page=formidable-settings">', '</a>') ?></div>
145
- <?php } ?>
146
- <input type="hidden" name="<?php echo $field_name ?>" value="1"/>
147
- <?php
148
- }else{
149
- do_action('frm_display_added_fields',$field);
150
- }
151
-
152
- if ($display['clear_on_focus']){ ?>
153
- <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm-show-click">
154
  <?php
155
- if ($display['default_blank'])
156
- FrmFieldsHelper::show_default_blank_js($field['id'], $field['default_blank']);
157
-
158
- FrmFieldsHelper::show_onfocus_js($field['id'], $field['clear_on_focus']);
159
- ?>
160
- </span>
161
- <?php
162
-
163
- do_action('frm_extra_field_display_options', $field);
164
- }
165
  ?>
166
- <div class="clear"></div>
167
- </div>
168
- <?php
169
- if ($display['description']){ ?>
170
- <div class="frm_ipe_field_desc description frm-show-click" id="field_description_<?php echo $field['id']; ?>"><?php echo ($field['description'] == '') ? __('(Click here to add a description or instructions)', 'formidable') : force_balance_tags($field['description']); ?></div>
171
  <?php
172
  }
173
 
 
 
174
  if ($display['options']){ ?>
175
  <div class="widget">
176
  <div class="widget-top">
177
- <div class="widget-title-action"><a class="widget-action"></a></div>
178
  <div class="widget-title"><h4><?php _e('Field Options', 'formidable') ?> (ID <?php echo $field['id'] ?>)</h4></div>
179
  </div>
180
  <div class="widget-inside">
181
  <table class="form-table" style="clear:none;">
182
  <?php $field_types = FrmFieldsHelper::get_field_types($field['type']); ?>
183
- <tr><td width="150px"><label><?php _e('Field Type', 'formidable') ?></label></td>
184
  <td>
185
  <div class="hide-if-no-js edit-slug-box frm_help" title="<?php _e('The field key can be used as an alternative to the field ID in many cases.', 'formidable') ?>">
186
  <?php _e('Field Key:', 'formidable') ?>
@@ -189,37 +162,35 @@ if ($display['options']){ ?>
189
  <input type="hidden" name="field_options[field_key_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['field_key']); ?>" />
190
  <?php } ?>
191
  </div>
192
-
193
- <?php if (!empty($field_types)){ ?>
194
- <select name="field_options[type_<?php echo $field['id'] ?>]">
195
- <?php foreach ($field_types as $fkey => $ftype){ ?>
196
- <option value="<?php echo $fkey ?>" <?php echo ($fkey == $field['type']) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists($fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>><?php echo $ftype ?></option>
197
  <?php
198
  unset($fkey);
199
  unset($ftype);
200
  } ?>
201
- </select>
202
- <?php }else if(isset($frm_all_field_selection[$field['type']])){ ?>
203
- <select disabled="disabled">
204
- <option value=""><?php echo $frm_all_field_selection[$field['type']] ?></option>
205
- </select>
206
- <?php } ?>
207
- <?php if ($display['required']){ ?>
208
  <label for="frm_req_field_<?php echo $field['id'] ?>" class="frm_inline_label"><input type="checkbox" id="frm_req_field_<?php echo $field['id'] ?>" class="frm_req_field" name="field_options[required_<?php echo $field['id'] ?>]" value="1" <?php echo ($field['required']) ? 'checked="checked"': ''; ?> /> <?php _e('Required', 'formidable') ?></label>
209
  <?php } ?>
210
- <?php if($display['unique']){
211
  if(!isset($field['unique']))
212
  $field['unique'] = false;
213
  ?>
214
- <label for="frm_uniq_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php _e('Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\' then no one else will be allowed to enter the same name.', 'formidable') ?>"><input type="checkbox" name="field_options[unique_<?php echo $field['id'] ?>]" id="frm_uniq_field_<?php echo $field['id'] ?>" value="1" <?php echo $field['unique'] ? ' checked="checked"' : ''; ?> onclick="frmMarkUnique(<?php echo $field['id'] ?>,<?php echo ($field['unique']) ? 1 : 0; ?>)"/> <?php _e('Unique', 'formidable') ?></label>
215
  <?php } ?>
216
- <?php if($display['read_only']){
217
  if(!isset($field['read_only']))
218
  $field['read_only'] = false;
219
  ?>
220
  <label for="frm_read_only_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php _e('Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable') ?>" ><input type="checkbox" id="frm_read_only_field_<?php echo $field['id'] ?>" name="field_options[read_only_<?php echo $field['id'] ?>]" value="1" <?php echo $field['read_only'] ? ' checked="checked"' : ''; ?>/> <?php _e('Read Only', 'formidable') ?></label>
221
- <?php } ?>
222
-
 
 
 
223
  <?php if ($display['required']){ ?>
224
  <div class="frm_required_details<?php echo $field['id'] . ( $field['required'] ? '' : ' frm_hidden'); ?>">
225
  <span class="howto"><?php _e('Indicate required field with', 'formidable') ?></span>
@@ -228,17 +199,17 @@ if ($display['options']){ ?>
228
  <?php } ?>
229
  </td>
230
  </tr>
231
-
232
  <?php if ($display['css']){ ?>
233
  <tr><td><label><?php _e('CSS layout classes', 'formidable') ?></label>
234
  <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable') ?>" ></span>
235
  </td>
236
  <td><input type="text" name="field_options[classes_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['classes']) ?>" id="frm_classes_<?php echo $field['id'] ?>" class="frm_classes frm_long_input" />
237
- </td>
238
  </tr>
239
  <?php } ?>
240
  <?php if ($display['label_position']){ ?>
241
- <tr><td width="150px"><label><?php _e('Label Position', 'formidable') ?></label></td>
242
  <td><select name="field_options[label_<?php echo $field['id'] ?>]">
243
  <option value=""<?php selected($field['label'], ''); ?>><?php _e('Default', 'formidable') ?></option>
244
  <option value="top"<?php selected($field['label'], 'top'); ?>><?php _e('Top', 'formidable') ?></option>
@@ -248,29 +219,32 @@ if ($display['options']){ ?>
248
  <option value="none"<?php selected($field['label'], 'none'); ?>><?php _e('None', 'formidable') ?></option>
249
  <option value="hidden"<?php selected($field['label'], 'hidden'); ?>><?php _e('Hidden (but leave the space)', 'formidable') ?></option>
250
  </select>
251
- </td>
252
  </tr>
253
  <?php } ?>
254
  <?php if ($display['size']){ ?>
255
- <tr><td width="150px"><label><?php _e('Field Size', 'formidable') ?></label></td>
256
  <td>
257
  <?php if(in_array($field['type'], array('select', 'time', 'data'))){ ?>
258
- <?php if(!isset($values['custom_style']) or $values['custom_style']){ ?>
259
- <label for="size_<?php echo $field['id'] ?>"><input type="checkbox" name="field_options[size_<?php echo $field['id'] ?>]" id="size_<?php echo $field['id'] ?>" value="1" <?php echo (isset($field['size']) and $field['size'])? 'checked="checked"':''; ?> /> <?php _e('automatic width', 'formidable') ?>
260
  <?php }
261
  }else{ ?>
262
- <input type="text" name="field_options[size_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['size']); ?>" size="5" /> <span class="howto"><?php echo ($field['type'] == 'textarea' || $field['type'] == 'rte')? __('columns wide', 'formidable') : __('characters wide', 'formidable') ?></span>
263
 
264
  <input type="text" name="field_options[max_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['max']); ?>" size="5" /> <span class="howto"><?php echo ($field['type'] == 'textarea' || $field['type'] == 'rte')? __('rows high', 'formidable') : __('characters maximum', 'formidable') ?></span>
265
  <?php } ?>
266
  </td>
267
  </tr>
268
  <?php } ?>
269
- <?php do_action('frm_field_options_form', $field, $display, $values); ?>
270
-
271
- <?php if ($display['required'] or $display['invalid'] or $display['unique']){ ?>
272
- <tr class="frm_validation_msg <?php echo ($display['invalid'] || $field['required'] || (isset($field['unique']) && $field['unique'])) ? '' : 'frm_hidden'; ?>"><td><?php _e('Validation', 'formidable') ?></td>
273
- <td class="frm_validation_box">
 
 
 
274
  <?php if ($display['required']){ ?>
275
  <p class="frm_required_details<?php echo $field['id'] . ($field['required'] ? '' : ' frm_hidden'); ?>"><label><?php _e('Required', 'formidable') ?></label>
276
  <input type="text" name="field_options[blank_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['blank']); ?>" />
@@ -287,17 +261,38 @@ if ($display['options']){ ?>
287
  <input type="text" name="field_options[unique_msg_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['unique_msg']); ?>" />
288
  </p>
289
  <?php } ?>
290
- <?php if ($display['default_blank']){ //TODO ?>
 
 
 
 
291
  <?php } ?>
 
 
292
  </td>
293
  </tr>
294
  <?php } ?>
295
-
296
  </table>
297
  </div>
298
  </div>
299
- <?php } ?>
300
- <?php if(!isset($ajax)){ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  </li>
302
- <?php } ?>
303
- <?php unset($display); ?>
 
 
1
  <?php
2
+
3
+ $display = apply_filters('frm_display_field_options', array(
4
+ 'type' => $field['type'], 'field_data' => $field,
5
+ 'required' => true, 'unique' => false, 'read_only' => false,
6
+ 'description' => true, 'options' => true, 'label_position' => true,
7
+ 'invalid' => false, 'size' => false, 'clear_on_focus' => false,
8
+ 'default_blank' => true, 'css' => true, 'conf_field' => false,
9
+ ));
10
+
11
+ $li_classes = 'form-field edit_form_item frm_field_box frm_top_container frm_not_divider edit_field_type_'. $display['type'];
12
+ $li_classes = apply_filters('frm_build_field_class', $li_classes, $field );
13
+
14
+ if ( isset($values) && isset($values['ajax_load']) && $values['ajax_load'] && isset($count) && $count > 10 && ! in_array($field['type'], array('divider', 'end_divider')) ) {
15
+ ?>
16
+ <li id="frm_field_id_<?php echo $field['id']; ?>" class="<?php echo $li_classes ?> frm_field_loading" data-fid="<?php echo $field['id'] ?>" data-formid="<?php echo ( 'divider' == $field['type'] ) ? $field['form_select'] : $field['form_id']; ?>" data-ftype="<?php echo esc_attr($display['type']) ?>">
17
  <img src="<?php echo FrmAppHelper::plugin_url() ?>/images/ajax_loader.gif" alt="<?php _e('Loading', 'formidable') ?>" />
18
  <span class="frm_hidden_fdata frm_hidden"><?php echo htmlspecialchars(json_encode($field)) ?></span>
19
  </li>
21
  return;
22
  }
23
 
24
+ $frm_settings = FrmAppHelper::get_settings();
25
+
26
+ if ( !isset($frm_all_field_selection) ) {
27
+ if ( isset($frm_field_selection) && isset($pro_field_selection) ) {
28
+ $frm_all_field_selection = array_merge($frm_field_selection, $pro_field_selection);
29
+ } else {
30
+ $pro_field_selection = FrmFieldsHelper::pro_field_selection();
31
+ $frm_all_field_selection = array_merge(FrmFieldsHelper::field_selection(), $pro_field_selection);
32
  }
33
  }
34
 
35
+ $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
 
 
 
36
 
37
+
38
+ if ( !isset($ajax) ) {
39
+ $li_classes .= ' ui-state-default widgets-holder-wrap'; ?>
40
+ <li id="frm_field_id_<?php echo $field['id']; ?>" class="<?php echo $li_classes ?>" data-fid="<?php echo $field['id'] ?>" data-formid="<?php echo ( 'divider' == $field['type'] ) ? $field['form_select'] : $field['form_id']; ?>">
41
+ <?php
42
+ }
43
+
44
+ if ( $field['type'] == 'divider' ) { ?>
45
+ <div class="divider_section_only">
46
+ <?php
47
+ }
48
+ ?>
49
+
50
+ <a href="javascript:void(0);" class="frm_bstooltip alignright frm-show-hover frm-move frm-hover-icon frm_icon_font frm_move_icon" title="<?php esc_attr_e('Move Field', 'formidable') ?>"> </a>
51
+ <a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_delete_icon frm_delete_field" title="<?php esc_attr_e('Delete Field', 'formidable') ?>"> </a>
52
+ <a href="#" class="frm_bstooltip alignright frm-show-hover frm-hover-icon frm_icon_font frm_duplicate_icon" title="<?php esc_attr_e('Duplicate Field', 'formidable') ?>"> </a>
53
  <input type="hidden" name="frm_fields_submitted[]" value="<?php echo esc_attr($field['id']) ?>" />
54
  <?php do_action('frm_extra_field_actions', $field['id']); ?>
55
+ <?php if ( $display['required'] ) { ?>
56
  <span id="require_field_<?php echo $field['id']; ?>">
57
+ <a href="javascript:void(0);" class="frm_req_field frm_action_icon frm_required_icon frm_icon_font alignleft frm_required<?php echo (int) $field['required'] ?>" id="req_field_<?php echo $field['id']; ?>" title="Click to Mark as <?php echo ($field['required'] == '0') ? '' : 'not '; ?>Required"></a>
58
  </span>
59
+ <?php }
60
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  ?>
62
+ <label class="<?php echo ( $field['type'] == 'end_divider' ) ? '' : 'frm_ipe_field_label'; ?> frm_primary_label <?php echo ($field['type'] == 'break') ? 'button': ''; ?>" id="field_label_<?php echo $field['id']; ?>"><?php echo ($field['name'] == '') ? __('(no label)') : force_balance_tags($field['name']); ?></label>
63
 
64
+
65
+ <div id="field_<?php echo $field['id'] ?>_inner_container" class="frm_inner_field_container">
66
+ <div class="frm_form_fields" data-ftype="<?php echo $display['type'] ?>">
67
  <?php
68
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-fields/show-build.php');
69
 
70
+ if ($display['clear_on_focus']){ ?>
71
+ <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm-show-click">
 
 
 
 
 
 
 
 
72
  <?php
73
+ if ( $display['default_blank'] ) {
74
+ FrmFieldsHelper::show_default_blank_js($field['default_blank']);
75
  }
76
+
77
+ FrmFieldsHelper::show_onfocus_js($field['clear_on_focus']);
78
  ?>
79
+ </span>
80
  <?php
81
+
82
+ do_action('frm_extra_field_display_options', $field);
83
+ }
84
+ ?>
85
+ <div class="clear"></div>
86
+ </div>
87
+ <?php
88
+ if ($display['description']){ ?>
89
+ <div class="frm_ipe_field_desc description <?php echo ($field['description'] == '') ? 'frm-show-click' : '' ?>" id="field_description_<?php echo $field['id']; ?>"><?php echo ($field['description'] == '') ? __('(Click to add description)', 'formidable') : force_balance_tags($field['description']); ?></div>
90
+ <input type="hidden" name="field_options[description_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['description']); ?>" />
91
+
92
+ <?php } ?>
93
+ </div> <?php //End field_x_inner_container div
94
+
95
+ if ( $display['conf_field'] ) { ?>
96
+ <div id="frm_conf_field_<?php echo $field['id'] ?>_container" class="frm_conf_field_container frm_form_fields frm_conf_details<?php echo $field['id'] . ($field['conf_field'] ? '' : ' frm_hidden'); ?>">
97
+ <div id="frm_conf_field_<?php echo $field['id'] ?>_inner_container" class="frm_inner_conf_container">
98
+ <input type="text" id="conf_field_<?php echo $field['field_key'] ?>" name="field_options[conf_input_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['conf_input']); ?>" <?php do_action('frm_field_input_html', $field) ?> />
99
+ <div class="frm_ipe_field_conf_desc description <?php echo ($field['conf_desc'] == '') ? 'frm-show-click' : '' ?>"><?php echo ($field['conf_desc'] == '') ? __('(Click to add description)', 'formidable') : force_balance_tags($field['conf_desc']); ?></div>
100
+ <input type="hidden" name="field_options[conf_desc_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['conf_desc']); ?>" />
101
+ </div>
102
+ <?php if ($display['clear_on_focus']){ ?>
103
+ <div class="alignleft">
104
+ <span id="frm_clear_on_focus_<?php echo $field['id'] ?>" class="frm-show-click">
105
+ <?php
106
+ if ( $display['default_blank'] ) {
107
+ FrmFieldsHelper::show_default_blank_js($field['default_blank']);
108
+ }
109
+
110
+ FrmFieldsHelper::show_onfocus_js($field['clear_on_focus']);
111
+ ?>
112
+ </span>
113
+ </div>
114
  <?php } ?>
115
+ </div>
116
+ <div class="clear"></div>
117
+ <?php }
118
+
119
+ if ( in_array($field['type'], array( 'select', 'radio', 'checkbox')) ) { ?>
120
  <div class="frm-show-click" style="margin-top:5px;">
121
+ <?php
 
122
  if ( isset($field['post_field']) && $field['post_field'] == 'post_category' ) {
123
  echo '<p class="howto">'. FrmFieldsHelper::get_term_link($field['taxonomy']) .'</p>';
124
+ } else if ( !isset($field['post_field']) || !in_array($field['post_field'], array('post_category', 'post_status')) ) {
125
+ ?>
 
 
 
 
 
 
 
 
 
 
126
  <div id="frm_add_field_<?php echo $field['id']; ?>">
127
+ <a href="javascript:void(0);" data-opttype="single" class="button frm_cb_button frm_add_opt"><?php _e('Add Option', 'formidable') ?></a>
128
+
129
+ <?php if ( FrmAppHelper::pro_is_installed() && $field['type'] != 'select' ) { ?>
130
+ <a href="javascript:void(0);" id="other_button_<?php echo $field['id']; ?>" data-opttype="other" data-ftype="<?php echo $field['type']?>" class="button frm_cb_button frm_add_opt<?php echo ( $field['type'] == 'radio' && $field['other'] == true ? ' frm_hidden' : '' ); ?>"><?php _e('Add "Other"', 'formidable') ?></a>
131
+ <input type="hidden" value="<?php echo $field['other']; ?>" id="other_input_<?php echo $field['id']; ?>" name="field_options[other_<?php echo $field['id']; ?>]">
132
+ <?php }
133
+
134
+ if (!isset($field['post_field']) or $field['post_field'] != 'post_category'){ ?>
135
+ <a href="<?php echo esc_url(admin_url('admin-ajax.php') .'?action=frm_import_choices&field_id='. $field['id'] .'&TB_iframe=1') ?>" title="<?php echo FrmAppHelper::truncate(esc_attr(strip_tags(str_replace('"', '&quot;', $field['name']))), 20) . ' '. __('Field Choices', 'formidable'); ?>" class="thickbox frm_orange"><?php _e('Bulk Edit Options', 'formidable') ?></a>
136
  <?php } ?>
137
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  <?php
139
+ }
 
 
 
 
 
 
 
 
 
140
  ?>
141
+ </div>
 
 
 
 
142
  <?php
143
  }
144
 
145
+ do_action('frm_before_field_options', $field);
146
+
147
  if ($display['options']){ ?>
148
  <div class="widget">
149
  <div class="widget-top">
150
+ <div class="widget-title-action"><a href="javascript:void(0);" class="widget-action"></a></div>
151
  <div class="widget-title"><h4><?php _e('Field Options', 'formidable') ?> (ID <?php echo $field['id'] ?>)</h4></div>
152
  </div>
153
  <div class="widget-inside">
154
  <table class="form-table" style="clear:none;">
155
  <?php $field_types = FrmFieldsHelper::get_field_types($field['type']); ?>
156
+ <tr><td style="width:150px"><label><?php _e('Field Type', 'formidable') ?></label></td>
157
  <td>
158
  <div class="hide-if-no-js edit-slug-box frm_help" title="<?php _e('The field key can be used as an alternative to the field ID in many cases.', 'formidable') ?>">
159
  <?php _e('Field Key:', 'formidable') ?>
162
  <input type="hidden" name="field_options[field_key_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['field_key']); ?>" />
163
  <?php } ?>
164
  </div>
165
+
166
+ <select <?php if ( count($field_types) == 1 ) { ?>disabled="disabled"<?php } else { ?>name="field_options[type_<?php echo $field['id'] ?>]"<?php } ?>>
167
+ <?php foreach ( $field_types as $fkey => $ftype ) { ?>
168
+ <option value="<?php echo $fkey ?>" <?php echo ($fkey == $field['type']) ? ' selected="selected"' : ''; ?> <?php echo array_key_exists($fkey, $disabled_fields ) ? 'disabled="disabled"' : ''; ?>><?php echo is_array($ftype) ? $ftype['name'] : $ftype ?> </option>
 
169
  <?php
170
  unset($fkey);
171
  unset($ftype);
172
  } ?>
173
+ </select>
174
+
175
+ <?php if ( $display['required'] ) { ?>
 
 
 
 
176
  <label for="frm_req_field_<?php echo $field['id'] ?>" class="frm_inline_label"><input type="checkbox" id="frm_req_field_<?php echo $field['id'] ?>" class="frm_req_field" name="field_options[required_<?php echo $field['id'] ?>]" value="1" <?php echo ($field['required']) ? 'checked="checked"': ''; ?> /> <?php _e('Required', 'formidable') ?></label>
177
  <?php } ?>
178
+ <?php if($display['unique']){
179
  if(!isset($field['unique']))
180
  $field['unique'] = false;
181
  ?>
182
+ <label for="frm_uniq_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php _e('Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\' then no one else will be allowed to enter the same name.', 'formidable') ?>"><input type="checkbox" name="field_options[unique_<?php echo $field['id'] ?>]" id="frm_uniq_field_<?php echo $field['id'] ?>" value="1" <?php checked($field['unique'], 1); ?> class="frm_mark_unique" /> <?php _e('Unique', 'formidable') ?></label>
183
  <?php } ?>
184
+ <?php if($display['read_only']){
185
  if(!isset($field['read_only']))
186
  $field['read_only'] = false;
187
  ?>
188
  <label for="frm_read_only_field_<?php echo $field['id'] ?>" class="frm_inline_label frm_help" title="<?php _e('Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable') ?>" ><input type="checkbox" id="frm_read_only_field_<?php echo $field['id'] ?>" name="field_options[read_only_<?php echo $field['id'] ?>]" value="1" <?php echo $field['read_only'] ? ' checked="checked"' : ''; ?>/> <?php _e('Read Only', 'formidable') ?></label>
189
+ <?php }
190
+
191
+ do_action('frm_field_options_form_top', $field, $display, $values);
192
+
193
+ ?>
194
  <?php if ($display['required']){ ?>
195
  <div class="frm_required_details<?php echo $field['id'] . ( $field['required'] ? '' : ' frm_hidden'); ?>">
196
  <span class="howto"><?php _e('Indicate required field with', 'formidable') ?></span>
199
  <?php } ?>
200
  </td>
201
  </tr>
202
+
203
  <?php if ($display['css']){ ?>
204
  <tr><td><label><?php _e('CSS layout classes', 'formidable') ?></label>
205
  <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Add a CSS class to the field container. Use our predefined classes to align multiple fields in single row.', 'formidable') ?>" ></span>
206
  </td>
207
  <td><input type="text" name="field_options[classes_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['classes']) ?>" id="frm_classes_<?php echo $field['id'] ?>" class="frm_classes frm_long_input" />
208
+ </td>
209
  </tr>
210
  <?php } ?>
211
  <?php if ($display['label_position']){ ?>
212
+ <tr><td style="width:150px"><label><?php _e('Label Position', 'formidable') ?></label></td>
213
  <td><select name="field_options[label_<?php echo $field['id'] ?>]">
214
  <option value=""<?php selected($field['label'], ''); ?>><?php _e('Default', 'formidable') ?></option>
215
  <option value="top"<?php selected($field['label'], 'top'); ?>><?php _e('Top', 'formidable') ?></option>
219
  <option value="none"<?php selected($field['label'], 'none'); ?>><?php _e('None', 'formidable') ?></option>
220
  <option value="hidden"<?php selected($field['label'], 'hidden'); ?>><?php _e('Hidden (but leave the space)', 'formidable') ?></option>
221
  </select>
222
+ </td>
223
  </tr>
224
  <?php } ?>
225
  <?php if ($display['size']){ ?>
226
+ <tr><td style="width:150px"><label><?php _e('Field Size', 'formidable') ?></label></td>
227
  <td>
228
  <?php if(in_array($field['type'], array('select', 'time', 'data'))){ ?>
229
+ <?php if ( ! isset($values['custom_style']) || $values['custom_style'] ) { ?>
230
+ <label for="size_<?php echo $field['id'] ?>"><input type="checkbox" name="field_options[size_<?php echo $field['id'] ?>]" id="size_<?php echo $field['id'] ?>" value="1" <?php echo (isset($field['size']) && $field['size'])? 'checked="checked"':''; ?> /> <?php _e('automatic width', 'formidable') ?></label>
231
  <?php }
232
  }else{ ?>
233
+ <input type="text" name="field_options[size_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['size']); ?>" size="5" /> <span class="howto"><?php _e('pixels wide', 'formidable') ?></span>
234
 
235
  <input type="text" name="field_options[max_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['max']); ?>" size="5" /> <span class="howto"><?php echo ($field['type'] == 'textarea' || $field['type'] == 'rte')? __('rows high', 'formidable') : __('characters maximum', 'formidable') ?></span>
236
  <?php } ?>
237
  </td>
238
  </tr>
239
  <?php } ?>
240
+ <?php do_action('frm_field_options_form', $field, $display, $values);
241
+
242
+ if ( $display['required'] || $display['invalid'] || $display['unique'] || $display['conf_field'] ) { ?>
243
+ <tr class="frm_validation_msg <?php echo ($display['invalid'] || $field['required'] || (isset($field['unique']) && $field['unique']) || ( isset($field['conf_field']) && $field['conf_field'] ) ) ? '' : 'frm_hidden'; ?>"><td colspan="2">
244
+ <div class="menu-settings">
245
+ <h3 class="frm_no_bg"><?php _e('Validation', 'formidable') ?></h3>
246
+
247
+ <div class="frm_validation_box">
248
  <?php if ($display['required']){ ?>
249
  <p class="frm_required_details<?php echo $field['id'] . ($field['required'] ? '' : ' frm_hidden'); ?>"><label><?php _e('Required', 'formidable') ?></label>
250
  <input type="text" name="field_options[blank_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['blank']); ?>" />
261
  <input type="text" name="field_options[unique_msg_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['unique_msg']); ?>" />
262
  </p>
263
  <?php } ?>
264
+ <?php if ( $display['conf_field'] ) { ?>
265
+ <p class="frm_conf_details<?php echo $field['id'] . ($field['conf_field'] ? '' : ' frm_hidden'); ?>">
266
+ <label><?php _e('Confirmation', 'formidable') ?></label>
267
+ <input type="text" name="field_options[conf_msg_<?php echo $field['id'] ?>]" value="<?php echo esc_attr($field['conf_msg']); ?>" />
268
+ </p>
269
  <?php } ?>
270
+ </div>
271
+ </div>
272
  </td>
273
  </tr>
274
  <?php } ?>
275
+
276
  </table>
277
  </div>
278
  </div>
279
+ <?php }
280
+
281
+ if ( $field['type'] == 'divider' ) { ?>
282
+ </div>
283
+ <div class="frm_no_section_fields">
284
+ <p class="howto"><?php _e('Drag fields from your form or the sidebar into this section', 'formidable') ?></p>
285
+ </div>
286
+ <ul class="start_divider frm_sorting">
287
+ <?php
288
+ } else if ( $field['type'] == 'end_divider' ) { ?>
289
+ </ul>
290
+ <?php
291
+ }
292
+
293
+ if ( !isset($ajax) ) { ?>
294
  </li>
295
+ <?php
296
+ }
297
+
298
+ unset($display);
classes/views/frm-forms/add_field_links.php CHANGED
@@ -1,22 +1,16 @@
1
- <div id="postbox-container-1" class="<?php echo FrmAppController::get_postbox_class(); ?>">
2
- <?php if(!isset($hide_preview) or !$hide_preview){
3
- if (!$values['is_template']){ ?>
4
- <p class="howto" style="margin-top:0;"><?php _e('Insert into a post, page, display or text widget', 'formidable') ?>:
5
- <input type="text" readonly="true" class="frm_select_box" value='[formidable id=<?php echo $id; ?>]' /></p>
6
- <?php } ?>
7
-
8
- <?php if(isset($values['form_key'])){ ?>
9
- <p class="frm_orange"><a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" target="_blank"><?php _e('Preview Form', 'formidable') ?></a>
10
- <?php global $frm_settings;
11
- if (!empty($frm_settings->preview_page_id)){ ?>
12
- <?php _e('or', 'formidable') ?>
13
- <a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('Preview in Current Theme', 'formidable') ?></a>
14
- <?php } ?>
15
- </p>
16
- <?php }
17
- } ?>
18
  <div id="frm_position_ele"></div>
19
-
 
20
  <div class="postbox frm_field_list">
21
  <div class="inside">
22
  <div id="taxonomy-linkcategory" class="categorydiv">
@@ -27,35 +21,66 @@
27
  </ul>
28
 
29
  <div id="frm-insert-fields" class="tabs-panel" style="max-height:none;overflow:visible;">
30
- <ul class="field_type_list">
31
- <?php
32
  $col_class = 'frm_col_one';
33
- foreach ($frm_field_selection as $field_key => $field_type){ ?>
34
- <li class="frmbutton button <?php echo $col_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>"><a href="javascript:add_frm_field_link(<?php echo $id ?>,'<?php echo $field_key ?>');"><?php echo $field_type ?></a></li>
35
- <?php
36
- $col_class = (empty($col_class)) ? 'frm_col_one' : '';
37
- } ?>
38
- </ul>
39
- <div class="clear"></div>
40
-
41
- <h4 class="title" style="margin-bottom:0;margin-top:4px;"><?php _e('Pro Fields', 'formidable') ?></h4>
42
- <ul<?php echo apply_filters('frm_drag_field_class', '') ?> style="margin-top:2px;">
43
- <?php $col_class = 'frm_col_one';
44
- foreach (FrmFieldsHelper::pro_field_selection() as $field_key => $field_type){ ?>
45
- <li class="frmbutton button <?php echo $col_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>"><?php echo apply_filters('frmpro_field_links', $field_type, $id, $field_key) ?></li>
46
- <?php
47
- $col_class = (empty($col_class)) ? 'frm_col_one' : '';
48
  } ?>
49
- </ul>
50
- <div class="clear"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  </div>
52
  <?php do_action('frm_extra_form_instructions'); ?>
53
-
54
  <div id="frm-layout-classes" class="tabs-panel" style="display:none;max-height:none;">
55
  <p class="howto"><?php _e('Add classes in the "CSS layout classes" field option', 'formidable') ?></p>
56
  <ul class="frm_code_list">
57
  <?php $classes = array(
58
- 'frm_first_half' => __('First 1/2', 'formidable'),
59
  'frm_last_half' => __('Last 1/2', 'formidable'),
60
  'frm_first_third' => __('First 1/3', 'formidable'),
61
  'frm_last_third' => __('Last 1/3', 'formidable'),
@@ -64,16 +89,16 @@
64
  'frm_third' => __('1/3', 'formidable'),
65
  'frm_fourth' => __('1/4', 'formidable'),
66
  'frm_first_fourth' => array('label' => __('First 1/4', 'formidable')),
67
- 'frm_last_fourth' => __('Last 1/4', 'formidable'),
68
  'frm_first_fifth' => __('First 1/5', 'formidable'),
69
  'frm_last_fifth' => __('Last 1/5', 'formidable'),
70
  'frm_fifth' => __('1/5', 'formidable'),
71
  'frm_inline' => array('label' => __('Inline', 'formidable'), 'title' => __('Align fields in a row without a specific width.', 'formidable')),
72
- 'frm_first_inline' => array('label' => __('First Inline', 'formidable'), 'title' => __('Align fields at the beginning of a row without a specific width.', 'formidable')),
73
  'frm_last_inline' => array('label' => __('Last Inline', 'formidable'), 'title' => __('Align fields at the end of a row without a specific width.', 'formidable')),
74
-
75
  'frm_full' => array('label' => __('100% width', 'formidable'), 'title' => __('Force the field to fill the full space with 100% width.', 'formidable')),
76
- 'frm_grid_first' => __('First Grid Row', 'formidable'),
77
  'frm_grid' => __('Even Grid Row', 'formidable'),
78
  'frm_grid_odd' => __('Odd Grid Row', 'formidable'),
79
  'frm_two_col' => array('label' => __('2 Col Options', 'formidable'), 'title' => __('Put your radio button or checkbox options into two columns.', 'formidable')),
@@ -85,18 +110,25 @@
85
  $classes = apply_filters('frm_layout_classes', $classes);
86
  $col = 'one';
87
  foreach($classes as $c => $d){
88
- $title = (!empty($d) and is_array($d) and isset($d['title'])) ? $d['title'] : '';
89
  ?>
90
  <li class="frm_col_<?php echo $col ?>">
91
- <a class="frmbutton frm_insert_code button show_frm_classes<?php if(!empty($title)) echo ' frm_help'; ?>" data-code="<?php echo esc_attr($c) ?>" href="javascript:void(0)" <?php if(!empty($title)){ ?>title="<?php echo esc_attr($title); ?>"<?php } ?>>
92
- <?php
93
- if(empty($d))
 
 
 
 
 
 
94
  echo $c;
95
- else if(!is_array($d))
96
  echo $d;
97
- else if(isset($d['label']))
98
  echo $d['label'];
99
- ?>
 
100
  </a>
101
  </li>
102
  <?php
@@ -107,19 +139,25 @@
107
  ?>
108
  </ul>
109
  </div>
110
-
111
- <?php
112
- $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
113
- $action = FrmAppHelper::get_param($action);
114
- $button = ($action == 'new' or $action == 'duplicate') ? __('Create', 'formidable') : __('Update', 'formidable');
115
- ?>
116
- <form method="post" id="frm_js_build_form">
117
- <input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
118
- <p><input type="button" onclick="frmSubmit<?php echo (isset($values['ajax_load']) and $values['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php echo esc_attr($button) ?>" class="frm_submit_form button-primary" id="frm_submit_side" />
119
- <span class="frm-loading-img"></span>
120
- </p>
121
- </form>
122
  </div>
123
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  </div>
125
- </div>
1
+ <div id="postbox-container-1" class="postbox-container">
2
+
3
+ <?php
4
+ $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
5
+ $action = FrmAppHelper::get_param($action);
6
+ $button = ($action == 'new' or $action == 'duplicate') ? __('Create', 'formidable') : __('Update', 'formidable');
7
+ ?>
8
+
9
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/_publish_box.php') ?>
10
+
 
 
 
 
 
 
 
11
  <div id="frm_position_ele"></div>
12
+
13
+
14
  <div class="postbox frm_field_list">
15
  <div class="inside">
16
  <div id="taxonomy-linkcategory" class="categorydiv">
21
  </ul>
22
 
23
  <div id="frm-insert-fields" class="tabs-panel" style="max-height:none;overflow:visible;">
24
+ <ul class="field_type_list">
25
+ <?php
26
  $col_class = 'frm_col_one';
27
+ foreach ( $frm_field_selection as $field_key => $field_type ) { ?>
28
+ <li class="frmbutton button <?php echo $col_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>"><a href="#" class="frm_add_field"><?php echo $field_type ?></a></li>
29
+ <?php
30
+ $col_class = (empty($col_class)) ? 'frm_col_one' : '';
31
+ unset($field_key, $field_type);
 
 
 
 
 
 
 
 
 
 
32
  } ?>
33
+ </ul>
34
+ <div class="clear"></div>
35
+ <hr/>
36
+ <ul<?php echo apply_filters('frm_drag_field_class', '') ?> style="margin-top:2px;">
37
+ <?php $col_class = 'frm_col_one';
38
+ $no_allow_class = apply_filters('frm_noallow_class', 'frm_noallow');
39
+ foreach ( FrmFieldsHelper::pro_field_selection() as $field_key => $field_type ) {
40
+
41
+ if ( is_array($field_type) ) {
42
+ $field_label = $field_type['name'];
43
+
44
+ if ( isset($field_type['switch_from']) ) { ?>
45
+ <li class="frmbutton button <?php echo $col_class .' '. $no_allow_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>" data-switchto="<?php echo $field_type['switch_from'] ?>" style="display:none !important;"><?php echo apply_filters('frmpro_field_links', $field_label, $id, $field_key) ?></li>
46
+ <?php
47
+ continue;
48
+ }
49
+
50
+ ?>
51
+ <li class="frmbutton button <?php echo $col_class .' '. $no_allow_class ?> frm_t<?php echo $field_key ?> dropdown" id="<?php echo $field_key ?>" <?php echo (isset($field_type['switch_to'])) ? 'data-switchto="'. $field_type['switch_to'] .'"' : ''; ?>>
52
+ <a href="#" id="frm-<?php echo $field_key ?>Drop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php echo $field_label ?> <b class="caret"></b></a>
53
+
54
+ <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-<?php echo $field_key ?>Drop">
55
+ <?php foreach ( $field_type['types'] as $k => $type ) {
56
+ ?>
57
+ <li class="frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>|<?php echo $k ?>"><?php echo apply_filters('frmpro_field_links', $type, $id, $field_key .'|'. $k) ?></li>
58
+ <?php
59
+ unset($k, $type);
60
+ } ?>
61
+ </ul>
62
+ </li>
63
+ <?php
64
+ } else {
65
+ $field_label = $field_type;
66
+ ?>
67
+ <li class="frmbutton button <?php echo $col_class .' '. $no_allow_class ?> frm_t<?php echo $field_key ?>" id="<?php echo $field_key ?>"><?php echo apply_filters('frmpro_field_links', $field_label, $id, $field_key) ?></li>
68
+ <?php
69
+ }
70
+
71
+ $col_class = empty($col_class) ? 'frm_col_one' : '';
72
+ unset($field_key, $field_type, $field_label);
73
+ } ?>
74
+ </ul>
75
+ <div class="clear"></div>
76
  </div>
77
  <?php do_action('frm_extra_form_instructions'); ?>
78
+
79
  <div id="frm-layout-classes" class="tabs-panel" style="display:none;max-height:none;">
80
  <p class="howto"><?php _e('Add classes in the "CSS layout classes" field option', 'formidable') ?></p>
81
  <ul class="frm_code_list">
82
  <?php $classes = array(
83
+ 'frm_first_half' => __('First 1/2', 'formidable'),
84
  'frm_last_half' => __('Last 1/2', 'formidable'),
85
  'frm_first_third' => __('First 1/3', 'formidable'),
86
  'frm_last_third' => __('Last 1/3', 'formidable'),
89
  'frm_third' => __('1/3', 'formidable'),
90
  'frm_fourth' => __('1/4', 'formidable'),
91
  'frm_first_fourth' => array('label' => __('First 1/4', 'formidable')),
92
+ 'frm_last_fourth' => __('Last 1/4', 'formidable'),
93
  'frm_first_fifth' => __('First 1/5', 'formidable'),
94
  'frm_last_fifth' => __('Last 1/5', 'formidable'),
95
  'frm_fifth' => __('1/5', 'formidable'),
96
  'frm_inline' => array('label' => __('Inline', 'formidable'), 'title' => __('Align fields in a row without a specific width.', 'formidable')),
97
+ 'frm_first_inline' => array('label' => __('First Inline', 'formidable'), 'title' => __('Align fields at the beginning of a row without a specific width.', 'formidable')),
98
  'frm_last_inline' => array('label' => __('Last Inline', 'formidable'), 'title' => __('Align fields at the end of a row without a specific width.', 'formidable')),
99
+
100
  'frm_full' => array('label' => __('100% width', 'formidable'), 'title' => __('Force the field to fill the full space with 100% width.', 'formidable')),
101
+ 'frm_grid_first' => __('First Grid Row', 'formidable'),
102
  'frm_grid' => __('Even Grid Row', 'formidable'),
103
  'frm_grid_odd' => __('Odd Grid Row', 'formidable'),
104
  'frm_two_col' => array('label' => __('2 Col Options', 'formidable'), 'title' => __('Put your radio button or checkbox options into two columns.', 'formidable')),
110
  $classes = apply_filters('frm_layout_classes', $classes);
111
  $col = 'one';
112
  foreach($classes as $c => $d){
113
+ $title = ( ! empty($d) && is_array($d) && isset($d['title']) ) ? $d['title'] : '';
114
  ?>
115
  <li class="frm_col_<?php echo $col ?>">
116
+ <a href="javascript:void(0);" class="frmbutton frm_insert_code button show_frm_classes<?php
117
+ if ( ! empty($title) ) {
118
+ echo ' frm_help';
119
+ } ?>" data-code="<?php echo esc_attr($c) ?>" <?php
120
+ if ( ! empty($title) ) {
121
+ ?>title="<?php echo esc_attr($title); ?>"<?php
122
+ } ?>>
123
+ <?php
124
+ if ( empty($d) ) {
125
  echo $c;
126
+ } else if ( !is_array($d) ) {
127
  echo $d;
128
+ } else if ( isset($d['label']) ) {
129
  echo $d['label'];
130
+ }
131
+ ?>
132
  </a>
133
  </li>
134
  <?php
139
  ?>
140
  </ul>
141
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
142
  </div>
143
  </div>
144
+
145
+ <div class="submitbox" id="major-publishing-actions">
146
+ <div id="delete-action">
147
+ <?php echo FrmFormsHelper::delete_trash_link($id, $values['status']); ?>
148
+ </div>
149
+
150
+ <div id="publishing-action">
151
+ <form method="post" id="frm_js_build_form">
152
+ <span class="spinner"></span>
153
+ <input type="hidden" id="frm_compact_fields" name="frm_compact_fields" value="" />
154
+ <input type="button" value="<?php echo esc_attr($button) ?>" class="frm_submit_form frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary button-large" id="frm_submit_side" />
155
+ </form>
156
+ </div>
157
+ <div class="clear"></div>
158
+ </div><!-- #major-publishing-actions -->
159
+
160
+
161
+
162
  </div>
163
+ </div>
classes/views/frm-forms/default-templates.php DELETED
@@ -1,47 +0,0 @@
1
- <?php FrmFormsHelper::get_template_dropdown($all_templates); ?>
2
-
3
- <h3><?php _e('Default Templates', 'formidable') ?></h3>
4
- <table class="widefat post fixed" id="posts-filter" cellspacing="0">
5
- <thead>
6
- <tr>
7
- <th class="manage-column" width="30%"><?php _e('Name') ?></th>
8
- <th class="manage-column"><?php _e('Description') ?></th>
9
- </tr>
10
- </thead>
11
- <?php if(empty($default_templates)){ ?>
12
- <tr><td colspan="2"><?php _e('No Templates Found', 'formidable') ?></td></tr>
13
- <?php
14
- }else{
15
- $alternate = false;
16
- foreach($default_templates as $form){
17
- $alternate = (!$alternate) ? 'alternate' : false;
18
- ?>
19
- <tr class="<?php echo $alternate ?>">
20
- <td class="post-title">
21
- <a class="row-title" href="<?php echo $url = FrmFormsHelper::get_direct_link($form->form_key, $form); ?>" title="<?php _e('View', 'formidable')?> <?php echo esc_attr($form->name) ?>" target="blank"><?php echo $form->name; ?></a><br/>
22
- <div class="row-actions">
23
- <?php if(current_user_can('frm_edit_forms')){ ?>
24
- <span><a href="?page=formidable&amp;frm_action=duplicate&amp;id=<?php echo $form->id; ?>"><?php _e('Create Form from Template', 'formidable') ?></a></span> |
25
- <?php } ?>
26
- <?php global $frm_settings;
27
- if ($frm_settings->preview_page_id > 0)
28
- $url = add_query_arg('form', $form->form_key, get_permalink($frm_settings->preview_page_id));
29
- ?>
30
- <span><a href="<?php echo $url ?>" target="blank"><?php _e('View', 'formidable') ?></a></span>
31
- </div>
32
- </td>
33
- <td><?php echo $form->description ?></td>
34
- </tr>
35
- <?php
36
- }
37
- }
38
- ?>
39
- <tfoot>
40
- <tr>
41
- <th class="manage-column"><?php _e('Name') ?></th>
42
- <th class="manage-column"><?php _e('Description') ?></th>
43
- </tr>
44
- </tfoot>
45
- </table>
46
-
47
- <br/><br/><h3><?php _e('Custom Templates', 'formidable') ?></h3>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-forms/edit.php CHANGED
@@ -3,51 +3,40 @@
3
  <h2><?php echo ( $form->is_template ? __('Templates', 'formidable') : __('Build', 'formidable')); ?>
4
  <a href="?page=formidable&amp;frm_action=new-selection" class="add-new-h2"><?php _e('Add New', 'formidable'); ?></a>
5
  </h2>
6
- <?php
7
- if ( ! $form->is_template ) {
8
- FrmAppController::get_form_nav($id, true);
9
- }
10
- require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
-
12
- if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
13
- <div id="poststuff" class="metabox-holder has-right-sidebar">
14
- <?php
15
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
16
- }else{ ?>
17
- <div id="poststuff">
18
- <?php } ?>
19
 
20
  <div id="post-body" class="metabox-holder columns-2">
21
  <div id="post-body-content">
22
- <div class="frm_form_builder<?php echo (isset($form->options['custom_style']) && $form->options['custom_style']) ? ' with_frm_style' : ''; ?>">
23
-
24
- <p style="margin-top:0;">
25
- <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
26
- <?php _e('or', 'formidable') ?>
27
- <a class="button-secondary cancel" href="?page=formidable<?php echo ($form->is_template) ? '-templates' : ''; ?>"><?php _e('Cancel', 'formidable') ?></a>
 
 
 
 
 
28
  <span class="frm-loading-img"></span>
29
  </p>
30
-
31
  <form method="post" id="frm_build_form">
32
  <input type="hidden" name="frm_action" value="update" />
33
  <input type="hidden" name="action" value="update" />
34
- <input type="hidden" name="id" value="<?php echo $id; ?>" />
35
 
36
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
37
 
38
- <p>
39
- <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
40
- <?php _e('or', 'formidable') ?>
41
- <a class="button-secondary cancel" href="?page=formidable<?php echo $form->is_template ? '-templates' : ''; ?>"><?php _e('Cancel', 'formidable') ?></a>
42
  <span class="frm-loading-img"></span>
43
  </p>
44
  </form>
45
  </div>
46
  </div>
47
- <?php
48
- if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
49
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
50
- ?>
51
  </div>
52
  </div>
53
  </div>
3
  <h2><?php echo ( $form->is_template ? __('Templates', 'formidable') : __('Build', 'formidable')); ?>
4
  <a href="?page=formidable&amp;frm_action=new-selection" class="add-new-h2"><?php _e('Add New', 'formidable'); ?></a>
5
  </h2>
6
+
7
+ <div id="poststuff">
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  <div id="post-body" class="metabox-holder columns-2">
10
  <div id="post-body-content">
11
+ <?php
12
+ if ( !$values['is_template'] ) {
13
+ FrmAppController::get_form_nav($id, true, 'hide');
14
+ }
15
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
16
+
17
+ ?>
18
+ <div class="frm_form_builder<?php echo FrmFormsHelper::get_form_style_class($form); ?>">
19
+
20
+ <p style="display:none;margin-top:0;">
21
+ <input type="button" value="<?php _e('Update', 'formidable') ?>" class="frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary" />
22
  <span class="frm-loading-img"></span>
23
  </p>
24
+
25
  <form method="post" id="frm_build_form">
26
  <input type="hidden" name="frm_action" value="update" />
27
  <input type="hidden" name="action" value="update" />
28
+ <input type="hidden" name="id" id="form_id" value="<?php echo $id; ?>" />
29
 
30
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
31
 
32
+ <p>
33
+ <input type="button" value="<?php _e('Update', 'formidable') ?>" class="frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary" />
 
 
34
  <span class="frm-loading-img"></span>
35
  </p>
36
  </form>
37
  </div>
38
  </div>
39
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php'); ?>
 
 
 
40
  </div>
41
  </div>
42
  </div>
classes/views/frm-forms/form.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php wp_nonce_field('frm_save_form_nonce', 'frm_save_form'); ?>
 
 
2
 
3
  <div id="frm_form_editor_container">
4
  <div id="titlediv">
@@ -8,26 +10,43 @@
8
  <strong><?php _e('Form Key:', 'formidable') ?></strong>
9
  <div id="editable-post-name" class="frm_ipe_form_key" title="<?php _e('Click to edit.', 'formidable') ?>"><?php echo $form->form_key; ?></div>
10
  </div>
11
- <div class="frm_ipe_form_desc alignleft" style="width:70%"><?php echo ($form->description == '') ? __('(Click here to add a description or instructions)', 'formidable') : force_balance_tags($form->description); ?></div>
12
  <div style="clear:both"></div>
13
  </div>
14
  </div>
15
 
16
  <div <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'class="postbox"' : ''; ?>>
17
- <div class="frm_no_fields <?php echo ( isset($values['fields']) && ! empty($values['fields']) ) ? 'frm_hidden' : ''; ?>">
18
- <div class="frm_brace">{</div>
19
- <div class="alignright frm_nofields_text">
20
- <div class="frm_all_field_inst"><?php _e('Add fields here', 'formidable') ?></div>
21
- <div class="frm_drag_inst"><?php _e('(Just click or drag)', 'formidable') ?></div>
22
- </div>
23
- </div>
24
- <ul id="new_fields" class="<?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'inside' : ''; ?>">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  <?php
26
  if ( isset($values['fields']) && ! empty($values['fields']) ) {
27
  $count = 0;
28
  foreach ( $values['fields'] as $field ) {
29
  $count++;
30
  $field_name = 'item_meta['. $field['id'] .']';
 
31
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
32
  unset($field, $field_name);
33
  }
1
  <?php wp_nonce_field('frm_save_form_nonce', 'frm_save_form'); ?>
2
+ <input type="hidden" name="status" value="<?php echo $values['status']; ?>" />
3
+ <input type="hidden" name="new_status" value="" />
4
 
5
  <div id="frm_form_editor_container">
6
  <div id="titlediv">
10
  <strong><?php _e('Form Key:', 'formidable') ?></strong>
11
  <div id="editable-post-name" class="frm_ipe_form_key" title="<?php _e('Click to edit.', 'formidable') ?>"><?php echo $form->form_key; ?></div>
12
  </div>
13
+ <div class="frm_ipe_form_desc alignleft" style="width:70%"><?php echo ($form->description == '') ? __('(Click to add description)', 'formidable') : force_balance_tags($form->description); ?></div>
14
  <div style="clear:both"></div>
15
  </div>
16
  </div>
17
 
18
  <div <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'class="postbox"' : ''; ?>>
19
+ <div class="frm_no_fields <?php echo ( isset($values['fields']) && ! empty($values['fields']) ) ? 'frm_hidden' : ''; ?>">
20
+ <div class="alignleft sketch1">
21
+ <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow1.png'; ?>" alt="" />
22
+ </div>
23
+ <div class="alignleft sketch1_text">
24
+ <?php _e('1. Name your form', 'formidable') ?>
25
+ </div>
26
+
27
+ <div class="alignright sketch2">
28
+ <?php _e('2. Click or drag a field to<br/>add it to your form', 'formidable') ?>
29
+ <div class="clear"></div>
30
+ <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow2.png'; ?>" alt="" />
31
+ </div>
32
+ <div class="clear"></div>
33
+
34
+ <div class="frm_drag_inst"><?php _e('Add Fields Here', 'formidable') ?></div>
35
+
36
+ <div class="alignleft sketch3">
37
+ <div class="alignright"><?php _e('3. Save your form', 'formidable') ?></div>
38
+ <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow3.png'; ?>" alt="" />
39
+ </div>
40
+ <div class="clear"></div>
41
+ </div>
42
+ <ul id="new_fields" class="frm_sorting <?php echo version_compare( $GLOBALS['wp_version'], '3.7.2', '>') ? 'inside' : ''; ?>">
43
  <?php
44
  if ( isset($values['fields']) && ! empty($values['fields']) ) {
45
  $count = 0;
46
  foreach ( $values['fields'] as $field ) {
47
  $count++;
48
  $field_name = 'item_meta['. $field['id'] .']';
49
+ $html_id = FrmFieldsHelper::get_html_id($field);
50
  require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field.php');
51
  unset($field, $field_name);
52
  }
classes/views/frm-forms/insert_form_popup.php CHANGED
@@ -1,70 +1,154 @@
1
  <script type="text/javascript">
2
- function frm_insert_form(){
3
- var form_id=jQuery("#frm_add_form_id").val();
4
- if(form_id==""){alert("<?php _e('Please select a form', 'formidable') ?>");return;}
5
- var title_qs=jQuery("#frm_display_title").is(":checked") ? " title=true" : "";
6
- var description_qs=jQuery("#frm_display_description").is(":checked") ? " description=true" : "";
7
- var win = window.dialogArguments || opener || parent || top;
8
- win.send_to_editor("[formidable id="+form_id+title_qs+description_qs+"]");
 
 
9
  }
10
-
11
- function frm_insert_display(){
12
- var display_id = jQuery("#frm_add_display_id").val();
13
- if(display_id==""){alert("<?php _e('Please select a view', 'formidable') ?>");return;}
14
- var filter_qs=jQuery("#frm_filter_content").is(":checked") ? " filter=1" : "";
15
- var win = window.dialogArguments || opener || parent || top;
16
- win.send_to_editor("[display-frm-data id="+display_id+filter_qs+"]");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
-
19
- function frm_insert_search(){
20
  var win = window.dialogArguments || opener || parent || top;
21
- win.send_to_editor("[frm-search]");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
 
 
 
 
 
 
23
  </script>
24
  <style type="text/css">
25
- #frm_popup_content h3{
26
- color:#5A5A5A;
27
- font-family:Georgia,"Times New Roman",Times,serif;
28
- font-weight:normal;
29
- font-size:1.6em;
30
- }
31
- .frm_box_line{border-bottom:1px solid #DFDFDF;display:block;margin:20px 0;}
32
  </style>
33
-
34
  <div id="frm_insert_form" style="display:none;">
35
- <div class="wrap" id="frm_popup_content">
36
- <h3><?php _e("Select a form to insert", "formidable"); ?></h3>
37
-
38
- <p><?php FrmFormsHelper::forms_dropdown( 'frm_add_form_id' )?></p>
39
-
40
- <p><label for="frm_display_title"><input type="checkbox" id="frm_display_title" /> <?php _e("Display form title", "formidable"); ?></label> &nbsp; &nbsp;
41
- <label for="frm_display_description"><input type="checkbox" id="frm_display_description" /> <?php _e("Display form description", "formidable"); ?></label>
42
- </p>
43
-
44
- <p><input type="button" class="button-primary" value="Insert Form" onclick="frm_insert_form();" /></p>
45
-
46
- <?php if(isset($displays) and !empty($displays)){ ?>
47
- <div class="frm_box_line"></div>
48
- <h3><?php _e('Select a view to insert', 'formidable'); ?></h3>
49
-
50
- <p>
51
- <select name="frm_add_display_id" id="frm_add_display_id">
52
- <option value=""></option>
53
- <?php foreach ($displays as $display){ ?>
54
- <option value="<?php echo $display->ID ?>"><?php echo $display->post_title ?></option>
55
  <?php } ?>
56
- </select>
57
- </p>
58
-
59
- <p><label for="frm_filter_content"><input type="checkbox" id="frm_filter_content" /> <?php _e("Filter shortcodes within the view content", "formidable"); ?></label>
60
- <span class="howto"><?php _e("Note: In some cases, this option can create an infinite loop", "formidable"); ?></span>
61
- </p>
62
-
63
- <p><input type="button" class="button-primary" value="Insert View" onclick="frm_insert_display();" /></p>
64
-
65
- <div class="frm_box_line"></div>
66
- <h3><?php _e("Insert a search box", "formidable"); ?></h3>
67
- <p><input type="button" class="button-primary" value="Insert Search" onclick="frm_insert_search();" /></p>
68
- <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  </div>
70
- </div>
1
  <script type="text/javascript">
2
+ function frmAdminPopupJS(){
3
+ function switchSc(){
4
+ jQuery('.frm_switch_sc').removeClass( 'active' );
5
+ jQuery(this).addClass( 'active' );
6
+ toggleMenu();
7
+ jQuery('#frm_popup_content .media-frame-title h1').html(jQuery(this).children('.howto').text() +' <span class="spinner" style="float:left;"></span><span class="dashicons dashicons-arrow-down"></span>');
8
+ var val = this.id.replace('sc-link-', '');
9
+ populateOpts(val);
10
+ return false;
11
  }
12
+
13
+ function populateOpts(val){
14
+ document.getElementById('frm_complete_shortcode').value = '['+ val +']';
15
+ jQuery('.frm_shortcode_option').hide();
16
+
17
+ var $settings = document.getElementById('sc-opts-'+ val);
18
+ if($settings !== null){
19
+ $settings.style.display = '';
20
+ jQuery(document.getElementById('sc-'+ val)).click();
21
+ }else{
22
+ var $scOpts = jQuery(document.getElementById('frm_shortcode_options'));
23
+ var $spinner = jQuery('.media-frame-title .spinner');
24
+ $spinner.show();
25
+ jQuery.ajax({
26
+ type:'POST',url:ajaxurl,
27
+ data:{action:'frm_get_shortcode_opts', shortcode:val},
28
+ success:function(html){
29
+ $spinner.hide();
30
+ $scOpts.append(html);
31
+ jQuery(document.getElementById('sc-'+ val)).click();
32
+ }
33
+ });
34
+ }
35
+ }
36
+
37
+ function addToShortcode(){
38
+ var sc = jQuery('input[name=frmsc]:checked').val();
39
+ var inputs = jQuery(document.getElementById('sc-opts-'+sc)).find('input, select');
40
+ var output = '['+sc;
41
+ inputs.each(function(){
42
+ var $thisInput = jQuery(this);
43
+ var attrId = this.id;
44
+ if ( attrId.indexOf('frmsc_') === 0){
45
+ var attrName = attrId.replace('frmsc_'+ sc +'_', '');
46
+ var attrVal = $thisInput.val();
47
+
48
+ if(($thisInput.attr('type') == 'checkbox' && !this.checked) || (($thisInput.attr('type') == 'text' || $thisInput.is('select')) && '' == attrVal)){
49
+ }else{
50
+ output += ' '+ attrName +'="'+ attrVal +'"';
51
+ }
52
+ }
53
+ });
54
+ output += ']';
55
+ document.getElementById('frm_complete_shortcode').value = output;
56
  }
57
+
58
+ function insertShortcode(){
59
  var win = window.dialogArguments || opener || parent || top;
60
+ win.send_to_editor(document.getElementById('frm_complete_shortcode').value);
61
+ }
62
+
63
+ function getFieldSelection(){
64
+ var form_id = this.value;
65
+ if(form_id){
66
+ var thisId = this.id;
67
+ jQuery.ajax({
68
+ type:'POST',url:ajaxurl,
69
+ data:{action:'frm_get_field_selection',field_id:0,form_id:form_id},
70
+ success:function(msg){
71
+ msg = msg.replace('name="field_options[form_select_0]"', 'id="'+ thisId.replace('frm_form_', '') +'"');
72
+ jQuery(document.getElementById(thisId+'_fields')).html(msg);
73
+ }
74
+ });
75
+ }
76
+ }
77
+
78
+ function toggleMenu(){
79
+ jQuery(document.getElementById('frm_popup_content')).find( '.media-menu' ).toggleClass( 'visible' );
80
+ }
81
+
82
+ return {
83
+ init: function(){
84
+ jQuery('.frm_switch_sc').click(switchSc);
85
+ jQuery('.button.frm_insert_form').click(function(){populateOpts('formidable')});
86
+ jQuery(document.getElementById('frm_insert_shortcode')).click(insertShortcode);
87
+
88
+ var $scOptsDiv = jQuery(document.getElementById('frm_shortcode_options'));
89
+ $scOptsDiv.on('change', 'select, input', addToShortcode);
90
+ $scOptsDiv.on('change', '.frm_get_field_selection', getFieldSelection);
91
+
92
+ jQuery('#frm_popup_content .media-modal-close').click(tb_remove);
93
+ jQuery('#frm_popup_content .media-frame-title h1').click(toggleMenu);
94
+ }
95
  }
96
+ }
97
+
98
+ var frmAdminPopup = frmAdminPopupJS();
99
+ jQuery(document).ready(function($){
100
+ frmAdminPopup.init();
101
+ });
102
  </script>
103
  <style type="text/css">
104
+ #TB_ajaxContent{height:auto !important;width:auto !important;}
 
 
 
 
 
 
105
  </style>
 
106
  <div id="frm_insert_form" style="display:none;">
107
+ <div id="frm_popup_content">
108
+ <div class="media-modal wp-core-ui">
109
+ <a href="#" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text"><?php _e('Close panel', 'formidable') ?></span></span></a>
110
+
111
+ <div class="media-modal-content">
112
+ <div class="media-frame mode-select wp-core-ui hide-router">
113
+
114
+ <div id="frm_insert_form_content">
115
+
116
+ <div class="media-frame-menu">
117
+ <div class="media-menu">
118
+ <?php foreach ( $shortcodes as $shortcode => $labels ) { ?>
119
+ <a href="#" class="media-menu-item frm_switch_sc" id="sc-link-<?php echo $shortcode ?>">
120
+ <?php echo $labels['name'] ?>
121
+ <span class="howto"><?php echo $labels['label'] ?></span>
122
+ </a>
 
 
 
 
123
  <?php } ?>
124
+ <div class="clear"></div>
125
+ </div>
126
+ </div>
127
+
128
+ <div class="media-frame-title"><h1><?php _e('Insert a Form', 'formidable') ?> <span class="spinner" style="float:left;"></span><span class="dashicons dashicons-arrow-down"></span></h1></div>
129
+
130
+ <div class="media-frame-content">
131
+ <div class="attachments-browser">
132
+ <div id="frm_shortcode_options" class="media-embed">
133
+
134
+ </div>
135
+ </div>
136
+ </div>
137
+
138
+ <div class="media-frame-toolbar">
139
+ <div class="media-toolbar">
140
+ <div class="media-toolbar-secondary">
141
+ <input type="text" value="" id="frm_complete_shortcode" />
142
+ </div>
143
+ <div class="media-toolbar-primary search-form">
144
+ <a href="javascript:void(0);" class="button-primary button button-large media-button-group" id="frm_insert_shortcode"><?php _e('Insert into Post', 'formidable') ?></a>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ </div>
149
+ </div>
150
+
151
+ </div>
152
+ </div>
153
  </div>
154
+ </div>
classes/views/frm-forms/list.php CHANGED
@@ -1,21 +1,24 @@
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
- <h2 style="height:34px;"><?php echo ($params['template'])? __('Templates', 'formidable') : __('Forms', 'formidable');
4
- if(!$params['template'] and current_user_can('frm_edit_forms')){ ?>
5
  <a href="?page=formidable&amp;frm_action=new-selection" class="add-new-h2"><?php _e('Add New', 'formidable'); ?></a>
6
  <?php } ?>
7
  </h2>
8
-
9
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
10
 
 
 
11
  <form id="posts-filter" method="get">
12
  <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>" />
13
  <input type="hidden" name="frm_action" value="list" />
14
- <?php $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' );
15
 
16
- if ($params['template']) require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/default-templates.php');
 
17
 
18
- $wp_list_table->display(); ?>
19
  </form>
20
 
21
  </div>
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
+ <h2 style="height:34px;"><?php echo $params['template'] ? __('Templates', 'formidable') : __('Forms', 'formidable');
4
+ if ( ! $params['template'] && current_user_can('frm_edit_forms') ) { ?>
5
  <a href="?page=formidable&amp;frm_action=new-selection" class="add-new-h2"><?php _e('Add New', 'formidable'); ?></a>
6
  <?php } ?>
7
  </h2>
8
+
9
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
10
 
11
+ <?php $wp_list_table->views(); ?>
12
+
13
  <form id="posts-filter" method="get">
14
  <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>" />
15
  <input type="hidden" name="frm_action" value="list" />
16
+ <?php
17
 
18
+ $wp_list_table->search_box( __( 'Search', 'formidable' ), 'entry' );
19
+ $wp_list_table->display();
20
 
21
+ ?>
22
  </form>
23
 
24
  </div>
classes/views/frm-forms/mb_html_tab.php CHANGED
@@ -3,14 +3,14 @@
3
  <?php
4
  $col = 'one';
5
  $entry_shortcodes = array(
6
- 'id' => __('Field ID', 'formidable'),
7
  'key' => __('Field Key', 'formidable'),
8
  'field_name' => __('Field Name', 'formidable'),
9
  'description' => __('Field Description', 'formidable'),
10
  'label_position' => __('Label Position', 'formidable'),
11
  'required_label' => __('Required Label', 'formidable'),
12
  'input' => __('Input Field', 'formidable'),
13
- 'input opt=1' => array('label' => __('Single Option', 'formidable'), 'title' => __('Show a single radio or checkbox option by replacing "1" with the order of the option', 'formidable')),
14
  'input label=0' => __('Hide Option Label', 'formidable'),
15
  'required_class' => array('label' => __('Required Class', 'formidable'), 'title' => __('Add class name if field is required', 'formidable')),
16
  'error_class' => array('label' => __('Error Class', 'formidable'), 'title' => __('Add class name if field has an error on form submit', 'formidable'))
@@ -19,36 +19,35 @@
19
  foreach($entry_shortcodes as $skey => $sname){
20
  ?>
21
  <li class="frm_col_<?php echo $col ?>">
22
- <a class="show_field_custom_html frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="<?php echo esc_attr($skey) ?>" href="javascript:void(0)" <?php echo is_array($sname) ? 'title="'. $sname['title'] .'"' : ''; ?>><?php echo is_array($sname) ? $sname['label'] : $sname; ?></a>
23
  </li>
24
  <?php
25
  $col = ($col == 'one') ? 'two' : 'one';
26
- unset($skey);
27
- unset($sname);
28
  }
29
  ?>
30
  </ul>
31
-
32
  <ul class="frm_code_list clear">
33
- <?php
34
  $col = 'one';
35
  foreach(array(
36
- 'form_name' => __('Form Name', 'formidable'), 'form_description' => __('Form Description', 'formidable'),
37
  'form_key' => __('Form Key', 'formidable'), 'deletelink' => __('Delete Entry Link', 'formidable')) as $skey => $sname){ ?>
38
  <li class="frm_col_<?php echo $col ?>">
39
- <a class="show_before_html show_after_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>" href="javascript:void(0)"><?php echo $sname; ?></a>
40
  </li>
41
  <?php
42
- $col = ($col == 'one') ? 'two' : 'one';
43
  }
44
-
45
  foreach(array(
46
  'button_label' => __('Button Label', 'formidable'), 'button_action' => __('Button Hook', 'formidable')) as $skey => $sname){ ?>
47
  <li class="frm_col_<?php echo $col ?>">
48
- <a class="show_submit_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>" href="javascript:void(0)"><?php echo $sname; ?></a>
49
  </li>
50
  <?php
51
- $col = ($col == 'one') ? 'two' : 'one';
52
  } ?>
53
  </ul>
54
  </div>
3
  <?php
4
  $col = 'one';
5
  $entry_shortcodes = array(
6
+ 'id' => __('Field ID', 'formidable'),
7
  'key' => __('Field Key', 'formidable'),
8
  'field_name' => __('Field Name', 'formidable'),
9
  'description' => __('Field Description', 'formidable'),
10
  'label_position' => __('Label Position', 'formidable'),
11
  'required_label' => __('Required Label', 'formidable'),
12
  'input' => __('Input Field', 'formidable'),
13
+ 'input opt=1' => array('label' => __('Single Option', 'formidable'), 'title' => __('Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable')),
14
  'input label=0' => __('Hide Option Label', 'formidable'),
15
  'required_class' => array('label' => __('Required Class', 'formidable'), 'title' => __('Add class name if field is required', 'formidable')),
16
  'error_class' => array('label' => __('Error Class', 'formidable'), 'title' => __('Add class name if field has an error on form submit', 'formidable'))
19
  foreach($entry_shortcodes as $skey => $sname){
20
  ?>
21
  <li class="frm_col_<?php echo $col ?>">
22
+ <a href="javascript:void(0)" class="show_field_custom_html frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="<?php echo esc_attr($skey) ?>" <?php echo is_array($sname) ? 'title="'. $sname['title'] .'"' : ''; ?>><?php echo is_array($sname) ? $sname['label'] : $sname; ?></a>
23
  </li>
24
  <?php
25
  $col = ($col == 'one') ? 'two' : 'one';
26
+ unset($skey, $sname);
 
27
  }
28
  ?>
29
  </ul>
30
+
31
  <ul class="frm_code_list clear">
32
+ <?php
33
  $col = 'one';
34
  foreach(array(
35
+ 'form_name' => __('Form Name', 'formidable'), 'form_description' => __('Form Description', 'formidable'),
36
  'form_key' => __('Form Key', 'formidable'), 'deletelink' => __('Delete Entry Link', 'formidable')) as $skey => $sname){ ?>
37
  <li class="frm_col_<?php echo $col ?>">
38
+ <a href="javascript:void(0)" class="show_before_html show_after_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname; ?></a>
39
  </li>
40
  <?php
41
+ $col = ($col == 'one') ? 'two' : 'one';
42
  }
43
+
44
  foreach(array(
45
  'button_label' => __('Button Label', 'formidable'), 'button_action' => __('Button Hook', 'formidable')) as $skey => $sname){ ?>
46
  <li class="frm_col_<?php echo $col ?>">
47
+ <a href="javascript:void(0)" class="show_submit_html frmbutton button frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname; ?></a>
48
  </li>
49
  <?php
50
+ $col = ($col == 'one') ? 'two' : 'one';
51
  } ?>
52
  </ul>
53
  </div>
classes/views/frm-forms/mb_insert_fields.php CHANGED
@@ -1,23 +1,6 @@
1
  <div id="frm_adv_info" class="postbox">
2
  <div class="handlediv" title="<?php _e('Click to toggle', 'formidable') ?>"><br/></div><h3 class="hndle"><span><?php _e('Customization', 'formidable') ?></span></h3>
3
  <div class="inside">
4
- <?php if($frm_vars['pro_is_installed']){
5
- FrmProDisplaysController::mb_tags_box($id);
6
- }else{ ?>
7
- <div id="taxonomy-linkcategory" class="categorydiv">
8
- <ul id="category-tabs" class="category-tabs frm-category-tabs">
9
- <li class="tabs" ><a href="#frm-insert-fields-box" id="frm_insert_fields_tab" ><?php _e( 'Insert Fields', 'formidable' ); ?></a></li>
10
- <li class="hide-if-no-js"><a href="#frm-html-tags" id="frm_html_tags_tab" ><?php _e( 'HTML Tags', 'formidable' ); ?></a></li>
11
- </ul>
12
- <div id="frm-insert-fields-box" class="tabs-panel" style="max-height:none;padding-right:0;">
13
- <br/><br/>
14
- <?php FrmAppController::update_message('insert field values into your messages'); ?>
15
- </div>
16
- <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_html_tab.php'); ?>
17
- </div>
18
- <?php
19
- } ?>
20
-
21
-
22
- </div>
23
  </div>
1
  <div id="frm_adv_info" class="postbox">
2
  <div class="handlediv" title="<?php _e('Click to toggle', 'formidable') ?>"><br/></div><h3 class="hndle"><span><?php _e('Customization', 'formidable') ?></span></h3>
3
  <div class="inside">
4
+ <?php FrmFormsController::mb_tags_box($id); ?>
5
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  </div>
classes/views/frm-forms/new-field-js.php CHANGED
@@ -1 +1 @@
1
- <?php _deprecated_file( basename(__FILE__), '1.07.10', null, __( 'This file no longer needs to be included.' ) ); ?>
1
+ <?php _deprecated_file( basename(__FILE__), '1.07.10', null, __( 'This file no longer needs to be included.' ) );
classes/views/frm-forms/new-selection.php CHANGED
@@ -1,14 +1,14 @@
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
  <h2><?php _e('Build New Form', 'formidable') ?></h2>
4
-
5
  <div class="clear"></div>
6
  <div id="menu-management" class="nav-menus-php frm-menu-boxes">
7
  <div class="menu-edit">
8
  <div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
9
- <div style="font-size:15px;background:transparent;" class="search"><?php _e('Pre-Built Form', 'formidable') ?></div>
10
  </div></div>
11
-
12
  <form method="get">
13
  <div id="post-body">
14
  <p><?php _e('Select a template to generate your form.', 'formidable'); ?></p>
@@ -21,20 +21,20 @@
21
  </select><br/>
22
  </div>
23
  <div id="nav-menu-footer">
24
- <div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Create', 'formidable') ?>" /></div>
25
 
26
  <div class="clear"></div>
27
  </div>
28
  </form>
29
  </div>
30
  </div>
31
-
32
  <div id="menu-management" class="nav-menus-php frm-menu-boxes">
33
  <div class="menu-edit">
34
  <div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
35
- <div style="font-size:15px;background:transparent;" class="search"><?php _e('Blank Form', 'formidable') ?></div>
36
  </div></div>
37
-
38
  <form method="get">
39
  <div id="post-body">
40
  <p style="padding-bottom:26px;"><?php _e('Start with a blank form and build anything.', 'formidable'); ?></p>
@@ -42,15 +42,15 @@
42
  <input type="hidden" name="page" value="formidable" />
43
  </div>
44
  <div id="nav-menu-footer">
45
- <div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Create', 'formidable') ?>" /></div>
46
 
47
  <div class="clear"></div>
48
  </div>
49
  </form>
50
  </div>
51
-
52
  <div class="clear"></div>
53
  </div>
54
-
55
  <div class="clear"></div>
56
  </div>
1
  <div class="wrap">
2
  <div class="frmicon icon32"><br/></div>
3
  <h2><?php _e('Build New Form', 'formidable') ?></h2>
4
+
5
  <div class="clear"></div>
6
  <div id="menu-management" class="nav-menus-php frm-menu-boxes">
7
  <div class="menu-edit">
8
  <div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
9
+ <div style="font-size:15px;background:transparent;" class="search"><?php _e('Start From Template', 'formidable') ?></div>
10
  </div></div>
11
+
12
  <form method="get">
13
  <div id="post-body">
14
  <p><?php _e('Select a template to generate your form.', 'formidable'); ?></p>
21
  </select><br/>
22
  </div>
23
  <div id="nav-menu-footer">
24
+ <div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Get Started', 'formidable') ?>" /></div>
25
 
26
  <div class="clear"></div>
27
  </div>
28
  </form>
29
  </div>
30
  </div>
31
+
32
  <div id="menu-management" class="nav-menus-php frm-menu-boxes">
33
  <div class="menu-edit">
34
  <div id="nav-menu-header"><div class="major-publishing-actions" style="padding:8px 0;">
35
+ <div style="font-size:15px;background:transparent;" class="search"><?php _e('Start From Scratch', 'formidable') ?></div>
36
  </div></div>
37
+
38
  <form method="get">
39
  <div id="post-body">
40
  <p style="padding-bottom:26px;"><?php _e('Start with a blank form and build anything.', 'formidable'); ?></p>
42
  <input type="hidden" name="page" value="formidable" />
43
  </div>
44
  <div id="nav-menu-footer">
45
+ <div class="major-publishing-actions"><input type="submit" class="button-primary" value="<?php _e('Get Started', 'formidable') ?>" /></div>
46
 
47
  <div class="clear"></div>
48
  </div>
49
  </form>
50
  </div>
51
+
52
  <div class="clear"></div>
53
  </div>
54
+
55
  <div class="clear"></div>
56
  </div>
classes/views/frm-forms/new.php CHANGED
@@ -1,53 +1,38 @@
1
  <div class="wrap">
2
- <div class="frmicon icon32"><br/></div>
3
  <h2><?php _e('Build New Form', 'formidable') ?>
4
  <a href="?page=formidable-new" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
5
  </h2>
6
- <?php
7
- if ( !$form->is_template ) {
8
- FrmAppController::get_form_nav($id, true);
9
- }
10
- require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
-
12
- if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
13
- <div id="poststuff" class="metabox-holder has-right-sidebar">
14
- <?php
15
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
16
- }else{ ?>
17
- <div id="poststuff">
18
- <?php } ?>
19
 
 
20
  <div id="post-body" class="metabox-holder columns-2">
21
  <div id="post-body-content">
22
- <div class="frm_form_builder<?php echo (isset($form->options['custom_style']) && $form->options['custom_style']) ? ' with_frm_style' : ''; ?>">
23
-
24
- <p style="margin-top:0;">
25
- <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Create', 'formidable') ?>" class="button-primary" />
26
- <?php _e('or', 'formidable') ?>
27
- <a class="button-secondary cancel" href="?page=formidable&amp;frm_action=destroy&amp;id=<?php echo $id; ?>"><?php _e('Cancel', 'formidable') ?></a>
28
- <span class="frm-loading-img"></span>
29
- </p>
30
-
 
31
  <form method="post" id="frm_build_form">
32
  <input type="hidden" name="frm_action" value="create" />
33
  <input type="hidden" name="action" value="create" />
34
- <input type="hidden" name="id" value="<?php echo $id; ?>" />
35
 
36
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
37
 
38
  <p>
39
- <input type="button" onclick="frmSubmit<?php echo (isset($form->options['ajax_load']) && $form->options['ajax_load']) ? 'Build' : 'NoAjax'; ?>(this)" value="<?php _e('Create', 'formidable') ?>" class="button-primary" />
40
- <?php _e('or', 'formidable') ?>
41
- <a class="button-secondary cancel" href="?page=formidable&amp;frm_action=destroy&amp;id=<?php echo $id; ?>"><?php _e('Cancel', 'formidable') ?></a>
42
  <span class="frm-loading-img"></span>
43
  </p>
44
  </form>
 
 
45
  </div>
46
- </div>
47
- <?php
48
- if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
49
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php');
50
- ?>
51
  </div>
52
  </div>
53
- </div>
1
  <div class="wrap">
2
+ <div class="frmicon icon32"><br/></div>
3
  <h2><?php _e('Build New Form', 'formidable') ?>
4
  <a href="?page=formidable-new" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
5
  </h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ <div id="poststuff">
8
  <div id="post-body" class="metabox-holder columns-2">
9
  <div id="post-body-content">
10
+ <?php
11
+ if ( !$values['is_template'] ) {
12
+ FrmAppController::get_form_nav($id, true, 'hide');
13
+ }
14
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
15
+
16
+ ?>
17
+
18
+ <div class="frm_form_builder<?php echo FrmFormsHelper::get_form_style_class($form); ?>">
19
+
20
  <form method="post" id="frm_build_form">
21
  <input type="hidden" name="frm_action" value="create" />
22
  <input type="hidden" name="action" value="create" />
23
+ <input type="hidden" name="id" id="form_id" value="<?php echo $id; ?>" />
24
 
25
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/form.php'); ?>
26
 
27
  <p>
28
+ <input type="button" value="<?php _e('Create', 'formidable') ?>" class="frm_submit_<?php echo ( isset($values['ajax_load']) && $values['ajax_load'] ) ? '': 'no_'; ?>ajax button-primary" />
 
 
29
  <span class="frm-loading-img"></span>
30
  </p>
31
  </form>
32
+
33
+ </div>
34
  </div>
35
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/add_field_links.php'); ?>
 
 
 
 
36
  </div>
37
  </div>
38
+ </div>
classes/views/frm-forms/notification.php DELETED
@@ -1,94 +0,0 @@
1
- <?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
2
- <div id="frm_notification_<?php echo $email_key ?>" class="tabs-panel notification_settings <?php if(!$first_email) echo 'panel_secondary' ?>" style="display:<?php echo ($a == 'notification_settings') ? 'block' : 'none'; ?>;">
3
- <table class="form-table <?php if(!$first_email) echo 'menu-settings'; ?>">
4
- <tr>
5
- <td><label><?php _e('From/Reply to', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Usually the name and email of the person filling out the form. Select from Text, Email, User ID, or hidden fields for the name. &lt;br/&gt;Defaults to your site name and admin email found on the WordPress General Settings page.', 'formidable') ?>"></span>
6
- </td>
7
- <td class="frm_email_reply_container">
8
- <div class="alignright frm_email_actions feature-filter">
9
- <?php echo $email_key; ?>
10
- <?php if ( $email_key !== 0 ) { ?>
11
- <span class="frm_email_icons">
12
- <a data-removeid="frm_notification_<?php echo $email_key ?>" class="frm_icon_font frm_delete_icon frm_remove_email"> </a>
13
- </span>
14
- <?php } ?>
15
- </div>
16
- <span class="howto"><?php _e('Name') ?></span>
17
-
18
- <select name="notification[<?php echo $email_key ?>][reply_to_name]" id="reply_to_name_<?php echo $email_key ?>" onchange="frmCheckCustomEmail(this.value,'reply_to_name',<?php echo $email_key ?>)">
19
- <option value=""><?php echo FrmAppHelper::truncate(get_option('blogname'), 80); ?></option>
20
- <option value="custom" <?php selected($notification['reply_to_name'], 'custom'); ?>><?php _e('Custom Name', 'formidable') ?></option>
21
- <?php
22
- if(!empty($values['fields'])){ ?>
23
- <optgroup label="<?php _e('Fields', 'formidable') ?>">
24
- <?php
25
- $field_select = array('text', 'email', 'user_id', 'hidden', 'select', 'radio');
26
- foreach($values['fields'] as $val_key => $fo){
27
- if(in_array($fo['type'], $field_select)){ ?>
28
- <option value="<?php echo $fo['id'] ?>" <?php selected($notification['reply_to_name'], $fo['id']); ?>><?php echo FrmAppHelper::truncate($fo['name'], 40) ?></option>
29
- <?php }else if($fo['type'] == 'data' and isset($fo['data_type']) and $fo['data_type'] != 'data'){
30
- if(isset($values['fields'][$val_key]['linked'])){
31
- foreach($values['fields'][$val_key]['linked'] as $linked_field){
32
- if(!in_array($linked_field->type, $field_select)) continue; ?>
33
- <option value="<?php echo $fo['id'] ?>|<?php echo $linked_field->id ?>" <?php selected($notification['reply_to_name'], $fo['id'] .'|'. $linked_field->id); ?>><?php echo $fo['name'] .': '. FrmAppHelper::truncate($linked_field->name, 40) ?></option>
34
- <?php }
35
- }
36
- }
37
- }
38
- } ?>
39
- </select>
40
-
41
- <span class="howto" ><?php _e('Email', 'formidable') ?></span>
42
- <select name="notification[<?php echo $email_key ?>][reply_to]" id="reply_to_<?php echo $email_key ?>" onchange="frmCheckCustomEmail(this.value,'reply_to',<?php echo $email_key ?>)">
43
- <option value=""><?php echo get_option('admin_email') ?></option>
44
- <option value="custom" <?php selected($notification['reply_to'], 'custom'); ?>><?php _e('Custom Address', 'formidable') ?></option>
45
- <?php
46
- if(!empty($values['fields'])){ ?>
47
- <optgroup label="<?php _e('Fields', 'formidable') ?>">
48
- <?php
49
- foreach($values['fields'] as $val_key => $fo){
50
- if(in_array($fo['type'], $field_select)){ ?>
51
- <option value="<?php echo $fo['id'] ?>" <?php selected($notification['reply_to'], $fo['id']); ?>><?php echo FrmAppHelper::truncate($fo['name'], 40) ?></option>
52
- <?php }else if($fo['type'] == 'data' and isset($fo['data_type']) and $fo['data_type'] != 'data'){
53
- if(isset($values['fields'][$val_key]['linked'])){ ?>
54
- <?php foreach($values['fields'][$val_key]['linked'] as $linked_field){
55
- if(!in_array($linked_field->type, $field_select)) continue; ?>
56
- <option value="<?php echo $fo['id'] ?>|<?php echo $linked_field->id ?>" <?php selected($notification['reply_to'], $fo['id'] .'|'. $linked_field->id); ?>><?php echo $fo['name'] .': '. FrmAppHelper::truncate($linked_field->name, 40) ?></option>
57
- <?php }
58
- }
59
- }
60
- }
61
- } ?>
62
- </select>
63
-
64
- <div id="frm_cust_reply_container_<?php echo $email_key ?>" <?php echo ($notification['reply_to_name'] == 'custom' or $notification['reply_to'] == 'custom') ? '' : 'style="display:none"'; ?>>
65
- <span class="howto" style="visibility:hidden;"><?php _e('Name') ?></span>
66
- <input type="text" name="notification[<?php echo $email_key ?>][cust_reply_to_name]" value="<?php echo esc_attr($notification['cust_reply_to_name']) ?>" id="cust_reply_to_name_<?php echo $email_key ?>" title="<?php _e('Name') ?>" <?php echo ($notification['reply_to_name'] == 'custom') ? '' : 'style="visibility:hidden;"'; ?> />
67
- <span class="howto" style="visibility:hidden;"><?php _e('Email', 'formidable') ?></span>
68
- <input type="text" name="notification[<?php echo $email_key ?>][cust_reply_to]" value="<?php echo esc_attr($notification['cust_reply_to']) ?>" id="cust_reply_to_<?php echo $email_key ?>" title="<?php _e('Email Address', 'formidable') ?>" <?php echo ($notification['reply_to'] == 'custom') ? '' : 'style="visibility:hidden;"'; ?> />
69
- </div>
70
- </td>
71
- </tr>
72
-
73
- <tr>
74
- <td colspan="2"><label><?php _e('Email Recipients', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e('To send to multiple addresses, separate each address with a comma. You can use [admin_email] to dynamically use the address on your WordPress General Settings page. &lt;br/&gt;PRO only: Leave blank if you do not want email notifications for this form.', 'formidable') ?>"></span>
75
- <input type="text" name="notification[<?php echo $email_key ?>][email_to]" value="<?php echo esc_attr($notification['email_to']); ?>" class="frm_not_email_to frm_long_input" id="email_to_<?php echo $email_key ?>" />
76
-
77
- <p><label><?php _e('Subject', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php echo esc_attr(sprintf(__('If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable'), $form->name, get_option('blogname'))); ?>"></span><br/>
78
- <input type="text" name="notification[<?php echo $email_key ?>][email_subject]" class="frm_not_email_subject frm_long_input" id="email_subject_<?php echo $email_key ?>" size="55" value="<?php echo esc_attr($notification['email_subject']); ?>" /></p>
79
-
80
- <p><label><?php _e('Message', 'formidable') ?> </label><br/>
81
- <textarea name="notification[<?php echo $email_key ?>][email_message]" class="frm_not_email_message frm_long_input" id="email_message_<?php echo $email_key ?>" cols="50" rows="5"><?php echo FrmAppHelper::esc_textarea($notification['email_message']) ?></textarea></p>
82
-
83
- <h4><?php _e('Options', 'formidable') ?> </h4>
84
- <label for="inc_user_info_<?php echo $email_key ?>"><input type="checkbox" name="notification[<?php echo $email_key ?>][inc_user_info]" class="frm_not_inc_user_info" id="inc_user_info_<?php echo $email_key ?>" value="1" <?php checked($notification['inc_user_info'], 1); ?> /> <?php _e('Append IP Address, Browser, and Referring URL to message', 'formidable') ?></label>
85
-
86
- <p><label for="plain_text_<?php echo $email_key ?>"><input type="checkbox" name="notification[<?php echo $email_key ?>][plain_text]" id="plain_text_<?php echo $email_key ?>" value="1" <?php checked($notification['plain_text'], 1); ?> /> <?php _e('Send Emails in Plain Text', 'formidable') ?></label></p>
87
- <?php
88
- if(!$frm_vars['pro_is_installed'])
89
- FrmAppController::update_message('send autoresponders or conditionally send email notifications');
90
-
91
- do_action('frm_additional_form_notification_options', $values, compact('notification', 'email_key')); ?>
92
- </td></tr>
93
- </table>
94
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/views/frm-forms/settings.php CHANGED
@@ -3,37 +3,22 @@
3
  <h2><?php _e('Settings', 'formidable') ?>
4
  <a href="#" class="add-new-h2" style="visibility:hidden;"></a>
5
  </h2>
6
- <?php FrmAppController::get_form_nav($id, true);
7
- require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
8
-
9
- if(version_compare( $GLOBALS['wp_version'], '3.3.3', '<')){ ?>
10
- <div id="poststuff" class="metabox-holder has-right-sidebar">
11
- <?php
12
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php');
13
- }else{ ?>
14
  <div id="poststuff">
15
- <?php } ?>
16
-
17
  <div id="post-body" class="metabox-holder columns-2">
18
  <div id="post-body-content">
19
-
20
- <form method="post" class="frm_form_settings">
21
- <p style="clear:left; margin-top:0;">
22
- <input type="submit" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
23
- <?php _e('or', 'formidable') ?>
24
- <a class="button-secondary cancel" href="<?php echo esc_url(admin_url('admin.php?page=formidable') . '&frm_action=edit&id='. $id) ?>"><?php _e('Cancel', 'formidable') ?></a>
25
- <?php do_action('frm_settings_buttons', $values); ?>
26
- </p>
27
-
28
- <div class="clear"></div>
29
 
30
- <input type="hidden" name="id" value="<?php echo $id; ?>" />
 
31
  <input type="hidden" name="frm_action" value="update_settings" />
32
- <div id="poststuff" class="metabox-holder">
33
- <div id="post-body">
34
  <div class="meta-box-sortables">
35
  <div class="categorydiv postbox">
36
- <h3 class="hndle"><span><?php echo FrmAppHelper::truncate($values['name'], 40) .' '. __('Settings', 'formidable') ?></span></h3>
37
  <div class="inside frm-help-tabs">
38
  <div id="contextual-help-back"></div>
39
  <div id="contextual-help-columns">
@@ -41,62 +26,61 @@
41
  <ul class="frm-category-tabs frm-form-setting-tabs">
42
  <?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
43
  <li <?php echo ($a == 'advanced_settings') ? 'class="tabs active"' : '' ?>><a href="#advanced_settings"><?php _e('General', 'formidable') ?></a></li>
44
- <li <?php echo ($a == 'notification_settings') ? 'class="tabs active"' : '' ?>><a href="#notification_settings"><?php _e('Emails', 'formidable') ?></a></li>
45
  <li <?php echo ($a == 'html_settings') ? 'class="tabs active"' : '' ?>><a href="#html_settings"><?php _e('Customize HTML', 'formidable') ?></a></li>
46
- <li <?php echo ($a == 'post_settings') ? 'class="tabs active"' : '' ?>><a href="#post_settings"><?php _e('Create Posts', 'formidable') ?></a></li>
47
  <?php foreach($sections as $sec_name => $section){ ?>
48
  <li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo $sec_name ?>_settings"><?php echo ucfirst($sec_name) ?></a></li>
49
  <?php } ?>
50
  </ul>
51
  </div>
52
  <div style="display:<?php echo ($a == 'advanced_settings') ? 'block' : 'none'; ?>;" class="advanced_settings tabs-panel">
53
- <table class="form-table">
54
- <tr><td colspan="2"><label for="custom_style"><input type="checkbox" name="options[custom_style]" id="custom_style" <?php echo ($values['custom_style']) ? ' checked="checked"' : ''; ?> value="1" />
55
- <?php _e('Use Formidable styling for this form', 'formidable') ?></label></td>
56
- </tr>
57
 
58
- <tr><td colspan="2"><label class="frm_left_label"><?php _e('Submit Button Text', 'formidable') ?></label>
59
- <input type="text" name="options[submit_value]" value="<?php echo esc_attr($values['submit_value']); ?>" /></td>
60
- </tr>
61
-
62
- <tr><td colspan="2"><label><?php _e('Action After Form Submission', 'formidable') ?></label>
63
- <?php if(!$frm_vars['pro_is_installed']){ ?>
64
- <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('You must upgrade to Formidable Pro to get access to the second two options.', 'formidable') ?>" ></span>
65
- <?php } ?><br/>
66
-
67
- <label for="success_action_message"><input type="radio" name="options[success_action]" id="success_action_message" value="message" <?php checked($values['success_action'], 'message') ?> /> <?php _e('Display a Message', 'formidable') ?></label>
68
- <label for="success_action_page" <?php echo $pro_feature ?>><input type="radio" name="options[success_action]" id="success_action_page" value="page" <?php checked($values['success_action'], 'page') ?> <?php if(!$frm_vars['pro_is_installed']) echo 'disabled="disabled" '; ?>/> <?php _e('Display content from another page', 'formidable') ?></label>
69
- <label for="success_action_redirect" <?php echo $pro_feature ?>><input type="radio" name="options[success_action]" id="success_action_redirect" value="redirect" <?php checked($values['success_action'], 'redirect') ?> <?php if(!$frm_vars['pro_is_installed']) echo 'disabled="disabled" '; ?>/> <?php _e('Redirect to URL', 'formidable') ?></label>
70
-
71
- <p class="frm_indent_opt success_action_redirect_box success_action_box" <?php echo ($values['success_action'] == 'redirect') ? '' : 'style="display:none;"'; ?>>
72
- <input type="text" name="options[success_url]" id="success_url" value="<?php if(isset($values['success_url'])) echo esc_attr($values['success_url']); ?>" style="width:98%" placeholder="http://example.com" />
73
- </p>
74
-
75
- <div class="frm_indent_opt success_action_message_box success_action_box" <?php echo ($values['success_action'] == 'message') ? '' : 'style="display:none;"'; ?>>
76
- <p><textarea id="success_msg" name="options[success_msg]" cols="50" rows="2" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['success_msg']); ?></textarea></p>
77
- <p class="frm_show_form_opt">
78
- <label for="show_form"><input type="checkbox" name="options[show_form]" id="show_form" value="1" <?php checked($values['show_form'], 1) ?> /> <?php _e('Show the form with the confirmation message', 'formidable')?></label>
79
- </p>
80
- </div>
81
-
82
- <?php if($frm_vars['pro_is_installed']){ ?>
83
- <p class="frm_indent_opt success_action_page_box success_action_box" <?php echo ($values['success_action'] == 'page') ? '' : 'style="display:none;"'; ?>>
84
  <label><?php _e('Use Content from Page', 'formidable') ?></label>
85
  <?php FrmAppHelper::wp_pages_dropdown( 'options[success_page_id]', $values['success_page_id'] ) ?>
86
- </p>
87
  <?php } ?>
88
  </td>
89
  </tr>
90
-
91
- <tr><td colspan="2"><label for="ajax_load"><input type="checkbox" name="options[ajax_load]" id="ajax_load" value="1"<?php echo ($values['ajax_load']) ? ' checked="checked"' : ''; ?> /> <?php _e('Load and save form builder page with AJAX', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Recommended for long forms.', 'formidable') ?>" ></span></td></tr>
92
-
93
-
94
- <?php do_action('frm_additional_form_options', $values); ?>
95
-
96
- <tr><td colspan="2"><label for="no_save"><input type="checkbox" name="options[no_save]" id="no_save" value="1" <?php checked($values['no_save'], 1); ?> /> <?php _e('Do not store any entries submitted from this form.', 'formidable') ?> <span class="howto"><?php _e('Warning: There is no way to retrieve unsaved entries.', 'formidable') ?></span></label></td></tr>
97
-
98
- <?php if (function_exists( 'akismet_http_post' )){ ?>
99
- <tr><td colspan="2"><?php _e('Use Akismet to check entries for spam for', 'formidable') ?>
 
 
100
  <select name="options[akismet]">
101
  <option value=""><?php _e('no one', 'formidable') ?></option>
102
  <option value="1" <?php selected($values['akismet'], 1)?>><?php _e('everyone', 'formidable') ?></option>
@@ -106,34 +90,103 @@
106
  </tr>
107
  <?php } ?>
108
  </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  </div>
110
 
111
- <?php
112
- $first_email = true;
113
- foreach($values['notification'] as $email_key => $notification){
114
- include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/notification.php');
115
- unset($email_key);
116
- unset($notification);
117
- $first_email = false;
118
- }
119
- if($frm_vars['pro_is_installed']){ ?>
120
- <div id="frm_email_add_button" class="notification_settings hide_with_tabs submit" style="display:<?php echo ($a == 'notification_settings') ? 'block' : 'none'; ?>;">
121
- <a href="javascript:frmAddEmailList(<?php echo $values['id'] ?>)" class="button-secondary">+ <?php _e('Add Notification', 'formidable') ?></a></td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  </div>
123
- <?php } ?>
124
-
125
  <div id="html_settings" class="tabs-panel" style="display:<?php echo ($a == 'html_settings') ? 'block' : 'none'; ?>;">
126
-
127
- <div id="post-body-content" class="frm_top_container" style="margin-right:260px;">
128
- <p><label class="frm_primary_label"><?php _e('Before Fields', 'formidable') ?></label>
 
 
 
 
 
129
  <textarea name="options[before_html]" rows="4" id="before_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['before_html']) ?></textarea></p>
130
 
131
  <div id="add_html_fields">
132
- <?php
133
  if (isset($values['fields'])){
134
  foreach($values['fields'] as $field){
135
  if (apply_filters('frm_show_custom_html', true, $field['type'])){ ?>
136
- <p><label class="frm_primary_label"><?php echo $field['name'] ?></label>
137
  <textarea name="field_options[custom_html_<?php echo $field['id'] ?>]" rows="7" id="custom_html_<?php echo $field['id'] ?>" class="field_custom_html frm_long_input"><?php echo FrmAppHelper::esc_textarea($field['custom_html']) ?></textarea></p>
138
  <?php }
139
  unset($field);
@@ -141,54 +194,40 @@
141
  } ?>
142
  </div>
143
 
144
- <p><label class="frm_primary_label"><?php _e('After Fields', 'formidable') ?></label>
145
- <textarea name="options[after_html]" rows="3" id="after_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['after_html']) ?></textarea></p>
146
-
147
- <p><label class="frm_primary_label"><?php _e('Submit Button', 'formidable') ?></label>
148
  <textarea name="options[submit_html]" rows="3" id="submit_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['submit_html']) ?></textarea></p>
149
  </div>
150
  </div>
151
- <div id="post_settings" class="tabs-panel" style="display:<?php echo ($a == 'post_settings') ? 'block' : 'none'; ?>;">
152
- <?php if($frm_vars['pro_is_installed'])
153
- FrmProFormsController::post_options($values);
154
- else
155
- FrmAppController::update_message('create and edit posts, pages, and custom post types through your forms');
156
- ?>
157
- </div>
158
-
159
  <?php foreach($sections as $sec_name => $section){ ?>
160
  <div id="<?php echo $sec_name ?>_settings" class="tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
161
  if(isset($section['class'])){
162
- call_user_func(array($section['class'], $section['function']), $values);
163
  }else{
164
- call_user_func((isset($section['function']) ? $section['function'] : $section), $values);
165
  } ?>
166
  </div>
167
  <?php } ?>
168
-
169
  <?php do_action('frm_add_form_option_section', $values); ?>
170
  <div class="clear"></div>
171
  </div>
172
  </div>
173
- </div>
174
- </div>
175
  </div>
176
 
177
  </div>
178
 
179
- <p>
180
  <input type="submit" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
181
- <?php _e('or', 'formidable') ?>
182
- <a class="button-secondary cancel" href="<?php echo admin_url('admin.php?page=formidable') ?>&amp;frm_action=edit&amp;id=<?php echo $id ?>"><?php _e('Cancel', 'formidable') ?></a>
183
  </p>
184
  </form>
185
 
186
 
187
  </div>
188
- <?php
189
- if(version_compare( $GLOBALS['wp_version'], '3.3.2', '>'))
190
- require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php');
191
- ?>
192
  </div>
193
  </div>
194
  </div>
3
  <h2><?php _e('Settings', 'formidable') ?>
4
  <a href="#" class="add-new-h2" style="visibility:hidden;"></a>
5
  </h2>
6
+
 
 
 
 
 
 
 
7
  <div id="poststuff">
 
 
8
  <div id="post-body" class="metabox-holder columns-2">
9
  <div id="post-body-content">
10
+ <?php
11
+ FrmAppController::get_form_nav($id, true);
12
+ require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
13
+ ?>
 
 
 
 
 
 
14
 
15
+ <form method="post" class="frm_form_settings">
16
+ <input type="hidden" name="id" id="form_id" value="<?php echo $id; ?>" />
17
  <input type="hidden" name="frm_action" value="update_settings" />
18
+
 
19
  <div class="meta-box-sortables">
20
  <div class="categorydiv postbox">
21
+ <h3 class="hndle"><span><?php echo __('Form Settings', 'formidable') ?></span></h3>
22
  <div class="inside frm-help-tabs">
23
  <div id="contextual-help-back"></div>
24
  <div id="contextual-help-columns">
26
  <ul class="frm-category-tabs frm-form-setting-tabs">
27
  <?php $a = isset($_GET['t']) ? $_GET['t'] : 'advanced_settings'; ?>
28
  <li <?php echo ($a == 'advanced_settings') ? 'class="tabs active"' : '' ?>><a href="#advanced_settings"><?php _e('General', 'formidable') ?></a></li>
29
+ <li <?php echo ($a == 'email_settings') ? 'class="tabs active"' : '' ?>><a href="#email_settings"><?php _e('Form Actions', 'formidable'); ?></a></li>
30
  <li <?php echo ($a == 'html_settings') ? 'class="tabs active"' : '' ?>><a href="#html_settings"><?php _e('Customize HTML', 'formidable') ?></a></li>
 
31
  <?php foreach($sections as $sec_name => $section){ ?>
32
  <li <?php echo ($a == $sec_name .'_settings') ? 'class="tabs active"' : '' ?>><a href="#<?php echo $sec_name ?>_settings"><?php echo ucfirst($sec_name) ?></a></li>
33
  <?php } ?>
34
  </ul>
35
  </div>
36
  <div style="display:<?php echo ($a == 'advanced_settings') ? 'block' : 'none'; ?>;" class="advanced_settings tabs-panel">
37
+ <h3 class="frm_first_h3"><?php _e('On Submit', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Choose what will happen after the user submits this form.', 'formidable'); if ( ! FrmAppHelper::pro_is_installed() ) { _e(' Upgrade to Formidable Pro to get access to all options in the dropdown.', 'formidable'); } ?>" ></span>
38
+ </h3>
 
 
39
 
40
+ <!--On Submit Section-->
41
+ <table class="form-table">
42
+ <tr>
43
+ <td style="width:175px;">
44
+ <select name="options[success_action]" id="success_action">
45
+ <option value="message" <?php selected($values['success_action'], 'message') ?>><?php _e('Show Message', 'formidable')?></option>
46
+ <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
47
+ <option value="redirect" <?php selected($values['success_action'], 'redirect');
48
+ ?>><?php _e('Redirect to URL', 'formidable') ?></option>
49
+ <option value="page" <?php selected($values['success_action'], 'page');
50
+ ?>><?php _e('Show Page Content', 'formidable')?></option>
51
+ <?php } else { ?>
52
+ <option value="redirect" disabled="disabled" <?php selected($values['success_action'], 'redirect');
53
+ ?>><?php _e('Redirect to URL', 'formidable'); echo ' '. __('(Pro feature)', 'formidable'); ?></option>
54
+ <option value="page" disabled="disabled" <?php selected($values['success_action'], 'page');
55
+ ?>><?php _e('Show Page Content', 'formidable'); echo ' '. __('(Pro feature)', 'formidable'); ?></option>
56
+ <?php } ?>
57
+ </select>
58
+ </td>
59
+ <td>
60
+ <span class="success_action_redirect_box success_action_box" <?php echo ($values['success_action'] == 'redirect') ? '' : 'style="display:none;"'; ?>>
61
+ <input type="text" name="options[success_url]" id="success_url" value="<?php if(isset($values['success_url'])) echo esc_attr($values['success_url']); ?>" style="width:95%" placeholder="http://example.com" />
62
+ </span>
63
+
64
+ <?php if ( FrmAppHelper::pro_is_installed() ){ ?>
65
+ <span class="success_action_page_box success_action_box" <?php echo ($values['success_action'] == 'page') ? '' : 'style="display:none;"'; ?>>
66
  <label><?php _e('Use Content from Page', 'formidable') ?></label>
67
  <?php FrmAppHelper::wp_pages_dropdown( 'options[success_page_id]', $values['success_page_id'] ) ?>
68
+ </span>
69
  <?php } ?>
70
  </td>
71
  </tr>
72
+ <tr <?php echo ($values['success_action'] == 'message') ? '' : 'style="display:none;"'; ?> class="frm_show_form_opt success_action_message_box success_action_box">
73
+ <td colspan="2">
74
+ <label for="show_form"><input type="checkbox" name="options[show_form]" id="show_form" value="1" <?php checked($values['show_form'], 1) ?> /> <?php _e('Show the form with the confirmation message', 'formidable')?></label>
75
+ </td>
76
+ </tr>
77
+ <tr>
78
+ <td colspan="2"><label for="no_save"><input type="checkbox" name="options[no_save]" id="no_save" value="1" <?php checked($values['no_save'], 1); ?> /> <?php _e('Do not store entries submitted from this form', 'formidable') ?></label>
79
+ </td>
80
+ </tr>
81
+ <?php if ( function_exists( 'akismet_http_post') ) { ?>
82
+ <tr>
83
+ <td colspan="2"><?php _e('Use Akismet to check entries for spam for', 'formidable') ?>
84
  <select name="options[akismet]">
85
  <option value=""><?php _e('no one', 'formidable') ?></option>
86
  <option value="1" <?php selected($values['akismet'], 1)?>><?php _e('everyone', 'formidable') ?></option>
90
  </tr>
91
  <?php } ?>
92
  </table>
93
+
94
+ <!--AJAX Section-->
95
+ <h3>AJAX <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Make stuff happen in the background without a page refresh', 'formidable') ?>" ></span></h3>
96
+ <table class="form-table">
97
+ <tr>
98
+ <td>
99
+ <label for="ajax_load"><input type="checkbox" name="options[ajax_load]" id="ajax_load" value="1"<?php echo ($values['ajax_load']) ? ' checked="checked"' : ''; ?> /> <?php _e('Load and save form builder page with AJAX', 'formidable') ?></label> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Recommended for long forms.', 'formidable') ?>" ></span>
100
+ </td>
101
+ </tr>
102
+ <?php do_action('frm_add_form_ajax_options', $values); ?>
103
+ </table>
104
+
105
+ <!--Permissions Section-->
106
+ <table class="form-table">
107
+ <?php do_action('frm_add_form_perm_options', $values); ?>
108
+ </table>
109
+
110
+ <!--Styling & Buttons Section-->
111
+ <h3><?php _e('Styling & Buttons', 'formidable') ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Select a style for this form and set the text for your buttons.', 'formidable') ?>" ></span></h3>
112
+ <table class="form-table">
113
+ <tr>
114
+ <td class="frm_left_label"><label for="custom_style"><?php _e('Style Template', 'formidable') ?></label></td>
115
+ <td><select name="options[custom_style]" id="custom_style">
116
+ <option value="1" <?php selected($values['custom_style'], 1) ?>><?php _e('Always use default', 'formidable')?></option>
117
+ <?php foreach ( $styles as $s ) { ?>
118
+ <option value="<?php echo $s->ID ?>" <?php selected($s->ID, $values['custom_style']) ?>><?php echo $s->post_title . ( empty($s->menu_order) ? '' : ' ('. __('default', 'formidable') .')' ) ?></option>
119
+ <?php } ?>
120
+ <option value="0" <?php selected($values['custom_style'], 0); selected($values['custom_style'], '') ?>><?php _e('Do not use Formidable styling', 'formidable')?></option>
121
+ </select></td>
122
+ </tr>
123
+ <tr>
124
+ <td><label><?php _e('Submit Button Text', 'formidable') ?></label></td>
125
+ <td><input type="text" name="options[submit_value]" value="<?php echo esc_attr($values['submit_value']); ?>" /></td>
126
+ </tr>
127
+ <?php do_action('frm_add_form_button_options', $values); ?>
128
+ </table>
129
+
130
+ <!--Message Section-->
131
+ <h3 id="frm_messages_header" class="<?php echo ( ( isset($values['edit_action']) && $values['edit_action'] == 'message' && isset($values['editable']) && $values['editable'] == 1 ) || $values['success_action'] == 'message' || $values['save_draft'] == 1 ) ? '' : 'frm_hidden'; ?>"><?php _e('Messages', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Set up your confirmation messages.', 'formidable') ?>" ></span></h3>
132
+ <table class="form-table">
133
+ <tr class="success_action_message_box success_action_box" <?php echo ($values['success_action'] == 'message') ? '' : 'style="display:none;"'; ?>>
134
+ <td>
135
+ <div><?php _e('On Submit', 'formidable') ?></div>
136
+ <textarea id="success_msg" name="options[success_msg]" cols="50" rows="2" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['success_msg']); ?></textarea>
137
+ </td>
138
+ </tr>
139
+ <?php do_action('frm_add_form_msg_options', $values); ?>
140
+ </table>
141
  </div>
142
 
143
+
144
+ <div id="frm_notification_settings" class="frm_email_settings email_settings tabs-panel widgets-holder-wrap" style="display:<?php echo ($a == 'email_settings') ? 'block' : 'none'; ?>;">
145
+ <div id="frm_email_addon_menu" class="manage-menus">
146
+ <h3><?php _e('Add New Action', 'formidable') ?></h3>
147
+ <ul class="frm_actions_list">
148
+ <?php
149
+
150
+ //For each add-on, add an li, class, and javascript function. If active, add an additional class.
151
+ foreach ( $action_controls as $action_control ) {
152
+ ?>
153
+ <li><a href="javascript:void(0)" class="frm_<?php echo $action_control->id_base ?>_action frm_bstooltip <?php
154
+ echo ( isset($action_control->action_options['active']) && $action_control->action_options['active']) ? 'frm_active_action ' : 'frm_inactive_action ';
155
+ echo $action_control->action_options['classes'];
156
+ ?>" title="<?php echo esc_attr($action_control->action_options['tooltip']) ?>" data-limit="<?php echo isset($action_control->action_options['limit']) ? $action_control->action_options['limit'] : '99' ?>" data-actiontype="<?php echo esc_attr($action_control->id_base) ?>"></a></li>
157
+ <?php
158
+ unset($actions_icon);
159
+ }
160
+ ?>
161
+ </ul>
162
+ </div>
163
+ <div class="frm_no_actions">
164
+ <div class="inner_actions">
165
+ <img src="<?php echo FrmAppHelper::plugin_url() .'/images/sketch_arrow1.png'; ?>" alt="" style="width:80px;"/>
166
+ <div class="clear"></div>
167
+ <?php _e('Click an action to add it to this form', 'formidable') ?>
168
+ </div>
169
+ </div>
170
+ <?php FrmFormActionsController::list_actions($form, $values); ?>
171
  </div>
172
+
 
173
  <div id="html_settings" class="tabs-panel" style="display:<?php echo ($a == 'html_settings') ? 'block' : 'none'; ?>;">
174
+
175
+ <div class="frm_field_html_box frm_top_container" style="margin-right:260px;">
176
+ <p><label><?php _e('Form Classes', 'formidable') ?></label>
177
+ <input type="text" name="options[form_class]" value="<?php echo esc_attr($values['form_class']) ?>" />
178
+ </p>
179
+ <div class="clear"></div>
180
+
181
+ <p><label><?php _e('Before Fields', 'formidable') ?></label>
182
  <textarea name="options[before_html]" rows="4" id="before_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['before_html']) ?></textarea></p>
183
 
184
  <div id="add_html_fields">
185
+ <?php
186
  if (isset($values['fields'])){
187
  foreach($values['fields'] as $field){
188
  if (apply_filters('frm_show_custom_html', true, $field['type'])){ ?>
189
+ <p><label><?php echo $field['name'] ?></label>
190
  <textarea name="field_options[custom_html_<?php echo $field['id'] ?>]" rows="7" id="custom_html_<?php echo $field['id'] ?>" class="field_custom_html frm_long_input"><?php echo FrmAppHelper::esc_textarea($field['custom_html']) ?></textarea></p>
191
  <?php }
192
  unset($field);
194
  } ?>
195
  </div>
196
 
197
+ <p><label><?php _e('After Fields', 'formidable') ?></label>
198
+ <textarea name="options[after_html]" rows="3" id="after_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['after_html']) ?></textarea></p>
199
+
200
+ <p><label><?php _e('Submit Button', 'formidable') ?></label>
201
  <textarea name="options[submit_html]" rows="3" id="submit_html" class="frm_long_input"><?php echo FrmAppHelper::esc_textarea($values['submit_html']) ?></textarea></p>
202
  </div>
203
  </div>
204
+
 
 
 
 
 
 
 
205
  <?php foreach($sections as $sec_name => $section){ ?>
206
  <div id="<?php echo $sec_name ?>_settings" class="tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
207
  if(isset($section['class'])){
208
+ call_user_func(array($section['class'], $section['function']), $values);
209
  }else{
210
+ call_user_func((isset($section['function']) ? $section['function'] : $section), $values);
211
  } ?>
212
  </div>
213
  <?php } ?>
214
+
215
  <?php do_action('frm_add_form_option_section', $values); ?>
216
  <div class="clear"></div>
217
  </div>
218
  </div>
 
 
219
  </div>
220
 
221
  </div>
222
 
223
+ <p>
224
  <input type="submit" value="<?php _e('Update', 'formidable') ?>" class="button-primary" />
 
 
225
  </p>
226
  </form>
227
 
228
 
229
  </div>
230
+ <?php require(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/sidebar-settings.php'); ?>
 
 
 
231
  </div>
232
  </div>
233
  </div>
classes/views/frm-forms/sidebar-settings.php CHANGED
@@ -1,33 +1,11 @@
1
- <div id="postbox-container-1" class="<?php echo FrmAppController::get_postbox_class(); ?>">
2
- <?php if(!isset($hide_preview) or !$hide_preview){
3
- if (!$values['is_template']){ ?>
4
- <p class="howto" style="margin-top:0;"><?php _e('Add to a post, page or text widget', 'formidable') ?>
5
- <a href="http://formidablepro.com/knowledgebase/publish-your-forms/" target="_blank" class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Key and id are generally synonymous. For more information on using this shortcode, click now.', 'formidable') ?>" ></a>
6
- <a href="javascript:void(0)" data-toggle=".frm_ext_sc"><?php _e('Show more', 'formidable') ?></a>
7
- <input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?>]" />
8
- <span class="frm_ext_sc">
9
- <input type="text" readonly="true" class="frm_select_box" value="[formidable id=<?php echo $id; ?> title=true description=true]" />
10
- <input type="text" readonly="true" class="frm_select_box" value="[formidable key=<?php echo $values['form_key']; ?>]" /><br/>
11
-
12
- <?php _e('Insert in a template', 'formidable') ?>
13
- <input type="text" readonly="true" class="frm_select_box" value="&lt;?php echo FrmFormsController::get_form_shortcode(array('id' => <?php echo $id; ?>, 'title' => false, 'description' => false)); ?&gt;" /><br/>
14
-
15
- <?php _e('Direct Link', 'formidable') ?>
16
- <input type="text" readonly="true" class="frm_select_box" value="<?php echo esc_attr(FrmFormsHelper::get_direct_link($values['form_key'])) ?>" />
17
- </span>
18
- </p>
19
- </tr>
20
- <?php } ?>
21
-
22
- <p class="frm_orange"><a href="<?php echo FrmFormsHelper::get_direct_link($values['form_key']); ?>" target="_blank"><?php _e('Preview Form', 'formidable') ?></a>
23
- <?php global $frm_settings;
24
- if ($frm_settings->preview_page_id > 0){ ?>
25
- <?php _e('or', 'formidable') ?>
26
- <a href="<?php echo add_query_arg('form', $values['form_key'], get_permalink($frm_settings->preview_page_id)) ?>" target="_blank"><?php _e('Preview in Current Theme', 'formidable') ?></a>
27
- <?php } ?>
28
- </p>
29
  <?php
30
- } ?>
31
-
32
- <?php include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_insert_fields.php') ?>
 
 
 
 
 
33
  </div>
1
+ <div id="postbox-container-1" class="postbox-container">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <?php
3
+
4
+ if ( !isset($hide_preview) || !$hide_preview ) {
5
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/_publish_box.php');
6
+ }
7
+
8
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_insert_fields.php');
9
+
10
+ ?>
11
  </div>
classes/views/frm-settings/form.php CHANGED
@@ -3,7 +3,7 @@
3
  <h2><?php _e('Global Settings', 'formidable'); ?></h2>
4
 
5
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
6
-
7
  <div id="poststuff" class="metabox-holder">
8
  <div id="post-body">
9
  <div class="meta-box-sortables">
@@ -23,138 +23,121 @@
23
  </div>
24
 
25
  <?php do_action('frm_before_settings'); ?>
26
-
27
  <form name="frm_settings_form" method="post" class="frm_settings_form" action="?page=formidable-settings<?php echo (isset($_GET['t'])) ? '&amp;t='. $_GET['t'] : ''; ?>">
28
  <input type="hidden" name="frm_action" value="process-form" />
29
  <input type="hidden" name="action" value="process-form" />
30
  <?php wp_nonce_field('process_form_nonce', 'process_form'); ?>
31
-
32
  <div class="general_settings tabs-panel" style="border-top:none;display:<?php echo ($a == 'general_settings') ? 'block' : 'none'; ?>;">
33
  <p class="submit" style="padding:0;">
34
  <input class="button-primary" type="submit" value="<?php _e('Update Options', 'formidable') ?>" />
35
  </p>
36
-
37
-
38
- <div class="menu-settings">
39
- <h3 class="frm_no_bg"><?php _e('Styling & Scripts', 'formidable'); ?></h3>
40
-
41
- <p><?php _e('Load Formidable styling', 'formidable') ?>
42
  <select id="frm_load_style" name="frm_load_style">
43
  <option value="all" <?php selected($frm_settings->load_style, 'all') ?>><?php _e('on every page of your site', 'formidable') ?></option>
44
  <option value="dynamic" <?php selected($frm_settings->load_style, 'dynamic') ?>><?php _e('only on applicable pages', 'formidable') ?></option>
45
  <option value="none" <?php selected($frm_settings->load_style, 'none') ?>><?php _e('Don\'t use Formidable styling on any page', 'formidable') ?></option>
46
  </select>
47
  </p>
48
-
49
  <p><label for="frm_use_html"><input type="checkbox" id="frm_use_html" name="frm_use_html" value="1" <?php checked($frm_settings->use_html, 1) ?> > <?php _e('Use HTML5 in forms', 'formidable') ?></label>
50
  </p>
51
-
52
  <?php do_action('frm_style_general_settings', $frm_settings); ?>
53
- </div>
54
-
55
- <div class="menu-settings">
56
- <h3 class="frm_no_bg"><?php _e('User Permissions', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Select users that are allowed access to Formidable. Without access to View Forms, users will be unable to see the Formidable menu.', 'formidable') ?>" ></span></h3>
57
- <p><?php foreach($frm_roles as $frm_role => $frm_role_description){ ?>
58
- <label class="frm_left_label"><?php echo $frm_role_description ?></label> <?php FrmAppHelper::wp_roles_dropdown( $frm_role, $frm_settings->$frm_role ) ?>
59
- <span class="clear"></span>
60
- <?php } ?></p>
61
- </div>
62
-
63
- <div class="menu-settings">
64
- <h3 class="frm_no_bg"><?php _e('reCAPTCHA', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog. reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot.', 'formidable') ?>" ></span></h3>
65
-
66
- <p class="howto">reCAPTCHA requires an API key, consisting of a "public" and a "private" key. You can sign up for a <a href="https://www.google.com/recaptcha/admin/create" target="_blank">free reCAPTCHA key</a>.</p>
67
-
68
- <!-- reCAPTCHA public key -->
69
- <p><label class="frm_left_label"><?php _e('Public Key', 'formidable') ?></label>
70
  <input type="text" name="frm_pubkey" id="frm_pubkey" size="42" value="<?php echo esc_attr($frm_settings->pubkey) ?>" /></p>
71
-
72
- <!-- reCAPTCHA private key -->
73
  <p><label class="frm_left_label"><?php _e('Private Key', 'formidable') ?></label>
74
  <input type="text" name="frm_privkey" id="frm_privkey" size="42" value="<?php echo esc_attr($frm_settings->privkey) ?>" /></p>
75
 
76
- <p><label class="frm_left_label"><?php _e('reCAPTCHA Theme', 'formidable') ?></label>
77
- <select name="frm_re_theme" id="frm_re_theme">
78
- <?php foreach($recaptcha_themes as $theme_value => $theme_name){ ?>
79
- <option value="<?php echo esc_attr($theme_value) ?>" <?php selected($frm_settings->re_theme, $theme_value) ?>><?php echo $theme_name ?></option>
80
- <?php }
81
- unset($recaptcha_themes, $theme_value, $theme_name);
82
- ?>
83
- </select></p>
84
-
85
  <p><label class="frm_left_label"><?php _e('reCAPTCHA Language', 'formidable') ?></label>
86
  <select name="frm_re_lang" id="frm_re_lang">
87
- <?php foreach(array('en' => __('English', 'formidable'), 'nl' => __('Dutch', 'formidable'), 'fr' => __('French', 'formidable'), 'de' => __('German', 'formidable'), 'pt' => __('Portuguese', 'formidable'), 'ru' => __('Russian', 'formidable'), 'es' => __('Spanish', 'formidable'), 'tr' => __('Turkish', 'formidable')) as $lang => $lang_name){ ?>
88
  <option value="<?php echo esc_attr($lang) ?>" <?php selected($frm_settings->re_lang, $lang) ?>><?php echo $lang_name ?></option>
89
  <?php } ?>
90
  </select></p>
91
- </div>
92
-
93
- <div class="menu-settings">
94
- <h3 class="frm_no_bg"><?php _e('Default Messages', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('You can override the success message and submit button settings on individual forms.', 'formidable') ?>" ></span></h3>
95
-
96
  <p><label class="frm_left_label"><?php _e('Failed/Duplicate Entry', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a form is submitted and passes validation, but something goes wrong.', 'formidable') ?>" ></span></label>
97
  <input type="text" id="frm_failed_msg" name="frm_failed_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->failed_msg) ?>" /></p>
98
-
99
  <p><label class="frm_left_label"><?php _e('Blank Field', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a required field is left blank.', 'formidable') ?>" ></span></label>
100
  <input type="text" id="frm_blank_msg" name="frm_blank_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->blank_msg) ?>" /></p>
101
 
102
  <p><label class="frm_left_label"><?php _e('Incorrect Field', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a field response is either incorrect or missing.', 'formidable') ?>" ></span></label>
103
  <input type="text" id="frm_invalid_msg" name="frm_invalid_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->invalid_msg) ?>" /></p>
104
 
105
- <?php if($frm_vars['pro_is_installed']){ ?>
106
  <p><label class="frm_left_label"><?php _e('Unique Value', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a user selects a value in a unique field that has already been used.', 'formidable') ?>" ></span></label>
107
  <input type="text" id="frm_unique_msg" name="frm_unique_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->unique_msg) ?>" /></p>
108
  <?php }else{ ?>
109
- <input type="hidden" id="frm_unique_msg" name="frm_unique_msg" value="<?php echo esc_attr($frm_settings->unique_msg) ?>" />
110
- <?php } ?>
111
- <input type="hidden" id="frm_login_msg" name="frm_login_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->login_msg) ?>" />
112
-
113
  <p><label class="frm_left_label"><?php _e('Success Message', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The default message seen after a form is submitted.', 'formidable') ?>" ></span></label>
114
  <input type="text" id="frm_success_msg" name="frm_success_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->success_msg) ?>" /></p>
115
 
116
  <p><label class="frm_left_label"><?php _e('Default Submit Button', 'formidable'); ?></label>
117
  <input type="text" value="<?php echo esc_attr($frm_settings->submit_value) ?>" id="frm_submit_value" name="frm_submit_value" class="frm_with_left_label" /></p>
118
- </div>
119
-
120
  <?php do_action('frm_settings_form', $frm_settings); ?>
121
-
122
- <?php if(!$frm_vars['pro_is_installed']){ ?>
123
  <div class="clear"></div>
124
- <div class="menu-settings">
125
- <h3 class="frm_no_bg"><?php _e('Miscellaneous', 'formidable') ?></h3>
126
- </div>
127
  <?php } ?>
128
  <p><label class="frm_left_label"><?php _e('Admin menu label', 'formidable'); ?></label>
129
  <input type="text" name="frm_menu" id="frm_menu" value="<?php echo esc_attr($frm_settings->menu) ?>" />
130
- <?php if (is_multisite() and is_super_admin()){ ?>
131
  <label for="frm_mu_menu"><input type="checkbox" name="frm_mu_menu" id="frm_mu_menu" value="1" <?php checked($frm_settings->mu_menu, 1) ?> /> <?php _e('Use this menu name site-wide', 'formidable'); ?></label>
132
  <?php } ?>
133
  </p>
134
-
135
  <p><label class="frm_left_label"><?php _e('Preview Page', 'formidable'); ?></label>
136
  <?php FrmAppHelper::wp_pages_dropdown('frm-preview-page-id', $frm_settings->preview_page_id ) ?>
137
  </p>
138
-
139
  <p><label class="frm_left_label"><?php _e('Tracking', 'formidable'); ?></label>
140
  <label for="frm_track"><input type="checkbox" id="frm_track" name="frm_track" value="1" <?php checked($frm_settings->track, 1) ?>> <?php _e('Track referrer information and pages visited', 'formidable') ?></label>
141
  </p>
142
  </div>
143
-
144
- <?php foreach($sections as $sec_name => $section){
145
  if($a == $sec_name .'_settings'){ ?>
146
- <style type="text/css">.<?php echo $sec_name ?>_settings{display:block !important;}</style><?php }?>
147
  <div id="<?php echo $sec_name ?>_settings" class="<?php echo $sec_name ?>_settings tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
148
  if(isset($section['class'])){
149
- call_user_func(array($section['class'], $section['function']));
150
  }else{
151
- call_user_func((isset($section['function']) ? $section['function'] : $section));
152
  } ?>
153
  </div>
154
  <?php } ?>
155
-
156
  <p class="alignright frm_uninstall" style="padding-top:1.25em;">
157
- <a href="javascript:frm_uninstall_now()"><?php _e('Uninstall Formidable', 'formidable') ?></a>
158
  <span class="spinner frm_spinner"></span>
159
  </p>
160
  <p class="submit">
@@ -170,3 +153,10 @@
170
 
171
  </div>
172
  </div>
 
 
 
 
 
 
 
3
  <h2><?php _e('Global Settings', 'formidable'); ?></h2>
4
 
5
  <?php require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
6
+
7
  <div id="poststuff" class="metabox-holder">
8
  <div id="post-body">
9
  <div class="meta-box-sortables">
23
  </div>
24
 
25
  <?php do_action('frm_before_settings'); ?>
26
+
27
  <form name="frm_settings_form" method="post" class="frm_settings_form" action="?page=formidable-settings<?php echo (isset($_GET['t'])) ? '&amp;t='. $_GET['t'] : ''; ?>">
28
  <input type="hidden" name="frm_action" value="process-form" />
29
  <input type="hidden" name="action" value="process-form" />
30
  <?php wp_nonce_field('process_form_nonce', 'process_form'); ?>
31
+
32
  <div class="general_settings tabs-panel" style="border-top:none;display:<?php echo ($a == 'general_settings') ? 'block' : 'none'; ?>;">
33
  <p class="submit" style="padding:0;">
34
  <input class="button-primary" type="submit" value="<?php _e('Update Options', 'formidable') ?>" />
35
  </p>
36
+
37
+
38
+ <h3><?php _e('Styling & Scripts', 'formidable'); ?></h3>
39
+
40
+ <p><label class="frm_left_label"><?php _e('Load Formidable styling', 'formidable') ?></label>
 
41
  <select id="frm_load_style" name="frm_load_style">
42
  <option value="all" <?php selected($frm_settings->load_style, 'all') ?>><?php _e('on every page of your site', 'formidable') ?></option>
43
  <option value="dynamic" <?php selected($frm_settings->load_style, 'dynamic') ?>><?php _e('only on applicable pages', 'formidable') ?></option>
44
  <option value="none" <?php selected($frm_settings->load_style, 'none') ?>><?php _e('Don\'t use Formidable styling on any page', 'formidable') ?></option>
45
  </select>
46
  </p>
47
+
48
  <p><label for="frm_use_html"><input type="checkbox" id="frm_use_html" name="frm_use_html" value="1" <?php checked($frm_settings->use_html, 1) ?> > <?php _e('Use HTML5 in forms', 'formidable') ?></label>
49
  </p>
50
+
51
  <?php do_action('frm_style_general_settings', $frm_settings); ?>
52
+
53
+ <h3><?php _e('User Permissions', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('Select users that are allowed access to Formidable. Without access to View Forms, users will be unable to see the Formidable menu.', 'formidable') ?>" ></span></h3>
54
+ <table class="form-table">
55
+ <?php foreach($frm_roles as $frm_role => $frm_role_description){ ?>
56
+ <tr>
57
+ <td class="frm_left_label"><label><?php echo $frm_role_description ?></label></td>
58
+ <td><?php FrmAppHelper::wp_roles_dropdown( $frm_role, $frm_settings->$frm_role, 'multiple' ) ?></td>
59
+ </tr>
60
+ <?php } ?>
61
+ </table>
62
+
63
+ <h3><?php _e('reCAPTCHA', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog. reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot.', 'formidable') ?>" ></span></h3>
64
+
65
+ <p class="howto">reCAPTCHA requires an API key, consisting of a "site" and a "private" key. You can sign up for a <a href="https://www.google.com/recaptcha/" target="_blank">free reCAPTCHA key</a>.</p>
66
+
67
+ <p><label class="frm_left_label"><?php _e('Site Key', 'formidable') ?></label>
 
68
  <input type="text" name="frm_pubkey" id="frm_pubkey" size="42" value="<?php echo esc_attr($frm_settings->pubkey) ?>" /></p>
69
+
 
70
  <p><label class="frm_left_label"><?php _e('Private Key', 'formidable') ?></label>
71
  <input type="text" name="frm_privkey" id="frm_privkey" size="42" value="<?php echo esc_attr($frm_settings->privkey) ?>" /></p>
72
 
 
 
 
 
 
 
 
 
 
73
  <p><label class="frm_left_label"><?php _e('reCAPTCHA Language', 'formidable') ?></label>
74
  <select name="frm_re_lang" id="frm_re_lang">
75
+ <?php foreach ( $captcha_lang as $lang => $lang_name ) { ?>
76
  <option value="<?php echo esc_attr($lang) ?>" <?php selected($frm_settings->re_lang, $lang) ?>><?php echo $lang_name ?></option>
77
  <?php } ?>
78
  </select></p>
79
+
80
+ <h3><?php _e('Default Messages', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('You can override the success message and submit button settings on individual forms.', 'formidable') ?>" ></span></h3>
81
+
 
 
82
  <p><label class="frm_left_label"><?php _e('Failed/Duplicate Entry', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a form is submitted and passes validation, but something goes wrong.', 'formidable') ?>" ></span></label>
83
  <input type="text" id="frm_failed_msg" name="frm_failed_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->failed_msg) ?>" /></p>
84
+
85
  <p><label class="frm_left_label"><?php _e('Blank Field', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a required field is left blank.', 'formidable') ?>" ></span></label>
86
  <input type="text" id="frm_blank_msg" name="frm_blank_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->blank_msg) ?>" /></p>
87
 
88
  <p><label class="frm_left_label"><?php _e('Incorrect Field', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a field response is either incorrect or missing.', 'formidable') ?>" ></span></label>
89
  <input type="text" id="frm_invalid_msg" name="frm_invalid_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->invalid_msg) ?>" /></p>
90
 
91
+ <?php if ( FrmAppHelper::pro_is_installed() ) { ?>
92
  <p><label class="frm_left_label"><?php _e('Unique Value', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The message seen when a user selects a value in a unique field that has already been used.', 'formidable') ?>" ></span></label>
93
  <input type="text" id="frm_unique_msg" name="frm_unique_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->unique_msg) ?>" /></p>
94
  <?php }else{ ?>
95
+ <input type="hidden" id="frm_unique_msg" name="frm_unique_msg" value="<?php echo esc_attr($frm_settings->unique_msg) ?>" />
96
+ <input type="hidden" id="frm_login_msg" name="frm_login_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->login_msg) ?>" />
97
+ <?php } ?>
98
+
99
  <p><label class="frm_left_label"><?php _e('Success Message', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php _e('The default message seen after a form is submitted.', 'formidable') ?>" ></span></label>
100
  <input type="text" id="frm_success_msg" name="frm_success_msg" class="frm_with_left_label" value="<?php echo esc_attr($frm_settings->success_msg) ?>" /></p>
101
 
102
  <p><label class="frm_left_label"><?php _e('Default Submit Button', 'formidable'); ?></label>
103
  <input type="text" value="<?php echo esc_attr($frm_settings->submit_value) ?>" id="frm_submit_value" name="frm_submit_value" class="frm_with_left_label" /></p>
104
+
 
105
  <?php do_action('frm_settings_form', $frm_settings); ?>
106
+
107
+ <?php if ( ! FrmAppHelper::pro_is_installed() ) { ?>
108
  <div class="clear"></div>
109
+ <h3><?php _e('Miscellaneous', 'formidable') ?></h3>
 
 
110
  <?php } ?>
111
  <p><label class="frm_left_label"><?php _e('Admin menu label', 'formidable'); ?></label>
112
  <input type="text" name="frm_menu" id="frm_menu" value="<?php echo esc_attr($frm_settings->menu) ?>" />
113
+ <?php if ( is_multisite() && is_super_admin() ) { ?>
114
  <label for="frm_mu_menu"><input type="checkbox" name="frm_mu_menu" id="frm_mu_menu" value="1" <?php checked($frm_settings->mu_menu, 1) ?> /> <?php _e('Use this menu name site-wide', 'formidable'); ?></label>
115
  <?php } ?>
116
  </p>
117
+
118
  <p><label class="frm_left_label"><?php _e('Preview Page', 'formidable'); ?></label>
119
  <?php FrmAppHelper::wp_pages_dropdown('frm-preview-page-id', $frm_settings->preview_page_id ) ?>
120
  </p>
121
+
122
  <p><label class="frm_left_label"><?php _e('Tracking', 'formidable'); ?></label>
123
  <label for="frm_track"><input type="checkbox" id="frm_track" name="frm_track" value="1" <?php checked($frm_settings->track, 1) ?>> <?php _e('Track referrer information and pages visited', 'formidable') ?></label>
124
  </p>
125
  </div>
126
+
127
+ <?php foreach($sections as $sec_name => $section){
128
  if($a == $sec_name .'_settings'){ ?>
129
+ <style type="text/css">.<?php echo $sec_name ?>_settings{display:block;}</style><?php }?>
130
  <div id="<?php echo $sec_name ?>_settings" class="<?php echo $sec_name ?>_settings tabs-panel" style="display:<?php echo ($a == $sec_name .'_settings') ? 'block' : 'none'; ?>;"><?php
131
  if(isset($section['class'])){
132
+ call_user_func(array($section['class'], $section['function']));
133
  }else{
134
+ call_user_func((isset($section['function']) ? $section['function'] : $section));
135
  } ?>
136
  </div>
137
  <?php } ?>
138
+
139
  <p class="alignright frm_uninstall" style="padding-top:1.25em;">
140
+ <a href="javascript:void(0)" id="frm_uninstall_now"><?php _e('Uninstall Formidable', 'formidable') ?></a>
141
  <span class="spinner frm_spinner"></span>
142
  </p>
143
  <p class="submit">
153
 
154
  </div>
155
  </div>
156
+
157
+ <script type="text/javascript">jQuery(document).ready(function($){
158
+ $('.frm_multiselect').multiselect({
159
+ templates: {ul:'<ul class="multiselect-container frm-dropdown-menu"></ul>'},
160
+ nonSelectedText:'<?php _e("Default", "formidable") ?>',
161
+ });
162
+ });</script>
classes/views/frm-settings/license_box.php CHANGED
@@ -1,10 +1,10 @@
1
  <div class="general_settings metabox-holder tabs-panel" style="min-height:0px;border-bottom:none;display:<?php echo ($a == 'general_settings') ? 'block' : 'none'; ?>;">
2
- <?php if (!is_multisite() or is_super_admin()){ ?>
3
  <div class="postbox">
4
  <div class="inside">
5
  <p class="alignright"><?php printf(__('%1$sClick here%2$s to get it now', 'formidable'), '<a href="http://formidablepro.com">', '</a>') ?> &#187;</p>
6
  <p><?php _e('Ready to take your forms to the next level?<br/>Formidable Pro will help you style forms, manage data, and get reports.', 'formidable') ?></p>
7
-
8
  <p>Already signed up? <a href="http://formidablepro.com/knowledgebase/manually-install-formidable-pro/" target="_blank"><?php _e('Click here', 'formidable') ?></a> to get installation instructions and download the pro version.</p>
9
  </div>
10
  </div>
1
  <div class="general_settings metabox-holder tabs-panel" style="min-height:0px;border-bottom:none;display:<?php echo ($a == 'general_settings') ? 'block' : 'none'; ?>;">
2
+ <?php if ( ! is_multisite() || is_super_admin() ) { ?>
3
  <div class="postbox">
4
  <div class="inside">
5
  <p class="alignright"><?php printf(__('%1$sClick here%2$s to get it now', 'formidable'), '<a href="http://formidablepro.com">', '</a>') ?> &#187;</p>
6
  <p><?php _e('Ready to take your forms to the next level?<br/>Formidable Pro will help you style forms, manage data, and get reports.', 'formidable') ?></p>
7
+
8
  <p>Already signed up? <a href="http://formidablepro.com/knowledgebase/manually-install-formidable-pro/" target="_blank"><?php _e('Click here', 'formidable') ?></a> to get installation instructions and download the pro version.</p>
9
  </div>
10
  </div>
classes/views/frm-settings/styling_tab.php DELETED
@@ -1,4 +0,0 @@
1
- <div class="frm_update_msg">
2
- This plugin version does not give you access to the visual form styler.<br/>
3
- <a href="http://formidablepro.com/pricing/" target="_blank">Compare</a> our plans to find a solution that's right for you.
4
- </div>
 
 
 
 
classes/views/frm-statistics/list.php CHANGED
@@ -5,11 +5,13 @@
5
  <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
  </h2>
7
 
8
- <?php
9
- if($form) FrmAppController::get_form_nav($form, true);
 
 
10
  require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
-
12
- FrmAppController::update_message('view reports and statistics on your saved entries');
13
  ?>
14
 
15
  <img src="http://fp.strategy11.com/wp-content/themes/formidablepro/images/reports1.png" alt="Reports" style="max-width:100%"/>
5
  <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
  </h2>
7
 
8
+ <?php
9
+ if ( $form ) {
10
+ FrmAppController::get_form_nav($form, true);
11
+ }
12
  require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
13
+
14
+ FrmAppHelper::update_message('view reports and statistics on your saved entries');
15
  ?>
16
 
17
  <img src="http://fp.strategy11.com/wp-content/themes/formidablepro/images/reports1.png" alt="Reports" style="max-width:100%"/>
classes/views/frm-statistics/list_displays.php CHANGED
@@ -5,10 +5,12 @@
5
  <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
  </h2>
7
 
8
- <?php
9
- if($form) FrmAppController::get_form_nav($form);
 
 
10
  require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
11
- FrmAppController::update_message('display collected data in lists, calendars, and other formats');
12
  ?>
13
 
14
  <img src="http://fp.strategy11.com/images/custom-display-settings.png" alt="Display" style="max-width:100%"/>
5
  <a href="#" class="add-new-h2" style="visibility:hidden;"><?php _e('Add New', 'formidable'); ?></a>
6
  </h2>
7
 
8
+ <?php
9
+ if ( $form ) {
10
+ FrmAppController::get_form_nav($form);
11
+ }
12
  require(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php');
13
+ FrmAppHelper::update_message('display collected data in lists, calendars, and other formats');
14
  ?>
15
 
16
  <img src="http://fp.strategy11.com/images/custom-display-settings.png" alt="Display" style="max-width:100%"/>
classes/views/shared/errors.php CHANGED
@@ -1,12 +1,24 @@
1
  <div class="clear"></div>
2
- <?php if (isset($message) && $message != ''){ if(is_admin() and !defined('DOING_AJAX')){ ?><div id="message" class="updated" style="padding:5px;"><?php } echo $message; if(is_admin() and !defined('DOING_AJAX')){ ?></div><?php } } ?>
 
 
 
 
 
 
 
 
 
3
 
4
- <?php if( isset($errors) && is_array($errors) && count($errors) > 0 ){ ?>
5
  <div class="error">
6
  <ul id="frm_errors">
7
- <?php foreach( $errors as $error )
 
8
  echo '<li>' . $error . '</li>';
 
9
  ?>
10
  </ul>
11
  </div>
12
- <?php } ?>
 
1
  <div class="clear"></div>
2
+ <?php
3
+ if ( isset($message) && $message != '' ) {
4
+ if ( FrmAppHelper::is_admin() ) {
5
+ ?><div id="message" class="updated" style="padding:5px;"><?php
6
+ echo $message;
7
+ ?></div><?php
8
+ } else {
9
+ echo $message;
10
+ }
11
+ }
12
 
13
+ if ( isset($errors) && is_array($errors) && count($errors) > 0 ) { ?>
14
  <div class="error">
15
  <ul id="frm_errors">
16
+ <?php
17
+ foreach( $errors as $error ) {
18
  echo '<li>' . $error . '</li>';
19
+ }
20
  ?>
21
  </ul>
22
  </div>
23
+ <?php
24
+ } ?>
classes/views/shared/form-nav.php CHANGED
@@ -1,9 +1,29 @@
1
- <?php if($form){ ?><p class="frm_title_head"><?php echo ($form->name == '') ? __('(no title)') : FrmAppHelper::truncate($form->name, 33) ?></p><?php } ?>
2
  <ul class="frm_form_nav">
3
- <li class="first"><a<?php if(($current_page == 'formidable') and isset($_GET['frm_action']) and (in_array($_GET['frm_action'], array('edit', 'new', 'duplicate')))) echo ' class="current_page"'; ?> href="<?php echo admin_url('admin.php?page=formidable') ?>&amp;frm_action=edit&amp;id=<?php echo $id ?>"><?php _e('Build', 'formidable') ?></a> </li>
4
- <li><a<?php if(($current_page == 'formidable') and isset($_GET['frm_action']) and $_GET['frm_action'] == 'settings') echo ' class="current_page"'; ?> href="<?php echo admin_url('admin.php?page=formidable') ?>&amp;frm_action=settings&amp;id=<?php echo $id ?>"><?php _e('Settings', 'formidable') ?></a> </li>
5
- <li> <a<?php if($current_page == 'formidable-entries') echo ' class="current_page"'; ?> href="<?php echo admin_url('admin.php?page=formidable') ?>-entries&amp;frm_action=list&amp;form=<?php echo $id ?>"><?php _e('Entries', 'formidable') ?></a></li>
6
- <li> <a<?php if($current_page == 'frm_display' or $pagenow == 'post.php' or $pagenow == 'post-new.php' or $current_page == 'formidable-entry-templates') echo ' class="current_page"'; ?> href="<?php echo esc_url(($frm_vars['pro_is_installed'] ? admin_url('edit.php?post_type=frm_display') : admin_url( 'admin.php?page=formidable-entry-templates')) ."&form={$id}&show_nav=1"); ?>"><?php _e('Views', 'formidable') ?></a></li>
7
- <li> <a<?php if($current_page == 'formidable-reports') echo ' class="current_page"'; ?> href="<?php echo esc_url(admin_url('admin.php?page=formidable') . "-reports&frm_action=show&form=$id&show_nav=1") ?>"><?php _e('Reports', 'formidable') ?></a></li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  <?php FrmFormsHelper::form_switcher(); ?>
9
  </ul>
 
 
 
 
 
1
+ <div id="titlediv">
2
  <ul class="frm_form_nav">
3
+ <li class="first"><a<?php
4
+ if ( ( $current_page == 'formidable') && isset($_GET['frm_action']) && (in_array($_GET['frm_action'], array('edit', 'new', 'duplicate'))) ) {
5
+ echo ' class="current_page"';
6
+ } ?> href="<?php echo admin_url('admin.php?page=formidable') ?>&amp;frm_action=edit&amp;id=<?php echo $id ?>"><?php _e('Build', 'formidable') ?></a> </li>
7
+ <li><a<?php
8
+ if ( ( $current_page == 'formidable') && isset($_GET['frm_action']) && $_GET['frm_action'] == 'settings' ) {
9
+ echo ' class="current_page"';
10
+ } ?> href="<?php echo admin_url('admin.php?page=formidable') ?>&amp;frm_action=settings&amp;id=<?php echo $id ?>"><?php _e('Settings', 'formidable') ?></a> </li>
11
+ <li> <a<?php
12
+ if ( $current_page == 'formidable-entries' ) {
13
+ echo ' class="current_page"';
14
+ } ?> href="<?php echo admin_url('admin.php?page=formidable') ?>-entries&amp;frm_action=list&amp;form=<?php echo $id ?>"><?php _e('Entries', 'formidable') ?></a></li>
15
+ <li> <a<?php
16
+ if ( $current_page == 'frm_display' || $pagenow == 'post.php' || $pagenow == 'post-new.php' || $current_page == 'formidable-entry-templates' ) {
17
+ echo ' class="current_page"';
18
+ } ?> href="<?php echo esc_url((FrmAppHelper::pro_is_installed() ? admin_url('edit.php?post_type=frm_display') : admin_url( 'admin.php?page=formidable-entry-templates')) ."&form={$id}&show_nav=1"); ?>"><?php _e('Views', 'formidable') ?></a></li>
19
+ <li> <a<?php
20
+ if ( $current_page == 'formidable' && isset($_GET['frm_action']) && in_array($_GET['frm_action'], array('reports')) ) {
21
+ echo ' class="current_page"';
22
+ } ?> href="<?php echo esc_url(admin_url('admin.php?page=formidable') . "&frm_action=reports&form=$id&show_nav=1") ?>"><?php _e('Reports', 'formidable') ?></a></li>
23
  <?php FrmFormsHelper::form_switcher(); ?>
24
  </ul>
25
+
26
+ <?php if($form && $title == 'show'){ ?>
27
+ <input id="title" type="text" value="<?php echo esc_attr($form->name == '' ? __('(no title)') : $form->name) ?>" readonly="readonly" disabled="disabled" />
28
+ <?php } ?>
29
+ </div>
classes/views/shared/head.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- if (isset($css_file)){
3
  if (is_array($css_file)){
4
  foreach ($css_file as $file)
5
  echo '<link rel="stylesheet" href="'. $file .'" type="text/css" />';
6
  }else{?>
7
  <link rel="stylesheet" href="<?php echo $css_file; ?>" type="text/css" />
8
- <?php }
9
  }
10
 
11
- if (isset($js_file)){
12
  if (is_array($js_file)){
13
  foreach ($js_file as $file)
14
  echo '<script type="text/javascript" src="'. $file .'"></script>';
15
  }else{?>
16
  <script type="text/javascript" src="<?php echo $js_file; ?>"></script>
17
- <?php
18
  }
19
  }
20
  ?>
1
+ <?php
2
+ if (isset($css_file)){
3
  if (is_array($css_file)){
4
  foreach ($css_file as $file)
5
  echo '<link rel="stylesheet" href="'. $file .'" type="text/css" />';
6
  }else{?>
7
  <link rel="stylesheet" href="<?php echo $css_file; ?>" type="text/css" />
8
+ <?php }
9
  }
10
 
11
+ if (isset($js_file)){
12
  if (is_array($js_file)){
13
  foreach ($js_file as $file)
14
  echo '<script type="text/javascript" src="'. $file .'"></script>';
15
  }else{?>
16
  <script type="text/javascript" src="<?php echo $js_file; ?>"></script>
17
+ <?php
18
  }
19
  }
20
  ?>
classes/views/shared/mb_adv_info.php ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="taxonomy-linkcategory" class="categorydiv">
2
+ <ul id="category-tabs" class="category-tabs frm-category-tabs">
3
+ <li class="tabs" ><a href="#frm-insert-fields-box" id="frm_insert_fields_tab"><?php _e( 'Insert Fields', 'formidable' ); ?></a></li>
4
+ <li class="hide-if-no-js"><a href="#frm-conditionals"><?php _e( 'Conditionals', 'formidable' ); ?></a></li>
5
+ <li class="hide-if-no-js"><a href="#frm-adv-info-tab"><?php _e( 'Advanced', 'formidable' ); ?></a></li>
6
+ <?php if($settings_tab){ ?>
7
+ <li id="frm_html_tab" class="hide-if-no-js" style="display:none;"><a href="#frm-html-tags" id="frm_html_tags_tab" ><?php _e( 'HTML Tags', 'formidable' ); ?></a></li>
8
+ <?php } ?>
9
+ </ul>
10
+
11
+ <div id="frm-insert-fields-box" class="tabs-panel" style="max-height:none;padding-right:0;">
12
+ <ul class="subsubsub" style="float:right;margin:0;">
13
+ <li><a href="javascript:void(0)" class="current frmids"><?php _e('IDs', 'formidable') ?></a> |</li>
14
+ <li><a href="javascript:void(0)" class="frmkeys"><?php _e('Keys', 'formidable') ?></a></li>
15
+ </ul>
16
+ <ul class="alignleft" style="margin:5px 0 0;"><li><?php _e('Fields from your form', 'formidable') ?>:</li></ul>
17
+ <ul class="frm_code_list frm_full_width" style="clear:both;max-height:150px;overflow:auto;">
18
+ <?php
19
+ if ( !empty($fields) ) {
20
+ global $wpdb;
21
+ $linked_forms[] = array();
22
+
23
+ foreach ( $fields as $f ) {
24
+ if ( $f->type == 'divider' && isset($f->field_options['repeat']) && $f->field_options['repeat'] ) {
25
+ $repeat_field = $f->id;
26
+ }
27
+
28
+ if ( FrmFieldsHelper::is_no_save_field($f->type) ) {
29
+ continue;
30
+ }
31
+
32
+ if ( $f->type == 'data' && (!isset($f->field_options['data_type']) || $f->field_options['data_type'] == 'data' || $f->field_options['data_type'] == '') ) {
33
+ continue;
34
+ }
35
+
36
+ FrmAppHelper::insert_opt_html(array(
37
+ 'id' => $f->id, 'key' => $f->field_key, 'name' => $f->name, 'type' => $f->type
38
+ ));
39
+
40
+ if ($f->type == 'data'){ //get all fields from linked form
41
+ if ( isset($f->field_options['form_select']) && is_numeric($f->field_options['form_select']) ){
42
+ $linked_form = $wpdb->get_var($wpdb->prepare("SELECT form_id FROM {$wpdb->prefix}frm_fields WHERE id=%d", $f->field_options['form_select']));
43
+ if(!in_array($linked_form, $linked_forms)){
44
+ $linked_forms[] = $linked_form;
45
+ $linked_fields = FrmField::getAll("fi.type not in ('". implode("','", FrmFieldsHelper::no_save_fields() ) ."') and fi.form_id =". (int) $linked_form);
46
+ $ldfe = '';
47
+ if ($linked_fields){
48
+ foreach ($linked_fields as $linked_field){
49
+ FrmAppHelper::insert_opt_html(array('id' => $f->id ." show=". $linked_field->id, 'key' => $f->field_key ." show=". $linked_field->field_key, 'name' => $linked_field->name, 'type' => $linked_field->type));
50
+
51
+ $ldfe = $linked_field->id;
52
+ unset($linked_field);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ $dfe = $f->id;
58
+ }
59
+ unset($f);
60
+ }
61
+ } ?>
62
+ </ul>
63
+
64
+ <?php _e('Helpers', 'formidable') ?>:
65
+ <ul class="frm_code_list">
66
+ <?php
67
+ $col = 'one';
68
+ $entry_shortcodes = array(
69
+ 'id' => __('Entry ID', 'formidable'),
70
+ 'key' => __('Entry Key', 'formidable'),
71
+ 'post_id' => __('Post ID', 'formidable'),
72
+ 'ip' => __('User IP', 'formidable'),
73
+ 'created-at' => __('Entry created', 'formidable'),
74
+ 'updated-at' => __('Entry updated', 'formidable'),
75
+ '' => '',
76
+ 'siteurl' => __('Site URL', 'formidable'),
77
+ 'sitename' => __('Site Name', 'formidable'),
78
+ );
79
+
80
+ if ( ! FrmAppHelper::pro_is_installed() ) {
81
+ unset($entry_shortcodes['post_id']);
82
+ }
83
+
84
+ if ($settings_tab) {
85
+ $entry_shortcodes['default-message'] = __('Default Msg', 'formidable');
86
+ $entry_shortcodes['default-html'] = __('Default HTML', 'formidable');
87
+ $entry_shortcodes['default-plain'] = __('Default Plain', 'formidable');
88
+ } else {
89
+ $entry_shortcodes['detaillink'] = __('Detail Link', 'formidable');
90
+ $entry_shortcodes['editlink location=&#34;front&#34; label=&#34;Edit&#34; page_id=x'] = __('Edit Entry Link', 'formidable');
91
+ $entry_shortcodes['evenodd'] = __('Even/Odd', 'formidable');
92
+ $entry_shortcodes['entry_count'] = __('Entry Count', 'formidable');
93
+ }
94
+
95
+
96
+ foreach ($entry_shortcodes as $skey => $sname) {
97
+ if (empty($skey)) {
98
+ $col = 'one';
99
+ echo '<li class="clear" style="display:block;height:10px;"></li>';
100
+ continue;
101
+ }
102
+ ?>
103
+ <li class="frm_col_<?php echo $col ?>">
104
+ <a href="javascript:void(0)" class="frmbutton button <?php
105
+ echo (in_array($skey, array('siteurl', 'sitename', 'entry_count'))) ? 'show_before_content show_after_content' : '';
106
+ echo (strpos($skey, 'default-') === 0) ? 'hide_frm_not_email_subject' : '';
107
+ ?> frm_insert_code" data-code="<?php echo esc_attr($skey) ?>"><?php echo $sname ?></a>
108
+ </li>
109
+ <?php
110
+ $col = ( $col == 'one' ) ? 'two' : 'one';
111
+ unset($skey, $sname);
112
+ }
113
+ ?>
114
+ </ul>
115
+ </div>
116
+
117
+ <div id="frm-conditionals" class="tabs-panel" style="display:none;max-height:none;padding-right:0;">
118
+ <?php if ( !empty($cond_shortcodes) ) { ?>
119
+ <ul class="subsubsub" style="float:right;margin:0;">
120
+ <li><a href="javascript:void(0)" class="current frmids"><?php _e('IDs', 'formidable') ?></a> |</li>
121
+ <li><a href="javascript:void(0)" class="frmkeys"><?php _e('Keys', 'formidable') ?></a></li>
122
+ </ul>
123
+ <ul class="alignleft" style="margin:5px 0 0;"><li><?php _e('Fields from your form', 'formidable') ?>:</li></ul>
124
+ <ul class="frm_code_list frm_full_width" style="clear:both;max-height:150px;overflow:auto;">
125
+ <?php if ( !empty($fields) ) {
126
+ foreach ( $fields as $f){
127
+ if ( FrmFieldsHelper::is_no_save_field($f->type) || ( $f->type == 'data' && ( ! isset($f->field_options['data_type']) || $f->field_options['data_type'] == 'data' || $f->field_options['data_type'] == '' ) ) ) {
128
+ continue;
129
+ }
130
+ ?>
131
+ <li>
132
+ <a href="javascript:void(0)" class="frmids alignright frm_insert_code" data-code="if <?php echo $f->id ?>]<?php esc_attr_e('Conditional text here', 'formidable') ?>[/if <?php echo $f->id ?>">[if <?php echo $f->id ?>]</a>
133
+ <a href="javascript:void(0)" class="frmkeys alignright frm_insert_code" data-code="if <?php echo esc_attr($f->field_key) ?>]something[/if <?php echo esc_attr($f->field_key) ?>">[if <?php echo FrmAppHelper::truncate($f->field_key, 10) ?>]</a>
134
+ <a href="javascript:void(0)" class="frm_insert_code" data-code="<?php echo esc_attr($f->id) ?>"><?php echo FrmAppHelper::truncate($f->name, 60) ?></a>
135
+ </li>
136
+ <?php
137
+
138
+ if ( $f->type == 'user_id' ) {
139
+ $uid = $f;
140
+ } else if ( $f->type == 'file' ) {
141
+ $file = $f;
142
+ }
143
+ unset($f);
144
+ }
145
+ } ?>
146
+ </ul>
147
+
148
+ <p class="howto"><?php _e('Click a button below to insert sample logic into your view', 'formidable') ?></p>
149
+ <ul class="frm_code_list">
150
+ <?php
151
+ $col = 'one';
152
+ foreach ($cond_shortcodes as $skey => $sname){
153
+ ?>
154
+ <li class="frm_col_<?php echo $col ?>">
155
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="if 125 <?php echo esc_attr($skey) ?>][/if 125"><?php echo $sname ?></a>
156
+ </li>
157
+ <?php
158
+ $col = ( $col == 'one' ) ? 'two' : 'one';
159
+ unset($skey, $sname);
160
+ }
161
+ ?>
162
+ </ul>
163
+ <?php } else {
164
+ FrmAppHelper::update_message('use inline conditional logic');
165
+ } ?>
166
+ </div>
167
+
168
+ <div id="frm-adv-info-tab" class="tabs-panel" style="display:none;max-height:355px;">
169
+ <ul class="frm_code_list">
170
+ <?php
171
+ $col = 'one';
172
+ foreach ($adv_shortcodes as $skey => $sname){
173
+ ?>
174
+ <li class="frm_col_<?php echo $col ?>">
175
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code <?php echo is_array($sname) ? 'frm_help' : ''; ?>" data-code="125 <?php echo esc_attr($skey) ?>" <?php echo is_array($sname) ? 'title="'. $sname['title'] .'"' : ''; ?>><?php echo is_array($sname) ? $sname['label'] : $sname; ?></a>
176
+ </li>
177
+ <?php
178
+ $col = ($col == 'one') ? 'two' : 'one';
179
+ unset($skey, $sname);
180
+ }
181
+ ?>
182
+ <?php if ( isset($file) ) { ?>
183
+ <li class="frm_col_<?php echo $col ?>">
184
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr($file->id) ?> size=thumbnail html=1"><?php _e('Image Size', 'formidable') ?></a>
185
+ </li>
186
+ <li class="frm_col_<?php echo $col = (($col == 'one') ? 'two' : 'one') ?>">
187
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr($file->id) ?> show=id"><?php _e('Image ID', 'formidable') ?></a>
188
+ </li>
189
+ <li class="frm_col_<?php echo $col = (($col == 'one') ? 'two' : 'one') ?>">
190
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr($file->id) ?> show=label"><?php _e('Image Name', 'formidable') ?></a>
191
+ </li>
192
+ <?php } ?>
193
+ </ul>
194
+
195
+ <div class="clear"></div>
196
+ <?php
197
+ FrmAppHelper::update_message('all of the advanced shortcode options');
198
+
199
+ if ( isset($uid) && ! empty($user_fields) ) {
200
+ $col = 'one'; ?>
201
+ <p class="howto"><?php _e('Insert user information', 'formidable') ?></p>
202
+ <ul class="frm_code_list">
203
+ <?php foreach($user_fields as $uk => $uf){ ?>
204
+ <li class="frm_col_<?php echo $col ?>">
205
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr($uid->id .' show="'. $uk .'"') ?>"><?php echo $uf ?></a>
206
+ </li>
207
+ <?php
208
+ $col = ($col == 'one') ? 'two' : 'one';
209
+ unset($uf, $uk);
210
+ }
211
+ unset($uid); ?>
212
+ </ul>
213
+ <?php }
214
+
215
+ if ( isset($repeat_field) ) { ?>
216
+ <div class="clear"></div>
217
+ <p class="howto"><?php _e('Repeating field options', 'formidable') ?></p>
218
+ <ul class="frm_code_list">
219
+ <li class="frm_col_one">
220
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr('foreach '. $repeat_field .'][/foreach') ?>"><?php _e('For Each', 'formidable')?></a>
221
+ </li>
222
+ </ul>
223
+ <?php
224
+ }
225
+
226
+ if ( isset($dfe) ) { ?>
227
+
228
+ <div class="clear"></div>
229
+ <p class="howto"><?php _e('Dynamic field options', 'formidable') ?></p>
230
+ <ul class="frm_code_list">
231
+ <li class="frm_col_one">
232
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr($dfe .' show="created-at"') ?>"><?php _e('Creation Date', 'formidable')?></a>
233
+ </li>
234
+ <?php if ( isset($ldfe) ) { ?>
235
+ <li class="frm_col_two">
236
+ <a href="javascript:void(0)" class="frmbutton button frm_insert_code" data-code="<?php echo esc_attr($dfe .' show="'. $ldfe .'"') ?>"><?php _e('Field From Entry', 'formidable')?></a>
237
+ </li>
238
+ <?php } ?>
239
+ </ul>
240
+ <?php } ?>
241
+
242
+ </div>
243
+
244
+ <?php
245
+ if ( $settings_tab ) {
246
+ include(FrmAppHelper::plugin_path() .'/classes/views/frm-forms/mb_html_tab.php');
247
+ }
248
+ ?>
249
+ </div>
250
+
251
+ <?php if (defined('DOING_AJAX')){ ?>
252
+ <script type="text/javascript">
253
+ jQuery(document).ready(function($){
254
+ jQuery('.categorydiv .category-tabs a').click(function(){
255
+ var t = $(this).attr('href');
256
+ $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
257
+ $(t).show().siblings('.tabs-panel').hide();
258
+ return false;
259
+ });
260
+ });
261
+ </script>
262
+ <?php } ?>
classes/views/shared/nav.php DELETED
@@ -1 +0,0 @@
1
- <?php _deprecated_file( basename(__FILE__), '1.06.07', null, __( 'This file no longer needs to be included.' ) ); ?>
 
classes/views/shared/update_message.php CHANGED
@@ -1,4 +1,4 @@
1
- <div class="frm_update_msg">
2
  This plugin version does not give you access to <?php echo $features ?>.<br/>
3
  <a href="http://formidablepro.com/pricing/" target="_blank">Compare</a> our plans or enter your license number <a href="<?php echo admin_url('admin.php?page=formidable-settings') ?>">here</a>
4
  </div>
1
+ <div class="frm_update_msg <?php echo $class ?>">
2
  This plugin version does not give you access to <?php echo $features ?>.<br/>
3
  <a href="http://formidablepro.com/pricing/" target="_blank">Compare</a> our plans or enter your license number <a href="<?php echo admin_url('admin.php?page=formidable-settings') ?>">here</a>
4
  </div>
classes/views/styles/_buttons.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p style="margin-top:0;">
2
+ <label for="frm_submit_style"><input type="checkbox" name="<?php echo $frm_style->get_field_name('submit_style') ?>" id="frm_submit_style" <?php echo $style->post_content['submit_style'] ? 'checked="checked"': ''; ?> value="1" /> <?php _e('Disable submit button styling', 'formidable'); ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e('Note: If disabled, you may not see the change take effect until you make 2 more styling changes or click "Update Options".', 'formidable') ?>" ></span></label>
3
+ </p>
4
+
5
+ <div class="posttypediv">
6
+ <ul class="posttype-tabs add-menu-item-tabs">
7
+ <li <?php echo ( 'default' == $current_tab ? ' class="tabs"' : '' ); ?>>
8
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=default#tabs-panel-button-default') ?>" class="nav-tab-link" data-type="tabs-panel-button-default" ><?php _e('Default', 'formidable') ?></a>
9
+ </li>
10
+ <li <?php echo ( 'button-hover' == $current_tab ? ' class="tabs"' : '' ); ?>>
11
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=button-hover#page-button-hover') ?>" class="nav-tab-link" data-type="tabs-panel-button-hover" ><?php _e('Hover', 'formidable') ?></a>
12
+ </li>
13
+ <li <?php echo ( 'button-click' == $current_tab ? ' class="tabs"' : '' ); ?>>
14
+ <a href="?page=formidable-styles&page-tab=button-click#tabs-panel-button-click" class="nav-tab-link" data-type="tabs-panel-button-click"><?php _e('Click', 'formidable') ?></a>
15
+ </li>
16
+ </ul><!-- .posttype-tabs -->
17
+
18
+ <div id="tabs-panel-button-default" class="tabs-panel <?php
19
+ echo ( 'default' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
20
+ ?>">
21
+ <div class="field-group field-group-border clearfix">
22
+ <label><?php _e('Size', 'formidable') ?></label>
23
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_font_size') ?>" id="frm_submit_font_size" value="<?php echo esc_attr($style->post_content['submit_font_size']) ?>" size="3" />
24
+ </div>
25
+
26
+ <div class="field-group clearfix">
27
+ <label><?php _e('Width', 'formidable') ?></label>
28
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_width') ?>" id="frm_submit_width" value="<?php echo esc_attr($style->post_content['submit_width']) ?>" size="5" />
29
+ </div>
30
+
31
+ <div class="field-group clearfix">
32
+ <label><?php _e('Height', 'formidable') ?></label>
33
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_height') ?>" id="frm_submit_height" value="<?php echo esc_attr($style->post_content['submit_height']) ?>" size="5" />
34
+ </div>
35
+
36
+ <div class="field-group clearfix">
37
+ <label><?php _e('Weight', 'formidable') ?></label>
38
+ <select name="<?php echo $frm_style->get_field_name('submit_weight') ?>" id="frm_submit_weight">
39
+ <option value="normal" <?php selected($style->post_content['submit_weight'], 'normal') ?>><?php _e('normal', 'formidable') ?></option>
40
+ <option value="bold" <?php selected($style->post_content['submit_weight'], 'bold') ?>><?php _e('bold', 'formidable') ?></option>
41
+ </select>
42
+ </div>
43
+
44
+ <div class="field-group clearfix">
45
+ <label><?php _e('Corners', 'formidable') ?></label>
46
+ <input type="text" value="<?php echo esc_attr($style->post_content['submit_border_radius']) ?>" name="<?php echo $frm_style->get_field_name('submit_border_radius') ?>" id="frm_submit_border_radius" size="4"/>
47
+ </div>
48
+
49
+ <div class="field-group field-group-border clearfix">
50
+ <label><?php _e('BG Color', 'formidable') ?></label>
51
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_bg_color') ?>" id="frm_submit_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_bg_color']) ?>" />
52
+ </div>
53
+
54
+ <div class="field-group clearfix">
55
+ <label><?php _e('Text', 'formidable') ?></label>
56
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_text_color') ?>" id="frm_submit_text_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_text_color']) ?>" />
57
+ </div>
58
+
59
+ <div class="field-group field-group-border clearfix">
60
+ <label><?php _e('Border', 'formidable') ?></label>
61
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_border_color') ?>" id="frm_submit_border_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_border_color']) ?>" />
62
+ </div>
63
+
64
+ <div class="field-group clearfix">
65
+ <label><?php _e('Thickness', 'formidable') ?></label>
66
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_border_width') ?>" id="frm_submit_border_width" value="<?php echo esc_attr($style->post_content['submit_border_width']) ?>" size="4" />
67
+ </div>
68
+
69
+ <div class="field-group clearfix">
70
+ <label><?php _e('Shadow', 'formidable') ?></label>
71
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_shadow_color') ?>" id="frm_submit_shadow_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_shadow_color']) ?>" />
72
+ </div>
73
+
74
+ <div class="clear"></div>
75
+ <div class="field-group field-group-border frm-full">
76
+ <label><?php _e('BG Image', 'formidable') ?></label>
77
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_bg_img') ?>" id="frm_submit_bg_img" value="<?php echo esc_attr($style->post_content['submit_bg_img']) ?>" />
78
+ </div>
79
+
80
+ <div class="field-group field-group-border clearfix">
81
+ <label><?php _e('Margin', 'formidable') ?></label>
82
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_margin') ?>" id="frm_submit_margin" value="<?php echo esc_attr($style->post_content['submit_margin']) ?>" size="6" />
83
+ </div>
84
+
85
+ <div class="field-group clearfix">
86
+ <label><?php _e('Padding', 'formidable') ?></label>
87
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_padding') ?>" id="frm_submit_padding" value="<?php echo esc_attr($style->post_content['submit_padding']) ?>" size="6" />
88
+ </div>
89
+ <div class="clear"></div>
90
+ </div><!-- /.tabs-panel -->
91
+
92
+ <div id="tabs-panel-button-hover" class="tabs-panel <?php
93
+ echo ( 'button-hover' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
94
+ ?>">
95
+ <div class="field-group clearfix">
96
+ <label><?php _e('BG Color', 'formidable') ?></label>
97
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_hover_bg_color') ?>" id="frm_submit_hover_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_hover_bg_color']) ?>" />
98
+ </div>
99
+
100
+ <div class="field-group clearfix">
101
+ <label><?php _e('Text', 'formidable') ?></label>
102
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_hover_color') ?>" id="frm_submit_hover_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_hover_color']) ?>" />
103
+ </div>
104
+
105
+ <div class="field-group clearfix">
106
+ <label><?php _e('Border', 'formidable') ?></label>
107
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_hover_border_color') ?>" id="frm_submit_hover_border_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_hover_border_color']) ?>" />
108
+ </div>
109
+
110
+ <div class="clear"></div>
111
+ </div><!-- /.tabs-panel -->
112
+
113
+ <div id="tabs-panel-button-click" class="tabs-panel <?php
114
+ echo ( 'button-click' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
115
+ ?>">
116
+ <div class="field-group clearfix">
117
+ <label><?php _e('BG Color', 'formidable') ?></label>
118
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_active_bg_color') ?>" id="frm_submit_active_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_active_bg_color']) ?>" />
119
+ </div>
120
+
121
+ <div class="field-group clearfix">
122
+ <label><?php _e('Text', 'formidable') ?></label>
123
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_active_color') ?>" id="frm_submit_active_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_active_color']) ?>" />
124
+ </div>
125
+
126
+ <div class="field-group clearfix">
127
+ <label><?php _e('Border', 'formidable') ?></label>
128
+ <input type="text" name="<?php echo $frm_style->get_field_name('submit_active_border_color') ?>" id="frm_submit_active_border_color" class="hex" value="<?php echo esc_attr($style->post_content['submit_active_border_color']) ?>" />
129
+ </div>
130
+
131
+ <div class="clear"></div>
132
+ </div><!-- /.tabs-panel -->
133
+
134
+ </div>
classes/views/styles/_check-box-radio-fields.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="field-group clearfix frm-half frm-first-row">
2
+ <label><?php _e('Radio', 'formidable') ?></label>
3
+ <select name="<?php echo $frm_style->get_field_name('radio_align') ?>" id="frm_radio_align">
4
+ <?php foreach (array('block' => 'Multiple Rows', 'inline' => 'Single Row') as $pos => $pos_label){ ?>
5
+ <option value="<?php echo $pos ?>" <?php selected($style->post_content['radio_align'], $pos) ?>><?php echo $pos_label ?></option>
6
+ <?php }?>
7
+ </select>
8
+ </div>
9
+
10
+ <div class="field-group clearfix frm-half frm-first-row">
11
+ <label><?php _e('Check Box', 'formidable') ?></label>
12
+ <select name="<?php echo $frm_style->get_field_name('check_align') ?>" id="frm_check_align">
13
+ <?php foreach (array('block' => 'Multiple Rows', 'inline' => 'Single Row') as $pos => $pos_label){ ?>
14
+ <option value="<?php echo $pos ?>" <?php selected($style->post_content['check_align'], $pos) ?>><?php echo $pos_label ?></option>
15
+ <?php }?>
16
+ </select>
17
+ </div>
18
+
19
+ <div class="field-group field-group-background clearfix">
20
+ <label><?php _e('Color', 'formidable') ?></label>
21
+ <input type="text" name="<?php echo $frm_style->get_field_name('check_label_color') ?>" id="frm_check_label_color" class="hex" value="<?php echo esc_attr($style->post_content['check_label_color']) ?>" />
22
+ </div>
23
+ <div class="field-group clearfix">
24
+ <label><?php _e('Weight', 'formidable') ?></label>
25
+ <select name="<?php echo $frm_style->get_field_name('check_weight') ?>" id="frm_check_weight">
26
+ <option value="normal" <?php selected($style->post_content['check_weight'], 'normal') ?>><?php _e('normal', 'formidable') ?></option>
27
+ <option value="bold" <?php selected($style->post_content['check_weight'], 'bold') ?>><?php _e('bold', 'formidable') ?></option>
28
+ </select>
29
+ </div>
30
+ <div class="field-group clearfix">
31
+ <label><?php _e('Size', 'formidable') ?></label>
32
+ <input type="text" name="<?php echo $frm_style->get_field_name('check_font_size') ?>" id="frm_check_font_size" value="<?php echo esc_attr($style->post_content['check_font_size']) ?>" size="3" />
33
+ </div>
classes/views/styles/_date-fields.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $jquery_themes = FrmStylesHelper::jquery_themes();
3
+
4
+ $alt_img_name = array(
5
+ 'ui-lightness' => 'ui_light',
6
+ 'ui-darkness' => 'ui_dark',
7
+ 'start' => 'start_menu',
8
+ 'redmond' => 'windoze',
9
+ 'vader' => 'black_matte',
10
+ 'mint-choc' => 'mint_choco',
11
+ );
12
+ $theme_names = array_keys($jquery_themes);
13
+ $theme_names = array_combine($theme_names, $theme_names);
14
+
15
+ foreach ( $theme_names as $k => $v ) {
16
+ $theme_names[$k] = str_replace('-', '_', $v);
17
+ unset($k, $v);
18
+ }
19
+
20
+ $alt_img_name = array_merge($theme_names, $alt_img_name);
21
+ unset($theme_names);
22
+
23
+ ?>
24
+
25
+ <div class="field-group clearfix frm-half frm-first-row">
26
+ <label><?php _e('Theme', 'formidable') ?></label>
27
+ <select name="<?php echo $frm_style->get_field_name('theme_selector') ?>">
28
+ <?php foreach ( $jquery_themes as $theme_name => $theme_title ) { ?>
29
+ <option value="<?php echo $theme_name ?>" id="90_<?php echo $alt_img_name[$theme_name]; ?>" <?php selected($theme_title, $style->post_content['theme_name']) ?>><?php echo $theme_title ?></option>
30
+ <?php } ?>
31
+ <option value="-1" <?php selected('-1', $style->post_content['theme_name']) ?>>&mdash; <?php _e('None', 'formidable') ?> &mdash;</option>
32
+ </select>
33
+ </div>
34
+
35
+ <div class="field-group clearfix frm-half frm-first-row" style="text-align:right;">
36
+ <img id="frm_show_cal" src="//jqueryui.com/resources/images/themeGallery/theme_90_<?php echo $alt_img_name[$style->post_content['theme_css']] ?>.png" alt="" style="width:90px;height:80px;margin-right:6px;" />
37
+ <input type="hidden" value="<?php echo esc_attr($style->post_content['theme_css']) ?>" id="frm_theme_css" name="<?php echo $frm_style->get_field_name('theme_css') ?>" />
38
+ <input type="hidden" value="<?php echo esc_attr($style->post_content['theme_name']) ?>" id="frm_theme_name" name="<?php echo $frm_style->get_field_name('theme_name') ?>" />
39
+ </div>
40
+ <div class="clear"></div>
classes/views/styles/_field-colors.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="posttypediv">
2
+ <ul class="posttype-tabs add-menu-item-tabs">
3
+ <li <?php echo ( 'default' == $current_tab ? ' class="tabs"' : '' ); ?>>
4
+ <a href="?page=formidable-styles&page-tab=default#tabs-panel-default-color" class="nav-tab-link" data-type="tabs-panel-default-color"><?php _e('Default', 'formidable') ?></a>
5
+ </li>
6
+ <li <?php echo ( 'active-color' == $current_tab ? ' class="tabs"' : '' ); ?>>
7
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=active-color#page-active-color') ?>" class="nav-tab-link" data-type="tabs-panel-active-color"><?php _e('Active', 'formidable') ?></a>
8
+ </li>
9
+ <li <?php echo ( 'active-error' == $current_tab ? ' class="tabs"' : '' ); ?>>
10
+ <a href="?page=formidable-styles&page-tab=active-error#tabs-panel-active-error" class="nav-tab-link" data-type="tabs-panel-active-error"><?php _e('Error', 'formidable') ?></a>
11
+ </li>
12
+ <li <?php echo ( 'read-only' == $current_tab ? ' class="tabs"' : '' ); ?>>
13
+ <a href="?page=formidable-styles&page-tab=read-only#tabs-panel-read-only" class="nav-tab-link" data-type="tabs-panel-read-only"><?php _e('Read Only', 'formidable') ?></a>
14
+ </li>
15
+ </ul><!-- .posttype-tabs -->
16
+
17
+ <div id="tabs-panel-default-color" class="tabs-panel <?php
18
+ echo ( 'default' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
19
+ ?>">
20
+ <div class="field-group field-group-border clearfix">
21
+ <label class="background"><?php _e('BG color', 'formidable') ?></label>
22
+ <input type="text" name="<?php echo $frm_style->get_field_name('bg_color') ?>" id="frm_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['bg_color']) ?>" />
23
+ </div>
24
+ <div class="field-group clearfix">
25
+ <label><?php _e('Text', 'formidable') ?></label>
26
+ <input type="text" name="<?php echo $frm_style->get_field_name('text_color') ?>" id="frm_text_color" class="hex" value="<?php echo esc_attr($style->post_content['text_color']) ?>" />
27
+ </div>
28
+
29
+ <div class="field-group field-group-border clearfix">
30
+ <label><?php _e('Border', 'formidable') ?></label>
31
+ <input type="text" name="<?php echo $frm_style->get_field_name('border_color') ?>" id="frm_border_color" class="hex" value="<?php echo esc_attr($style->post_content['border_color']) ?>" />
32
+ </div>
33
+ <div class="field-group clearfix">
34
+ <label><?php _e('Thickness', 'formidable') ?></label>
35
+ <input type="text" name="<?php echo $frm_style->get_field_name('field_border_width') ?>" id="frm_field_border_width" value="<?php echo esc_attr($style->post_content['field_border_width']) ?>" size="4" />
36
+ </div>
37
+ <div class="field-group clearfix">
38
+ <label><?php _e('Style', 'formidable')?></label>
39
+ <select name="<?php echo $frm_style->get_field_name('field_border_style') ?>" id="frm_field_border_style">
40
+ <option value="solid" <?php selected($style->post_content['field_border_style'], 'solid') ?>><?php _e('solid', 'formidable') ?></option>
41
+ <option value="dotted" <?php selected($style->post_content['field_border_style'], 'dotted') ?>><?php _e('dotted', 'formidable') ?></option>
42
+ <option value="dashed" <?php selected($style->post_content['field_border_style'], 'dashed') ?>><?php _e('dashed', 'formidable') ?></option>
43
+ <option value="double" <?php selected($style->post_content['field_border_style'], 'double') ?>><?php _e('double', 'formidable') ?></option>
44
+ </select>
45
+ </div>
46
+ <div class="clear"></div>
47
+ </div><!-- /.tabs-panel -->
48
+
49
+ <div id="tabs-panel-active-color" class="tabs-panel <?php
50
+ echo ( 'active-color' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
51
+ ?>">
52
+ <div class="field-group field-group-border clearfix">
53
+ <label class="background"><?php _e('BG color', 'formidable') ?></label>
54
+ <input type="text" name="<?php echo $frm_style->get_field_name('bg_color_active') ?>" id="frm_bg_color_active" class="hex" value="<?php echo esc_attr($style->post_content['bg_color_active']) ?>" />
55
+ </div>
56
+ <div class="field-group clearfix">
57
+ <label><?php _e('Border', 'formidable') ?></label>
58
+ <input type="text" name="<?php echo $frm_style->get_field_name('border_color_active') ?>" id="frm_border_color_active" class="hex" value="<?php echo esc_attr($style->post_content['border_color_active']) ?>" />
59
+ </div>
60
+ <div class="clear"></div>
61
+ </div><!-- /.tabs-panel -->
62
+
63
+ <div id="tabs-panel-active-error" class="tabs-panel <?php
64
+ echo ( 'active-error' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
65
+ ?>">
66
+ <div class="field-group field-group-border clearfix">
67
+ <label class="background"><?php _e('BG color', 'formidable') ?></label>
68
+ <input type="text" name="<?php echo $frm_style->get_field_name('bg_color_error') ?>" id="frm_bg_color_error" class="hex" value="<?php echo esc_attr($style->post_content['bg_color_error']) ?>" />
69
+ </div>
70
+ <div class="field-group clearfix">
71
+ <label><?php _e('Text', 'formidable') ?></label>
72
+ <input type="text" name="<?php echo $frm_style->get_field_name('text_color_error') ?>" id="frm_text_color_error" class="hex" value="<?php echo esc_attr($style->post_content['text_color_error']) ?>" />
73
+ </div>
74
+
75
+ <div class="field-group field-group-border clearfix">
76
+ <label><?php _e('Border', 'formidable') ?></label>
77
+ <input type="text" name="<?php echo $frm_style->get_field_name('border_color_error') ?>" id="frm_border_color_error" class="hex" value="<?php echo esc_attr($style->post_content['border_color_error']) ?>" />
78
+ </div>
79
+ <div class="field-group clearfix">
80
+ <label><?php _e('Thickness', 'formidable') ?></label>
81
+ <input type="text" name="<?php echo $frm_style->get_field_name('border_width_error') ?>" id="frm_border_width_error" value="<?php echo esc_attr($style->post_content['border_width_error']) ?>" size="4" />
82
+ </div>
83
+ <div class="field-group clearfix">
84
+ <label><?php _e('Style', 'formidable') ?></label>
85
+ <select name="<?php echo $frm_style->get_field_name('border_style_error') ?>" id="frm_border_style_error">
86
+ <option value="solid" <?php selected($style->post_content['border_style_error'], 'solid') ?>><?php _e('solid', 'formidable') ?></option>
87
+ <option value="dotted" <?php selected($style->post_content['border_style_error'], 'dotted') ?>><?php _e('dotted', 'formidable') ?></option>
88
+ <option value="dashed" <?php selected($style->post_content['border_style_error'], 'dashed') ?>><?php _e('dashed', 'formidable') ?></option>
89
+ <option value="double" <?php selected($style->post_content['border_style_error'], 'double') ?>><?php _e('double', 'formidable') ?></option>
90
+ </select>
91
+ </div>
92
+
93
+ <div class="clear"></div>
94
+ </div><!-- /.tabs-panel -->
95
+
96
+ <div id="tabs-panel-read-only" class="tabs-panel <?php
97
+ echo ( 'read-only' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
98
+ ?>">
99
+ <div class="field-group field-group-border clearfix">
100
+ <label class="background"><?php _e('BG color', 'formidable') ?></label>
101
+ <input type="text" name="<?php echo $frm_style->get_field_name('bg_color_disabled') ?>" id="frm_bg_color_disabled" class="hex" value="<?php echo esc_attr($style->post_content['bg_color_disabled']) ?>" />
102
+ </div>
103
+ <div class="field-group clearfix">
104
+ <label><?php _e('Text', 'formidable') ?></label>
105
+ <input type="text" name="<?php echo $frm_style->get_field_name('text_color_disabled') ?>" id="frm_text_color_disabled" class="hex" value="<?php echo esc_attr($style->post_content['text_color_disabled']) ?>" />
106
+ </div>
107
+
108
+ <div class="field-group clearfix">
109
+ <label><?php _e('Border', 'formidable') ?></label>
110
+ <input type="text" name="<?php echo $frm_style->get_field_name('border_color_disabled') ?>" id="frm_border_color_disabled" class="hex" value="<?php echo esc_attr($style->post_content['border_color_disabled']) ?>" />
111
+ </div>
112
+ <div class="clear"></div>
113
+ </div><!-- /.tabs-panel -->
114
+ </div>
classes/views/styles/_field-description.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="field-group field-group-background clearfix frm-first-row">
2
+ <label><?php _e('Color', 'formidable') ?></label>
3
+ <input type="text" name="<?php echo $frm_style->get_field_name('description_color') ?>" id="frm_description_color" class="hex" value="<?php echo esc_attr($style->post_content['description_color']) ?>" />
4
+ </div>
5
+ <div class="field-group clearfix frm-first-row">
6
+ <label><?php _e('Weight', 'formidable') ?></label>
7
+ <select name="<?php echo $frm_style->get_field_name('description_weight') ?>" id="frm_description_weight">
8
+ <option value="normal" <?php selected($style->post_content['description_weight'], 'normal') ?>><?php _e('normal', 'formidable') ?></option>
9
+ <option value="bold" <?php selected($style->post_content['description_weight'], 'bold') ?>><?php _e('bold', 'formidable') ?></option>
10
+ </select>
11
+ </div>
12
+ <div class="field-group clearfix frm-first-row">
13
+ <label><?php _e('Style', 'formidable') ?></label>
14
+ <select name="<?php echo $frm_style->get_field_name('description_style') ?>" id="frm_description_style">
15
+ <option value="normal" <?php selected($style->post_content['description_style'], 'normal') ?>><?php _e('normal', 'formidable') ?></option>
16
+ <option value="italic" <?php selected($style->post_content['description_style'], 'italic') ?>><?php _e('italic', 'formidable') ?></option>
17
+ </select>
18
+ </div>
19
+ <div class="field-group clearfix">
20
+ <label><?php _e('Size', 'formidable') ?></label>
21
+ <input type="text" name="<?php echo $frm_style->get_field_name('description_font_size') ?>" id="frm_description_font_size" value="<?php echo esc_attr($style->post_content['description_font_size']) ?>" size="3" />
22
+ </div>
23
+
24
+ <div class="field-group clearfix">
25
+ <label><?php _e('Align', 'formidable') ?></label>
26
+ <select name="<?php echo $frm_style->get_field_name('description_align') ?>" id="frm_description_align">
27
+ <option value="left" <?php selected($style->post_content['description_align'], 'left') ?>><?php _e('left', 'formidable') ?></option>
28
+ <option value="right" <?php selected($style->post_content['description_align'], 'right') ?>><?php _e('right', 'formidable') ?></option>
29
+ </select>
30
+ </div>
31
+ <div class="clear"></div>
classes/views/styles/_field-labels.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="field-group field-group-background clearfix frm-first-row">
2
+ <label><?php _e('Color', 'formidable') ?></label>
3
+ <input type="text" name="<?php echo $frm_style->get_field_name('label_color') ?>" id="frm_label_color" class="hex" value="<?php echo esc_attr($style->post_content['label_color']) ?>" />
4
+ </div>
5
+ <div class="field-group clearfix frm-first-row">
6
+ <label><?php _e('Weight', 'formidable') ?></label>
7
+ <select name="<?php echo $frm_style->get_field_name('weight') ?>" id="frm_weight">
8
+ <option value="normal" <?php selected($style->post_content['weight'], 'normal') ?>>normal</option>
9
+ <option value="bold" <?php selected($style->post_content['weight'], 'bold') ?>>bold</option>
10
+ </select>
11
+ </div>
12
+ <div class="field-group clearfix frm-first-row">
13
+ <label><?php _e('Size', 'formidable') ?></label>
14
+ <input type="text" name="<?php echo $frm_style->get_field_name('font_size') ?>" id="frm_font_size" value="<?php echo esc_attr($style->post_content['font_size']) ?>" size="3" />
15
+ </div>
16
+
17
+ <div class="field-group clearfix clear">
18
+ <label><?php _e('Position', 'formidable') ?></label>
19
+ <select name="<?php echo $frm_style->get_field_name('position') ?>" id="frm_position">
20
+ <?php foreach (array('none' => 'top', 'left' => 'left', 'right' => 'right') as $pos => $pos_label){ ?>
21
+ <option value="<?php echo $pos ?>" <?php selected($style->post_content['position'], $pos) ?>><?php echo $pos_label ?></option>
22
+ <?php }?>
23
+ </select>
24
+ </div>
25
+
26
+ <div class="field-group clearfix">
27
+ <label><?php _e('Align', 'formidable') ?></label>
28
+ <select name="<?php echo $frm_style->get_field_name('align') ?>" id="frm_align">
29
+ <option value="left" <?php selected($style->post_content['align'], 'left') ?>><?php _e('left', 'formidable') ?></option>
30
+ <option value="right" <?php selected($style->post_content['align'], 'right') ?>><?php _e('right', 'formidable') ?></option>
31
+ </select>
32
+ </div>
33
+
34
+ <div class="field-group clearfix">
35
+ <label><?php _e('Width', 'formidable') ?></label>
36
+ <input type="text" name="<?php echo $frm_style->get_field_name('width') ?>" id="frm_width" value="<?php echo esc_attr($style->post_content['width']) ?>" />
37
+ </div>
38
+
39
+ <div class="field-group clearfix clear">
40
+ <label><?php _e('Padding', 'formidable') ?></label>
41
+ <input type="text" name="<?php echo $frm_style->get_field_name('label_padding') ?>" id="frm_label_padding" value="<?php echo esc_attr($style->post_content['label_padding']) ?>" />
42
+ </div>
43
+
44
+ <div class="clear"></div>
45
+ <h3><?php _e('Required Indicator', 'formidable') ?></h3>
46
+ <div class="field-group field-group-border clearfix after-h3">
47
+ <label class="background"><?php _e('Color', 'formidable') ?></label>
48
+ <input type="text" name="<?php echo $frm_style->get_field_name('required_color') ?>" id="frm_required_color" class="hex" value="<?php echo esc_attr($style->post_content['required_color']) ?>" />
49
+ </div>
50
+ <div class="field-group clearfix after-h3">
51
+ <label><?php _e('Weight', 'formidable') ?></label>
52
+ <select name="<?php echo $frm_style->get_field_name('required_weight') ?>" id="frm_required_weight">
53
+ <option value="normal" <?php selected($style->post_content['required_weight'], 'normal') ?>><?php _e('normal', 'formidable') ?></option>
54
+ <option value="bold" <?php selected($style->post_content['required_weight'], 'bold') ?>><?php _e('bold', 'formidable') ?></option>
55
+ </select>
56
+ </div>
57
+ <div class="clear"></div>
classes/views/styles/_field-sizes.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="field-group clearfix frm-first-row">
2
+ <label><?php _e('Size', 'formidable') ?></label>
3
+ <input type="text" name="<?php echo $frm_style->get_field_name('field_font_size') ?>" id="frm_field_font_size" value="<?php echo esc_attr($style->post_content['field_font_size']) ?>" />
4
+ </div>
5
+
6
+ <div class="field-group clearfix frm-first-row">
7
+ <label><?php _e('Height', 'formidable') ?></label>
8
+ <input type="text" name="<?php echo $frm_style->get_field_name('field_height') ?>" id="frm_field_height" value="<?php echo esc_attr($style->post_content['field_height']) ?>" />
9
+ </div>
10
+
11
+ <div class="field-group clearfix frm-first-row">
12
+ <label><?php _e('Width', 'formidable') ?></label>
13
+ <input type="text" name="<?php echo $frm_style->get_field_name('field_width') ?>" id="frm_field_width" value="<?php echo esc_attr($style->post_content['field_width']) ?>" />
14
+ </div>
15
+
16
+ <div class="clear"></div>
17
+ <p style="margin-bottom:0;">
18
+ <label><input type="checkbox" name="<?php echo $frm_style->get_field_name('auto_width') ?>" id="frm_auto_width" value="1" <?php checked($style->post_content['auto_width'], 1) ?> />
19
+ <?php _e('Automatic Width for drop-down fields', 'formidable') ?></label>
20
+ </p>
21
+
22
+ <div class="field-group clearfix">
23
+ <label><?php _e('Padding', 'formidable') ?></label>
24
+ <input type="text" name="<?php echo $frm_style->get_field_name('field_pad') ?>" id="frm_field_pad" value="<?php echo esc_attr($style->post_content['field_pad']) ?>" />
25
+ </div>
26
+
27
+ <div class="field-group clearfix">
28
+ <label><?php _e('Margin', 'formidable') ?></label>
29
+ <input type="text" name="<?php echo $frm_style->get_field_name('field_margin') ?>" id="frm_field_margin" value="<?php echo esc_attr($style->post_content['field_margin']) ?>" />
30
+ </div>
31
+
32
+ <div class="field-group clearfix">
33
+ <label><?php _e('Corners', 'formidable') ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e('Formidable uses CSS3 border-radius for corner rounding, which is not currently supported by Internet Explorer.', 'formidable') ?>" ></span></label>
34
+ <input type="text" value="<?php echo esc_attr($style->post_content['border_radius']) ?>" name="<?php echo $frm_style->get_field_name('border_radius') ?>" id="frm_border_radius" />
35
+ </div>
classes/views/styles/_form-messages.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="posttypediv">
2
+ <ul class="posttype-tabs add-menu-item-tabs">
3
+ <li <?php echo ( 'default' == $current_tab ? ' class="tabs"' : '' ); ?>>
4
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=default#tabs-panel-success-msg') ?>" class="nav-tab-link" data-type="tabs-panel-success-msg" ><?php _e('Success', 'formidable') ?></a>
5
+ </li>
6
+ <li <?php echo ( 'error-msg' == $current_tab ? ' class="tabs"' : '' ); ?>>
7
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=error-msge#page-error-msg') ?>" class="nav-tab-link" data-type="tabs-panel-error-msg" ><?php _e('Error', 'formidable') ?></a>
8
+ </li>
9
+ </ul><!-- .posttype-tabs -->
10
+
11
+ <div id="tabs-panel-success-msg" class="tabs-panel <?php
12
+ echo ( 'default' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
13
+ ?>">
14
+ <div class="field-group field-group-border clearfix">
15
+ <label><?php _e('BG Color', 'formidable') ?></label>
16
+ <div class="hasPicker">
17
+ <input name="<?php echo $frm_style->get_field_name('success_bg_color') ?>" id="frm_success_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['success_bg_color']) ?>" type="text" /></div>
18
+ </div>
19
+ <div class="field-group clearfix">
20
+ <label><?php _e('Border', 'formidable') ?></label>
21
+ <input type="text" name="<?php echo $frm_style->get_field_name('success_border_color') ?>" id="frm_success_border_color" class="hex" value="<?php echo esc_attr($style->post_content['success_border_color']) ?>" />
22
+ </div>
23
+ <div class="field-group clearfix">
24
+ <label><?php _e('Text', 'formidable') ?></label>
25
+ <input name="<?php echo $frm_style->get_field_name('success_text_color') ?>" id="frm_success_text_color" class="hex" value="<?php echo esc_attr($style->post_content['success_text_color']) ?>" type="text" />
26
+ </div>
27
+ <div class="field-group clearfix">
28
+ <label><?php _e('Size', 'formidable') ?></label>
29
+ <input type="text" name="<?php echo $frm_style->get_field_name('success_font_size') ?>" id="frm_success_font_size" value="<?php echo esc_attr($style->post_content['success_font_size']) ?>" size="3" />
30
+ </div>
31
+ <div class="clear"></div>
32
+ </div><!-- /.tabs-panel -->
33
+
34
+ <div id="tabs-panel-error-msg" class="tabs-panel <?php
35
+ echo ( 'error-msg' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
36
+ ?>">
37
+ <div class="field-group field-group-border clearfix">
38
+ <label><?php _e('BG Color', 'formidable') ?></label>
39
+ <div class="hasPicker">
40
+ <input type="text" name="<?php echo $frm_style->get_field_name('error_bg') ?>" id="frm_error_bg" class="hex" value="<?php echo esc_attr($style->post_content['error_bg']) ?>" /></div>
41
+ </div>
42
+ <div class="field-group clearfix">
43
+ <label><?php _e('Border', 'formidable') ?></label>
44
+ <input type="text" name="<?php echo $frm_style->get_field_name('error_border') ?>" id="frm_error_border" class="hex" value="<?php echo esc_attr($style->post_content['error_border']) ?>" />
45
+ </div>
46
+ <div class="field-group clearfix">
47
+
48
+ <label><?php _e('Text', 'formidable') ?></label>
49
+ <input type="text" name="<?php echo $frm_style->get_field_name('error_text') ?>" id="frm_error_text" class="hex" value="<?php echo esc_attr($style->post_content['error_text']) ?>" />
50
+ </div>
51
+
52
+ <div class="field-group clearfix">
53
+ <label><?php _e('Size', 'formidable') ?></label>
54
+ <input type="text" name="<?php echo $frm_style->get_field_name('error_font_size') ?>" id="frm_error_font_size" value="<?php echo esc_attr($style->post_content['error_font_size']) ?>" size="3" />
55
+ </div>
56
+ <div class="clear"></div>
57
+ </div><!-- /.tabs-panel -->
58
+
59
+ </div>
classes/views/styles/_general.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="field-group clearfix frm-first-row">
2
+ <label><?php _e('Alignment', 'formidable') ?></label>
3
+ <select name="<?php echo $frm_style->get_field_name('form_align') ?>" id="frm_form_align">
4
+ <option value="left" <?php selected($style->post_content['form_align'], 'left') ?>><?php _e('left', 'formidable') ?></option>
5
+ <option value="right" <?php selected($style->post_content['form_align'], 'right') ?>><?php _e('right', 'formidable') ?></option>
6
+ <option value="center" <?php selected($style->post_content['form_align'], 'center') ?>><?php _e('center', 'formidable') ?></option>
7
+ </select>
8
+ </div>
9
+
10
+ <div class="field-group clearfix frm-first-row">
11
+ <label><?php _e('Max Width', 'formidable') ?></label>
12
+ <input type="text" name="<?php echo $frm_style->get_field_name('form_width') ?>" value="<?php echo esc_attr($style->post_content['form_width']) ?>"/>
13
+ </div>
14
+
15
+ <div class="field-group clearfix frm-first-row">
16
+ <label><?php _e('Background', 'formidable') ?></label>
17
+ <input type="text" name="<?php echo $frm_style->get_field_name('fieldset_bg_color') ?>" id="frm_fieldset_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['fieldset_bg_color']) ?>" size="4" />
18
+ </div>
19
+
20
+ <div class="field-group field-group-border clearfix">
21
+ <label><?php _e('Border', 'formidable') ?></label>
22
+ <input type="text" name="<?php echo $frm_style->get_field_name('fieldset') ?>" id="frm_fieldset" value="<?php echo esc_attr($style->post_content['fieldset']) ?>" size="4" />
23
+ </div>
24
+
25
+ <div class="field-group clearfix">
26
+ <label><?php _e('Color', 'formidable') ?></label>
27
+ <input type="text" name="<?php echo $frm_style->get_field_name('fieldset_color') ?>" id="frm_fieldset_color" class="hex" value="<?php echo esc_attr($style->post_content['fieldset_color']) ?>" />
28
+ </div>
29
+
30
+ <div class="field-group clearfix">
31
+ <label><?php _e('Padding', 'formidable') ?></label>
32
+ <input type="text" name="<?php echo $frm_style->get_field_name('fieldset_padding') ?>" id="frm_fieldset_padding" value="<?php echo esc_attr($style->post_content['fieldset_padding']) ?>" size="4" />
33
+ </div>
34
+
35
+ <div class="field-group clearfix" style="padding-right:0;width:100%;">
36
+ <label><?php _e('Font Family', 'formidable') ?></label>
37
+ <input type="text" name="<?php echo $frm_style->get_field_name('font') ?>" id="frm_font" value="<?php echo esc_attr($style->post_content['font']) ?>" class="frm_full_width" />
38
+ </div>
39
+
40
+ <div class="field-group clearfix frm-half">
41
+ <label><?php _e('Direction', 'formidable') ?></label>
42
+ <select name="<?php echo $frm_style->get_field_name('direction') ?>" id="frm_form_align">
43
+ <option value="ltr" <?php selected($style->post_content['direction'], 'ltr') ?>><?php _e('Left to Right', 'formidable') ?></option>
44
+ <option value="rtl" <?php selected($style->post_content['direction'], 'rtl') ?>><?php _e('Right to Left', 'formidable') ?></option>
45
+ </select>
46
+ </div>
47
+
48
+ <div class="clear"></div>
49
+ <div class="field-group clearfix frm-half">
50
+ <label><?php _e('Title Size', 'formidable') ?></label>
51
+ <input type="text" name="<?php echo $frm_style->get_field_name('title_size') ?>" id="frm_title_size" value="<?php echo esc_attr($style->post_content['title_size']) ?>" />
52
+ </div>
53
+
54
+ <div class="field-group clearfix frm-half">
55
+ <label><?php _e('Color', 'formidable') ?></label>
56
+ <input type="text" name="<?php echo $frm_style->get_field_name('title_color') ?>" id="frm_title_color" class="hex" value="<?php echo esc_attr($style->post_content['title_color']) ?>" />
57
+ </div>
58
+
59
+ <div class="field-group clearfix frm-half">
60
+ <label><?php _e('Description Size', 'formidable') ?></label>
61
+ <input type="text" name="<?php echo $frm_style->get_field_name('form_desc_size') ?>" id="frm_form_desc_size" value="<?php echo esc_attr($style->post_content['form_desc_size']) ?>" />
62
+ </div>
63
+
64
+ <div class="field-group clearfix frm-half">
65
+ <label><?php _e('Color', 'formidable') ?></label>
66
+ <input type="text" name="<?php echo $frm_style->get_field_name('form_desc_color') ?>" id="frm_form_desc_color" class="hex" value="<?php echo esc_attr($style->post_content['form_desc_color']) ?>" />
67
+ </div>
68
+
69
+ <div class="clear"></div>
70
+ <p style="margin-bottom:0;">
71
+ <label><input type="checkbox" name="<?php echo $frm_style->get_field_name('important_style') ?>" id="frm_important_style" value="1" <?php checked($style->post_content['important_style'], 1) ?> />
72
+ <?php _e('Override theme styling', 'formidable') ?> <span class="frm_help frm_icon_font frm_tooltip_icon" title="<?php esc_attr_e('This will add !important to many of the lines in the Formidable styling to make sure it will be used.', 'formidable') ?>" ></span>
73
+ </label>
74
+ </p>
classes/views/styles/_sample_form.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="frm_forms with_frm_style frm_style_<?php echo $style->post_name ?>">
2
+ <div class="frm-show-form">
3
+ <div class="frm_error_style">
4
+ <strong><?php echo __('SAMPLE:', 'formidable') .'</strong> '. $frm_settings->invalid_msg ?>
5
+ </div>
6
+
7
+ <div id="message" class="frm_message"><strong><?php echo __('SAMPLE:', 'formidable') .'</strong> '. $frm_settings->success_msg ?></div>
8
+ <?php $pos_class = 'frm_pos_container '. ($style->post_content['position'] == 'none' ? 'frm_top_container' : 'frm_'. $style->post_content['position'] .'_container'); ?>
9
+
10
+ <h3><?php _e('Form Title', 'formidable') ?></h3>
11
+ <div class="frm_description"><p><?php _e('This is an example form description for styling purposes.', 'formidable') ?></p></div>
12
+
13
+ <div class="frm_form_fields frm_sample_form">
14
+ <fieldset>
15
+ <div class="frm_form_field frm_first_half form-field <?php echo $pos_class ?>">
16
+ <label class="frm_primary_label"><?php _e('Text field', 'formidable') ?> <span class="frm_required">*</span></label>
17
+ <input type="text" value="<?php echo esc_attr( __('This is sample text', 'formidable')) ?>"/>
18
+ <div class="frm_description"><?php _e('A field with a description', 'formidable') ?></div>
19
+ </div>
20
+
21
+ <div class="frm_form_field form-field frm_last_half frm_blank_field <?php echo $pos_class ?>">
22
+ <label class="frm_primary_label"><?php _e('Text field with error', 'formidable') ?> <span class="frm_required">*</span></label>
23
+ <input type="text" value="<?php echo esc_attr( __('This is sample text', 'formidable')) ?>"/>
24
+ <div class="frm_error"><?php echo $frm_settings->blank_msg ?></div>
25
+ </div>
26
+
27
+ <div class="frm_form_field frm_first_half form-field frm_focus_field <?php echo $pos_class ?>">
28
+ <label class="frm_primary_label"><?php _e('Text field in active state', 'formidable') ?> <span class="frm_required">*</span></label>
29
+ <input type="text" value="<?php echo esc_attr( __('Active state will be seen when the field is clicked', 'formidable')) ?>" />
30
+ </div>
31
+
32
+ <div class="frm_form_field frm_last_half form-field <?php echo $pos_class ?>">
33
+ <label class="frm_primary_label"><?php _e('Read-only field', 'formidable') ?></label>
34
+ <input type="text" value="<?php echo esc_attr( __('This field is not editable', 'formidable')) ?>" disabled="disabled" />
35
+ </div>
36
+
37
+ <div class="frm_form_field frm_section_heading form-field frm_first_half">
38
+ <h3 class="frm_pos_top frm_trigger active frm_section_spacing"><i class="frm_icon_font frm_arrow_icon frm_before_collapse"></i> <?php _e('Collapsible Section', 'formidable') ?> <i class="frm_icon_font frm_arrow_icon frm_after_collapse"></i></h3>
39
+ <div class="frm_toggle_container">
40
+
41
+
42
+ <div id="frm_field_1028_container" class="frm_form_field form-field <?php echo $pos_class ?>">
43
+ <label for="field_wq7w5e" class="frm_primary_label"><?php _e('Drop-down Select', 'formidable') ?></label>
44
+
45
+ <select name="item_meta[1028]" id="field_wq7w5e" >
46
+ <option value=""> </option>
47
+ <option value=""><?php _e('Option 1', 'formidable') ?></option>
48
+ </select>
49
+ </div>
50
+
51
+ <div class="frm_form_field form-field frm_first_half <?php echo $pos_class ?>">
52
+ <label class="frm_primary_label"><?php _e('Radio Buttons', 'formidable') ?></label>
53
+ <div class="frm_radio"><input type="radio" /><label><?php _e('Option 1', 'formidable') ?></label></div>
54
+ <div class="frm_radio"><input type="radio" /><label><?php _e('Option 2', 'formidable') ?></label></div>
55
+ </div>
56
+
57
+ <div class="frm_form_field form-field frm_last_half <?php echo $pos_class ?>">
58
+ <label class="frm_primary_label"><?php _e('Check Boxes', 'formidable') ?></label>
59
+ <div class="frm_checkbox"><label><input type="checkbox" /><?php _e('Option 1', 'formidable') ?></label></div>
60
+ <div class="frm_checkbox"><label><input type="checkbox" /><?php _e('Option 2', 'formidable') ?></label></div>
61
+ </div>
62
+ </div>
63
+ </div>
64
+
65
+ <div id="frm_field_304_container" class="frm_form_field frm_section_heading form-field frm_last_half">
66
+ <h3 class="frm_pos_top"><?php _e('Section Heading', 'formidable') ?></h3>
67
+ <div class="frm_description frm_section_spacing"><?php _e('This is an example of a section description', 'formidable') ?></div>
68
+
69
+ <div class="frm_form_field form-field">
70
+ <div id="datepicker_sample" style="margin-bottom:<?php echo $style->post_content['field_margin'] ?>;"></div>
71
+ </div>
72
+
73
+ </div>
74
+
75
+ <div class="frm_form_field frm_section_heading form-field frm_first_half">
76
+ <h3 class="<?php echo $pos_class ?> frm_section_spacing"><?php _e('Repeatable Section', 'formidable') ?></h3>
77
+ <div>
78
+ <div class="frm_repeat_sec">
79
+ <div class="frm_form_field form-field frm_full <?php echo $pos_class ?>">
80
+ <label class="frm_primary_label"><?php _e('Text Area', 'formidable') ?></label>
81
+ <textarea></textarea>
82
+ <div class="frm_description"><?php _e('Another field with a description', 'formidable') ?></div>
83
+ </div>
84
+
85
+ <div class="frm_form_field frm_hidden_container">
86
+ <a href="javascript:void(0)" class="frm_button"><i class="frm_icon_font frm_minus_icon"> </i> <?php _e('Remove', 'formidable') ?></a>
87
+ <a href="javascript:void(0)" class="frm_button"><i class="frm_icon_font frm_plus_icon"> </i> <?php _e('Add', 'formidable') ?></a>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </div>
92
+
93
+ <div class="frm_submit">
94
+ <input type="submit" disabled="disabled" style="opacity:1;" value="<?php echo esc_attr( __('Submit', 'formidable')) ?>" />
95
+ </div>
96
+
97
+ </fieldset>
98
+ </div>
99
+ </div>
100
+ </div>
classes/views/styles/_section-fields.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="posttypediv">
2
+ <ul class="posttype-tabs add-menu-item-tabs">
3
+ <li <?php echo ( 'default' == $current_tab ? ' class="tabs"' : '' ); ?>>
4
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=default#tabs-panel-headings') ?>" class="nav-tab-link" data-type="tabs-panel-headings" ><?php _e('Headings', 'formidable') ?></a>
5
+ </li>
6
+ <li <?php echo ( 'collapse' == $current_tab ? ' class="tabs"' : '' ); ?>>
7
+ <a href="<?php echo esc_url('?page=formidable-styles&page-tab=collapse#page-collapse') ?>" class="nav-tab-link" data-type="tabs-panel-collapse" ><?php _e('Collapsible', 'formidable') ?></a>
8
+ </li>
9
+ <li <?php echo ( 'repeat' == $current_tab ? ' class="tabs"' : '' ); ?>>
10
+ <a href="?page=formidable-styles&page-tab=repeat#tabs-panel-repeat" class="nav-tab-link" data-type="tabs-panel-repeat"><?php _e('Repeatable', 'formidable') ?></a>
11
+ </li>
12
+ </ul><!-- .posttype-tabs -->
13
+
14
+ <div id="tabs-panel-headings" class="tabs-panel <?php
15
+ echo ( 'default' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
16
+ ?>">
17
+ <div class="field-group field-group-background">
18
+ <label><?php _e('Color', 'formidable') ?></label>
19
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_color') ?>" id="frm_section_color" class="hex" value="<?php echo esc_attr($style->post_content['section_color']) ?>" />
20
+ </div>
21
+
22
+ <div class="field-group">
23
+ <label><?php _e('Weight', 'formidable') ?></label>
24
+ <select name="<?php echo $frm_style->get_field_name('section_weight') ?>" id="frm_section_weight">
25
+ <option value="normal" <?php selected($style->post_content['section_weight'], 'normal') ?>><?php _e('normal', 'formidable') ?></option>
26
+ <option value="bold" <?php selected($style->post_content['section_weight'], 'bold') ?>><?php _e('bold', 'formidable') ?></option>
27
+ </select>
28
+ </div>
29
+
30
+ <div class="field-group">
31
+ <label><?php _e('Size', 'formidable') ?></label>
32
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_font_size') ?>" id="frm_section_font_size" value="<?php echo esc_attr($style->post_content['section_font_size']) ?>" />
33
+ </div>
34
+
35
+ <div class="field-group field-group-border frm-half">
36
+ <label><?php _e('Padding', 'formidable') ?></label>
37
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_pad') ?>" id="frm_section_pad" value="<?php echo esc_attr($style->post_content['section_pad']) ?>" />
38
+ </div>
39
+
40
+ <div class="field-group frm-half">
41
+ <label class="background"><?php _e('BG color', 'formidable') ?></label>
42
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_bg_color') ?>" id="frm_section_bg_color" class="hex" value="<?php echo esc_attr($style->post_content['section_bg_color']) ?>" />
43
+ </div>
44
+
45
+ <div class="field-group field-group-border frm-half">
46
+ <label><?php _e('Top Margin', 'formidable') ?></label>
47
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_mar_top') ?>" id="frm_section_mar_top" value="<?php echo esc_attr($style->post_content['section_mar_top']) ?>" />
48
+ </div>
49
+ <div class="field-group frm-half">
50
+ <label><?php _e('Bottom Margin', 'formidable') ?></label>
51
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_mar_bottom') ?>" id="frm_section_mar_bottom" value="<?php echo esc_attr($style->post_content['section_mar_bottom']) ?>" />
52
+ </div>
53
+
54
+ <div class="field-group field-group-border">
55
+ <label><?php _e('Border', 'formidable') ?></label>
56
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_border_color') ?>" id="frm_section_border_color" class="hex" value="<?php echo esc_attr($style->post_content['section_border_color']) ?>" />
57
+ </div>
58
+ <div class="field-group">
59
+ <label><?php _e('Thickness', 'formidable') ?></label>
60
+ <input type="text" name="<?php echo $frm_style->get_field_name('section_border_width') ?>" id="frm_section_border_width" value="<?php echo esc_attr($style->post_content['section_border_width']) ?>" />
61
+ </div>
62
+ <div class="field-group">
63
+ <label><?php _e('Style', 'formidable') ?></label>
64
+ <select name="<?php echo $frm_style->get_field_name('section_border_style') ?>" id="frm_section_border_style">
65
+ <option value="solid" <?php selected($style->post_content['section_border_style'], 'solid') ?>><?php _e('solid', 'formidable') ?></option>
66
+ <option value="dotted" <?php selected($style->post_content['section_border_style'], 'dotted') ?>><?php _e('dotted', 'formidable') ?></option>
67
+ <option value="dashed" <?php selected($style->post_content['section_border_style'], 'dashed') ?>><?php _e('dashed', 'formidable') ?></option>
68
+ <option value="double" <?php selected($style->post_content['section_border_style'], 'double') ?>><?php _e('double', 'formidable') ?></option>
69
+ </select>
70
+ </div>
71
+
72
+ <div class="field-group field-group-border frm-half">
73
+ <label><?php _e('Border Position', 'formidable') ?></label>
74
+ <select name="<?php echo $frm_style->get_field_name('section_border_loc') ?>" id="frm_section_border_loc">
75
+ <option value="-top" <?php selected($style->post_content['section_border_loc'], '-top') ?>><?php _e('top', 'formidable') ?></option>
76
+ <option value="-bottom" <?php selected($style->post_content['section_border_loc'], '-bottom') ?>><?php _e('bottom', 'formidable') ?></option>
77
+ <option value="-left" <?php selected($style->post_content['section_border_loc'], '-left') ?>><?php _e('left', 'formidable') ?></option>
78
+ <option value="-right" <?php selected($style->post_content['section_border_loc'], '-right') ?>><?php _e('right', 'formidable') ?></option>
79
+ <option value="" <?php selected($style->post_content['section_border_loc'], '') ?>><?php _e('all', 'formidable') ?></option>
80
+ </select>
81
+ </div>
82
+ <div class="clear"></div>
83
+ </div><!-- /.tabs-panel -->
84
+
85
+ <div id="tabs-panel-collapse" class="tabs-panel <?php
86
+ echo ( 'collapse' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
87
+ ?>">
88
+ <div class="field-group frm-half">
89
+ <label><?php _e('Icons', 'formidable') ?></label>
90
+ <?php FrmStylesHelper::bs_icon_select($style, $frm_style, 'arrow'); ?>
91
+ </div>
92
+
93
+ <div class="field-group frm-half">
94
+ <label><?php _e('Icon Position', 'formidable') ?></label>
95
+ <select name="<?php echo $frm_style->get_field_name('collapse_pos') ?>" id="frm_collapse_pos">
96
+ <option value="after" <?php selected($style->post_content['collapse_pos'], 'after') ?>><?php _e('After Heading', 'formidable') ?></option>
97
+ <option value="before" <?php selected($style->post_content['collapse_pos'], 'before') ?>><?php _e('Before Heading', 'formidable') ?></option>
98
+ </select>
99
+ </div>
100
+ <div class="clear"></div>
101
+ </div><!-- /.tabs-panel -->
102
+
103
+ <div id="tabs-panel-repeat" class="tabs-panel <?php
104
+ echo ( 'repeat' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
105
+ ?>">
106
+ <div class="field-group frm-half">
107
+ <label><?php _e('Icons', 'formidable') ?></label>
108
+ <?php FrmStylesHelper::bs_icon_select($style, $frm_style, 'minus'); ?>
109
+ </div>
110
+ <div class="clear"></div>
111
+ </div><!-- /.tabs-panel -->
112
+
113
+ </div>
classes/views/styles/custom_css.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="nav-menus-php">
2
+ <div class="wrap">
3
+ <?php FrmStylesHelper::style_menu('custom_css'); ?>
4
+
5
+ <p><?php _e('You can add custom css here or in your theme style.css', 'formidable') ?></p>
6
+
7
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
8
+
9
+ <form method="post">
10
+ <input type="hidden" name="ID" value="<?php echo $style->ID ?>" />
11
+ <input type="hidden" name="<?php echo $frm_style->get_field_name('post_title', ''); ?>" value="<?php echo esc_attr($style->post_title) ?>" />
12
+ <input type="hidden" name="<?php echo $frm_style->get_field_name('menu_order', ''); ?>" value="<?php echo esc_attr($style->menu_order) ?>" />
13
+ <input type="hidden" name="style_name" value="frm_style_<?php echo $style->post_name ?>" />
14
+ <input type="hidden" name="frm_action" value="save_css" />
15
+ <?php wp_nonce_field( 'frm_custom_css_nonce', 'frm_custom_css' ); ?>
16
+
17
+ <textarea name="<?php echo $frm_style->get_field_name('custom_css') ?>" id="custom_css" class="hide-if-js" style="width:100%;"><?php echo FrmAppHelper::esc_textarea($style->post_content['custom_css']) ?></textarea>
18
+
19
+ <?php
20
+ foreach ( $style->post_content as $k => $v ) {
21
+ if ( $k == 'custom_css' ) {
22
+ continue;
23
+ }
24
+ ?>
25
+ <input type="hidden" value="<?php echo esc_attr($v) ?>" name="<?php echo $frm_style->get_field_name($k) ?>" />
26
+ <?php
27
+ } ?>
28
+ <p class="button-controls"><input type="submit" name="nav-menu-locations" id="nav-menu-locations" class="button button-primary left" value="<?php _e('Save Changes', 'formidable') ?>" /></p>
29
+
30
+ </form>
31
+ </div>
32
+ </div>
classes/views/styles/manage.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="nav-menus-php">
2
+ <div class="wrap">
3
+ <?php FrmStylesHelper::style_menu('manage'); ?>
4
+
5
+ <p><?php printf(__('Easily change which template your forms are using by making changes below or %1$screate a new style%2$s.', 'formidable'), '<a href="?page=formidable-styles&frm_action=new_style">', '</a>'); ?></p>
6
+
7
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
8
+
9
+ <div id="menu-locations-wrap">
10
+ <form method="post">
11
+ <input type="hidden" name="frm_action" value="manage_styles"/>
12
+ <table class="widefat fixed" id="menu-locations-table">
13
+ <thead>
14
+ <tr>
15
+ <th scope="col" class="manage-column column-locations"><?php _e('Form Title', 'formidable') ?></th>
16
+ <th scope="col" class="manage-column column-menus"><?php _e('Assigned Style Templates', 'formidable') ?></th>
17
+ </tr>
18
+ </thead>
19
+
20
+ <tbody class="menu-locations">
21
+ <?php
22
+ if ( $forms ) {
23
+ foreach ( $forms as $form ) {
24
+ $this_style = isset($form->options['custom_style']) ? (int) $form->options['custom_style'] : 1;
25
+ if ( 1 == $this_style ) {
26
+ // use the default style
27
+ $this_style = $default_style->ID;
28
+ }
29
+ ?>
30
+ <tr id="menu-locations-row">
31
+ <td class="menu-location-title"><strong><?php echo empty($form->name) ? __('(no title)') : $form->name ?></strong></td>
32
+ <td class="menu-location-menus">
33
+ <input type="hidden" name="prev_style[<?php echo $form->id ?>]" value="<?php echo esc_attr($this_style) ?>" />
34
+ <select name="style[<?php echo $form->id ?>]">
35
+ <?php foreach ( $styles as $s ) { ?>
36
+ <option value="<?php echo $s->ID ?>" <?php selected($s->ID, $this_style) ?>><?php echo $s->post_title . ( empty($s->menu_order) ? '' : ' ('. __('default', 'formidable') .')' ) ?></option>
37
+ <?php } ?>
38
+ <option value="" <?php selected(0, $this_style) ?>><?php _e('Styling disabled', 'formidable') ?></option>
39
+ </select>
40
+
41
+ </td><!-- .menu-location-menus -->
42
+ </tr><!-- #menu-locations-row -->
43
+ <?php
44
+ }
45
+ } else {
46
+ ?>
47
+ <tr>
48
+ <td><?php _e('No Forms Found', 'formidable') ?></td>
49
+ </tr>
50
+ <?php
51
+ }
52
+ ?>
53
+ </tbody>
54
+ </table>
55
+ <p class="button-controls"><input type="submit" name="nav-menu-locations" id="nav-menu-locations" class="button button-primary left" value="<?php _e('Save Changes', 'formidable') ?>" /></p>
56
+ <?php wp_nonce_field( 'frm_manage_style_nonce', 'frm_manage_style' ); ?>
57
+ </form>
58
+ </div><!-- #menu-locations-wrap -->
59
+ </div><!-- /.wrap-->
classes/views/styles/show.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="nav-menus-php">
2
+ <div class="wrap">
3
+ <?php FrmStylesHelper::style_menu(); ?>
4
+
5
+ <?php include(FrmAppHelper::plugin_path() .'/classes/views/shared/errors.php'); ?>
6
+
7
+ <div class="manage-menus">
8
+ <span class="add-edit-menu-action">
9
+ <?php if ( count($styles) < 2 && !empty($style->ID) ) {
10
+ printf(__('Edit your style below, or %1$screate a new style%2$s.', 'formidable'), '<a href="?page=formidable-styles&frm_action=new_style">', '</a>');
11
+
12
+ } else { ?>
13
+ <form method="get">
14
+ <input type="hidden" name="page" value="<?php echo $_GET['page'] ?>"/>
15
+ <input type="hidden" name="frm_action" value="edit" />
16
+ <label class="selected-menu"><?php _e('Select a style to edit:', 'formidable'); ?></label>
17
+ <select name="id">
18
+ <option value=""><?php _e('&mdash; Select &mdash;') ?></option>
19
+ <?php foreach ( $styles as $s ) { ?>
20
+ <option value="<?php echo $s->ID ?>" <?php selected($s->ID, $style->ID) ?>><?php echo $s->post_title . (empty($s->menu_order) ? '' : ' ('. __('default', 'formidable') .')') ?></option>
21
+ <?php } ?>
22
+ </select>
23
+ <span class="submit-btn">
24
+ <input type="submit" class="button-secondary" value="<?php _e('Select', 'formidable') ?>"/>
25
+ </span>
26
+ </form>
27
+ <span class="add-new-menu-action"><?php printf(__('or %1$screate a new style%2$s.', 'formidable'), '<a href="?page=formidable-styles&frm_action=new_style">', '</a>'); ?></span>
28
+ <?php
29
+ } ?>
30
+
31
+ </span>
32
+ </div><!-- /manage-menus -->
33
+
34
+ <form id="frm_styling_form" action="" name="frm_styling_form" method="post">
35
+ <input type="hidden" name="ID" value="<?php echo $style->ID ?>" />
36
+ <input type="hidden" name="frm_action" value="save" />
37
+ <textarea name="<?php echo $frm_style->get_field_name('custom_css') ?>" class="frm_hidden"><?php echo FrmAppHelper::esc_textarea($style->post_content['custom_css']) ?></textarea>
38
+ <?php wp_nonce_field( 'frm_style_nonce', 'frm_style' ); ?>
39
+
40
+ <div id="nav-menus-frame">
41
+ <div id="menu-settings-column" class="metabox-holder">
42
+ <div class="clear"></div>
43
+
44
+ <div class="styling_settings">
45
+ <input type="hidden" name="style_name" value="frm_style_<?php echo $style->post_name ?>" />
46
+ <?php FrmStylesController::do_accordion_sections( FrmStylesController::$screen, 'side', compact('style', 'frm_style') ); ?>
47
+ </div>
48
+
49
+ </div><!-- /#menu-settings-column -->
50
+
51
+
52
+ <div id="menu-management-liquid">
53
+ <div id="menu-management">
54
+ <div class="menu-edit blank-slate">
55
+ <div id="nav-menu-header">
56
+ <div class="major-publishing-actions">
57
+ <label class="menu-name-label howto open-label" for="menu-name">
58
+ <span><?php _e('Style Name', 'formidable') ?></span>
59
+ <input id="menu-name" name="<?php echo $frm_style->get_field_name('post_title', ''); ?>" type="text" class="menu-name regular-text menu-item-textbox" title="<?php esc_attr_e('Enter style name here', 'formidable') ?>" value="<?php echo esc_attr($style->post_title) ?>" />
60
+ </label>
61
+
62
+ <input name="prev_menu_order" type="hidden" value="<?php echo esc_attr($style->menu_order) ?>" />
63
+ <label class="menu-name-label howto open-label default-style-box" for="menu_order">
64
+ <span>
65
+ <?php if ( $style->menu_order ) { ?>
66
+ <input name="<?php echo $frm_style->get_field_name('menu_order', ''); ?>" type="hidden" value="1" />
67
+ <input id="menu_order" disabled="disabled" type="checkbox" value="1" <?php checked($style->menu_order, 1) ?> />
68
+ <?php } else { ?>
69
+ <input id="menu_order" name="<?php echo $frm_style->get_field_name('menu_order', ''); ?>" type="checkbox" value="1" <?php checked($style->menu_order, 1) ?> />
70
+ <?php } ?>
71
+ <?php _e('Make default style', 'formidable') ?></span>
72
+ </label>
73
+
74
+ <div class="publishing-action">
75
+ <input type="submit" id="save_menu_header" class="button button-primary menu-save" value="<?php esc_attr_e('Save Style', 'formidable'); ?>" />
76
+ </div><!-- END .publishing-action -->
77
+ </div><!-- END .major-publishing-actions -->
78
+ </div><!-- END .nav-menu-header -->
79
+ <div id="post-body">
80
+ <div id="post-body-content">
81
+
82
+ <?php include( dirname(__FILE__) .'/_sample_form.php') ?>
83
+
84
+ </div><!-- /#post-body-content -->
85
+ </div><!-- /#post-body -->
86
+ <div id="nav-menu-footer" class="submitbox">
87
+ <div class="major-publishing-actions">
88
+ <?php if ( !empty($style->ID) && empty($style->menu_order) ) { ?>
89
+ <a href="<?php echo admin_url('admin.php?page=formidable-styles&frm_action=destroy&id='. $style->ID); ?>" class="submitdelete deletion" style="padding-right:10px;"><?php _e('Delete Style', 'formidable') ?></a>
90
+ <?php } ?>
91
+ <?php
92
+ if ( $style->ID ) {
93
+ echo '<span class="howto"><span>.frm_style_'. $style->post_name .'</span></span>';
94
+ } ?>
95
+ <div class="publishing-action">
96
+ <input type="button" value="<?php esc_attr_e('Reset to Default', 'formidable') ?>" class="button-secondary frm_reset_style" />
97
+ <input type="submit" id="save_menu_header" class="button button-primary menu-save" value="<?php esc_attr_e('Save Style', 'formidable'); ?>" />
98
+ </div><!-- END .publishing-action -->
99
+ </div><!-- END .major-publishing-actions -->
100
+ </div><!-- /#nav-menu-footer -->
101
+ </div><!-- /.menu-edit -->
102
+ </div><!-- /#menu-management -->
103
+ </div><!-- /#menu-management-liquid -->
104
+ </div><!-- /#nav-menus-frame -->
105
+ </form>
106
+ </div><!-- /.wrap-->
107
+ </div><!-- /.nav-menu-php -->
108
+
109
+ <script type="text/javascript">jQuery('.control-section.accordion-section.open').removeClass('open');</script>
110
+ <div id="this_css"></div>
classes/views/xml/default-templates.xml CHANGED
File without changes
classes/views/xml/forms_xml.php CHANGED
@@ -1,10 +1,8 @@
1
- <?php
2
 
3
  if ( !$item_ids )
4
  return;
5
 
6
- $frm_form = new FrmForm();
7
-
8
  // fetch 20 posts at a time rather than loading the entire table into memory
9
  while ( $next_set = array_splice( $item_ids, 0, 20 ) ) {
10
  $where = 'WHERE id IN (' . join( ',', $next_set ) . ')';
@@ -26,10 +24,11 @@ foreach ( $forms as $form ) {
26
  <editable><?php echo $form->editable ?></editable>
27
  <options><?php echo FrmXMLHelper::cdata($form->options) ?></options>
28
  <status><?php echo FrmXMLHelper::cdata($form->status) ?></status>
 
29
  <?php
30
-
31
  $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_fields WHERE form_id=%d ORDER BY field_order", $form->id));
32
-
33
  foreach ( $fields as $field ){ ?>
34
  <field>
35
  <id><?php echo $field->id ?></id>
@@ -40,7 +39,7 @@ foreach ( $forms as $form ) {
40
  <default_value><?php echo FrmXMLHelper::cdata($field->default_value) ?></default_value>
41
  <field_order><?php echo $field->field_order ?></field_order>
42
  <form_id><?php echo $field->form_id ?></form_id>
43
- <required><?php echo (bool)$field->required ?></required>
44
  <options><?php echo FrmXMLHelper::cdata($field->options) ?></options>
45
  <field_options><?php echo FrmXMLHelper::cdata($field->field_options) ?></field_options>
46
  </field>
1
+ <?php
2
 
3
  if ( !$item_ids )
4
  return;
5
 
 
 
6
  // fetch 20 posts at a time rather than loading the entire table into memory
7
  while ( $next_set = array_splice( $item_ids, 0, 20 ) ) {
8
  $where = 'WHERE id IN (' . join( ',', $next_set ) . ')';
24
  <editable><?php echo $form->editable ?></editable>
25
  <options><?php echo FrmXMLHelper::cdata($form->options) ?></options>
26
  <status><?php echo FrmXMLHelper::cdata($form->status) ?></status>
27
+ <parent_form_id><?php echo $form->parent_form_id ?></parent_form_id>
28
  <?php
29
+
30
  $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_fields WHERE form_id=%d ORDER BY field_order", $form->id));
31
+
32
  foreach ( $fields as $field ){ ?>
33
  <field>
34
  <id><?php echo $field->id ?></id>
39
  <default_value><?php echo FrmXMLHelper::cdata($field->default_value) ?></default_value>
40
  <field_order><?php echo $field->field_order ?></field_order>
41
  <form_id><?php echo $field->form_id ?></form_id>
42
+ <required><?php echo (bool) $field->required ?></required>
43
  <options><?php echo FrmXMLHelper::cdata($field->options) ?></options>
44
  <field_options><?php echo FrmXMLHelper::cdata($field->field_options) ?></field_options>
45
  </field>
classes/views/xml/import_form.php CHANGED
@@ -14,10 +14,11 @@
14
  <br/>
15
  <form enctype="multipart/form-data" method="post">
16
  <input type="hidden" name="frm_action" value="import_xml" />
 
17
  <p><label><?php echo apply_filters('frm_upload_instructions2', __('Choose a Formidable XML file', 'formidable')) ?> (<?php printf(__('Maximum size: %s', 'formidable'), ini_get('upload_max_filesize')) ?>)</label>
18
  <input type="file" name="frm_import_file" size="25" />
19
  </p>
20
-
21
  <?php do_action('frm_csv_opts', $forms) ?>
22
 
23
  <p class="submit">
@@ -26,19 +27,16 @@
26
  </form>
27
  </div>
28
  </div>
29
-
30
-
31
  <div class="postbox">
32
  <h3 class="hndle"><span><?php _e('Export', 'formidable') ?></span></h3>
33
  <div class="inside with_frm_style">
34
  <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" id="frm_export_xml">
35
  <input type="hidden" name="action" value="frm_export_xml" />
36
- <?php //wp_nonce_field('export-xml'); ?>
 
37
  <table class="form-table">
38
- <?php if (count($export_format) == 1) {
39
- reset($export_format); ?>
40
- <tr><td colspan="2"><input type="hidden" name="format" value="<?php echo key($export_format) ?>" /></td></tr>
41
- <?php } else { ?>
42
  <tr class="form-field">
43
  <th scope="row"><label for="format"><?php _e('Export Format', 'formidable'); ?></label></th>
44
  <td>
@@ -46,8 +44,11 @@
46
  <?php foreach ( $export_format as $t => $type ){ ?>
47
  <option value="<?php echo $t ?>" data-support="<?php echo esc_attr($type['support']) ?>" <?php echo isset($type['count']) ? 'data-count="'. esc_attr($type['count']) .'"' : ''; ?>><?php echo isset($type['name']) ? $type['name'] : $t ?></option>
48
  <?php } ?>
 
 
 
49
  </select>
50
-
51
  <ul class="frm_hidden csv_opts export-filters">
52
  <li>
53
  <label for="csv_format"><?php _e('Format', 'formidable') ?>:</label>
@@ -60,15 +61,14 @@
60
  <option value="macintosh" <?php selected($csv_format, 'macintosh'); ?>><?php _e('Macintosh', 'formidable') ?></option>
61
  </select>
62
  </li>
63
-
64
  <li><label for="csv_col_sep"><?php _e('Column separation', 'formidable') ?>:</label>
65
  <input name="csv_col_sep" value="," type="text" style="width:45px;" /></li>
66
  </ul>
67
  </td>
68
  </tr>
69
- <?php } ?>
70
-
71
- <?php if (count($export_types) == 1) {
72
  reset($export_types); ?>
73
  <tr><td colspan="2"><input type="hidden" name="type[]" value="<?php echo key($export_types) ?>" /></td></tr>
74
  <?php } else { ?>
@@ -88,12 +88,12 @@
88
  <td>
89
  <select name="frm_export_forms[]" multiple="multiple" class="frm_chzn">
90
  <?php foreach($forms as $form){ ?>
91
- <option value="<?php echo $form->id ?>"><?php
92
  echo ($form->name == '') ? '(no title)' : $form->name;
93
  echo ' &mdash; '. $form->form_key;
94
  if ( $form->is_template && $form->default_template ) {
95
  echo ' '. __('(default template)', 'formidable');
96
- } else if ( $form->is_template ) {
97
  echo ' '. __('(template)', 'formidable');
98
  }
99
  ?></option>
14
  <br/>
15
  <form enctype="multipart/form-data" method="post">
16
  <input type="hidden" name="frm_action" value="import_xml" />
17
+ <?php wp_nonce_field('import-xml-nonce', 'import-xml'); ?>
18
  <p><label><?php echo apply_filters('frm_upload_instructions2', __('Choose a Formidable XML file', 'formidable')) ?> (<?php printf(__('Maximum size: %s', 'formidable'), ini_get('upload_max_filesize')) ?>)</label>
19
  <input type="file" name="frm_import_file" size="25" />
20
  </p>
21
+
22
  <?php do_action('frm_csv_opts', $forms) ?>
23
 
24
  <p class="submit">
27
  </form>
28
  </div>
29
  </div>
30
+
31
+
32
  <div class="postbox">
33
  <h3 class="hndle"><span><?php _e('Export', 'formidable') ?></span></h3>
34
  <div class="inside with_frm_style">
35
  <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" id="frm_export_xml">
36
  <input type="hidden" name="action" value="frm_export_xml" />
37
+ <?php wp_nonce_field('export-xml-nonce', 'export-xml'); ?>
38
+
39
  <table class="form-table">
 
 
 
 
40
  <tr class="form-field">
41
  <th scope="row"><label for="format"><?php _e('Export Format', 'formidable'); ?></label></th>
42
  <td>
44
  <?php foreach ( $export_format as $t => $type ){ ?>
45
  <option value="<?php echo $t ?>" data-support="<?php echo esc_attr($type['support']) ?>" <?php echo isset($type['count']) ? 'data-count="'. esc_attr($type['count']) .'"' : ''; ?>><?php echo isset($type['name']) ? $type['name'] : $t ?></option>
46
  <?php } ?>
47
+ <?php if ( ! isset($export_format['csv']) ) { ?>
48
+ <option value="csv" disabled="disabled">CSV <?php _e('(Pro feature)', 'formidable'); ?></option>
49
+ <?php } ?>
50
  </select>
51
+
52
  <ul class="frm_hidden csv_opts export-filters">
53
  <li>
54
  <label for="csv_format"><?php _e('Format', 'formidable') ?>:</label>
61
  <option value="macintosh" <?php selected($csv_format, 'macintosh'); ?>><?php _e('Macintosh', 'formidable') ?></option>
62
  </select>
63
  </li>
64
+
65
  <li><label for="csv_col_sep"><?php _e('Column separation', 'formidable') ?>:</label>
66
  <input name="csv_col_sep" value="," type="text" style="width:45px;" /></li>
67
  </ul>
68
  </td>
69
  </tr>
70
+
71
+ <?php if (count($export_types) == 1) {
 
72
  reset($export_types); ?>
73
  <tr><td colspan="2"><input type="hidden" name="type[]" value="<?php echo key($export_types) ?>" /></td></tr>
74
  <?php } else { ?>
88
  <td>
89
  <select name="frm_export_forms[]" multiple="multiple" class="frm_chzn">
90
  <?php foreach($forms as $form){ ?>
91
+ <option value="<?php echo $form->id ?>"><?php
92
  echo ($form->name == '') ? '(no title)' : $form->name;
93
  echo ' &mdash; '. $form->form_key;
94
  if ( $form->is_template && $form->default_template ) {
95
  echo ' '. __('(default template)', 'formidable');
96
+ } else if ( $form->is_template ) {
97
  echo ' '. __('(template)', 'formidable');
98
  }
99
  ?></option>
classes/views/xml/posts_xml.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php
3
+
4
+ if ( !$item_ids )
5
+ return;
6
+
7
+ global $wp_query;
8
+ $wp_query->in_the_loop = true; // Fake being in the loop.
9
+
10
+ // fetch 20 posts at a time rather than loading the entire table into memory
11
+ while ( $next_posts = array_splice( $item_ids, 0, 20 ) ) {
12
+ $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
13
+ $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
14
+
15
+ // Begin Loop
16
+ foreach ( $posts as $post ) {
17
+ setup_postdata( $post );
18
+ $is_sticky = is_sticky( $post->ID ) ? 1 : 0;
19
+ ?>
20
+ <view>
21
+ <title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title>
22
+ <link><?php the_permalink_rss() ?></link>
23
+ <post_author><?php echo FrmXMLHelper::cdata( get_the_author_meta( 'login' ) ); ?></post_author>
24
+ <description></description>
25
+ <content><?php echo FrmXMLHelper::cdata( apply_filters( 'the_content_export', $post->post_content ) ); ?></content>
26
+ <excerpt><?php echo FrmXMLHelper::cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); ?></excerpt>
27
+ <post_id><?php echo $post->ID; ?></post_id>
28
+ <post_date><?php echo $post->post_date; ?></post_date>
29
+ <post_date_gmt><?php echo $post->post_date_gmt; ?></post_date_gmt>
30
+ <comment_status><?php echo $post->comment_status; ?></comment_status>
31
+ <ping_status><?php echo $post->ping_status; ?></ping_status>
32
+ <post_name><?php echo $post->post_name; ?></post_name>
33
+ <status><?php echo $post->post_status; ?></status>
34
+ <post_parent><?php echo $post->post_parent; ?></post_parent>
35
+ <menu_order><?php echo $post->menu_order; ?></menu_order>
36
+ <post_type><?php echo $post->post_type; ?></post_type>
37
+ <post_password><?php echo $post->post_password; ?></post_password>
38
+ <is_sticky><?php echo $is_sticky; ?></is_sticky>
39
+ <?php if ( $post->post_type == 'attachment' ) : ?>
40
+ <attachment_url><?php echo wp_get_attachment_url( $post->ID ); ?></attachment_url>
41
+ <?php endif; ?>
42
+ <?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
43
+ foreach ( $postmeta as $meta ) :
44
+ if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) )
45
+ continue;
46
+ ?>
47
+ <postmeta>
48
+ <meta_key><?php echo $meta->meta_key; ?></meta_key>
49
+ <meta_value><?php echo FrmXMLHelper::cdata( $meta->meta_value ); ?></meta_value>
50
+ </postmeta>
51
+ <?php endforeach;
52
+
53
+ $taxonomies = get_object_taxonomies( $post->post_type );
54
+ if ( !empty( $taxonomies ) ){
55
+ $terms = wp_get_object_terms( $post->ID, $taxonomies );
56
+
57
+ foreach ( (array) $terms as $term ) {
58
+ echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . FrmXMLHelper::cdata( $term->name ) . "</category>\n";
59
+ }
60
+ } ?>
61
+ </view>
62
+ <?php
63
+ }
64
+ }
65
+
66
+ if ( empty( $taxonomies ) )
67
+ return;
68
+
69
+ global $frm_inc_tax;
70
+ if(empty($frm_inc_tax))
71
+ $frm_inc_tax = array();
72
+
73
+ foreach ( (array) $terms as $term ) {
74
+ if(in_array($term->term_id, $frm_inc_tax))
75
+ return;
76
+ $frm_inc_tax[] = $term->term_id;
77
+ $label = ($term->taxonomy == 'category' || $term->taxonomy == 'tag') ? $term->taxonomy : 'term'; ?>
78
+ <term><term_id><?php echo $term->term_id ?></term_id><term_taxonomy><?php echo $term->taxonomy; ?></term_taxonomy><?php if(!empty($term->name)){ echo '<term_name>' . FrmXMLHelper::cdata( $term->name ) . '</term_name>';} ?><?php if(!empty($term->description)){ ?><term_description><?php echo FrmXMLHelper::cdata( $term->description ) ?></term_description><?php } ?><term_slug><?php echo $term->slug; ?></term_slug></term>
79
+ <?php
80
+ }
81
+ ?>
classes/views/xml/xml.php CHANGED
@@ -3,30 +3,29 @@
3
  <channel>
4
  <title><?php bloginfo_rss( 'name' ); ?></title>
5
  <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
6
- <base_blog_url><?php bloginfo_rss( 'url' ); ?></base_blog_url>
7
 
8
  <?php
9
  foreach($type as $tb_type){
10
-
11
  if(!isset($tables[$tb_type])){
12
  do_action('frm_xml_import_'. $tb_type, $args);
13
  continue;
14
  }
15
-
16
  //no records
17
  if(!isset($records[$tb_type]))
18
  continue;
19
 
20
  $item_ids = $records[$tb_type];
21
- if ( file_exists(dirname(__FILE__) .'/'. $tb_type .'_xml.php') ) {
 
 
22
  include(dirname(__FILE__) .'/'. $tb_type .'_xml.php');
23
  } else if ( file_exists( FrmAppHelper::plugin_path() .'/pro/classes/views/xml/'. $tb_type .'_xml.php') ){
24
  include( FrmAppHelper::plugin_path() .'/pro/classes/views/xml/'. $tb_type .'_xml.php' );
25
  }
26
- unset($item_ids);
27
- unset($records[$tb_type]);
28
-
29
- unset($tb_type);
30
  }
31
 
32
  ?>
3
  <channel>
4
  <title><?php bloginfo_rss( 'name' ); ?></title>
5
  <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
 
6
 
7
  <?php
8
  foreach($type as $tb_type){
9
+
10
  if(!isset($tables[$tb_type])){
11
  do_action('frm_xml_import_'. $tb_type, $args);
12
  continue;
13
  }
14
+
15
  //no records
16
  if(!isset($records[$tb_type]))
17
  continue;
18
 
19
  $item_ids = $records[$tb_type];
20
+ if ( in_array($tb_type, array('styles', 'actions') ) ) {
21
+ include(dirname(__FILE__) .'/posts_xml.php');
22
+ } else if ( file_exists(dirname(__FILE__) .'/'. $tb_type .'_xml.php') ) {
23
  include(dirname(__FILE__) .'/'. $tb_type .'_xml.php');
24
  } else if ( file_exists( FrmAppHelper::plugin_path() .'/pro/classes/views/xml/'. $tb_type .'_xml.php') ){
25
  include( FrmAppHelper::plugin_path() .'/pro/classes/views/xml/'. $tb_type .'_xml.php' );
26
  }
27
+
28
+ unset($item_ids, $records[$tb_type], $tb_type);
 
 
29
  }
30
 
31
  ?>
classes/widgets/FrmShowForm.php CHANGED
@@ -8,55 +8,65 @@ class FrmShowForm extends WP_Widget {
8
  }
9
 
10
  function widget( $args, $instance ) {
11
- extract($args);
12
-
13
- $frm_form = new FrmForm();
14
- $form_name = $frm_form->getName( $instance['form'] );
15
- $title = apply_filters('widget_title', empty($instance['title']) ? $form_name : $instance['title']);
 
 
16
  $instance['description'] = isset($instance['description']) ? $instance['description'] : false;
17
-
18
- echo $before_widget;
19
- $select_class = (isset($instance['select_width']) and $instance['select_width']) ? ' frm_set_select' : '';
20
- echo '<div class="frm_form_widget'.$select_class.'">';
21
- if ( $title )
22
- echo $before_title . stripslashes($title) . $after_title;
23
-
24
- if(isset($instance['size']) and is_numeric($instance['size'])){
25
- global $frm_vars;
 
26
  $frm_vars['sidebar_width'] = $instance['size'];
27
  }
28
-
29
  echo FrmFormsController::show_form($instance['form'], '', false, $instance['description']);
30
  $frm_vars['sidebar_width'] = '';
31
  echo '</div>';
32
- echo $after_widget;
33
  }
34
 
35
  function update( $new_instance, $old_instance ) {
36
  return $new_instance;
37
  }
38
 
39
- function form( $instance ) {
40
  //Defaults
41
- $instance = wp_parse_args( (array) $instance, array('title' => false, 'form' => false, 'description' => false, 'size' => 20, 'select_width' => false) );
 
 
 
42
  ?>
43
  <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'formidable') ?>:</label>
44
  <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( stripslashes($instance['title']) ); ?>" /></p>
45
-
46
  <p><label for="<?php echo $this->get_field_id('form'); ?>"><?php _e('Form', 'formidable') ?>:</label>
47
- <?php FrmFormsHelper::forms_dropdown( $this->get_field_name('form'), $instance['form'], false, $this->get_field_id('form') )?>
 
 
 
 
48
  </p>
49
-
50
  <p><label for="<?php echo $this->get_field_id('description'); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" value="1" />
51
  <?php _e('Show Description', 'formidable') ?></label></p>
52
-
53
  <p><label for="<?php echo $this->get_field_id('select_width'); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['select_width'], true) ?> id="<?php echo $this->get_field_id('select_width'); ?>" name="<?php echo $this->get_field_name('select_width'); ?>" value="1" />
54
  <?php _e('Fit Select Boxes into SideBar', 'formidable') ?></label></p>
55
-
56
  <p><label class="checkbox" for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Field Size', 'formidable') ?>:</label>
57
-
58
  <input type="text" size="3" id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>" value="<?php echo esc_attr( $instance['size'] ); ?>" /> <span class="howto" style="display:inline;"><?php _e('characters wide', 'formidable') ?></span></p>
59
  <p class="description"><?php _e('If your text fields are too big for your sidebar insert a size here.', 'formidable') ?></p>
60
- <?php
61
  }
62
  }
8
  }
9
 
10
  function widget( $args, $instance ) {
11
+ if ( empty($instance['title']) ) {
12
+ $title = FrmForm::getName( $instance['form'] );
13
+ } else {
14
+ $title = $instance['title'];
15
+ }
16
+ $title = apply_filters('widget_title', $title);
17
+
18
  $instance['description'] = isset($instance['description']) ? $instance['description'] : false;
19
+
20
+ echo $args['before_widget'];
21
+ $select_class = (isset($instance['select_width']) && $instance['select_width']) ? ' frm_set_select' : '';
22
+ echo '<div class="frm_form_widget'. $select_class .'">';
23
+ if ( $title ) {
24
+ echo $args['before_title'] . stripslashes($title) . $args['after_title'];
25
+ }
26
+
27
+ global $frm_vars;
28
+ if ( isset($instance['size']) && is_numeric($instance['size']) ) {
29
  $frm_vars['sidebar_width'] = $instance['size'];
30
  }
31
+
32
  echo FrmFormsController::show_form($instance['form'], '', false, $instance['description']);
33
  $frm_vars['sidebar_width'] = '';
34
  echo '</div>';
35
+ echo $args['after_widget'];
36
  }
37
 
38
  function update( $new_instance, $old_instance ) {
39
  return $new_instance;
40
  }
41
 
42
+ function form( $instance ) {
43
  //Defaults
44
+ $instance = wp_parse_args( (array) $instance, array(
45
+ 'title' => false, 'form' => false, 'description' => false,
46
+ 'size' => '140px', 'select_width' => false,
47
+ ) );
48
  ?>
49
  <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'formidable') ?>:</label>
50
  <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( stripslashes($instance['title']) ); ?>" /></p>
51
+
52
  <p><label for="<?php echo $this->get_field_id('form'); ?>"><?php _e('Form', 'formidable') ?>:</label>
53
+ <?php
54
+ FrmFormsHelper::forms_dropdown( $this->get_field_name('form'), $instance['form'], array(
55
+ 'blank' => false, 'field_id' => $this->get_field_id('form'),
56
+ ) );
57
+ ?>
58
  </p>
59
+
60
  <p><label for="<?php echo $this->get_field_id('description'); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" value="1" />
61
  <?php _e('Show Description', 'formidable') ?></label></p>
62
+
63
  <p><label for="<?php echo $this->get_field_id('select_width'); ?>"><input class="checkbox" type="checkbox" <?php checked($instance['select_width'], true) ?> id="<?php echo $this->get_field_id('select_width'); ?>" name="<?php echo $this->get_field_name('select_width'); ?>" value="1" />
64
  <?php _e('Fit Select Boxes into SideBar', 'formidable') ?></label></p>
65
+
66
  <p><label class="checkbox" for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Field Size', 'formidable') ?>:</label>
67
+
68
  <input type="text" size="3" id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>" value="<?php echo esc_attr( $instance['size'] ); ?>" /> <span class="howto" style="display:inline;"><?php _e('characters wide', 'formidable') ?></span></p>
69
  <p class="description"><?php _e('If your text fields are too big for your sidebar insert a size here.', 'formidable') ?></p>
70
+ <?php
71
  }
72
  }
css/_single_theme.css.php ADDED
@@ -0,0 +1,786 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( isset($_GET['frm_style_setting']) || isset($_GET['flat']) ) {
4
+ if ( isset($_GET['frm_style_setting']) ){
5
+ extract($_GET['frm_style_setting']['post_content']);
6
+ } else {
7
+ extract($_GET);
8
+ }
9
+
10
+ $important_style = isset($important_style) ? $important_style : 0;
11
+ $auto_width = isset($auto_width) ? $auto_width : 0;
12
+ $submit_style = isset($submit_style) ? $submit_style : 0;
13
+
14
+ if ( isset($_GET['style_name']) && !empty($_GET['style_name']) ) {
15
+ $style_class = $_GET['style_name'] .'.with_frm_style';
16
+ } else {
17
+ $style_class = 'with_frm_style';
18
+ }
19
+
20
+ } else {
21
+ $style_class = 'frm_style_'. $style->post_name .'.with_frm_style';
22
+ extract($style->post_content);
23
+ }
24
+
25
+ $important = empty($important_style) ? '' : ' !important';
26
+ $label_margin = (int) $width + 15;
27
+
28
+ $minus_icons = FrmStylesHelper::minus_icons();
29
+ $arrow_icons = FrmStylesHelper::arrow_icons();
30
+
31
+ if ( ! isset($collapse_icon) ) {
32
+ $collapse_icon = 0;
33
+ }
34
+
35
+ ?>
36
+
37
+ .frm_forms.<?php echo $style_class ?>{
38
+ max-width:<?php echo $form_width . $important ?>;
39
+ direction:<?php echo $direction . $important ?>;
40
+ <?php if ( 'rtl' == $direction ) { ?>
41
+ unicode-bidi:embed;
42
+ <?php } ?>
43
+ }
44
+
45
+ .<?php echo $style_class ?>,
46
+ .<?php echo $style_class ?> form{
47
+ text-align:<?php echo $form_align . $important ?>;
48
+ }
49
+
50
+ .<?php echo $style_class ?> fieldset{
51
+ border:<?php echo $fieldset ?> solid #<?php echo $fieldset_color . $important ?>;
52
+ margin:0;
53
+ padding:<?php echo $fieldset_padding . $important ?>;
54
+ background-color:<?php echo empty($fieldset_bg_color) ? 'transparent' : '#'. $fieldset_bg_color; ?>;
55
+ }
56
+
57
+ .<?php echo $style_class ?> .frm-show-form > h3{
58
+ font-size:<?php echo $title_size . $important ?>;
59
+ color:#<?php echo $title_color . $important ?>;
60
+ }
61
+
62
+ .<?php echo $style_class ?> .frm-show-form .frm_section_heading h3{
63
+ padding:<?php echo $section_pad . $important ?>;
64
+ margin:0<?php echo $important ?>;
65
+ font-size:<?php echo $section_font_size . $important ?>;
66
+ font-weight:<?php echo $section_weight . $important ?>;
67
+ color:#<?php echo $section_color . $important ?>;
68
+ border:none<?php echo $important ?>;
69
+ border<?php echo $section_border_loc ?>:<?php echo $section_border_width .' '. $section_border_style .' #'. $section_border_color . $important ?>;
70
+ background-color:<?php echo empty($section_bg_color) ? 'transparent' : '#'. $section_bg_color . $important; ?>
71
+ }
72
+
73
+ .<?php echo $style_class ?> h3 .frm_<?php echo $collapse_pos ?>_collapse{
74
+ display:inline;
75
+ }
76
+ .<?php echo $style_class ?> h3 .frm_<?php echo ( 'after' == $collapse_pos ) ? 'before' : 'after'; ?>_collapse{
77
+ display:none;
78
+ }
79
+
80
+ .menu-edit #post-body-content .<?php echo $style_class ?> .frm_section_heading h3{
81
+ margin:0;
82
+ }
83
+
84
+ .<?php echo $style_class ?> .frm_section_heading{
85
+ margin-top:<?php echo $section_mar_top . $important ?>;
86
+ }
87
+
88
+ .<?php echo $style_class ?> .frm-show-form .frm_section_heading .frm_section_spacing,
89
+ .menu-edit #post-body-content .<?php echo $style_class ?> .frm-show-form .frm_section_heading .frm_section_spacing{
90
+ margin-bottom:<?php echo $section_mar_bottom . $important ?>;
91
+ }
92
+
93
+ .<?php echo $style_class ?> .frm_repeat_sec{
94
+ margin-bottom:<?php echo $field_margin. $important ?>;
95
+ margin-top:<?php echo $field_margin. $important ?>;
96
+ }
97
+
98
+ .<?php echo $style_class ?> label.frm_primary_label,
99
+ .<?php echo $style_class ?>.frm_login_form label{
100
+ font-family:<?php echo stripslashes($font) ?>;
101
+ font-size:<?php echo $font_size . $important ?>;
102
+ color:#<?php echo $label_color . $important ?>;
103
+ font-weight:<?php echo $weight . $important ?>;
104
+ text-align:<?php echo $align . $important ?>;
105
+ margin:0;
106
+ padding:<?php echo $label_padding . $important ?>;
107
+ width:auto;
108
+ display:block;
109
+ }
110
+
111
+ .<?php echo $style_class ?> .frm_icon_font{
112
+ color:#<?php echo $label_color . $important ?>;
113
+ }
114
+
115
+ .<?php echo $style_class ?> .frm_icon_font.frm_minus_icon:before{
116
+ content:"\e<?php echo isset($minus_icons[$repeat_icon]) ? $minus_icons[$repeat_icon]['-'] : $minus_icons[1]['-'] ?>";
117
+ }
118
+
119
+ .<?php echo $style_class ?> .frm_icon_font.frm_plus_icon:before{
120
+ content:"\e<?php echo isset($minus_icons[$repeat_icon]) ? $minus_icons[$repeat_icon]['+'] : $minus_icons[1]['+'] ?>";
121
+ }
122
+
123
+ .<?php echo $style_class ?> .frm_trigger.active .frm_icon_font.frm_arrow_icon:before{
124
+ content:"\e<?php echo isset($arrow_icons[$collapse_icon]) ? $arrow_icons[$collapse_icon]['-'] : $arrow_icons[1]['-'] ?>";
125
+ }
126
+
127
+ .<?php echo $style_class ?> .frm_trigger .frm_icon_font.frm_arrow_icon:before{
128
+ content:"\e<?php echo isset($arrow_icons[$collapse_icon]) ? $arrow_icons[$collapse_icon]['+'] : $arrow_icons[1]['+'] ?>";
129
+ }
130
+
131
+ .<?php echo $style_class ?> .form-field{
132
+ margin-bottom:<?php echo $field_margin. $important ?>;
133
+ }
134
+ .<?php echo $style_class ?> .frm_grid,
135
+ .<?php echo $style_class ?> .frm_grid_first,
136
+ .<?php echo $style_class ?> .frm_grid_odd {
137
+ margin-bottom:0<?php echo $important ?>;
138
+ }
139
+ .<?php echo $style_class ?> .form-field.frm_section_heading{
140
+ margin-bottom:0<?php echo $important ?>;
141
+ }
142
+
143
+ .<?php echo $style_class ?> p.description,
144
+ .<?php echo $style_class ?> div.description,
145
+ .<?php echo $style_class ?> div.frm_description,
146
+ .<?php echo $style_class ?> .frm-show-form > div.frm_description,
147
+ .<?php echo $style_class ?> .frm_error{
148
+ margin:0;
149
+ padding:0;
150
+ font-family:<?php echo stripslashes($font) . $important ?>;
151
+ font-size:<?php echo $description_font_size . $important ?>;
152
+ color:#<?php echo $description_color . $important ?>;
153
+ font-weight:<?php echo $description_weight . $important ?>;
154
+ text-align:<?php echo $description_align . $important ?>;
155
+ font-style:<?php echo $description_style . $important ?>;
156
+ max-width:100%;
157
+ }
158
+
159
+ /* Form description */
160
+ .<?php echo $style_class ?> .frm-show-form > div.frm_description p{
161
+ font-size:<?php echo $form_desc_size . $important ?>;
162
+ color:#<?php echo $form_desc_color . $important ?>;
163
+ }
164
+
165
+ .<?php echo $style_class ?> .frm_left_container p.description,
166
+ .<?php echo $style_class ?> .frm_left_container div.description,
167
+ .<?php echo $style_class ?> .frm_left_container div.frm_description,
168
+ .<?php echo $style_class ?> .frm_left_container .frm_error{
169
+ margin-left:<?php echo $label_margin ?>px;
170
+ }
171
+
172
+ .<?php echo $style_class ?> .form-field.frm_col_field div.frm_description{
173
+ width:<?php echo ($field_width == '' ? 'auto' : $field_width) . $important ?>;
174
+ max-width:100%;
175
+ }
176
+
177
+ .<?php echo $style_class ?> .frm_left_container .attachment-thumbnail{
178
+ clear:both;
179
+ margin-left:<?php echo $label_margin ?>px<?php echo $important ?>;
180
+ }
181
+
182
+ .<?php echo $style_class ?> .frm_right_container p.description,
183
+ .<?php echo $style_class ?> .frm_right_container div.description,
184
+ .<?php echo $style_class ?> .frm_right_container div.frm_description,
185
+ .<?php echo $style_class ?> .frm_right_container .frm_error{
186
+ margin-right:<?php echo $label_margin ?>px<?php echo $important ?>;
187
+ }
188
+
189
+ .<?php echo $style_class ?> .frm_inline_container label.frm_primary_label,
190
+ .<?php echo $style_class ?> .frm_inline_container .frm_opt_container{
191
+ display:inline<?php echo $important ?>;
192
+ }
193
+
194
+ .<?php echo $style_class ?> .frm_left_container label.frm_primary_label{
195
+ display:inline<?php echo $important ?>;
196
+ width:<?php echo $width ?>;
197
+ }
198
+
199
+ .<?php echo $style_class ?> .frm_right_container label.frm_primary_label,
200
+ .<?php echo $style_class ?> .frm_pos_right{
201
+ display:inline<?php echo $important ?>;
202
+ width:<?php echo $width . $important; ?>;
203
+ }
204
+
205
+ .<?php echo $style_class ?> .frm_none_container label.frm_primary_label,
206
+ .<?php echo $style_class ?> .frm_pos_none{
207
+ display:none<?php echo $important ?>;
208
+ }
209
+
210
+ .<?php echo $style_class ?> .frm_scale label{
211
+ font-weight:<?php echo $check_weight . $important ?>;
212
+ }
213
+
214
+ .<?php echo $style_class ?> .frm_required{
215
+ color:#<?php echo $required_color . $important; ?>;
216
+ font-weight:<?php echo $required_weight . $important; ?>;
217
+ }
218
+
219
+ .<?php echo $style_class ?> input[type=text],
220
+ .<?php echo $style_class ?> input[type=password],
221
+ .<?php echo $style_class ?> input[type=email],
222
+ .<?php echo $style_class ?> input[type=number],
223
+ .<?php echo $style_class ?> input[type=url],
224
+ .<?php echo $style_class ?> input[type=tel],
225
+ .<?php echo $style_class ?> input[type=search],
226
+ .<?php echo $style_class ?> select,
227
+ .<?php echo $style_class ?> textarea,
228
+ .<?php echo $style_class ?> .chosen-container{
229
+ font-family:<?php echo stripslashes($font) . $important ?>;
230
+ font-size:<?php echo $field_font_size ?>;
231
+ margin-bottom:0<?php echo $important ?>;
232
+ }
233
+
234
+ .<?php echo $style_class ?> input[type=text],
235
+ .<?php echo $style_class ?> input[type=password],
236
+ .<?php echo $style_class ?> input[type=email],
237
+ .<?php echo $style_class ?> input[type=number],
238
+ .<?php echo $style_class ?> input[type=url],
239
+ .<?php echo $style_class ?> input[type=tel],
240
+ .<?php echo $style_class ?> input[type=phone],
241
+ .<?php echo $style_class ?> input[type=search],
242
+ .<?php echo $style_class ?> select,
243
+ .<?php echo $style_class ?> textarea,
244
+ .frm_form_fields_style,
245
+ .<?php echo $style_class ?> .frm_scroll_box .frm_opt_container,
246
+ .frm_form_fields_active_style,
247
+ .frm_form_fields_error_style,
248
+ .<?php echo $style_class ?> .chosen-container-multi .chosen-choices,
249
+ .<?php echo $style_class ?> .chosen-container-single .chosen-single{
250
+ color:#<?php echo $text_color . $important ?>;
251
+ background-color:#<?php echo $bg_color . $important; ?>;
252
+ <?php if ( ! empty($important) ) {
253
+ echo 'background-image:none'. $important .';';
254
+ }
255
+ ?>
256
+ border-color:#<?php echo $border_color . $important ?>;
257
+ border-width:<?php echo $field_border_width . $important ?>;
258
+ border-style:<?php echo $field_border_style . $important ?>;
259
+ -moz-border-radius:<?php echo $border_radius . $important ?>;
260
+ -webkit-border-radius:<?php echo $border_radius . $important ?>;
261
+ border-radius:<?php echo $border_radius . $important ?>;
262
+ width:<?php echo ($field_width == '' ? 'auto' : $field_width) . $important ?>;
263
+ max-width:100%;
264
+ font-size:<?php echo $field_font_size . $important ?>;
265
+ padding:<?php echo $field_pad . $important ?>;
266
+ -webkit-box-sizing:border-box;
267
+ -moz-box-sizing:border-box;
268
+ box-sizing:border-box;
269
+ outline:none<?php echo $important ?>;
270
+ font-weight:normal;
271
+ box-shadow:0 1px 1px rgba(0, 0, 0, 0.075) inset;
272
+ }
273
+
274
+ .<?php echo $style_class ?> input[type=text],
275
+ .<?php echo $style_class ?> input[type=password],
276
+ .<?php echo $style_class ?> input[type=email],
277
+ .<?php echo $style_class ?> input[type=number],
278
+ .<?php echo $style_class ?> input[type=url],
279
+ .<?php echo $style_class ?> input[type=tel],
280
+ .<?php echo $style_class ?> input[type=file],
281
+ .<?php echo $style_class ?> input[type=search],
282
+ .<?php echo $style_class ?> select{
283
+ height:<?php echo ($field_height == '' ? 'auto' : $field_height) . $important ?>;
284
+ line-height:1.3<?php echo $important ?>;
285
+ }
286
+
287
+ .<?php echo $style_class ?> select[multiple="multiple"]{
288
+ height:auto <?php echo $important ?>;
289
+ }
290
+
291
+ .<?php echo $style_class ?> input[type=file]{
292
+ color:#<?php echo $text_color . $important ?>;
293
+ border:none;
294
+ padding:0px;
295
+ font-family:<?php echo stripslashes($font) ?>;
296
+ font-size:<?php echo $field_font_size ?>;
297
+ }
298
+
299
+ .<?php echo $style_class ?> .frm_default,
300
+ .<?php echo $style_class ?> .placeholder,
301
+ .<?php echo $style_class ?> .chosen-container-multi .chosen-choices li.search-field .default,
302
+ .<?php echo $style_class ?> .chosen-container-single .chosen-default{
303
+ color:#<?php echo $text_color . $important ?>;
304
+ font-style:italic;
305
+ }
306
+
307
+ .<?php echo $style_class ?> select{
308
+ width:<?php echo ($auto_width ? 'auto' : $field_width) . $important ?>;
309
+ max-width:100%;
310
+ }
311
+
312
+ .<?php echo $style_class ?> input.frm_other_input{
313
+ width:auto <?php echo $important; ?>;
314
+ margin-left:5px <?php echo $important ?>;
315
+ }
316
+
317
+ .<?php echo $style_class ?> .wp-editor-wrap{
318
+ width:<?php echo $field_width . $important ?>;
319
+ max-width:100%;
320
+ }
321
+
322
+ .<?php echo $style_class ?> .wp-editor-container textarea{
323
+ border:none<?php echo $important ?>;
324
+ }
325
+
326
+ .<?php echo $style_class ?> .mceIframeContainer{
327
+ background-color:#<?php echo $bg_color . $important ?>;
328
+ }
329
+
330
+ .<?php echo $style_class ?> .auto_width input,
331
+ .<?php echo $style_class ?> input.auto_width,
332
+ .<?php echo $style_class ?> select.auto_width,
333
+ .<?php echo $style_class ?> textarea.auto_width{
334
+ width:auto<?php echo $important ?>;
335
+ }
336
+
337
+ .<?php echo $style_class ?> input[disabled],
338
+ .<?php echo $style_class ?> select[disabled],
339
+ .<?php echo $style_class ?> textarea[disabled],
340
+ .<?php echo $style_class ?> input[readonly],
341
+ .<?php echo $style_class ?> select[readonly],
342
+ .<?php echo $style_class ?> textarea[readonly]{
343
+ background-color:#<?php echo $bg_color_disabled . $important ?>;
344
+ color:#<?php echo $text_color_disabled . $important ?>;
345
+ border-color:#<?php echo $border_color_disabled . $important ?>;
346
+ }
347
+
348
+
349
+ .<?php echo $style_class ?> .form-field input:focus,
350
+ .<?php echo $style_class ?> select:focus,
351
+ .<?php echo $style_class ?> textarea:focus,
352
+ .<?php echo $style_class ?> .frm_focus_field input[type=text],
353
+ .<?php echo $style_class ?> .frm_focus_field input[type=password],
354
+ .<?php echo $style_class ?> .frm_focus_field input[type=email],
355
+ .<?php echo $style_class ?> .frm_focus_field input[type=number],
356
+ .<?php echo $style_class ?> .frm_focus_field input[type=url],
357
+ .<?php echo $style_class ?> .frm_focus_field input[type=tel],
358
+ .<?php echo $style_class ?> .frm_focus_field input[type=search],
359
+ .frm_form_fields_active_style,
360
+ .<?php echo $style_class ?> .chosen-container-active .chosen-choices{
361
+ background-color:#<?php echo $bg_color_active . $important ?>;
362
+ border-color:#<?php echo $border_color_active . $important ?>;
363
+ box-shadow:0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(<?php echo FrmStylesHelper::hex2rgb($border_color_active) ?>, 0.6);
364
+ }
365
+
366
+ <?php if ( ! $submit_style ) { ?>
367
+ .<?php echo $style_class ?> input[type=submit],
368
+ .<?php echo $style_class ?> .frm_submit input[type=button],
369
+ .frm_form_submit_style,
370
+ .<?php echo $style_class ?>.frm_login_form input[type=submit]{
371
+ width:<?php echo ($submit_width == '' ? 'auto' : $submit_width) . $important ?>;
372
+ font-family:<?php echo stripslashes($font) ?>;
373
+ font-size:<?php echo $submit_font_size; ?>;
374
+ height:<?php echo $submit_height . $important ?>;
375
+ line-height:normal <?php echo $important ?>;
376
+ text-align:center;
377
+ background:#<?php echo $submit_bg_color; if ( ! empty($submit_bg_img) ) echo ' url('. $submit_bg_img .')'; ?>;
378
+ border-width:<?php echo $submit_border_width ?>;
379
+ border-color:#<?php echo $submit_border_color . $important ?>;
380
+ border-style:solid;
381
+ color:#<?php echo $submit_text_color . $important ?>;
382
+ cursor:pointer;
383
+ font-weight:<?php echo $submit_weight . $important ?>;
384
+ -moz-border-radius:<?php echo $submit_border_radius . $important ?>;
385
+ -webkit-border-radius:<?php echo $submit_border_radius . $important ?>;
386
+ border-radius:<?php echo $submit_border_radius . $important ?>;
387
+ text-shadow:none;
388
+ padding:<?php echo $submit_padding . $important ?>;
389
+ -moz-box-sizing:border-box;
390
+ box-sizing:border-box;
391
+ -ms-box-sizing:border-box;
392
+ -moz-box-shadow:0 1px 1px #<?php echo $submit_shadow_color; ?>;
393
+ -webkit-box-shadow:0px 1px 1px #<?php echo $submit_shadow_color; ?>;
394
+ box-shadow:0 1px 1px #<?php echo $submit_shadow_color; ?>;
395
+ -ms-filter:"progid:DXImageTransform.Microsoft.Shadow(Strength=3, Direction=135, Color='#<?php echo $submit_shadow_color; ?>')";
396
+ filter:progid:DXImageTransform.Microsoft.Shadow(Strength=3, Direction=135, Color='#<?php echo $submit_shadow_color; ?>');
397
+ margin-top:<?php echo $submit_margin ?>;
398
+ margin-bottom:<?php echo $submit_margin ?>;
399
+ vertical-align:middle;
400
+ }
401
+
402
+ <?php
403
+ if ( empty($submit_bg_img) ) {
404
+ ?>.<?php echo $style_class ?> input[type=submit]:hover,
405
+ .<?php echo $style_class ?> .frm_submit input[type=button]:hover,
406
+ .<?php echo $style_class ?>.frm_login_form input[type=submit]:hover{
407
+ background:#<?php echo $submit_hover_bg_color . $important ?>;
408
+ border-color:#<?php echo $submit_hover_border_color . $important ?>;
409
+ color:#<?php echo $submit_hover_color . $important ?>;
410
+ }
411
+
412
+ .<?php echo $style_class ?>.frm_center_submit .frm_submit .frm_ajax_loading{
413
+ margin-bottom:<?php echo $submit_margin ?>;
414
+ }
415
+
416
+ .<?php echo $style_class ?>.frm_inline_form .frm_submit input[type=submit]{
417
+ margin-top:<?php echo ( str_replace( 'px', '', $font_size ) + 9 ) . 'px' . $important ?>;
418
+ margin-bottom:<?php echo ( str_replace( 'px', '', $font_size ) + 9 ) . 'px' . $important ?>;
419
+ }
420
+
421
+ .<?php echo $style_class ?> input[type=submit]:focus,
422
+ .<?php echo $style_class ?> .frm_submit input[type=button]:focus,
423
+ .<?php echo $style_class ?>.frm_login_form input[type=submit]:focus.
424
+ .<?php echo $style_class ?> input[type=submit]:active,
425
+ .<?php echo $style_class ?> .frm_submit input[type=button]:active,
426
+ .<?php echo $style_class ?>.frm_login_form input[type=submit]:active{
427
+ background:#<?php echo $submit_active_bg_color . $important ?>;
428
+ border-color:#<?php echo $submit_active_border_color . $important ?>;
429
+ color:#<?php echo $submit_active_color . $important ?>;
430
+ }
431
+ <?php
432
+ }
433
+
434
+ }
435
+ ?>
436
+
437
+ .<?php echo $style_class ?> a.frm_save_draft{
438
+ font-family:<?php echo stripslashes($font) ?>;
439
+ font-size:<?php echo $submit_font_size ?>;
440
+ font-weight:<?php echo $submit_weight ?>;
441
+ }
442
+
443
+ .<?php echo $style_class ?> #frm_field_cptch_number_container{
444
+ font-family:<?php echo stripslashes($font) ?>;
445
+ font-size:<?php echo $font_size . $important ?>;
446
+ color:#<?php echo $label_color . $important ?>;
447
+ font-weight:<?php echo $weight . $important ?>;
448
+ clear:both;
449
+ }
450
+
451
+ .<?php echo $style_class ?> .frm_radio{
452
+ display:<?php echo $radio_align . $important ?>;
453
+ }
454
+
455
+ .<?php echo $style_class ?> .frm_left_container .frm_radio{
456
+ margin<?php echo ($radio_align == 'block' ? "-left:{$label_margin}px;" : ':0') . $important; ?>
457
+ }
458
+
459
+ .<?php echo $style_class ?> .frm_right_container .frm_radio{
460
+ margin<?php echo ($radio_align == 'block' ? "-right:{$label_margin}px;" : ':0') . $important; ?>
461
+ }
462
+
463
+ .<?php echo $style_class ?> .horizontal_radio .frm_radio{
464
+ margin:0 5px 0 0<?php echo $important ?>;
465
+ }
466
+
467
+ .<?php echo $style_class ?> .frm_checkbox{
468
+ display:<?php echo $check_align . $important ?>;
469
+ }
470
+
471
+ .<?php echo $style_class ?> .frm_left_container .frm_checkbox{
472
+ margin<?php echo ($check_align == 'block') ? "-left:{$label_margin}px;" : ':0'; ?>
473
+ }
474
+
475
+ .<?php echo $style_class ?> .frm_right_container .frm_checkbox{
476
+ margin<?php echo ($check_align == 'block') ? "-right:{$label_margin}px;" : ':0'; ?>
477
+ }
478
+
479
+ .<?php echo $style_class ?> .horizontal_radio .frm_checkbox,
480
+ .<?php echo $style_class ?> .horizontal_radio .frm_radio,
481
+ .horizontal_radio .frm_catlevel_1{
482
+ display:inline-block<?php echo $important ?>;
483
+ }
484
+
485
+ .<?php echo $style_class ?> .frm_radio label,
486
+ .<?php echo $style_class ?> .frm_checkbox label{
487
+ font-family:<?php echo stripslashes($font) . $important ?>;
488
+ font-size:<?php echo $check_font_size . $important ?>;
489
+ color:#<?php echo $check_label_color . $important ?>;
490
+ font-weight:<?php echo $check_weight . $important ?>;
491
+ display:inline;
492
+ }
493
+
494
+ .<?php echo $style_class ?> .frm_blank_field input[type=text],
495
+ .<?php echo $style_class ?> .frm_blank_field input[type=password],
496
+ .<?php echo $style_class ?> .frm_blank_field input[type=url],
497
+ .<?php echo $style_class ?> .frm_blank_field input[type=tel],
498
+ .<?php echo $style_class ?> .frm_blank_field input[type=number],
499
+ .<?php echo $style_class ?> .frm_blank_field input[type=email],
500
+ .<?php echo $style_class ?> .frm_blank_field textarea,
501
+ .<?php echo $style_class ?> .frm_blank_field select,
502
+ .frm_form_fields_error_style,
503
+ .<?php echo $style_class ?> .frm_blank_field .g-recaptcha iframe,
504
+ .<?php echo $style_class ?> .frm_blank_field .chosen-container-multi .chosen-choices{
505
+ color:#<?php echo $text_color_error . $important ?>;
506
+ background-color:#<?php echo $bg_color_error ?>;
507
+ border-color:#<?php echo $border_color_error . $important ?>;
508
+ border-width:<?php echo $border_width_error . $important ?>;
509
+ border-style:<?php echo $border_style_error . $important ?>;
510
+ }
511
+
512
+ .<?php echo $style_class ?> .frm_error{
513
+ font-weight:<?php echo $weight . $important ?>;
514
+ }
515
+
516
+ .<?php echo $style_class ?> .frm_blank_field label,
517
+ .<?php echo $style_class ?> .frm_error{
518
+ color:#<?php echo $border_color_error . $important ?>;
519
+ }
520
+
521
+ .<?php echo $style_class ?> .frm_error_style{
522
+ background-color:#<?php echo $error_bg . $important ?>;
523
+ border:1px solid #<?php echo $error_border . $important ?>;
524
+ color:#<?php echo $error_text . $important ?>;
525
+ font-size:<?php echo $error_font_size . $important ?>;
526
+ margin:0;
527
+ margin-bottom:<?php echo $field_margin ?>;
528
+ }
529
+
530
+ .<?php echo $style_class ?> .frm_message,
531
+ .frm_success_style{
532
+ border:1px solid #<?php echo $success_border_color ?>;
533
+ background-color:#<?php echo $success_bg_color ?>;
534
+ color:#<?php echo $success_text_color ?>;
535
+ }
536
+
537
+ .<?php echo $style_class ?> .frm_message{
538
+ margin:5px 0 15px;
539
+ font-size:<?php echo $success_font_size . $important ?>;
540
+ }
541
+
542
+ .<?php echo $style_class ?> .frm-grid td,
543
+ .frm-grid th{
544
+ border-color:#<?php echo $border_color ?>;
545
+ }
546
+
547
+ .form_results.<?php echo $style_class ?>{
548
+ border-color:<?php echo $field_border_width ?> solid #<?php echo $border_color . $important ?>;
549
+ }
550
+
551
+ .form_results.<?php echo $style_class ?> tr td{
552
+ color:#<?php echo $text_color . $important ?>;
553
+ border-top:<?php echo $field_border_width ?> solid #<?php echo $border_color . $important ?>;
554
+ }
555
+
556
+ .form_results.<?php echo $style_class ?> tr.frm_even,
557
+ .frm-grid .frm_even{
558
+ background-color:#<?php echo $bg_color . $important ?>;
559
+ }
560
+
561
+ .<?php echo $style_class ?> #frm_loading .progress-striped .progress-bar{
562
+ background-image:linear-gradient(45deg, #<?php echo $border_color ?> 25%, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0) 50%, #<?php echo $border_color ?> 50%, #<?php echo $border_color ?> 75%, rgba(0, 0, 0, 0) 75%, rgba(0, 0, 0, 0));
563
+ }
564
+
565
+ .<?php echo $style_class ?> #frm_loading .progress-bar{
566
+ background-color:#<?php echo $bg_color ?>;
567
+ }
568
+
569
+ .<?php echo $style_class ?> .frm_grid,
570
+ .<?php echo $style_class ?> .frm_grid_first,
571
+ .<?php echo $style_class ?> .frm_grid_odd{
572
+ border-color:#<?php echo $border_color ?>;
573
+ }
574
+
575
+ .<?php echo $style_class ?> .frm_grid.frm_blank_field,
576
+ .<?php echo $style_class ?> .frm_grid_first.frm_blank_field,
577
+ .<?php echo $style_class ?> .frm_grid_odd.frm_blank_field{
578
+ background-color:#<?php echo $error_bg ?>;
579
+ border-color:#<?php echo $error_border ?>;
580
+ }
581
+
582
+ .<?php echo $style_class ?> .frm_grid_first,
583
+ .<?php echo $style_class ?> .frm_grid_odd{
584
+ background-color:#<?php echo $bg_color ?>;
585
+ }
586
+
587
+ .<?php echo $style_class ?> .frm_grid{
588
+ background-color:#<?php echo $bg_color_active ?>;
589
+ }
590
+
591
+ .<?php echo $style_class ?> .frm_form_field.frm_html_scroll_box{
592
+ background-color:#<?php echo $bg_color . $important ?>;
593
+ border-color:#<?php echo $border_color . $important ?>;
594
+ border-width:<?php echo $field_border_width . $important ?>;
595
+ border-style:<?php echo $field_border_style . $important ?>;
596
+ -moz-border-radius:<?php echo $border_radius . $important ?>;
597
+ -webkit-border-radius:<?php echo $border_radius . $important ?>;
598
+ border-radius:<?php echo $border_radius . $important ?>;
599
+ width:<?php echo ($field_width == '' ? 'auto' : $field_width) . $important ?>;
600
+ font-size:<?php echo $field_font_size . $important ?>;
601
+ padding:<?php echo $field_pad . $important ?>;
602
+ outline:none<?php echo $important ?>;
603
+ }
604
+
605
+ .<?php echo $style_class ?> .frm_form_field.frm_total input,
606
+ .<?php echo $style_class ?> .frm_form_field.frm_total textarea{
607
+ color:#<?php echo $text_color . $important ?>;
608
+ background-color:transparent<?php echo $important ?>;
609
+ border:none<?php echo $important ?>;
610
+ display:inline<?php echo $important ?>;
611
+ width:auto<?php echo $important ?>;
612
+ }
613
+
614
+ .<?php echo $style_class ?> .frm_button{
615
+ padding-top:<?php echo $field_pad . $important ?>;
616
+ padding-bottom:<?php echo $field_pad . $important ?>;
617
+ -moz-border-radius:<?php echo $border_radius . $important ?>;
618
+ -webkit-border-radius:<?php echo $border_radius . $important ?>;
619
+ border-radius:<?php echo $border_radius . $important ?>;
620
+ font-size:<?php echo $submit_font_size . $important ?>;
621
+ font-family:<?php echo stripslashes($font) . $important ?>;
622
+ font-weight:<?php echo $submit_weight . $important ?>;
623
+ color:#<?php echo $submit_text_color . $important ?>;
624
+ background:#<?php echo $submit_bg_color ?>;
625
+ border-width:<?php echo $submit_border_width ?>;
626
+ border-color:#<?php echo $submit_border_color . $important ?>;
627
+ }
628
+ .<?php echo $style_class ?> .frm_button .frm_icon_font:before{
629
+ font-size:<?php echo $submit_font_size . $important ?>;
630
+ vertical-align:bottom;
631
+ }
632
+
633
+ /* RTL Grids */
634
+ <?php if ('rtl' == $direction ) { ?>
635
+ .<?php echo $style_class ?> .frm_form_fields div.rating-cancel,
636
+ .<?php echo $style_class ?> .frm_form_fields div.star-rating{
637
+ float:right;
638
+ }
639
+
640
+ .<?php echo $style_class ?> .frm_form_field.frm_third,
641
+ .<?php echo $style_class ?> .frm_form_field.frm_fourth,
642
+ .<?php echo $style_class ?> .frm_form_field.frm_fifth,
643
+ .<?php echo $style_class ?> .frm_form_field.frm_inline,
644
+
645
+ .<?php echo $style_class ?> .frm_form_field.frm_left_half,
646
+ .<?php echo $style_class ?> .frm_form_field.frm_left_third,
647
+ .<?php echo $style_class ?> .frm_form_field.frm_left_two_thirds,
648
+ .<?php echo $style_class ?> .frm_form_field.frm_left_fourth,
649
+ .<?php echo $style_class ?> .frm_form_field.frm_left_fifth,
650
+ .<?php echo $style_class ?> .frm_form_field.frm_left_inline,
651
+ .<?php echo $style_class ?> .frm_form_field.frm_first_half,
652
+ .<?php echo $style_class ?> .frm_form_field.frm_first_third,
653
+ .<?php echo $style_class ?> .frm_form_field.frm_first_two_thirds,
654
+ .<?php echo $style_class ?> .frm_form_field.frm_first_fourth,
655
+ .<?php echo $style_class ?> .frm_form_field.frm_first_fifth,
656
+ .<?php echo $style_class ?> .frm_form_field.frm_first_inline{
657
+ float:right;
658
+ }
659
+
660
+ .<?php echo $style_class ?> .frm_form_field.frm_right_half,
661
+ .<?php echo $style_class ?> .frm_form_field.frm_right_third,
662
+ .<?php echo $style_class ?> .frm_form_field.frm_right_two_thirds,
663
+ .<?php echo $style_class ?> .frm_form_field.frm_right_fourth,
664
+ .<?php echo $style_class ?> .frm_form_field.frm_right_fifth,
665
+ .<?php echo $style_class ?> .frm_form_field.frm_right_inline,
666
+ .<?php echo $style_class ?> .frm_form_field.frm_last_half,
667
+ .<?php echo $style_class ?> .frm_form_field.frm_last_third,
668
+ .<?php echo $style_class ?> .frm_form_field.frm_last_two_thirds,
669
+ .<?php echo $style_class ?> .frm_form_field.frm_last_fourth,
670
+ .<?php echo $style_class ?> .frm_form_field.frm_last_fifth,
671
+ .<?php echo $style_class ?> .frm_form_field.frm_last_inline{
672
+ float:left;
673
+ }
674
+
675
+ .<?php echo $style_class ?> .frm_form_field.frm_left_half,
676
+ .<?php echo $style_class ?> .frm_form_field.frm_first_half{
677
+ margin-left:4%;
678
+ margin-right:0
679
+ }
680
+
681
+ .<?php echo $style_class ?> .frm_form_field.frm_left_half.frm_left_container .frm_primary_label,
682
+ .<?php echo $style_class ?> .frm_form_field.frm_right_half.frm_left_container .frm_primary_label,
683
+ .<?php echo $style_class ?> .frm_form_field.frm_first_half.frm_left_container .frm_primary_label,
684
+ .<?php echo $style_class ?> .frm_form_field.frm_last_half.frm_left_container .frm_primary_label{
685
+ padding-left:10px;
686
+ padding-right:0;
687
+ }
688
+
689
+ .<?php echo $style_class ?> .frm_form_field.frm_left_half.frm_right_container .frm_primary_label,
690
+ .<?php echo $style_class ?> .frm_form_field.frm_right_half.frm_right_container .frm_primary_label,
691
+ .<?php echo $style_class ?> .frm_form_field.frm_first_half.frm_right_container .frm_primary_label,
692
+ .<?php echo $style_class ?> .frm_form_field.frm_last_half.frm_right_container .frm_primary_label{
693
+ padding-right:10px;
694
+ padding-left:0;
695
+ }
696
+
697
+ .<?php echo $style_class ?> .frm_form_field.frm_left_third,
698
+ .<?php echo $style_class ?> .frm_form_field.frm_first_third,
699
+ .<?php echo $style_class ?> .frm_form_field.frm_third,
700
+ .<?php echo $style_class ?> .frm_form_field.frm_left_two_thirds,
701
+ .<?php echo $style_class ?> .frm_form_field.frm_first_two_thirds{
702
+ margin-right:0;
703
+ margin-left:5%;
704
+ }
705
+
706
+ .<?php echo $style_class ?> .frm_form_field.frm_left_fourth,
707
+ .<?php echo $style_class ?> .frm_form_field.frm_fourth,
708
+ .<?php echo $style_class ?> .frm_form_field.frm_first_fourth{
709
+ margin-right:0;
710
+ margin-left:4%;
711
+ }
712
+
713
+ .<?php echo $style_class ?> .frm_form_field.frm_left_fifth,
714
+ .<?php echo $style_class ?> .frm_form_field.frm_fifth,
715
+ .<?php echo $style_class ?> .frm_form_field.frm_first_fifth{
716
+ margin-right:0;
717
+ margin-left:5%;
718
+ }
719
+
720
+ .<?php echo $style_class ?> .frm_form_field.frm_left_inline,
721
+ .<?php echo $style_class ?> .frm_form_field.frm_first_inline,
722
+ .<?php echo $style_class ?> .frm_form_field.frm_inline{
723
+ margin-right:0;
724
+ margin-left:4%;
725
+ }
726
+
727
+ .<?php echo $style_class ?> .frm_grid .frm_primary_label,
728
+ .<?php echo $style_class ?> .frm_grid_first .frm_primary_label,
729
+ .<?php echo $style_class ?> .frm_grid_odd .frm_primary_label,
730
+ .<?php echo $style_class ?> .frm_grid .frm_radio,
731
+ .<?php echo $style_class ?> .frm_grid_first .frm_radio,
732
+ .<?php echo $style_class ?> .frm_grid_odd .frm_radio,
733
+ .<?php echo $style_class ?> .frm_grid .frm_checkbox,
734
+ .<?php echo $style_class ?> .frm_grid_first .frm_checkbox,
735
+ .<?php echo $style_class ?> .frm_grid_odd .frm_checkbox{
736
+ float:right !important;
737
+ margin-right:0 !important;
738
+ }
739
+
740
+ .<?php echo $style_class ?> .frm_grid_first .frm_radio label input,
741
+ .<?php echo $style_class ?> .frm_grid .frm_radio label input,
742
+ .<?php echo $style_class ?> .frm_grid_odd .frm_radio label input,
743
+ .<?php echo $style_class ?> .frm_grid_first .frm_checkbox label input,
744
+ .<?php echo $style_class ?> .frm_grid .frm_checkbox label input,
745
+ .<?php echo $style_class ?> .frm_grid_odd .frm_checkbox label input{
746
+ float:left;
747
+ }
748
+
749
+ .<?php echo $style_class ?> .frm_form_field.frm_two_col .frm_radio,
750
+ .<?php echo $style_class ?> .frm_form_field.frm_three_col .frm_radio,
751
+ .<?php echo $style_class ?> .frm_form_field.frm_four_col .frm_radio,
752
+ .<?php echo $style_class ?> .frm_form_field.frm_two_col .frm_checkbox,
753
+ .<?php echo $style_class ?> .frm_form_field.frm_three_col .frm_checkbox,
754
+ .<?php echo $style_class ?> .frm_form_field.frm_four_col .frm_checkbox{
755
+ float:right;
756
+ }
757
+ <?php } ?>
758
+ /* Start Chosen */
759
+ .<?php echo $style_class ?> .chosen-container{
760
+ font-size:<?php echo $field_font_size . $important ?>;
761
+ }
762
+
763
+ .<?php echo $style_class ?> .chosen-container-single .chosen-single{
764
+ height:<?php echo ($field_height == 'auto' || $field_height == '') ? '25px' : $field_height ?>;
765
+ line-height:1.3<?php echo $important ?>;
766
+ }
767
+
768
+ .<?php echo $style_class ?> .chosen-container-single .chosen-single div{
769
+ <?php
770
+ // calculate the top position based on field padding
771
+ $top_pad = explode(' ', $field_pad);
772
+ $top_pad = reset($top_pad); // the top padding is listed first
773
+ $pad_unit = preg_replace('/[0-9]+/', '', $top_pad); //px, em, rem...
774
+ $top_margin = (int) str_replace($pad_unit, '', $top_pad) / 2;
775
+ ?>
776
+ top:<?php echo $top_margin . $pad_unit . $important ?>;
777
+ }
778
+
779
+ .<?php echo $style_class ?> .chosen-container-single .chosen-search input[type="text"]{
780
+ height:<?php echo ($field_height == 'auto' || $field_height == '') ? 'auto' : $field_height ?>;
781
+ }
782
+
783
+ .<?php echo $style_class ?> .chosen-container-multi .chosen-choices li.search-field input[type="text"]{
784
+ height:15px<?php echo $important ?>;
785
+ }
786
+ /* End Chosen */
css/codemirror.css ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* BASICS */
2
+
3
+ .CodeMirror {
4
+ /* Set height, width, borders, and global font properties here */
5
+ font-family: monospace;
6
+ height: 300px;
7
+ }
8
+ .CodeMirror-scroll {
9
+ /* Set scrolling behaviour here */
10
+ overflow: auto;
11
+ }
12
+
13
+ /* PADDING */
14
+
15
+ .CodeMirror-lines {
16
+ padding: 4px 0; /* Vertical padding around content */
17
+ }
18
+ .CodeMirror pre {
19
+ padding: 0 4px; /* Horizontal padding of content */
20
+ }
21
+
22
+ .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
23
+ background-color: white; /* The little square between H and V scrollbars */
24
+ }
25
+
26
+ /* GUTTER */
27
+
28
+ .CodeMirror-gutters {
29
+ border-right: 1px solid #ddd;
30
+ background-color: #f7f7f7;
31
+ white-space: nowrap;
32
+ }
33
+ .CodeMirror-linenumbers {}
34
+ .CodeMirror-linenumber {
35
+ padding: 0 3px 0 5px;
36
+ min-width: 20px;
37
+ text-align: right;
38
+ color: #999;
39
+ -moz-box-sizing: content-box;
40
+ box-sizing: content-box;
41
+ }
42
+
43
+ .CodeMirror-guttermarker { color: black; }
44
+ .CodeMirror-guttermarker-subtle { color: #999; }
45
+
46
+ /* CURSOR */
47
+
48
+ .CodeMirror div.CodeMirror-cursor {
49
+ border-left: 1px solid black;
50
+ }
51
+ /* Shown when moving in bi-directional text */
52
+ .CodeMirror div.CodeMirror-secondarycursor {
53
+ border-left: 1px solid silver;
54
+ }
55
+ .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
56
+ width: auto;
57
+ border: 0;
58
+ background: #7e7;
59
+ }
60
+ .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursors {
61
+ z-index: 1;
62
+ }
63
+
64
+ .cm-animate-fat-cursor {
65
+ width: auto;
66
+ border: 0;
67
+ -webkit-animation: blink 1.06s steps(1) infinite;
68
+ -moz-animation: blink 1.06s steps(1) infinite;
69
+ animation: blink 1.06s steps(1) infinite;
70
+ }
71
+ @-moz-keyframes blink {
72
+ 0% { background: #7e7; }
73
+ 50% { background: none; }
74
+ 100% { background: #7e7; }
75
+ }
76
+ @-webkit-keyframes blink {
77
+ 0% { background: #7e7; }
78
+ 50% { background: none; }
79
+ 100% { background: #7e7; }
80
+ }
81
+ @keyframes blink {
82
+ 0% { background: #7e7; }
83
+ 50% { background: none; }
84
+ 100% { background: #7e7; }
85
+ }
86
+
87
+ /* Can style cursor different in overwrite (non-insert) mode */
88
+ div.CodeMirror-overwrite div.CodeMirror-cursor {}
89
+
90
+ .cm-tab { display: inline-block; text-decoration: inherit; }
91
+
92
+ .CodeMirror-ruler {
93
+ border-left: 1px solid #ccc;
94
+ position: absolute;
95
+ }
96
+
97
+ /* DEFAULT THEME */
98
+
99
+ .cm-s-default .cm-keyword {color: #708;}
100
+ .cm-s-default .cm-atom {color: #219;}
101
+ .cm-s-default .cm-number {color: #164;}
102
+ .cm-s-default .cm-def {color: #00f;}
103
+ .cm-s-default .cm-variable,
104
+ .cm-s-default .cm-punctuation,
105
+ .cm-s-default .cm-property,
106
+ .cm-s-default .cm-operator {}
107
+ .cm-s-default .cm-variable-2 {color: #05a;}
108
+ .cm-s-default .cm-variable-3 {color: #085;}
109
+ .cm-s-default .cm-comment {color: #a50;}
110
+ .cm-s-default .cm-string {color: #a11;}
111
+ .cm-s-default .cm-string-2 {color: #f50;}
112
+ .cm-s-default .cm-meta {color: #555;}
113
+ .cm-s-default .cm-qualifier {color: #555;}
114
+ .cm-s-default .cm-builtin {color: #30a;}
115
+ .cm-s-default .cm-bracket {color: #997;}
116
+ .cm-s-default .cm-tag {color: #170;}
117
+ .cm-s-default .cm-attribute {color: #00c;}
118
+ .cm-s-default .cm-header {color: blue;}
119
+ .cm-s-default .cm-quote {color: #090;}
120
+ .cm-s-default .cm-hr {color: #999;}
121
+ .cm-s-default .cm-link {color: #00c;}
122
+
123
+ .cm-negative {color: #d44;}
124
+ .cm-positive {color: #292;}
125
+ .cm-header, .cm-strong {font-weight: bold;}
126
+ .cm-em {font-style: italic;}
127
+ .cm-link {text-decoration: underline;}
128
+
129
+ .cm-s-default .cm-error {color: #f00;}
130
+ .cm-invalidchar {color: #f00;}
131
+
132
+ /* Default styles for common addons */
133
+
134
+ div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
135
+ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
136
+ .CodeMirror-matchingtag { background: rgba(2