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 +298 -273 6.33.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,12 +97,12 @@
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 );
@@ -81,9 +107,9 @@
81 107 if ( $form_id ) {
82 108 self::get_columns_for_form( $form_id, $columns );
83 109 } else {
84 110 $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
85 - $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
111 + $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
86 112 $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' );
87 113 }
88 114
89 115 $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
@@ -89,9 +115,9 @@
89 115 $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
90 116 $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
91 117 self::maybe_add_ip_col( $form_id, $columns );
92 118
93 - $frm_vars['cols'] = $columns;
119 + $frm_vars['cols'] = $columns;
94 120
95 121 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
96 122 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
97 123 add_screen_option(
@@ -101,26 +127,16 @@
101 127 'default' => 20,
102 128 'option' => 'formidable_page_formidable_entries_per_page',
103 129 )
104 130 );
105 - }
131 + }
106 132
107 - return $columns;
108 - }
133 + return $columns;
134 + }
109 135
110 136 private static function get_columns_for_form( $form_id, &$columns ) {
111 137 $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
112 138
113 - /**
114 - * Allows changing fields in the Entries list table heading.
115 - *
116 - * @since 5.0.04
117 - *
118 - * @param array $fields Array of fields.
119 - * @param array $args The arguments. Contains `form_id`.
120 - */
121 - $form_cols = apply_filters( 'frm_fields_in_entries_list_table', $form_cols, compact( 'form_id' ) );
122 -
123 139 foreach ( $form_cols as $form_col ) {
124 140 if ( FrmField::is_no_save_field( $form_col->type ) ) {
125 141 continue;
126 142 }
@@ -179,71 +195,69 @@
179 195
180 196 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
181 197 $this_page_name = self::hidden_column_key();
182 198 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
183 - return $check;
184 - }
199 + return $check;
200 + }
185 201
186 202 if ( empty( $prev_value ) ) {
187 203 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
188 204 }
189 205
190 - global $frm_vars;
206 + global $frm_vars;
191 207 //add a check so we don't create a loop
192 208 $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
193 209
194 - return $check;
195 - }
210 + return $check;
211 + }
196 212
197 - /**
198 - * Add hidden columns back from other forms
199 - */
213 + //add hidden columns back from other forms
200 214 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
201 215 $this_page_name = self::hidden_column_key();
202 216 if ( $meta_key != $this_page_name ) {
203 - return;
204 - }
217 + return;
218 + }
205 219
206 220 global $frm_vars;
207 221 if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
208 - return; // Don't continue if there's no previous value.
222 + return; //don't continue if there's no previous value
209 223 }
210 224
211 - foreach ( $meta_value as $mk => $mv ) {
212 - // Remove blank values.
213 - if ( empty( $mv ) ) {
214 - unset( $meta_value[ $mk ] );
215 - }
216 - }
225 + foreach ( $meta_value as $mk => $mv ) {
226 + //remove blank values
227 + if ( empty( $mv ) ) {
228 + unset( $meta_value[ $mk ] );
229 + }
230 + }
217 231
218 232 $cur_form_prefix = reset( $meta_value );
219 233 $cur_form_prefix = explode( '_', $cur_form_prefix );
220 - $cur_form_prefix = $cur_form_prefix[0];
221 - $save = false;
234 + $cur_form_prefix = $cur_form_prefix[0];
235 + $save = false;
222 236
223 - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
237 + foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
224 238 if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
225 - // Don't add blank cols or process included cols.
226 - continue;
227 - }
239 + //don't add blank cols or process included cols
240 + continue;
241 + }
228 242
229 243 $form_prefix = explode( '_', $prev_hidden );
230 - $form_prefix = $form_prefix[0];
231 - if ( $form_prefix == $cur_form_prefix ) {
232 - // Don't add back columns that are meant to be hidden.
233 - continue;
234 - }
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 + }
235 249
236 - $meta_value[] = $prev_hidden;
237 - $save = true;
250 + $meta_value[] = $prev_hidden;
251 + $save = true;
238 252 unset( $form_prefix );
239 - }
253 + }
240 254
241 255 if ( $save ) {
242 256 $user_id = get_current_user_id();
243 257 update_user_option( $user_id, $this_page_name, $meta_value, true );
244 - }
245 - }
258 + }
259 + }
246 260
247 261 /**
248 262 * @since 2.05.07
249 263 */
@@ -248,9 +262,8 @@
248 262 * @since 2.05.07
249 263 */
250 264 private static function hidden_column_key( $menu_name = '' ) {
251 265 $base = self::base_column_key( $menu_name );
252 -
253 266 return 'manage' . $base . 'columnshidden';
254 267 }
255 268
256 269 /**
@@ -259,23 +272,21 @@
259 272 private static function base_column_key( $menu_name = '' ) {
260 273 if ( empty( $menu_name ) ) {
261 274 $menu_name = FrmAppHelper::get_menu_name();
262 275 }
263 -
264 276 return sanitize_title( $menu_name ) . '_page_formidable-entries';
265 277 }
266 278
267 279 public static function save_per_page( $save, $option, $value ) {
268 - if ( $option == 'formidable_page_formidable_entries_per_page' ) {
269 - $save = (int) $value;
270 - }
280 + if ( $option == 'formidable_page_formidable_entries_per_page' ) {
281 + $save = (int) $value;
282 + }
283 + return $save;
284 + }
271 285
272 - return $save;
273 - }
274 -
275 286 public static function sortable_columns() {
276 287 $form_id = FrmForm::get_current_form_id();
277 - $fields = FrmField::get_all_for_form( $form_id );
288 + $fields = FrmField::get_all_for_form( $form_id );
278 289
279 290 $columns = array(
280 291 $form_id . '_id' => 'id',
281 292 $form_id . '_created_at' => 'created_at',
@@ -285,9 +296,10 @@
285 296 $form_id . '_is_draft' => 'is_draft',
286 297 );
287 298
288 299 foreach ( $fields as $field ) {
289 - 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
290 302 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
291 303 }
292 304 }
293 305
@@ -293,32 +305,9 @@
293 305
294 306 return $columns;
295 307 }
296 308
297 - /**
298 - * Can't sort on checkboxes because they are sorted serialized.
299 - * Some post content can be sorted but not everything.
300 - *
301 - * @param stdClass $field
302 - * @return bool
303 - */
304 - private static function field_supports_sorting( $field ) {
305 - $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
306 - return apply_filters( 'frm_field_column_is_sortable', $is_sortable, $field );
307 - }
308 -
309 - /**
310 - * @param mixed $result Option value from database for hidden columns in entries table.
311 - * @return array
312 - */
313 309 public static function hidden_columns( $result ) {
314 - if ( ! is_array( $result ) ) {
315 - // Force an unexpected value to be an array.
316 - // Since $result is a filtered option and gets saved to the database, it's possible it could be a string.
317 - // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
318 - $result = array();
319 - }
320 -
321 310 $form_id = FrmForm::get_current_form_id();
322 311
323 312 $hidden = self::user_hidden_columns_for_form( $form_id, $result );
324 313
@@ -325,10 +314,10 @@
325 314 global $frm_vars;
326 315 $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
327 316
328 317 if ( ! empty( $hidden ) ) {
329 - $result = $hidden;
330 - $i = $i - count( $result );
318 + $result = $hidden;
319 + $i = $i - count( $result );
331 320 $max_columns = 11;
332 321 } else {
333 322 $max_columns = 8;
334 323 }
@@ -357,9 +346,8 @@
357 346
358 347 unset( $form_prefix );
359 348 }
360 349 }
361 -
362 350 return $hidden;
363 351 }
364 352
365 353 /**
@@ -373,9 +361,9 @@
373 361 $remove_first = array(
374 362 $atts['form_id'] . '_item_key' => '',
375 363 $atts['form_id'] . '_id' => '',
376 364 );
377 - $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
365 + $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
378 366
379 367 $i = $atts['i'];
380 368
381 369 foreach ( $cols as $col_key => $col ) {
@@ -392,67 +380,65 @@
392 380 }
393 381 }
394 382
395 383 public static function display_list( $message = '', $errors = array() ) {
396 - global $wpdb, $frm_vars;
384 + global $wpdb, $frm_vars;
397 385
398 - $form = FrmForm::maybe_get_current_form();
386 + $form = FrmForm::maybe_get_current_form();
399 387 $params = FrmForm::get_admin_params( $form );
400 388
401 - if ( $form ) {
402 - $params['form'] = $form->id;
403 - $frm_vars['current_form'] = $form;
389 + if ( $form ) {
390 + $params['form'] = $form->id;
391 + $frm_vars['current_form'] = $form;
404 392
405 393 self::get_delete_form_time( $form, $errors );
406 394 }
407 395
408 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
396 + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
409 397
410 - $wp_list_table = new $table_class( array( 'params' => $params ) );
398 + $wp_list_table = new $table_class( array( 'params' => $params ) );
411 399
412 - $pagenum = $wp_list_table->get_pagenum();
400 + $pagenum = $wp_list_table->get_pagenum();
413 401
414 - $wp_list_table->prepare_items();
402 + $wp_list_table->prepare_items();
415 403
416 - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
417 - 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 ) {
418 406 $url = add_query_arg( 'paged', $total_pages );
419 - if ( headers_sent() ) {
420 - FrmAppHelper::js_redirect( $url, true );
421 - } else {
422 - wp_redirect( esc_url_raw( $url ) );
423 - }
424 - die();
425 - }
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 + }
426 414
427 415 if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
428 - $message = __( 'Your import is complete', 'formidable' );
429 - }
416 + $message = __( 'Your import is complete', 'formidable' );
417 + }
430 418
431 - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
432 - }
419 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' );
420 + }
433 421
434 422 private static function get_delete_form_time( $form, &$errors ) {
435 423 if ( 'trash' == $form->status ) {
436 424 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
437 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
438 -
439 - /* translators: %1$s: Time string */
440 - $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 );
441 427 }
442 428 }
443 429
444 - /* Back End CRUD */
430 + /* Back End CRUD */
445 431 public static function show( $id = 0 ) {
446 432 FrmAppHelper::permission_check( 'frm_view_entries' );
447 433
448 - if ( ! $id ) {
434 + if ( ! $id ) {
449 435 $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
450 436
451 - if ( ! $id ) {
437 + if ( ! $id ) {
452 438 $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
453 - }
454 - }
439 + }
440 + }
455 441
456 442 $entry = FrmEntry::getOne( $id, true );
457 443 if ( ! $entry ) {
458 444 echo '<div id="form_show_entry_page" class="wrap">' .
@@ -457,86 +443,142 @@
457 443 if ( ! $entry ) {
458 444 echo '<div id="form_show_entry_page" class="wrap">' .
459 445 esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
460 446 '</div>';
461 -
462 447 return;
463 448 }
464 449
465 - $data = $entry->description;
450 + $data = maybe_unserialize( $entry->description );
466 451 if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
467 452 $data = array( 'referrer' => $data );
468 453 }
469 454
470 455 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
471 - $form = FrmForm::getOne( $entry->form_id );
456 + $to_emails = array();
457 + $form = FrmForm::getOne( $entry->form_id );
472 458
473 459 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
474 - }
460 + }
475 461
476 - /**
477 - * Destroy an entry from the admin page.
478 - * 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.
479 - *
480 - * @return void
481 - */
482 - public static function destroy() {
483 - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
484 - if ( false !== $permission_error ) {
485 - wp_die( esc_html( $permission_error ) );
486 - }
462 + public static function destroy() {
463 + FrmAppHelper::permission_check( 'frm_delete_entries' );
487 464
488 465 $params = FrmForm::get_admin_params();
489 466
490 467 if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
491 468 self::unlink_post( $params['id'] );
492 - }
469 + }
493 470
494 - $message = '';
495 - if ( FrmEntry::destroy( $params['id'] ) ) {
496 - $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;
497 530 }
498 531
499 - self::display_list( $message );
532 + $wpdb->query( $meta_query ); // WPCS: unprepared SQL ok.
533 + return $wpdb->query( $entry_query ); // WPCS: unprepared SQL ok.
500 534 }
501 535
502 536 /**
503 - * @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
504 540 */
505 - public static function destroy_all() {
506 - _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' );
507 - if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) {
508 - 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;
509 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;
510 552 }
511 553
512 - public static function process_entry( $errors = '', $ajax = false ) {
554 + public static function process_entry( $errors = '', $ajax = false ) {
513 555 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
514 - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
515 - return;
516 - }
556 + if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
557 + return;
558 + }
517 559
518 - global $frm_vars;
560 + global $frm_vars;
519 561
520 562 $form = FrmForm::getOne( $form_id );
521 - if ( ! $form ) {
522 - return;
523 - }
563 + if ( ! $form ) {
564 + return;
565 + }
524 566
525 567 $params = FrmForm::get_params( $form );
526 568
527 - if ( ! isset( $frm_vars['form_params'] ) ) {
528 - $frm_vars['form_params'] = array();
529 - }
569 + if ( ! isset( $frm_vars['form_params'] ) ) {
570 + $frm_vars['form_params'] = array();
571 + }
530 572 $frm_vars['form_params'][ $form->id ] = $params;
531 573
532 574 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
533 - return;
534 - }
575 + return;
576 + }
535 577
536 - if ( $errors == '' && ! $ajax ) {
537 - $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
538 - }
578 + if ( $errors == '' && ! $ajax ) {
579 + $errors = FrmEntryValidate::validate( $_POST );
580 + }
539 581
540 582 /**
541 583 * Use this filter to add trigger actions and add errors after
542 584 * all other errors have been processed
@@ -546,27 +588,26 @@
546 588 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
547 589
548 590 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
549 591
550 - if ( empty( $errors ) ) {
592 + if ( empty( $errors ) ) {
551 593 $_POST['frm_skip_cookie'] = 1;
552 - $do_success = false;
553 - if ( $params['action'] === 'create' ) {
594 + $do_success = false;
595 + if ( $params['action'] == 'create' ) {
554 596 if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
555 - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
556 -
597 + $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
557 598 $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
558 - $do_success = true;
559 - }
560 - }
599 + $do_success = true;
600 + }
601 + }
561 602
562 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
603 + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
563 604 if ( $do_success ) {
564 605 FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
565 606 }
566 - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
567 - }
568 - }
607 + unset( $_POST['frm_skip_cookie'] );
608 + }
609 + }
569 610
570 611 /**
571 612 * Escape url entities before redirect
572 613 *
@@ -572,9 +613,8 @@
572 613 *
573 614 * @since 3.0
574 615 *
575 616 * @param string $url
576 - *
577 617 * @return string
578 618 */
579 619 public static function prepare_redirect_url( $url ) {
580 620 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
@@ -579,34 +619,29 @@
579 619 public static function prepare_redirect_url( $url ) {
580 620 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
581 621 }
582 622
583 - public static function delete_entry_before_redirect( $url, $form, $atts ) {
584 - 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 + }
585 627
586 - return $url;
587 - }
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 + }
588 632
589 - /**
590 - * Delete entry if not redirected.
591 - *
592 - * @param array $atts
593 - */
594 - public static function delete_entry_after_save( $atts ) {
595 - self::_delete_entry( $atts['entry_id'], $atts['form'] );
596 - }
633 + private static function _delete_entry( $entry_id, $form ) {
634 + if ( ! $form ) {
635 + return;
636 + }
597 637
598 - private static function _delete_entry( $entry_id, $form ) {
599 - if ( ! $form ) {
600 - return;
601 - }
602 -
603 - FrmAppHelper::unserialize_or_decode( $form->options );
604 - 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'] ) {
605 640 self::unlink_post( $entry_id );
606 - FrmEntry::destroy( $entry_id );
607 - }
608 - }
641 + FrmEntry::destroy( $entry_id );
642 + }
643 + }
609 644
610 645 /**
611 646 * Unlink entry from post
612 647 */
@@ -622,34 +657,31 @@
622 657 * @return array|string
623 658 */
624 659 public static function show_entry_shortcode( $atts ) {
625 660 $defaults = array(
626 - 'id' => false,
627 - 'entry' => false,
628 - 'fields' => false,
629 - 'plain_text' => false,
630 - 'user_info' => false,
631 - 'include_blank' => false,
632 - 'default_email' => false,
633 - 'form_id' => false,
634 - 'format' => 'text',
635 - 'array_key' => 'key',
636 - 'direction' => 'ltr',
637 - 'font_size' => '',
638 - 'text_color' => '',
639 - 'border_width' => '',
640 - 'border_color' => '',
641 - 'bg_color' => '',
642 - 'alt_bg_color' => '',
643 - 'class' => '',
644 - 'clickable' => false,
645 - 'exclude_fields' => '',
646 - 'include_fields' => '',
647 - 'include_extras' => '',
648 - 'inline_style' => 1,
649 - 'child_array' => false, // return embedded fields as nested array
650 - 'line_breaks' => true,
651 - '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
652 684 );
653 685 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
654 686
655 687 $atts = shortcode_atts( $defaults, $atts );
@@ -658,12 +690,11 @@
658 690 $shortcode_atts = array(
659 691 'format' => $atts['format'],
660 692 'plain_text' => $atts['plain_text'],
661 693 );
694 + $entry_shortcode_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
695 + $formatted_entry = $entry_shortcode_formatter->content();
662 696
663 - $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
664 - $formatted_entry = $entry_formatter->content();
665 -
666 697 } else {
667 698
668 699 $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
669 700 $formatted_entry = $entry_formatter->get_formatted_entry_values();
@@ -672,37 +703,31 @@
672 703
673 704 return $formatted_entry;
674 705 }
675 706
676 - public static function entry_sidebar( $entry = false ) {
677 - $data = array();
678 - $id = 0;
679 -
707 + public static function entry_sidebar( $entry ) {
708 + $data = maybe_unserialize( $entry->description );
680 709 $date_format = get_option( 'date_format' );
681 710 $time_format = get_option( 'time_format' );
682 -
683 - if ( $entry ) {
684 - $id = $entry->id;
685 - $data = $entry->description;
686 - if ( isset( $data['browser'] ) ) {
687 - $browser = FrmEntriesHelper::get_browser( $data['browser'] );
688 - }
689 - /**
690 - * Add or remove information in the entry sidebar.
691 - *
692 - * @since 5.5.2
693 - * @param array $data
694 - */
695 - $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
711 + if ( isset( $data['browser'] ) ) {
712 + $browser = FrmEntriesHelper::get_browser( $data['browser'] );
696 713 }
697 714
698 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 );
699 724 }
700 725
701 726 /**
702 - * @deprecated 4.0
727 + * @deprecated 1.07.05
728 + * @codeCoverageIgnore
703 729 */
704 - public static function contextual_help( $help, $screen_id, $screen ) {
705 - _deprecated_function( __METHOD__, '4.0' );
706 - return $help;
730 + public static function get_form( $filename, $form, $title, $description ) {
731 + return FrmDeprecated::get_form( $filename, $form, $title, $description );
707 732 }
708 733 }