PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmEntriesController.php +301 -277 6.53.06.06 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmEntriesController {
7 4
8 5 public static function menu() {
@@ -9,16 +6,9 @@
9 6 FrmAppHelper::force_capability( 'frm_view_entries' );
10 7
11 8 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
12 9
13 - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed();
14 - if ( ! $views_installed ) {
15 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' );
16 - }
17 -
18 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
19 - self::load_manage_entries_hooks();
20 - }
10 + self::load_manage_entries_hooks();
21 11 }
22 12
23 13 /**
24 14 * @since 2.05.07
@@ -23,11 +13,11 @@
23 13 /**
24 14 * @since 2.05.07
25 15 */
26 16 private static function load_manage_entries_hooks() {
27 - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
17 + if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new' ) ) ) {
28 18 $menu_name = FrmAppHelper::get_menu_name();
29 - $base = self::base_column_key( $menu_name );
19 + $base = self::base_column_key( $menu_name );
30 20
31 21 add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
32 22 add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
33 23 add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
@@ -35,28 +25,64 @@
35 25 add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 );
36 26 }
37 27 }
38 28
39 - /* Display in Back End */
40 - public static function route() {
29 + /* Display in Back End */
30 + public static function route() {
41 31 $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
42 - FrmAppHelper::include_svg();
43 32
44 - switch ( $action ) {
45 - case 'show':
46 - case 'destroy':
47 - return self::$action();
33 + switch ( $action ) {
34 + case 'show':
35 + case 'destroy':
36 + case 'destroy_all':
37 + return self::$action();
48 38
49 - default:
50 - do_action( 'frm_entry_action_route', $action );
51 - if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
52 - return;
53 - }
39 + default:
40 + do_action( 'frm_entry_action_route', $action );
41 + if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
42 + return;
43 + }
54 44
55 - return self::display_list();
56 - }
57 - }
45 + return self::display_list();
46 + }
47 + }
58 48
49 + public static function contextual_help( $help, $screen_id, $screen ) {
50 + // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
51 + if ( ! method_exists( $screen, 'add_help_tab' ) ) {
52 + return $help;
53 + }
54 +
55 + $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
56 + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
57 + $show_help = ( $page == 'formidable-entries' && ( empty( $action ) || $action == 'list' ) );
58 + if ( ! $show_help ) {
59 + return $help;
60 + }
61 +
62 + unset( $action, $page );
63 +
64 + $screen->add_help_tab(
65 + array(
66 + 'id' => 'formidable-entries-tab',
67 + 'title' => __( 'Overview', 'formidable' ),
68 + 'content' => '<p>' .
69 + esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .
70 + '</p> <p>' .
71 + esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) .
72 + '</p>',
73 + )
74 + );
75 +
76 + $screen->set_help_sidebar(
77 + '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' .
78 + '<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/knowledgebase/manage-entries-from-the-back-end/?utm_source=WordPress&utm_medium=entries&utm_campaign=liteplugin' ) ) . '" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' .
79 + '<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'https://formidableforms.com/support/?utm_source=WordPress&utm_medium=entries&utm_campaign=liteplugin' ) ) . '" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>'
80 + );
81 +
82 + return $help;
83 + }
84 +
59 85 /**
60 86 * Prevent the "screen options" tab from showing when
61 87 * editing or creating an entry
62 88 *
@@ -71,28 +97,27 @@
71 97 return $show_screen;
72 98 }
73 99
74 100 public static function manage_columns( $columns ) {
75 - global $frm_vars;
101 + global $frm_vars;
76 102 $form_id = FrmForm::get_current_form_id();
77 103
78 - $columns[ $form_id . '_id' ] = 'ID';
104 + $columns[ $form_id . '_id' ] = 'ID';
79 105 $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
80 106
81 107 if ( $form_id ) {
82 108 self::get_columns_for_form( $form_id, $columns );
83 109 } else {
84 - $columns[ $form_id . '_form_id' ] = esc_html__( 'Form', 'formidable' );
85 - $columns[ $form_id . '_name' ] = esc_html__( 'Entry Name', 'formidable' );
86 - $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' );
110 + $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
111 + $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
112 + $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' );
87 113 }
88 114
89 - $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
90 115 $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
91 116 $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
92 117 self::maybe_add_ip_col( $form_id, $columns );
93 118
94 - $frm_vars['cols'] = $columns;
119 + $frm_vars['cols'] = $columns;
95 120
96 121 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
97 122 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
98 123 add_screen_option(
@@ -97,31 +122,21 @@
97 122 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
98 123 add_screen_option(
99 124 'per_page',
100 125 array(
101 - 'label' => esc_html__( 'Entries', 'formidable' ),
126 + 'label' => __( 'Entries', 'formidable' ),
102 127 'default' => 20,
103 128 'option' => 'formidable_page_formidable_entries_per_page',
104 129 )
105 130 );
106 - }
131 + }
107 132
108 - return $columns;
109 - }
133 + return $columns;
134 + }
110 135
111 136 private static function get_columns_for_form( $form_id, &$columns ) {
112 137 $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
113 138
114 - /**
115 - * Allows changing fields in the Entries list table heading.
116 - *
117 - * @since 5.0.04
118 - *
119 - * @param array $fields Array of fields.
120 - * @param array $args The arguments. Contains `form_id`.
121 - */
122 - $form_cols = apply_filters( 'frm_fields_in_entries_list_table', $form_cols, compact( 'form_id' ) );
123 -
124 139 foreach ( $form_cols as $form_col ) {
125 140 if ( FrmField::is_no_save_field( $form_col->type ) ) {
126 141 continue;
127 142 }
@@ -180,71 +195,69 @@
180 195
181 196 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
182 197 $this_page_name = self::hidden_column_key();
183 198 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
184 - return $check;
185 - }
199 + return $check;
200 + }
186 201
187 202 if ( empty( $prev_value ) ) {
188 203 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
189 204 }
190 205
191 - global $frm_vars;
206 + global $frm_vars;
192 207 //add a check so we don't create a loop
193 208 $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
194 209
195 - return $check;
196 - }
210 + return $check;
211 + }
197 212
198 - /**
199 - * Add hidden columns back from other forms
200 - */
213 + //add hidden columns back from other forms
201 214 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
202 215 $this_page_name = self::hidden_column_key();
203 216 if ( $meta_key != $this_page_name ) {
204 - return;
205 - }
217 + return;
218 + }
206 219
207 220 global $frm_vars;
208 221 if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
209 - return; // Don't continue if there's no previous value.
222 + return; //don't continue if there's no previous value
210 223 }
211 224
212 - foreach ( $meta_value as $mk => $mv ) {
213 - // Remove blank values.
214 - if ( empty( $mv ) ) {
215 - unset( $meta_value[ $mk ] );
216 - }
217 - }
225 + foreach ( $meta_value as $mk => $mv ) {
226 + //remove blank values
227 + if ( empty( $mv ) ) {
228 + unset( $meta_value[ $mk ] );
229 + }
230 + }
218 231
219 232 $cur_form_prefix = reset( $meta_value );
220 233 $cur_form_prefix = explode( '_', $cur_form_prefix );
221 - $cur_form_prefix = $cur_form_prefix[0];
222 - $save = false;
234 + $cur_form_prefix = $cur_form_prefix[0];
235 + $save = false;
223 236
224 - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
237 + foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
225 238 if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
226 - // Don't add blank cols or process included cols.
227 - continue;
228 - }
239 + //don't add blank cols or process included cols
240 + continue;
241 + }
229 242
230 243 $form_prefix = explode( '_', $prev_hidden );
231 - $form_prefix = $form_prefix[0];
232 - if ( $form_prefix == $cur_form_prefix ) {
233 - // Don't add back columns that are meant to be hidden.
234 - continue;
235 - }
244 + $form_prefix = $form_prefix[0];
245 + if ( $form_prefix == $cur_form_prefix ) {
246 + //don't add back columns that are meant to be hidden
247 + continue;
248 + }
236 249
237 - $meta_value[] = $prev_hidden;
238 - $save = true;
250 + $meta_value[] = $prev_hidden;
251 + $save = true;
239 252 unset( $form_prefix );
240 - }
253 + }
241 254
242 255 if ( $save ) {
243 256 $user_id = get_current_user_id();
244 257 update_user_option( $user_id, $this_page_name, $meta_value, true );
245 - }
246 - }
258 + }
259 + }
247 260
248 261 /**
249 262 * @since 2.05.07
250 263 */
@@ -249,9 +262,8 @@
249 262 * @since 2.05.07
250 263 */
251 264 private static function hidden_column_key( $menu_name = '' ) {
252 265 $base = self::base_column_key( $menu_name );
253 -
254 266 return 'manage' . $base . 'columnshidden';
255 267 }
256 268
257 269 /**
@@ -260,23 +272,21 @@
260 272 private static function base_column_key( $menu_name = '' ) {
261 273 if ( empty( $menu_name ) ) {
262 274 $menu_name = FrmAppHelper::get_menu_name();
263 275 }
264 -
265 276 return sanitize_title( $menu_name ) . '_page_formidable-entries';
266 277 }
267 278
268 279 public static function save_per_page( $save, $option, $value ) {
269 - if ( $option == 'formidable_page_formidable_entries_per_page' ) {
270 - $save = (int) $value;
271 - }
280 + if ( $option == 'formidable_page_formidable_entries_per_page' ) {
281 + $save = (int) $value;
282 + }
283 + return $save;
284 + }
272 285
273 - return $save;
274 - }
275 -
276 286 public static function sortable_columns() {
277 287 $form_id = FrmForm::get_current_form_id();
278 - $fields = FrmField::get_all_for_form( $form_id );
288 + $fields = FrmField::get_all_for_form( $form_id );
279 289
280 290 $columns = array(
281 291 $form_id . '_id' => 'id',
282 292 $form_id . '_created_at' => 'created_at',
@@ -286,9 +296,10 @@
286 296 $form_id . '_is_draft' => 'is_draft',
287 297 );
288 298
289 299 foreach ( $fields as $field ) {
290 - if ( self::field_supports_sorting( $field ) ) {
300 + if ( $field->type != 'checkbox' && ( ! isset( $field->field_options['post_field'] ) || $field->field_options['post_field'] == '' ) ) {
301 + // Can't sort on checkboxes because they are stored serialized, or post fields
291 302 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
292 303 }
293 304 }
294 305
@@ -294,32 +305,9 @@
294 305
295 306 return $columns;
296 307 }
297 308
298 - /**
299 - * Can't sort on checkboxes because they are sorted serialized.
300 - * Some post content can be sorted but not everything.
301 - *
302 - * @param stdClass $field
303 - * @return bool
304 - */
305 - private static function field_supports_sorting( $field ) {
306 - $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
307 - return apply_filters( 'frm_field_column_is_sortable', $is_sortable, $field );
308 - }
309 -
310 - /**
311 - * @param mixed $result Option value from database for hidden columns in entries table.
312 - * @return array
313 - */
314 309 public static function hidden_columns( $result ) {
315 - if ( ! is_array( $result ) ) {
316 - // Force an unexpected value to be an array.
317 - // Since $result is a filtered option and gets saved to the database, it's possible it could be a string.
318 - // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
319 - $result = array();
320 - }
321 -
322 310 $form_id = FrmForm::get_current_form_id();
323 311
324 312 $hidden = self::user_hidden_columns_for_form( $form_id, $result );
325 313
@@ -326,10 +314,10 @@
326 314 global $frm_vars;
327 315 $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
328 316
329 317 if ( ! empty( $hidden ) ) {
330 - $result = $hidden;
331 - $i = $i - count( $result );
318 + $result = $hidden;
319 + $i = $i - count( $result );
332 320 $max_columns = 11;
333 321 } else {
334 322 $max_columns = 8;
335 323 }
@@ -358,9 +346,8 @@
358 346
359 347 unset( $form_prefix );
360 348 }
361 349 }
362 -
363 350 return $hidden;
364 351 }
365 352
366 353 /**
@@ -374,9 +361,9 @@
374 361 $remove_first = array(
375 362 $atts['form_id'] . '_item_key' => '',
376 363 $atts['form_id'] . '_id' => '',
377 364 );
378 - $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
365 + $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
379 366
380 367 $i = $atts['i'];
381 368
382 369 foreach ( $cols as $col_key => $col ) {
@@ -393,67 +380,65 @@
393 380 }
394 381 }
395 382
396 383 public static function display_list( $message = '', $errors = array() ) {
397 - global $wpdb, $frm_vars;
384 + global $wpdb, $frm_vars;
398 385
399 - $form = FrmForm::maybe_get_current_form();
386 + $form = FrmForm::maybe_get_current_form();
400 387 $params = FrmForm::get_admin_params( $form );
401 388
402 - if ( $form ) {
403 - $params['form'] = $form->id;
404 - $frm_vars['current_form'] = $form;
389 + if ( $form ) {
390 + $params['form'] = $form->id;
391 + $frm_vars['current_form'] = $form;
405 392
406 393 self::get_delete_form_time( $form, $errors );
407 394 }
408 395
409 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
396 + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
410 397
411 - $wp_list_table = new $table_class( array( 'params' => $params ) );
398 + $wp_list_table = new $table_class( array( 'params' => $params ) );
412 399
413 - $pagenum = $wp_list_table->get_pagenum();
400 + $pagenum = $wp_list_table->get_pagenum();
414 401
415 - $wp_list_table->prepare_items();
402 + $wp_list_table->prepare_items();
416 403
417 - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
418 - if ( $pagenum > $total_pages && $total_pages > 0 ) {
404 + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
405 + if ( $pagenum > $total_pages && $total_pages > 0 ) {
419 406 $url = add_query_arg( 'paged', $total_pages );
420 - if ( headers_sent() ) {
421 - FrmAppHelper::js_redirect( $url, true );
422 - } else {
423 - wp_redirect( esc_url_raw( $url ) );
424 - }
425 - die();
426 - }
407 + if ( headers_sent() ) {
408 + echo FrmAppHelper::js_redirect( $url ); // WPCS: XSS ok.
409 + } else {
410 + wp_redirect( esc_url_raw( $url ) );
411 + }
412 + die();
413 + }
427 414
428 415 if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
429 - $message = __( 'Your import is complete', 'formidable' );
430 - }
416 + $message = __( 'Your import is complete', 'formidable' );
417 + }
431 418
432 - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
433 - }
419 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' );
420 + }
434 421
435 422 private static function get_delete_form_time( $form, &$errors ) {
436 423 if ( 'trash' == $form->status ) {
437 424 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
438 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
439 -
440 - /* translators: %1$s: Time string */
441 - $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 );
425 + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
426 + $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 );
442 427 }
443 428 }
444 429
445 - /* Back End CRUD */
430 + /* Back End CRUD */
446 431 public static function show( $id = 0 ) {
447 432 FrmAppHelper::permission_check( 'frm_view_entries' );
448 433
449 - if ( ! $id ) {
434 + if ( ! $id ) {
450 435 $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
451 436
452 - if ( ! $id ) {
437 + if ( ! $id ) {
453 438 $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
454 - }
455 - }
439 + }
440 + }
456 441
457 442 $entry = FrmEntry::getOne( $id, true );
458 443 if ( ! $entry ) {
459 444 echo '<div id="form_show_entry_page" class="wrap">' .
@@ -458,86 +443,142 @@
458 443 if ( ! $entry ) {
459 444 echo '<div id="form_show_entry_page" class="wrap">' .
460 445 esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
461 446 '</div>';
462 -
463 447 return;
464 448 }
465 449
466 - $data = $entry->description;
450 + $data = maybe_unserialize( $entry->description );
467 451 if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
468 452 $data = array( 'referrer' => $data );
469 453 }
470 454
471 455 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
472 - $form = FrmForm::getOne( $entry->form_id );
456 + $to_emails = array();
457 + $form = FrmForm::getOne( $entry->form_id );
473 458
474 459 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
475 - }
460 + }
476 461
477 - /**
478 - * Destroy an entry from the admin page.
479 - * This is triggered from the entries list from the "Delete" row action, and also from the "Delete Entry" trigger in the view/edit entry sidebar.
480 - *
481 - * @return void
482 - */
483 - public static function destroy() {
484 - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
485 - if ( false !== $permission_error ) {
486 - wp_die( esc_html( $permission_error ) );
487 - }
462 + public static function destroy() {
463 + FrmAppHelper::permission_check( 'frm_delete_entries' );
488 464
489 465 $params = FrmForm::get_admin_params();
490 466
491 467 if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
492 468 self::unlink_post( $params['id'] );
493 - }
469 + }
494 470
495 - $message = '';
496 - if ( FrmEntry::destroy( $params['id'] ) ) {
497 - $message = __( 'Entry was successfully deleted', 'formidable' );
471 + $message = '';
472 + if ( FrmEntry::destroy( $params['id'] ) ) {
473 + $message = __( 'Entry was Successfully Destroyed', 'formidable' );
474 + }
475 +
476 + self::display_list( $message );
477 + }
478 +
479 + public static function destroy_all() {
480 + if ( ! current_user_can( 'frm_delete_entries' ) ) {
481 + $frm_settings = FrmAppHelper::get_settings();
482 + wp_die( esc_html( $frm_settings->admin_permission ) );
483 + }
484 +
485 + $params = FrmForm::get_admin_params();
486 + $message = '';
487 + $errors = array();
488 + $form_id = (int) $params['form'];
489 +
490 + if ( $form_id ) {
491 + $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
492 + $action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 );
493 +
494 + if ( $action ) {
495 + // this action takes a while, so only trigger it if there are posts to delete
496 + foreach ( $entry_ids as $entry_id ) {
497 + do_action( 'frm_before_destroy_entry', $entry_id );
498 + unset( $entry_id );
499 + }
500 + }
501 +
502 + $results = self::delete_form_entries( $form_id );
503 + if ( $results ) {
504 + FrmEntry::clear_cache();
505 + $message = __( 'Entries were Successfully Destroyed', 'formidable' );
506 + }
507 + } else {
508 + $errors = __( 'No entries were specified', 'formidable' );
509 + }
510 +
511 + self::display_list( $message, $errors );
512 + }
513 +
514 + /**
515 + * @since 3.01
516 + * @param int $form_id
517 + */
518 + private static function delete_form_entries( $form_id ) {
519 + global $wpdb;
520 +
521 + $form_ids = self::get_child_form_ids( $form_id );
522 +
523 + $meta_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) WHERE form_id=%d", $form_id );
524 + $entry_query = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id );
525 +
526 + if ( ! empty( $form_ids ) ) {
527 + $form_query = ' OR form_id in (' . $form_ids . ')';
528 + $meta_query .= $form_query;
529 + $entry_query .= $form_query;
498 530 }
499 531
500 - self::display_list( $message );
532 + $wpdb->query( $meta_query ); // WPCS: unprepared SQL ok.
533 + return $wpdb->query( $entry_query ); // WPCS: unprepared SQL ok.
501 534 }
502 535
503 536 /**
504 - * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite.
537 + * @since 3.01
538 + * @param int $form_id
539 + * @param bool|string $implode
505 540 */
506 - public static function destroy_all() {
507 - _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' );
508 - if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) {
509 - FrmProEntriesController::destroy_all();
541 + private static function get_child_form_ids( $form_id, $implode = ',' ) {
542 + $form_ids = array();
543 + $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) );
544 + if ( $child_form_ids ) {
545 + $form_ids = $child_form_ids;
510 546 }
547 + $form_ids = array_filter( $form_ids, 'is_numeric' );
548 + if ( $implode ) {
549 + $form_ids = implode( $implode, $form_ids );
550 + }
551 + return $form_ids;
511 552 }
512 553
513 - public static function process_entry( $errors = '', $ajax = false ) {
554 + public static function process_entry( $errors = '', $ajax = false ) {
514 555 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
515 - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
516 - return;
517 - }
556 + if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
557 + return;
558 + }
518 559
519 - global $frm_vars;
560 + global $frm_vars;
520 561
521 562 $form = FrmForm::getOne( $form_id );
522 - if ( ! $form ) {
523 - return;
524 - }
563 + if ( ! $form ) {
564 + return;
565 + }
525 566
526 567 $params = FrmForm::get_params( $form );
527 568
528 - if ( ! isset( $frm_vars['form_params'] ) ) {
529 - $frm_vars['form_params'] = array();
530 - }
569 + if ( ! isset( $frm_vars['form_params'] ) ) {
570 + $frm_vars['form_params'] = array();
571 + }
531 572 $frm_vars['form_params'][ $form->id ] = $params;
532 573
533 574 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
534 - return;
535 - }
575 + return;
576 + }
536 577
537 - if ( $errors == '' && ! $ajax ) {
538 - $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
539 - }
578 + if ( $errors == '' && ! $ajax ) {
579 + $errors = FrmEntryValidate::validate( $_POST );
580 + }
540 581
541 582 /**
542 583 * Use this filter to add trigger actions and add errors after
543 584 * all other errors have been processed
@@ -547,27 +588,26 @@
547 588 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
548 589
549 590 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
550 591
551 - if ( empty( $errors ) ) {
592 + if ( empty( $errors ) ) {
552 593 $_POST['frm_skip_cookie'] = 1;
553 - $do_success = false;
554 - if ( $params['action'] === 'create' ) {
594 + $do_success = false;
595 + if ( $params['action'] == 'create' ) {
555 596 if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
556 - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
557 -
597 + $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
558 598 $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
559 - $do_success = true;
560 - }
561 - }
599 + $do_success = true;
600 + }
601 + }
562 602
563 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
603 + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
564 604 if ( $do_success ) {
565 605 FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
566 606 }
567 - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
568 - }
569 - }
607 + unset( $_POST['frm_skip_cookie'] );
608 + }
609 + }
570 610
571 611 /**
572 612 * Escape url entities before redirect
573 613 *
@@ -573,9 +613,8 @@
573 613 *
574 614 * @since 3.0
575 615 *
576 616 * @param string $url
577 - *
578 617 * @return string
579 618 */
580 619 public static function prepare_redirect_url( $url ) {
581 620 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
@@ -580,34 +619,29 @@
580 619 public static function prepare_redirect_url( $url ) {
581 620 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
582 621 }
583 622
584 - public static function delete_entry_before_redirect( $url, $form, $atts ) {
585 - self::_delete_entry( $atts['id'], $form );
623 + public static function delete_entry_before_redirect( $url, $form, $atts ) {
624 + self::_delete_entry( $atts['id'], $form );
625 + return $url;
626 + }
586 627
587 - return $url;
588 - }
628 + //Delete entry if not redirected
629 + public static function delete_entry_after_save( $atts ) {
630 + self::_delete_entry( $atts['entry_id'], $atts['form'] );
631 + }
589 632
590 - /**
591 - * Delete entry if not redirected.
592 - *
593 - * @param array $atts
594 - */
595 - public static function delete_entry_after_save( $atts ) {
596 - self::_delete_entry( $atts['entry_id'], $atts['form'] );
597 - }
633 + private static function _delete_entry( $entry_id, $form ) {
634 + if ( ! $form ) {
635 + return;
636 + }
598 637
599 - private static function _delete_entry( $entry_id, $form ) {
600 - if ( ! $form ) {
601 - return;
602 - }
603 -
604 - FrmAppHelper::unserialize_or_decode( $form->options );
605 - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
638 + $form->options = maybe_unserialize( $form->options );
639 + if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
606 640 self::unlink_post( $entry_id );
607 - FrmEntry::destroy( $entry_id );
608 - }
609 - }
641 + FrmEntry::destroy( $entry_id );
642 + }
643 + }
610 644
611 645 /**
612 646 * Unlink entry from post
613 647 */
@@ -623,34 +657,31 @@
623 657 * @return array|string
624 658 */
625 659 public static function show_entry_shortcode( $atts ) {
626 660 $defaults = array(
627 - 'id' => false,
628 - 'entry' => false,
629 - 'fields' => false,
630 - 'plain_text' => false,
631 - 'user_info' => false,
632 - 'include_blank' => false,
633 - 'default_email' => false,
634 - 'form_id' => false,
635 - 'format' => 'text',
636 - 'array_key' => 'key',
637 - 'direction' => 'ltr',
638 - 'font_size' => '',
639 - 'text_color' => '',
640 - 'border_width' => '',
641 - 'border_color' => '',
642 - 'bg_color' => '',
643 - 'alt_bg_color' => '',
644 - 'class' => '',
645 - 'clickable' => false,
646 - 'exclude_fields' => '',
647 - 'include_fields' => '',
648 - 'include_extras' => '',
649 - 'inline_style' => 1,
650 - 'child_array' => false, // return embedded fields as nested array
651 - 'line_breaks' => true,
652 - 'array_separator' => ', ',
661 + 'id' => false,
662 + 'entry' => false,
663 + 'fields' => false,
664 + 'plain_text' => false,
665 + 'user_info' => false,
666 + 'include_blank' => false,
667 + 'default_email' => false,
668 + 'form_id' => false,
669 + 'format' => 'text',
670 + 'array_key' => 'key',
671 + 'direction' => 'ltr',
672 + 'font_size' => '',
673 + 'text_color' => '',
674 + 'border_width' => '',
675 + 'border_color' => '',
676 + 'bg_color' => '',
677 + 'alt_bg_color' => '',
678 + 'clickable' => false,
679 + 'exclude_fields' => '',
680 + 'include_fields' => '',
681 + 'include_extras' => '',
682 + 'inline_style' => 1,
683 + 'child_array' => false, // return embedded fields as nested array
653 684 );
654 685 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
655 686
656 687 $atts = shortcode_atts( $defaults, $atts );
@@ -659,12 +690,11 @@
659 690 $shortcode_atts = array(
660 691 'format' => $atts['format'],
661 692 'plain_text' => $atts['plain_text'],
662 693 );
694 + $entry_shortcode_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
695 + $formatted_entry = $entry_shortcode_formatter->content();
663 696
664 - $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
665 - $formatted_entry = $entry_formatter->content();
666 -
667 697 } else {
668 698
669 699 $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
670 700 $formatted_entry = $entry_formatter->get_formatted_entry_values();
@@ -673,37 +703,31 @@
673 703
674 704 return $formatted_entry;
675 705 }
676 706
677 - public static function entry_sidebar( $entry = false ) {
678 - $data = array();
679 - $id = 0;
680 -
707 + public static function entry_sidebar( $entry ) {
708 + $data = maybe_unserialize( $entry->description );
681 709 $date_format = get_option( 'date_format' );
682 710 $time_format = get_option( 'time_format' );
683 -
684 - if ( $entry ) {
685 - $id = $entry->id;
686 - $data = $entry->description;
687 - if ( isset( $data['browser'] ) ) {
688 - $browser = FrmEntriesHelper::get_browser( $data['browser'] );
689 - }
690 - /**
691 - * Add or remove information in the entry sidebar.
692 - *
693 - * @since 5.5.2
694 - * @param array $data
695 - */
696 - $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
711 + if ( isset( $data['browser'] ) ) {
712 + $browser = FrmEntriesHelper::get_browser( $data['browser'] );
697 713 }
698 714
699 715 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
716 + }
717 +
718 + /**
719 + * @deprecated 1.07.05
720 + * @codeCoverageIgnore
721 + */
722 + public static function show_form( $id = '', $key = '', $title = false, $description = false ) {
723 + return FrmDeprecated::show_form( $id, $key, $title, $description );
700 724 }
701 725
702 726 /**
703 - * @deprecated 4.0
727 + * @deprecated 1.07.05
728 + * @codeCoverageIgnore
704 729 */
705 - public static function contextual_help( $help, $screen_id, $screen ) {
706 - _deprecated_function( __METHOD__, '4.0' );
707 - return $help;
730 + public static function get_form( $filename, $form, $title, $description ) {
731 + return FrmDeprecated::get_form( $filename, $form, $title, $description );
708 732 }
709 733 }