PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +413 -143 6.5.2 → trunk View file →
@@ -4,16 +4,23 @@
4 4 }
5 5
6 6 class FrmEntriesController {
7 7
8 + /**
9 + * @return void
10 + */
8 11 public static function menu() {
9 12 FrmAppHelper::force_capability( 'frm_view_entries' );
10 13
11 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
14 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
12 15
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 + $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
17 +
18 + if ( $views_installed ) {
19 + self::maybe_redirect_to_views_index();
20 + } else {
21 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
22 + self::maybe_redirect_to_views_upsell();
16 23 }
17 24
18 25 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
19 26 self::load_manage_entries_hooks();
@@ -20,24 +27,98 @@
20 27 }
21 28 }
22 29
23 30 /**
31 + * This function is called when views is installed.
32 + * The Views add-on uses a different URL for the Views tab than the upsell page.
33 + * If the user is on the upsell page, instead of showing a permission error on reload,
34 + * redirect to the views index page.
35 + *
36 + * @since 6.14.1
37 + *
38 + * @return void
39 + */
40 + private static function maybe_redirect_to_views_index() {
41 + if ( ! FrmAppHelper::is_admin_page( 'formidable-views' ) ) {
42 + return;
43 + }
44 +
45 + $query_args = array(
46 + 'post_type' => 'frm_display',
47 + );
48 + $query_args = self::add_url_params_to_views_redirect_query_args( $query_args );
49 +
50 + wp_safe_redirect( add_query_arg( $query_args, admin_url( 'edit.php' ) ) );
51 + die();
52 + }
53 +
54 + /**
55 + * This function is called when views is inactive.
56 + * A user may deactivate views but then try to reload the views index.
57 + * Instead of showing a permission error, redirect to the views upsell page.
58 + *
59 + * @since 6.14.1
60 + *
61 + * @return void
62 + */
63 + private static function maybe_redirect_to_views_upsell() {
64 + global $pagenow;
65 +
66 + if ( 'edit.php' !== $pagenow || 'frm_display' !== FrmAppHelper::simple_get( 'post_type' ) ) {
67 + return;
68 + }
69 +
70 + $query_args = array(
71 + 'page' => 'formidable-views',
72 + );
73 + $query_args = self::add_url_params_to_views_redirect_query_args( $query_args );
74 +
75 + wp_safe_redirect( add_query_arg( $query_args, admin_url( 'admin.php' ) ) );
76 + die();
77 + }
78 +
79 + /**
80 + * @since 6.14.1
81 + *
82 + * @param array $query_args
83 + *
84 + * @return array
85 + */
86 + private static function add_url_params_to_views_redirect_query_args( $query_args ) {
87 + $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 );
88 + $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
89 +
90 + if ( $form_id ) {
91 + $query_args['form'] = $form_id;
92 + }
93 +
94 + return $query_args;
95 + }
96 +
97 + /**
24 98 * @since 2.05.07
99 + *
100 + * @return void
25 101 */
26 102 private static function load_manage_entries_hooks() {
27 - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
28 - $menu_name = FrmAppHelper::get_menu_name();
29 - $base = self::base_column_key( $menu_name );
103 + if ( in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
104 + add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 );
105 + return;
106 + }
30 107
31 - add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
32 - add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
33 - add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
34 - } else {
35 - add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 );
36 - }
108 + $menu_name = FrmAppHelper::get_menu_name();
109 + $base = self::base_column_key( $menu_name );
110 +
111 + add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
112 + add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
113 + add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
37 114 }
38 115
39 - /* Display in Back End */
116 + /**
117 + * Display in Back End.
118 + *
119 + * @return mixed
120 + */
40 121 public static function route() {
41 122 $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
42 123 FrmAppHelper::include_svg();
43 124
@@ -47,13 +128,15 @@
47 128 return self::$action();
48 129
49 130 default:
50 131 do_action( 'frm_entry_action_route', $action );
132 +
51 133 if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
52 - return;
134 + return null;
53 135 }
54 136
55 - return self::display_list();
137 + self::display_list();
138 + return null;
56 139 }
57 140 }
58 141
59 142 /**
@@ -60,18 +143,30 @@
60 143 * Prevent the "screen options" tab from showing when
61 144 * editing or creating an entry
62 145 *
63 146 * @since 3.0
147 + *
148 + * @param bool $show_screen Whether to show the screen options tab.
149 + * @param object $screen The current screen object.
150 + *
151 + * @return bool
64 152 */
65 153 public static function remove_screen_options( $show_screen, $screen ) {
66 - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
67 - if ( $screen->id == $menu_name . '_page_formidable-entries' ) {
68 - $show_screen = false;
154 + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
155 + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
156 +
157 + if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) {
158 + return false;
69 159 }
70 160
71 161 return $show_screen;
72 162 }
73 163
164 + /**
165 + * @param array $columns
166 + *
167 + * @return array
168 + */
74 169 public static function manage_columns( $columns ) {
75 170 global $frm_vars;
76 171 $form_id = FrmForm::get_current_form_id();
77 172
@@ -86,16 +181,16 @@
86 181 $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' );
87 182 }
88 183
89 184 $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
90 - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
91 - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
185 + $columns[ $form_id . '_created_at' ] = esc_html__( 'Entry creation date', 'formidable' );
186 + $columns[ $form_id . '_updated_at' ] = esc_html__( 'Entry update date', 'formidable' );
92 187 self::maybe_add_ip_col( $form_id, $columns );
93 188
94 189 $frm_vars['cols'] = $columns;
190 + $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
95 191
96 - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
97 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
192 + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ), true ) ) {
98 193 add_screen_option(
99 194 'per_page',
100 195 array(
101 196 'label' => esc_html__( 'Entries', 'formidable' ),
@@ -107,8 +202,14 @@
107 202
108 203 return $columns;
109 204 }
110 205
206 + /**
207 + * @param int|string $form_id
208 + * @param array $columns
209 + *
210 + * @return void
211 + */
111 212 private static function get_columns_for_form( $form_id, &$columns ) {
112 213 $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
113 214
114 215 /**
@@ -125,9 +226,10 @@
125 226 if ( FrmField::is_no_save_field( $form_col->type ) ) {
126 227 continue;
127 228 }
128 229
129 - $has_child_fields = $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] );
230 + $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] );
231 +
130 232 if ( $has_child_fields ) {
131 233 self::add_subform_cols( $form_col, $form_id, $columns );
132 234 } else {
133 235 self::add_field_cols( $form_col, $form_id, $columns );
@@ -136,12 +238,19 @@
136 238 }
137 239
138 240 /**
139 241 * @since 3.01
242 + *
243 + * @param object $field The field object.
244 + * @param int|string $form_id The form ID.
245 + * @param array $columns The columns array.
246 + *
247 + * @return void
140 248 */
141 249 private static function add_subform_cols( $field, $form_id, &$columns ) {
142 250 $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] );
143 - if ( empty( $sub_form_cols ) ) {
251 +
252 + if ( ! $sub_form_cols ) {
144 253 return;
145 254 }
146 255
147 256 foreach ( $sub_form_cols as $k => $sub_form_col ) {
@@ -148,8 +257,9 @@
148 257 if ( FrmField::is_no_save_field( $sub_form_col->type ) ) {
149 258 unset( $sub_form_cols[ $k ] );
150 259 continue;
151 260 }
261 +
152 262 $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
153 263 unset( $sub_form_col );
154 264 }
155 265 }
@@ -155,24 +265,62 @@
155 265 }
156 266
157 267 /**
158 268 * @since 3.01
269 + *
270 + * @param object $field The field object.
271 + * @param int|string $form_id The form ID.
272 + * @param array $columns The columns array.
273 + *
274 + * @return void
159 275 */
160 276 private static function add_field_cols( $field, $form_id, &$columns ) {
161 277 $col_id = $field->field_key;
162 - if ( $field->form_id != $form_id ) {
278 +
279 + if ( (int) $field->form_id !== (int) $form_id ) {
163 280 $col_id .= '-_-form' . $field->form_id;
164 281 }
165 282
166 - $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
167 - $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] == 'post_status';
168 - if ( $has_separate_value && ! $is_post_status ) {
169 - $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
283 + $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
284 + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
285 + $include_column_for_sep_val = $has_separate_value && ! $is_post_status;
286 +
287 + if ( $include_column_for_sep_val ) {
288 + $columns[ $form_id . '_frmsep_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val );
170 289 }
171 290
172 - $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
291 + $columns[ $form_id . '_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, false );
173 292 }
174 293
294 + /**
295 + * Appends "(Value)" or "(Label)" to the field name if it's an option field that has a separate value/label.
296 + *
297 + * @since 6.25.1
298 + *
299 + * @param object $field
300 + * @param bool $include_column_for_sep_val
301 + * @param bool $is_value
302 + *
303 + * @return string
304 + */
305 + private static function maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, $is_value = true ) {
306 + $field_name = FrmAppHelper::truncate( $field->name, 35 );
307 +
308 + if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox', 'product', 'ranking' ), true ) ) {
309 + return $field_name;
310 + }
311 +
312 + $append_text = $is_value ? esc_html__( 'value', 'formidable' ) : esc_html__( 'label', 'formidable' );
313 +
314 + return sprintf( '%s (%s)', $field_name, $append_text );
315 + }
316 +
317 + /**
318 + * @param int|string $form_id The form ID.
319 + * @param array $columns The columns array.
320 + *
321 + * @return void
322 + */
175 323 private static function maybe_add_ip_col( $form_id, &$columns ) {
176 324 if ( FrmAppHelper::ips_saved() ) {
177 325 $columns[ $form_id . '_ip' ] = 'IP';
178 326 }
@@ -177,21 +325,32 @@
177 325 $columns[ $form_id . '_ip' ] = 'IP';
178 326 }
179 327 }
180 328
329 + /**
330 + * @param bool $check The check value.
331 + * @param int $object_id The object ID.
332 + * @param string $meta_key The meta key.
333 + * @param mixed $meta_value The meta value.
334 + * @param mixed $prev_value The previous value.
335 + *
336 + * @return bool
337 + */
181 338 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
182 339 $this_page_name = self::hidden_column_key();
340 +
341 + // phpcs:ignore Universal.Operators.StrictComparisons
183 342 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
184 343 return $check;
185 344 }
186 345
187 - if ( empty( $prev_value ) ) {
346 + if ( ! $prev_value ) {
188 347 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
189 348 }
190 349
191 350 global $frm_vars;
192 - //add a check so we don't create a loop
193 - $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
351 + // Add a check so we don't create a loop.
352 + $frm_vars['prev_hidden_cols'] = ! empty( $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
194 353
195 354 return $check;
196 355 }
197 356
@@ -196,23 +355,34 @@
196 355 }
197 356
198 357 /**
199 358 * Add hidden columns back from other forms
359 + *
360 + * @param int $meta_id The meta ID.
361 + * @param int $object_id The object ID.
362 + * @param string $meta_key The meta key.
363 + * @param array $meta_value The meta value.
364 + *
365 + * @return void
200 366 */
201 367 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
202 368 $this_page_name = self::hidden_column_key();
369 +
370 + // phpcs:ignore Universal.Operators.StrictComparisons
203 371 if ( $meta_key != $this_page_name ) {
204 372 return;
205 373 }
206 374
207 375 global $frm_vars;
208 - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
209 - return; // Don't continue if there's no previous value.
376 +
377 + if ( empty( $frm_vars['prev_hidden_cols'] ) ) {
378 + // Don't continue if there's no previous value.
379 + return;
210 380 }
211 381
212 382 foreach ( $meta_value as $mk => $mv ) {
213 383 // Remove blank values.
214 - if ( empty( $mv ) ) {
384 + if ( ! $mv ) {
215 385 unset( $meta_value[ $mk ] );
216 386 }
217 387 }
218 388
@@ -221,9 +391,10 @@
221 391 $cur_form_prefix = $cur_form_prefix[0];
222 392 $save = false;
223 393
224 394 foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
225 - if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
395 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
396 + if ( ! $prev_hidden || in_array( $prev_hidden, $meta_value ) ) {
226 397 // Don't add blank cols or process included cols.
227 398 continue;
228 399 }
229 400
@@ -228,9 +399,10 @@
228 399 }
229 400
230 401 $form_prefix = explode( '_', $prev_hidden );
231 402 $form_prefix = $form_prefix[0];
232 - if ( $form_prefix == $cur_form_prefix ) {
403 +
404 + if ( $form_prefix === $cur_form_prefix ) {
233 405 // Don't add back columns that are meant to be hidden.
234 406 continue;
235 407 }
236 408
@@ -238,42 +410,62 @@
238 410 $save = true;
239 411 unset( $form_prefix );
240 412 }
241 413
242 - if ( $save ) {
243 - $user_id = get_current_user_id();
244 - update_user_option( $user_id, $this_page_name, $meta_value, true );
414 + if ( ! $save ) {
415 + return;
245 416 }
417 +
418 + update_user_option( get_current_user_id(), $this_page_name, $meta_value, true );
246 419 }
247 420
248 421 /**
249 422 * @since 2.05.07
423 + *
424 + * @param string $menu_name
425 + *
426 + * @return string
250 427 */
251 428 private static function hidden_column_key( $menu_name = '' ) {
252 429 $base = self::base_column_key( $menu_name );
253 -
254 430 return 'manage' . $base . 'columnshidden';
255 431 }
256 432
257 433 /**
258 434 * @since 2.05.07
435 + *
436 + * @param string $menu_name
437 + *
438 + * @return string
259 439 */
260 440 private static function base_column_key( $menu_name = '' ) {
261 - if ( empty( $menu_name ) ) {
441 + if ( ! $menu_name ) {
262 442 $menu_name = FrmAppHelper::get_menu_name();
263 443 }
264 444
265 - return sanitize_title( $menu_name ) . '_page_formidable-entries';
445 + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
446 +
447 + return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
266 448 }
267 449
450 + /**
451 + * @param int $save
452 + * @param string $option
453 + * @param string $value
454 + *
455 + * @return int
456 + */
268 457 public static function save_per_page( $save, $option, $value ) {
269 - if ( $option == 'formidable_page_formidable_entries_per_page' ) {
270 - $save = (int) $value;
458 + if ( $option === 'formidable_page_formidable_entries_per_page' ) {
459 + return (int) $value;
271 460 }
272 461
273 462 return $save;
274 463 }
275 464
465 + /**
466 + * @return array
467 + */
276 468 public static function sortable_columns() {
277 469 $form_id = FrmForm::get_current_form_id();
278 470 $fields = FrmField::get_all_for_form( $form_id );
279 471
@@ -285,8 +477,14 @@
285 477 $form_id . '_item_key' => 'item_key',
286 478 $form_id . '_is_draft' => 'is_draft',
287 479 );
288 480
481 + if ( ! $form_id ) {
482 + $columns[ $form_id . '_user_id' ] = 'user_id';
483 + $columns[ $form_id . '_name' ] = 'name';
484 + $columns[ $form_id . '_form_id' ] = 'form_id';
485 + }
486 +
289 487 foreach ( $fields as $field ) {
290 488 if ( self::field_supports_sorting( $field ) ) {
291 489 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
292 490 }
@@ -299,8 +497,9 @@
299 497 * Can't sort on checkboxes because they are sorted serialized.
300 498 * Some post content can be sorted but not everything.
301 499 *
302 500 * @param stdClass $field
501 + *
303 502 * @return bool
304 503 */
305 504 private static function field_supports_sorting( $field ) {
306 505 $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
@@ -308,11 +507,14 @@
308 507 }
309 508
310 509 /**
311 510 * @param mixed $result Option value from database for hidden columns in entries table.
511 + *
312 512 * @return array
313 513 */
314 514 public static function hidden_columns( $result ) {
515 + global $frm_vars;
516 +
315 517 if ( ! is_array( $result ) ) {
316 518 // Force an unexpected value to be an array.
317 519 // Since $result is a filtered option and gets saved to the database, it's possible it could be a string.
318 520 // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
@@ -318,21 +520,16 @@
318 520 // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
319 521 $result = array();
320 522 }
321 523
322 - $form_id = FrmForm::get_current_form_id();
524 + $form_id = FrmForm::get_current_form_id();
525 + $hidden = self::user_hidden_columns_for_form( $form_id, $result );
526 + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
527 + $max_columns = 11;
323 528
324 - $hidden = self::user_hidden_columns_for_form( $form_id, $result );
325 -
326 - global $frm_vars;
327 - $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
328 -
329 - if ( ! empty( $hidden ) ) {
330 - $result = $hidden;
331 - $i = $i - count( $result );
332 - $max_columns = 11;
333 - } else {
334 - $max_columns = 8;
529 + if ( $hidden ) {
530 + $result = $hidden;
531 + $i = $i - count( $result );
335 532 }
336 533
337 534 if ( $i <= $max_columns ) {
338 535 return $result;
@@ -344,21 +541,29 @@
344 541 }
345 542
346 543 /**
347 544 * @since 2.05.07
545 + *
546 + * @param int|string $form_id
547 + * @param mixed $result
548 + *
549 + * @return array
348 550 */
349 551 private static function user_hidden_columns_for_form( $form_id, $result ) {
350 552 $hidden = array();
553 +
351 554 foreach ( (array) $result as $r ) {
352 - if ( ! empty( $r ) ) {
353 - list( $form_prefix, $field_key ) = explode( '_', $r );
555 + if ( ! $r ) {
556 + continue;
557 + }
354 558
355 - if ( (int) $form_prefix == (int) $form_id ) {
356 - $hidden[] = $r;
357 - }
559 + list( $form_prefix, $field_key ) = explode( '_', $r );
358 560
359 - unset( $form_prefix );
561 + if ( (int) $form_prefix === (int) $form_id ) {
562 + $hidden[] = $r;
360 563 }
564 +
565 + unset( $form_prefix );
361 566 }
362 567
363 568 return $hidden;
364 569 }
@@ -366,8 +571,13 @@
366 571 /**
367 572 * Remove some columns by default when there are too many
368 573 *
369 574 * @since 2.05.07
575 + *
576 + * @param array $atts
577 + * @param array $result
578 + *
579 + * @return void
370 580 */
371 581 private static function remove_excess_cols( $atts, &$result ) {
372 582 global $frm_vars;
373 583
@@ -375,19 +585,18 @@
375 585 $atts['form_id'] . '_item_key' => '',
376 586 $atts['form_id'] . '_id' => '',
377 587 );
378 588 $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
589 + $i = $atts['i'];
379 590
380 - $i = $atts['i'];
381 -
382 591 foreach ( $cols as $col_key => $col ) {
383 592 if ( $i <= $atts['max_columns'] ) {
384 593 break;
385 594 }
386 595
387 - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
596 + if ( ! $result || ! in_array( $col_key, $result, true ) ) {
388 597 $result[] = $col_key;
389 - $i--;
598 + --$i;
390 599 }
391 600
392 601 unset( $col_key, $col );
393 602 }
@@ -392,8 +601,14 @@
392 601 unset( $col_key, $col );
393 602 }
394 603 }
395 604
605 + /**
606 + * @param string $message
607 + * @param array $errors
608 + *
609 + * @return void
610 + */
396 611 public static function display_list( $message = '', $errors = array() ) {
397 612 global $wpdb, $frm_vars;
398 613
399 614 $form = FrmForm::maybe_get_current_form();
@@ -405,28 +620,29 @@
405 620
406 621 self::get_delete_form_time( $form, $errors );
407 622 }
408 623
409 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
410 -
624 + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
411 625 $wp_list_table = new $table_class( array( 'params' => $params ) );
626 + $pagenum = $wp_list_table->get_pagenum();
412 627
413 - $pagenum = $wp_list_table->get_pagenum();
414 -
415 628 $wp_list_table->prepare_items();
416 629
417 630 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
631 +
418 632 if ( $pagenum > $total_pages && $total_pages > 0 ) {
419 633 $url = add_query_arg( 'paged', $total_pages );
634 +
420 635 if ( headers_sent() ) {
421 636 FrmAppHelper::js_redirect( $url, true );
422 637 } else {
423 - wp_redirect( esc_url_raw( $url ) );
638 + wp_safe_redirect( esc_url_raw( $url ) );
424 639 }
640 +
425 641 die();
426 642 }
427 643
428 - if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
644 + if ( ! $message && isset( $_GET['import-message'] ) ) {
429 645 $message = __( 'Your import is complete', 'formidable' );
430 646 }
431 647
432 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
@@ -431,19 +647,33 @@
431 647
432 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
433 649 }
434 650
651 + /**
652 + * @param object $form
653 + * @param array $errors
654 + *
655 + * @return void
656 + */
435 657 private static function get_delete_form_time( $form, &$errors ) {
436 - if ( 'trash' == $form->status ) {
437 - $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() ) );
658 + if ( 'trash' !== $form->status ) {
659 + return;
660 + }
439 661
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 );
442 - }
662 + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
663 + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, $form->options['trash_time'] ?? time() );
664 +
665 + /* translators: %1$s: Time string */
666 + $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 );
443 667 }
444 668
445 - /* Back End CRUD */
669 + /**
670 + * Back End CRUD.
671 + *
672 + * @param int $id
673 + *
674 + * @return void
675 + */
446 676 public static function show( $id = 0 ) {
447 677 FrmAppHelper::permission_check( 'frm_view_entries' );
448 678
449 679 if ( ! $id ) {
@@ -454,17 +684,22 @@
454 684 }
455 685 }
456 686
457 687 $entry = FrmEntry::getOne( $id, true );
688 +
458 689 if ( ! $entry ) {
459 - echo '<div id="form_show_entry_page" class="wrap">' .
460 - esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
461 - '</div>';
462 -
690 + FrmAppController::show_error_modal(
691 + array(
692 + 'title' => __( 'You can\'t view the entry', 'formidable' ),
693 + 'body' => __( 'You are trying to view an entry that does not exist', 'formidable' ),
694 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
695 + )
696 + );
463 697 return;
464 698 }
465 699
466 700 $data = $entry->description;
701 +
467 702 if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
468 703 $data = array( 'referrer' => $data );
469 704 }
470 705
@@ -470,9 +705,9 @@
470 705
471 706 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
472 707 $form = FrmForm::getOne( $entry->form_id );
473 708
474 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
709 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php';
475 710 }
476 711
477 712 /**
478 713 * Destroy an entry from the admin page.
@@ -481,19 +716,27 @@
481 716 * @return void
482 717 */
483 718 public static function destroy() {
484 719 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
720 +
485 721 if ( false !== $permission_error ) {
486 - wp_die( esc_html( $permission_error ) );
722 + $error_args = array(
723 + 'title' => __( 'Verification failed', 'formidable' ),
724 + 'body' => $permission_error,
725 + 'cancel_url' => admin_url( 'admin.php?page=formidable-entries' ),
726 + );
727 + FrmAppController::show_error_modal( $error_args );
728 + return;
487 729 }
488 730
489 731 $params = FrmForm::get_admin_params();
490 732
491 - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
733 + if ( ! empty( $params['keep_post'] ) ) {
492 734 self::unlink_post( $params['id'] );
493 735 }
494 736
495 737 $message = '';
738 +
496 739 if ( FrmEntry::destroy( $params['id'] ) ) {
497 740 $message = __( 'Entry was successfully deleted', 'formidable' );
498 741 }
499 742
@@ -500,20 +743,17 @@
500 743 self::display_list( $message );
501 744 }
502 745
503 746 /**
504 - * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite.
747 + * @param array|string $errors
748 + * @param bool $ajax
749 + *
750 + * @return void
505 751 */
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();
510 - }
511 - }
512 -
513 752 public static function process_entry( $errors = '', $ajax = false ) {
514 753 $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
754 +
755 + if ( FrmAppHelper::is_admin() || empty( $_POST ) || ! $form_id || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
516 756 return;
517 757 }
518 758
519 759 global $frm_vars;
@@ -518,12 +758,19 @@
518 758
519 759 global $frm_vars;
520 760
521 761 $form = FrmForm::getOne( $form_id );
762 +
522 763 if ( ! $form ) {
523 764 return;
524 765 }
525 766
767 + $is_preview = 'frm_forms_preview' === FrmAppHelper::simple_get( 'action' );
768 +
769 + if ( $is_preview && FrmFormsHelper::should_block_preview( $form->form_key ) ) {
770 + return;
771 + }
772 +
526 773 $params = FrmForm::get_params( $form );
527 774
528 775 if ( ! isset( $frm_vars['form_params'] ) ) {
529 776 $frm_vars['form_params'] = array();
@@ -533,8 +780,9 @@
533 780 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
534 781 return;
535 782 }
536 783
784 + // phpcs:ignore Universal.Operators.StrictComparisons
537 785 if ( $errors == '' && ! $ajax ) {
538 786 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
539 787 }
540 788
@@ -547,26 +795,28 @@
547 795 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
548 796
549 797 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
550 798
551 - if ( empty( $errors ) ) {
552 - $_POST['frm_skip_cookie'] = 1;
553 - $do_success = false;
554 - if ( $params['action'] === 'create' ) {
555 - 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
799 + if ( $errors ) {
800 + return;
801 + }
557 802
558 - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
559 - $do_success = true;
560 - }
561 - }
803 + $_POST['frm_skip_cookie'] = 1;
804 + $do_success = false;
562 805
563 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
564 - if ( $do_success ) {
565 - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
566 - }
567 - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
806 + if ( $params['action'] === 'create' && apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
807 + $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
808 +
809 + $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
810 + $do_success = true;
568 811 }
812 +
813 + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
814 +
815 + if ( $do_success ) {
816 + FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
817 + }
818 + unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
569 819 }
570 820
571 821 /**
572 822 * Escape url entities before redirect
@@ -580,11 +830,19 @@
580 830 public static function prepare_redirect_url( $url ) {
581 831 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
582 832 }
583 833
834 + /**
835 + * Delete entry if redirected.
836 + *
837 + * @param string $url
838 + * @param object $form
839 + * @param array $atts
840 + *
841 + * @return string
842 + */
584 843 public static function delete_entry_before_redirect( $url, $form, $atts ) {
585 844 self::_delete_entry( $atts['id'], $form );
586 -
587 845 return $url;
588 846 }
589 847
590 848 /**
@@ -590,13 +848,23 @@
590 848 /**
591 849 * Delete entry if not redirected.
592 850 *
593 851 * @param array $atts
852 + *
853 + * @return void
594 854 */
595 855 public static function delete_entry_after_save( $atts ) {
596 856 self::_delete_entry( $atts['entry_id'], $atts['form'] );
597 857 }
598 858
859 + /**
860 + * Delete entry if not redirected.
861 + *
862 + * @param int $entry_id
863 + * @param object $form
864 + *
865 + * @return void
866 + */
599 867 private static function _delete_entry( $entry_id, $form ) {
600 868 if ( ! $form ) {
601 869 return;
602 870 }
@@ -601,16 +869,23 @@
601 869 return;
602 870 }
603 871
604 872 FrmAppHelper::unserialize_or_decode( $form->options );
605 - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
606 - self::unlink_post( $entry_id );
607 - FrmEntry::destroy( $entry_id );
873 +
874 + if ( empty( $form->options['no_save'] ) ) {
875 + return;
608 876 }
877 +
878 + self::unlink_post( $entry_id );
879 + FrmEntry::destroy( $entry_id );
609 880 }
610 881
611 882 /**
612 883 * Unlink entry from post
884 + *
885 + * @param int $entry_id
886 + *
887 + * @return void
613 888 */
614 889 private static function unlink_post( $entry_id ) {
615 890 global $wpdb;
616 891 $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) );
@@ -617,9 +892,9 @@
617 892 FrmEntry::clear_cache();
618 893 }
619 894
620 895 /**
621 - * @param $atts
896 + * @param array $atts
622 897 *
623 898 * @return array|string
624 899 */
625 900 public static function show_entry_shortcode( $atts ) {
@@ -646,39 +921,39 @@
646 921 'exclude_fields' => '',
647 922 'include_fields' => '',
648 923 'include_extras' => '',
649 924 'inline_style' => 1,
650 - 'child_array' => false, // return embedded fields as nested array
925 + 'table_style' => '',
926 + // Return embedded fields as nested array.
927 + 'child_array' => false,
651 928 'line_breaks' => true,
652 929 'array_separator' => ', ',
653 930 );
654 931 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
932 + $atts = shortcode_atts( $defaults, $atts );
655 933
656 - $atts = shortcode_atts( $defaults, $atts );
657 -
658 934 if ( $atts['default_email'] ) {
659 - $shortcode_atts = array(
935 + $shortcode_atts = array(
660 936 'format' => $atts['format'],
661 937 'plain_text' => $atts['plain_text'],
662 938 );
663 -
664 939 $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
665 - $formatted_entry = $entry_formatter->content();
940 + return $entry_formatter->content();
941 + }
666 942
667 - } else {
943 + $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
668 944
669 - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
670 - $formatted_entry = $entry_formatter->get_formatted_entry_values();
671 -
672 - }
673 -
674 - return $formatted_entry;
945 + return $entry_formatter->get_formatted_entry_values();
675 946 }
676 947
948 + /**
949 + * @param false|object $entry
950 + *
951 + * @return void
952 + */
677 953 public static function entry_sidebar( $entry = false ) {
678 - $data = array();
679 - $id = 0;
680 -
954 + $data = array();
955 + $id = 0;
681 956 $date_format = get_option( 'date_format' );
682 957 $time_format = get_option( 'time_format' );
683 958
684 959 if ( $entry ) {
@@ -683,8 +958,9 @@
683 958
684 959 if ( $entry ) {
685 960 $id = $entry->id;
686 961 $data = $entry->description;
962 +
687 963 if ( isset( $data['browser'] ) ) {
688 964 $browser = FrmEntriesHelper::get_browser( $data['browser'] );
689 965 }
690 966 /**
@@ -690,20 +966,14 @@
690 966 /**
691 967 * Add or remove information in the entry sidebar.
692 968 *
693 969 * @since 5.5.2
970 + *
694 971 * @param array $data
972 + * @param array{entry:\stdClass} $entry
695 973 */
696 974 $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
697 975 }
698 976
699 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
700 - }
701 -
702 - /**
703 - * @deprecated 4.0
704 - */
705 - public static function contextual_help( $help, $screen_id, $screen ) {
706 - _deprecated_function( __METHOD__, '4.0' );
707 - return $help;
977 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php';
708 978 }
709 979 }