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/helpers/FrmEntriesListHelper.php +97 -47 6.25 → trunk View file →
@@ -4,18 +4,23 @@
4 4 }
5 5
6 6 class FrmEntriesListHelper extends FrmListHelper {
7 7
8 + /**
9 + * @var string|null
10 + */
8 11 protected $column_name;
9 - protected $item;
10 - protected $field;
11 12
12 13 /**
13 14 * @since 4.07
15 + *
14 16 * @var bool|int
15 17 */
16 18 public $total_items = 0;
17 19
20 + /**
21 + * @param array $args
22 + */
18 23 public function __construct( $args ) {
19 24 parent::__construct( $args );
20 25 $this->screen->set_screen_reader_content(
21 26 array(
@@ -28,10 +33,9 @@
28 33 * @return void
29 34 */
30 35 public function prepare_items() {
31 36 $this->set_per_page();
32 - $s_query = array();
33 -
37 + $s_query = array();
34 38 $join_form_in_query = false;
35 39
36 40 $this->items = $this->get_entry_items( $s_query, $join_form_in_query );
37 41 $this->set_total_items( $s_query );
@@ -37,8 +41,13 @@
37 41 $this->set_total_items( $s_query );
38 42 $this->prepare_pagination();
39 43 }
40 44
45 + /**
46 + * @param array $s_query
47 + *
48 + * @return void
49 + */
41 50 protected function set_total_items( $s_query ) {
42 51 $this->total_items = FrmEntry::getRecordCount( $s_query );
43 52 }
44 53
@@ -45,8 +54,10 @@
45 54 /**
46 55 * Prepares pagination.
47 56 *
48 57 * @since 6.5.4
58 + *
59 + * @return void
49 60 */
50 61 protected function prepare_pagination() {
51 62 global $per_page;
52 63
@@ -61,8 +72,10 @@
61 72 /**
62 73 * Sets the global $per_page variable
63 74 *
64 75 * @since 6.5.4
76 + *
77 + * @return void
65 78 */
66 79 protected function set_per_page() {
67 80 global $per_page;
68 81 $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
@@ -78,16 +91,16 @@
78 91 */
79 92 protected function get_entry_items( &$s_query, &$join_form_in_query ) {
80 93 global $per_page;
81 94 $s_query = $this->get_search_query( $join_form_in_query );
82 - $order = $this->get_order_by();
83 95 $limit = $this->get_limit( $per_page );
84 96
85 - return FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
97 + return FrmEntry::getAll( $s_query, $this->get_order_by(), $limit, true, $join_form_in_query );
86 98 }
87 99
88 100 /**
89 101 * @since 6.5.4
102 + *
90 103 * @return string
91 104 */
92 105 protected function get_order_by() {
93 106 $orderby = self::get_param(
@@ -104,9 +117,9 @@
104 117 );
105 118
106 119 FrmAppController::apply_saved_sort_preference( $orderby, $order );
107 120
108 - if ( strpos( $orderby, 'meta' ) !== false ) {
121 + if ( str_contains( $orderby, 'meta' ) ) {
109 122 $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
110 123
111 124 if ( in_array( $order_field_type, array( 'number', 'scale', 'star' ), true ) ) {
112 125 $orderby .= '+0';
@@ -119,8 +132,9 @@
119 132 /**
120 133 * @since 6.5.4
121 134 *
122 135 * @param int $per_page
136 + *
123 137 * @return string
124 138 */
125 139 protected function get_limit( $per_page ) {
126 140 $page = $this->get_pagenum();
@@ -137,8 +151,9 @@
137 151 /**
138 152 * @since 6.5.4
139 153 *
140 154 * @param bool $join_form_in_query
155 + *
141 156 * @return array
142 157 */
143 158 protected function get_search_query( &$join_form_in_query ) {
144 159 $form_id = $this->params['form'];
@@ -162,9 +177,9 @@
162 177 'sanitize' => 'sanitize_text_field',
163 178 )
164 179 );
165 180
166 - if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
181 + if ( $s !== '' && FrmAppHelper::pro_is_installed() ) {
167 182 $fid = self::get_param( array( 'param' => 'fid' ) );
168 183 $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
169 184 }
170 185
@@ -174,8 +189,9 @@
174 189 /**
175 190 * @since 6.5.4
176 191 *
177 192 * @param int|string $form_id
193 + *
178 194 * @return array<int>
179 195 */
180 196 protected function get_form_ids( $form_id ) {
181 197 return array( (int) $form_id );
@@ -190,11 +206,23 @@
190 206 'param' => 's',
191 207 'sanitize' => 'sanitize_text_field',
192 208 )
193 209 );
194 - if ( ! empty( $s ) ) {
195 - esc_html_e( 'No Entries Found', 'formidable' );
196 210
211 + if ( $s !== '' ) {
212 + $current_url = set_url_scheme(
213 + 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' )
214 + );
215 + $clear_url = remove_query_arg( 's', $current_url );
216 +
217 + echo '<p>';
218 + printf(
219 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
220 + esc_html__( 'No entries match your search. %1$sClear search%2$s', 'formidable' ),
221 + '<a href="' . esc_url( $clear_url ) . '">',
222 + '</a>'
223 + );
224 + echo '</p>';
197 225 return;
198 226 }
199 227
200 228 $form_id = $this->params['form'];
@@ -202,8 +230,9 @@
202 230
203 231 if ( $form_id ) {
204 232 $form = FrmForm::getOne( $form_id );
205 233 }
234 +
206 235 $has_form = ! empty( $form );
207 236
208 237 if ( ! $has_form ) {
209 238 $has_form = FrmForm::getAll( array(), '', 1 );
@@ -215,8 +244,11 @@
215 244 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php';
216 245 }
217 246
218 247 /**
248 + * @param string $text Text.
249 + * @param string $input_id Input ID.
250 + *
219 251 * @return void
220 252 */
221 253 public function search_box( $text, $input_id ) {
222 254 // Searching is a pro feature
@@ -222,42 +254,56 @@
222 254 // Searching is a pro feature
223 255 }
224 256
225 257 /**
258 + * @param string $which
259 + *
226 260 * @return void
227 261 */
228 262 protected function display_tablenav( $which ) {
229 - $is_footer = ( $which !== 'top' );
263 + $is_footer = $which !== 'top';
264 +
230 265 if ( $is_footer && ! empty( $this->items ) ) {
266 + $utm = array(
267 + 'campaign' => 'spam-protection',
268 + 'content' => 'entries-list-spam-protection',
269 + );
270 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
231 271 ?>
232 272 <p>
233 273 <?php esc_html_e( 'Getting spam form submissions?', 'formidable' ); ?>
234 - <a href="https://formidableforms.com/knowledgebase/add-spam-protection/" target="_blank">
274 + <a href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/add-spam-protection/' ) ); ?>" target="_blank">
235 275 <?php esc_html_e( 'Learn how to prevent them.', 'formidable' ); ?>
236 276 </a>
237 277 </p>
238 278 <?php
279 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
239 280 }
240 281 parent::display_tablenav( $which );
241 282 }
242 283
243 284 /**
285 + * @param string $which
286 + *
244 287 * @return void
245 288 */
246 289 protected function extra_tablenav( $which ) {
247 290 $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
248 - if ( $which === 'top' && ! $form_id ) {
249 - echo '<div class="alignleft actions">';
250 291
251 - // Override the referrer to prevent it from being used for the screen options.
252 - echo '<input type="hidden" name="_wp_http_referer" value="" />';
292 + if ( $which !== 'top' || $form_id ) {
293 + return;
294 + }
253 295
254 - echo '<label for="form" class="screen-reader-text">' . esc_html__( 'Filter by form', 'formidable' ) . '</label>';
296 + echo '<div class="alignleft actions">';
255 297
256 - FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) );
257 - submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) );
258 - echo '</div>';
259 - }
298 + // Override the referrer to prevent it from being used for the screen options.
299 + echo '<input type="hidden" name="_wp_http_referer" value="" />';
300 +
301 + echo '<label for="form" class="screen-reader-text">' . esc_html__( 'Filter by form', 'formidable' ) . '</label>';
302 +
303 + FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) );
304 + submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) );
305 + echo '</div>';
260 306 }
261 307
262 308 /**
263 309 * Gets the name of the primary column in the Entries screen
@@ -263,18 +309,17 @@
263 309 * Gets the name of the primary column in the Entries screen
264 310 *
265 311 * @since 2.0.14
266 312 *
267 - * @return string $primary_column
313 + * @return string Primary column.
268 314 */
269 315 protected function get_primary_column_name() {
270 - $columns = get_column_headers( $this->screen );
271 - $hidden = get_hidden_columns( $this->screen );
272 -
316 + $columns = get_column_headers( $this->screen );
317 + $hidden = get_hidden_columns( $this->screen );
273 318 $primary_column = '';
274 319
275 320 foreach ( $columns as $column_key => $column_display_name ) {
276 - if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden ) ) {
321 + if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden, true ) ) {
277 322 $primary_column = $column_key;
278 323 break;
279 324 }
280 325 }
@@ -285,8 +330,9 @@
285 330 /**
286 331 * @since 6.12
287 332 *
288 333 * @param object $item
334 + *
289 335 * @return string
290 336 */
291 337 private static function get_entry_label( $item ) {
292 338 if ( $item->name ) {
@@ -296,8 +342,11 @@
296 342 return sprintf( __( 'Entry %d', 'formidable' ), $item->id );
297 343 }
298 344
299 345 /**
346 + * @param stdClass $item
347 + * @param string $style
348 + *
300 349 * @return string
301 350 */
302 351 public function single_row( $item, $style = '' ) {
303 352 // Set up the hover actions for this user
@@ -310,9 +359,9 @@
310 359
311 360 // Set up the checkbox ( because the user is editable, otherwise its empty )
312 361 $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
313 362 /* translators: %s: Form name */
314 - $checkbox .= "<label for='cb-item-action-{$item->id}'><span class='screen-reader-text'>" . esc_html( sprintf( __( 'Select %s', 'formidable' ), self::get_entry_label( $item ) ) ) . '</span></label>';
363 + $checkbox .= "<label for='cb-item-action-{$item->id}'><span class='screen-reader-text'>" . esc_html( sprintf( __( 'Select %s', 'formidable' ), self::get_entry_label( $item ) ) ) . '</span></label>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
315 364
316 365 $r = "<tr id='item-action-{$item->id}'$style>";
317 366
318 367 list( $columns, $hidden, , $primary ) = $this->get_column_info();
@@ -326,9 +375,9 @@
326 375 $class .= ' column-primary';
327 376 }
328 377
329 378 if ( in_array( $column_name, $hidden, true ) ) {
330 - $class .= ' frm_hidden';
379 + $class .= ' hidden';
331 380 } elseif ( ! $action_col && ! in_array( $column_name, $action_columns, true ) ) {
332 381 $action_col = $column_name;
333 382 }
334 383
@@ -333,10 +382,9 @@
333 382 }
334 383
335 384 $attributes = 'class="' . esc_attr( $class ) . '"';
336 385 unset( $class );
337 - $attributes .= ' data-colname="' . $column_display_name . '"';
338 -
386 + $attributes .= ' data-colname="' . $column_display_name . '"';
339 387 $form_id = $this->params['form'] ? $this->params['form'] : 0;
340 388 $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
341 389
342 390 if ( $this->column_name === 'cb' ) {
@@ -341,15 +389,12 @@
341 389
342 390 if ( $this->column_name === 'cb' ) {
343 391 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
344 392 } else {
345 - if ( in_array( $column_name, $hidden, true ) ) {
346 - $val = '';
347 - } else {
348 - $val = $this->column_value( $item );
349 - }
393 + $val = in_array( $column_name, $hidden, true ) ? '' : $this->column_value( $item );
394 + $r .= "<td $attributes>";
350 395
351 - $r .= "<td $attributes>";
396 + // phpcs:ignore Universal.Operators.StrictComparisons
352 397 if ( $column_name == $action_col ) {
353 398 $edit_link = admin_url( 'admin.php?page=formidable-entries&frm_action=edit&id=' . $item->id );
354 399 $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
355 400 $r .= $action_links;
@@ -355,15 +400,14 @@
355 400 $r .= $action_links;
356 401 } else {
357 402 $r .= $val;
358 403 }
404 +
359 405 $r .= '</td>';
360 - }
406 + }//end if
361 407 unset( $val );
362 408 }//end foreach
363 - $r .= '</tr>';
364 -
365 - return $r;
409 + return $r . '</tr>';
366 410 }
367 411
368 412 /**
369 413 * Get the column names that the logged in user can action on
@@ -375,8 +419,10 @@
375 419 }
376 420
377 421 /**
378 422 * @param object $item
423 + *
424 + * @return mixed
379 425 */
380 426 private function column_value( $item ) {
381 427 $col_name = $this->maybe_fix_column_name( $this->column_name );
382 428
@@ -404,8 +450,9 @@
404 450 break;
405 451 case 'form_id':
406 452 $form_id = $item->form_id;
407 453 $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' );
454 +
408 455 if ( $user_can_edit_forms ) {
409 456 $val = FrmFormsHelper::edit_form_link( $form_id );
410 457 } else {
411 458 $val = FrmFormsHelper::edit_form_link_label( $form_id );
@@ -422,8 +469,9 @@
422 469 $val = $item->parent_item_id;
423 470 break;
424 471 default:
425 472 $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
473 +
426 474 if ( $val === false ) {
427 475 $this->get_column_value( $item, $val );
428 476 }
429 477
@@ -446,13 +494,14 @@
446 494 *
447 495 * @since 6.11.2
448 496 *
449 497 * @param string $column_name
498 + *
450 499 * @return string
451 500 */
452 501 private function maybe_fix_column_name( $column_name ) {
453 - if ( 0 === strpos( $column_name, '0_' ) ) {
454 - $column_name = substr( $column_name, 2 );
502 + if ( str_starts_with( $column_name, '0_' ) ) {
503 + return substr( $column_name, 2 );
455 504 }
456 505 return $column_name;
457 506 }
458 507
@@ -463,13 +512,13 @@
463 512 *
464 513 * @return void
465 514 */
466 515 private function get_actions( &$actions, $item, $view_link ) {
467 - $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
516 + $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . esc_html__( 'View', 'formidable' ) . '</a>';
468 517
469 518 if ( current_user_can( 'frm_delete_entries' ) ) {
470 519 $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
471 - $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" data-frmverify="' . esc_attr__( 'Permanently delete this entry?', 'formidable' ) . '" data-frmverify-btn="frm-button-red">' . __( 'Delete', 'formidable' ) . '</a>';
520 + $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" data-frmverify="' . esc_attr__( 'Permanently delete this entry?', 'formidable' ) . '" data-frmverify-btn="frm-button-red">' . esc_html__( 'Delete', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
472 521 }
473 522
474 523 $actions = apply_filters( 'frm_row_actions', $actions, $item );
475 524 }
@@ -475,9 +524,9 @@
475 524 }
476 525
477 526 /**
478 527 * @param object $item
479 - * @param false $val
528 + * @param mixed $val
480 529 *
481 530 * @return void
482 531 */
483 532 private function get_column_value( $item, &$val ) {
@@ -482,9 +531,9 @@
482 531 */
483 532 private function get_column_value( $item, &$val ) {
484 533 $col_name = $this->column_name;
485 534
486 - if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
535 + if ( str_starts_with( $col_name, 'frmsep_' ) ) {
487 536 $sep_val = true;
488 537 $col_name = str_replace( 'frmsep_', '', $col_name );
489 538 } else {
490 539 $sep_val = false;
@@ -489,13 +538,14 @@
489 538 } else {
490 539 $sep_val = false;
491 540 }
492 541
493 - if ( strpos( $col_name, '-_-' ) ) {
542 + if ( str_contains( $col_name, '-_-' ) ) {
494 543 list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
495 544 }
496 545
497 546 $field = FrmField::getOne( $col_name );
547 +
498 548 if ( ! $field ) {
499 549 return;
500 550 }
501 551