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 +92 -46 6.25.1 → 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,17 +254,21 @@
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 ) ) {
231 266 $utm = array(
232 267 'campaign' => 'spam-protection',
233 268 'content' => 'entries-list-spam-protection',
234 269 );
270 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
235 271 ?>
236 272 <p>
237 273 <?php esc_html_e( 'Getting spam form submissions?', 'formidable' ); ?>
238 274 <a href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/add-spam-protection/' ) ); ?>" target="_blank">
@@ -239,29 +275,35 @@
239 275 <?php esc_html_e( 'Learn how to prevent them.', 'formidable' ); ?>
240 276 </a>
241 277 </p>
242 278 <?php
279 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
243 280 }
244 281 parent::display_tablenav( $which );
245 282 }
246 283
247 284 /**
285 + * @param string $which
286 + *
248 287 * @return void
249 288 */
250 289 protected function extra_tablenav( $which ) {
251 290 $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
252 - if ( $which === 'top' && ! $form_id ) {
253 - echo '<div class="alignleft actions">';
254 291
255 - // Override the referrer to prevent it from being used for the screen options.
256 - echo '<input type="hidden" name="_wp_http_referer" value="" />';
292 + if ( $which !== 'top' || $form_id ) {
293 + return;
294 + }
257 295
258 - echo '<label for="form" class="screen-reader-text">' . esc_html__( 'Filter by form', 'formidable' ) . '</label>';
296 + echo '<div class="alignleft actions">';
259 297
260 - FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) );
261 - submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) );
262 - echo '</div>';
263 - }
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>';
264 306 }
265 307
266 308 /**
267 309 * Gets the name of the primary column in the Entries screen
@@ -267,18 +309,17 @@
267 309 * Gets the name of the primary column in the Entries screen
268 310 *
269 311 * @since 2.0.14
270 312 *
271 - * @return string $primary_column
313 + * @return string Primary column.
272 314 */
273 315 protected function get_primary_column_name() {
274 - $columns = get_column_headers( $this->screen );
275 - $hidden = get_hidden_columns( $this->screen );
276 -
316 + $columns = get_column_headers( $this->screen );
317 + $hidden = get_hidden_columns( $this->screen );
277 318 $primary_column = '';
278 319
279 320 foreach ( $columns as $column_key => $column_display_name ) {
280 - if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden ) ) {
321 + if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden, true ) ) {
281 322 $primary_column = $column_key;
282 323 break;
283 324 }
284 325 }
@@ -289,8 +330,9 @@
289 330 /**
290 331 * @since 6.12
291 332 *
292 333 * @param object $item
334 + *
293 335 * @return string
294 336 */
295 337 private static function get_entry_label( $item ) {
296 338 if ( $item->name ) {
@@ -300,8 +342,11 @@
300 342 return sprintf( __( 'Entry %d', 'formidable' ), $item->id );
301 343 }
302 344
303 345 /**
346 + * @param stdClass $item
347 + * @param string $style
348 + *
304 349 * @return string
305 350 */
306 351 public function single_row( $item, $style = '' ) {
307 352 // Set up the hover actions for this user
@@ -314,9 +359,9 @@
314 359
315 360 // Set up the checkbox ( because the user is editable, otherwise its empty )
316 361 $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
317 362 /* translators: %s: Form name */
318 - $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
319 364
320 365 $r = "<tr id='item-action-{$item->id}'$style>";
321 366
322 367 list( $columns, $hidden, , $primary ) = $this->get_column_info();
@@ -330,9 +375,9 @@
330 375 $class .= ' column-primary';
331 376 }
332 377
333 378 if ( in_array( $column_name, $hidden, true ) ) {
334 - $class .= ' frm_hidden';
379 + $class .= ' hidden';
335 380 } elseif ( ! $action_col && ! in_array( $column_name, $action_columns, true ) ) {
336 381 $action_col = $column_name;
337 382 }
338 383
@@ -337,10 +382,9 @@
337 382 }
338 383
339 384 $attributes = 'class="' . esc_attr( $class ) . '"';
340 385 unset( $class );
341 - $attributes .= ' data-colname="' . $column_display_name . '"';
342 -
386 + $attributes .= ' data-colname="' . $column_display_name . '"';
343 387 $form_id = $this->params['form'] ? $this->params['form'] : 0;
344 388 $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
345 389
346 390 if ( $this->column_name === 'cb' ) {
@@ -345,15 +389,12 @@
345 389
346 390 if ( $this->column_name === 'cb' ) {
347 391 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
348 392 } else {
349 - if ( in_array( $column_name, $hidden, true ) ) {
350 - $val = '';
351 - } else {
352 - $val = $this->column_value( $item );
353 - }
393 + $val = in_array( $column_name, $hidden, true ) ? '' : $this->column_value( $item );
394 + $r .= "<td $attributes>";
354 395
355 - $r .= "<td $attributes>";
396 + // phpcs:ignore Universal.Operators.StrictComparisons
356 397 if ( $column_name == $action_col ) {
357 398 $edit_link = admin_url( 'admin.php?page=formidable-entries&frm_action=edit&id=' . $item->id );
358 399 $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
359 400 $r .= $action_links;
@@ -359,15 +400,14 @@
359 400 $r .= $action_links;
360 401 } else {
361 402 $r .= $val;
362 403 }
404 +
363 405 $r .= '</td>';
364 - }
406 + }//end if
365 407 unset( $val );
366 408 }//end foreach
367 - $r .= '</tr>';
368 -
369 - return $r;
409 + return $r . '</tr>';
370 410 }
371 411
372 412 /**
373 413 * Get the column names that the logged in user can action on
@@ -379,8 +419,10 @@
379 419 }
380 420
381 421 /**
382 422 * @param object $item
423 + *
424 + * @return mixed
383 425 */
384 426 private function column_value( $item ) {
385 427 $col_name = $this->maybe_fix_column_name( $this->column_name );
386 428
@@ -408,8 +450,9 @@
408 450 break;
409 451 case 'form_id':
410 452 $form_id = $item->form_id;
411 453 $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' );
454 +
412 455 if ( $user_can_edit_forms ) {
413 456 $val = FrmFormsHelper::edit_form_link( $form_id );
414 457 } else {
415 458 $val = FrmFormsHelper::edit_form_link_label( $form_id );
@@ -426,8 +469,9 @@
426 469 $val = $item->parent_item_id;
427 470 break;
428 471 default:
429 472 $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
473 +
430 474 if ( $val === false ) {
431 475 $this->get_column_value( $item, $val );
432 476 }
433 477
@@ -450,13 +494,14 @@
450 494 *
451 495 * @since 6.11.2
452 496 *
453 497 * @param string $column_name
498 + *
454 499 * @return string
455 500 */
456 501 private function maybe_fix_column_name( $column_name ) {
457 - if ( 0 === strpos( $column_name, '0_' ) ) {
458 - $column_name = substr( $column_name, 2 );
502 + if ( str_starts_with( $column_name, '0_' ) ) {
503 + return substr( $column_name, 2 );
459 504 }
460 505 return $column_name;
461 506 }
462 507
@@ -467,13 +512,13 @@
467 512 *
468 513 * @return void
469 514 */
470 515 private function get_actions( &$actions, $item, $view_link ) {
471 - $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>';
472 517
473 518 if ( current_user_can( 'frm_delete_entries' ) ) {
474 519 $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
475 - $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
476 521 }
477 522
478 523 $actions = apply_filters( 'frm_row_actions', $actions, $item );
479 524 }
@@ -479,9 +524,9 @@
479 524 }
480 525
481 526 /**
482 527 * @param object $item
483 - * @param false $val
528 + * @param mixed $val
484 529 *
485 530 * @return void
486 531 */
487 532 private function get_column_value( $item, &$val ) {
@@ -486,9 +531,9 @@
486 531 */
487 532 private function get_column_value( $item, &$val ) {
488 533 $col_name = $this->column_name;
489 534
490 - if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
535 + if ( str_starts_with( $col_name, 'frmsep_' ) ) {
491 536 $sep_val = true;
492 537 $col_name = str_replace( 'frmsep_', '', $col_name );
493 538 } else {
494 539 $sep_val = false;
@@ -493,13 +538,14 @@
493 538 } else {
494 539 $sep_val = false;
495 540 }
496 541
497 - if ( strpos( $col_name, '-_-' ) ) {
542 + if ( str_contains( $col_name, '-_-' ) ) {
498 543 list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
499 544 }
500 545
501 546 $field = FrmField::getOne( $col_name );
547 +
502 548 if ( ! $field ) {
503 549 return;
504 550 }
505 551