PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.07
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 +57 -269 6.26.15.2.07 View file →
@@ -3,106 +3,51 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmEntriesListHelper extends FrmListHelper {
7 -
8 - /**
9 - * @var string|null
10 - */
11 7 protected $column_name;
8 + protected $item;
9 + protected $field;
12 10
13 11 /**
14 12 * @since 4.07
15 - *
16 - * @var bool|int
17 13 */
18 14 public $total_items = 0;
19 15
20 - public function __construct( $args ) {
21 - parent::__construct( $args );
22 - $this->screen->set_screen_reader_content(
23 - array(
24 - 'heading_list' => esc_html__( 'Entries list', 'formidable' ),
25 - )
26 - );
27 - }
28 -
29 - /**
30 - * @return void
31 - */
32 16 public function prepare_items() {
33 - $this->set_per_page();
34 - $s_query = array();
17 + global $per_page;
35 18
36 - $join_form_in_query = false;
19 + $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
20 + $form_id = $this->params['form'];
37 21
38 - $this->items = $this->get_entry_items( $s_query, $join_form_in_query );
39 - $this->set_total_items( $s_query );
40 - $this->prepare_pagination();
41 - }
22 + $s_query = array();
42 23
43 - /**
44 - * @param array $s_query
45 - *
46 - * @return void
47 - */
48 - protected function set_total_items( $s_query ) {
49 - $this->total_items = FrmEntry::getRecordCount( $s_query );
50 - }
24 + if ( $form_id ) {
25 + $s_query['it.form_id'] = $form_id;
26 + $join_form_in_query = false;
27 + } else {
28 + $s_query[] = array(
29 + 'or' => 1,
30 + 'parent_form_id' => null,
31 + 'parent_form_id <' => 1,
32 + );
33 + $join_form_in_query = true;
34 + }
51 35
52 - /**
53 - * Prepares pagination.
54 - *
55 - * @since 6.5.4
56 - *
57 - * @return void
58 - */
59 - protected function prepare_pagination() {
60 - global $per_page;
61 -
62 - $this->set_pagination_args(
36 + $s = self::get_param(
63 37 array(
64 - 'total_items' => $this->total_items,
65 - 'per_page' => $per_page,
38 + 'param' => 's',
39 + 'sanitize' => 'sanitize_text_field',
66 40 )
67 41 );
68 - }
69 42
70 - /**
71 - * Sets the global $per_page variable
72 - *
73 - * @since 6.5.4
74 - *
75 - * @return void
76 - */
77 - protected function set_per_page() {
78 - global $per_page;
79 - $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
80 - }
43 + if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
44 + $fid = self::get_param( array( 'param' => 'fid' ) );
45 + $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
46 + }
81 47
82 - /**
83 - * @since 6.5.4
84 - *
85 - * @param array $s_query
86 - * @param bool $join_form_in_query
87 - *
88 - * @return array
89 - */
90 - protected function get_entry_items( &$s_query, &$join_form_in_query ) {
91 - global $per_page;
92 - $s_query = $this->get_search_query( $join_form_in_query );
93 - $order = $this->get_order_by();
94 - $limit = $this->get_limit( $per_page );
48 + $s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
95 49
96 - return FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
97 - }
98 -
99 - /**
100 - * @since 6.5.4
101 - *
102 - * @return string
103 - */
104 - protected function get_order_by() {
105 50 $orderby = self::get_param(
106 51 array(
107 52 'param' => 'orderby',
108 53 'default' => 'id',
@@ -107,36 +52,22 @@
107 52 'param' => 'orderby',
108 53 'default' => 'id',
109 54 )
110 55 );
111 - $order = self::get_param(
56 +
57 + if ( strpos( $orderby, 'meta' ) !== false ) {
58 + $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
59 + $orderby .= in_array( $order_field_type, array( 'number', 'scale', 'star' ) ) ? '+0' : '';
60 + }
61 +
62 + $order = self::get_param(
112 63 array(
113 64 'param' => 'order',
114 65 'default' => 'DESC',
115 66 )
116 67 );
68 + $order = FrmDb::esc_order( $orderby . ' ' . $order );
117 69
118 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
119 -
120 - if ( strpos( $orderby, 'meta' ) !== false ) {
121 - $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
122 -
123 - if ( in_array( $order_field_type, array( 'number', 'scale', 'star' ), true ) ) {
124 - $orderby .= '+0';
125 - }
126 - }
127 -
128 - return FrmDb::esc_order( $orderby . ' ' . $order );
129 - }
130 -
131 - /**
132 - * @since 6.5.4
133 - *
134 - * @param int $per_page
135 - *
136 - * @return string
137 - */
138 - protected function get_limit( $per_page ) {
139 70 $page = $this->get_pagenum();
140 71 $start = (int) self::get_param(
141 72 array(
142 73 'param' => 'start',
@@ -143,63 +74,21 @@
143 74 'default' => ( $page - 1 ) * $per_page,
144 75 )
145 76 );
146 77
147 - return FrmDb::esc_limit( $start . ',' . $per_page );
148 - }
78 + $limit = FrmDb::esc_limit( $start . ',' . $per_page );
79 + $this->items = FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
80 + $total_items = FrmEntry::getRecordCount( $s_query );
81 + $this->total_items = $total_items;
149 82
150 - /**
151 - * @since 6.5.4
152 - *
153 - * @param bool $join_form_in_query
154 - *
155 - * @return array
156 - */
157 - protected function get_search_query( &$join_form_in_query ) {
158 - $form_id = $this->params['form'];
159 - $s_query = array();
160 -
161 - if ( $form_id ) {
162 - $form_ids = $this->get_form_ids( $form_id );
163 - $s_query['it.form_id'] = count( $form_ids ) > 1 ? $form_ids : $form_ids[0];
164 - } else {
165 - $s_query[] = array(
166 - 'or' => 1,
167 - 'parent_form_id' => null,
168 - 'parent_form_id <' => 1,
169 - );
170 - $join_form_in_query = true;
171 - }
172 -
173 - $s = self::get_param(
83 + $this->set_pagination_args(
174 84 array(
175 - 'param' => 's',
176 - 'sanitize' => 'sanitize_text_field',
85 + 'total_items' => $total_items,
86 + 'per_page' => $per_page,
177 87 )
178 88 );
179 -
180 - if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
181 - $fid = self::get_param( array( 'param' => 'fid' ) );
182 - $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
183 - }
184 -
185 - return apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
186 89 }
187 90
188 - /**
189 - * @since 6.5.4
190 - *
191 - * @param int|string $form_id
192 - *
193 - * @return array<int>
194 - */
195 - protected function get_form_ids( $form_id ) {
196 - return array( (int) $form_id );
197 - }
198 -
199 - /**
200 - * @return void
201 - */
202 91 public function no_items() {
203 92 $s = self::get_param(
204 93 array(
205 94 'param' => 's',
@@ -205,9 +94,8 @@
205 94 'param' => 's',
206 95 'sanitize' => 'sanitize_text_field',
207 96 )
208 97 );
209 -
210 98 if ( ! empty( $s ) ) {
211 99 esc_html_e( 'No Entries Found', 'formidable' );
212 100
213 101 return;
@@ -218,9 +106,8 @@
218 106
219 107 if ( $form_id ) {
220 108 $form = FrmForm::getOne( $form_id );
221 109 }
222 -
223 110 $has_form = ! empty( $form );
224 111
225 112 if ( ! $has_form ) {
226 113 $has_form = FrmForm::getAll( array(), '', 1 );
@@ -228,38 +115,22 @@
228 115 }
229 116
230 117 $colspan = $this->get_column_count();
231 118
232 - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php';
119 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
233 120 }
234 121
235 - /**
236 - * @param string $text Text.
237 - * @param string $input_id Input ID.
238 - *
239 - * @return void
240 - */
241 122 public function search_box( $text, $input_id ) {
242 123 // Searching is a pro feature
243 124 }
244 125
245 - /**
246 - * @param string $which
247 - *
248 - * @return void
249 - */
250 126 protected function display_tablenav( $which ) {
251 127 $is_footer = ( $which !== 'top' );
252 -
253 128 if ( $is_footer && ! empty( $this->items ) ) {
254 - $utm = array(
255 - 'campaign' => 'spam-protection',
256 - 'content' => 'entries-list-spam-protection',
257 - );
258 129 ?>
259 130 <p>
260 131 <?php esc_html_e( 'Getting spam form submissions?', 'formidable' ); ?>
261 - <a href="<?php echo esc_url( FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/add-spam-protection/' ) ); ?>" target="_blank">
132 + <a href="https://formidableforms.com/knowledgebase/add-spam-protection/" target="_blank">
262 133 <?php esc_html_e( 'Learn how to prevent them.', 'formidable' ); ?>
263 134 </a>
264 135 </p>
265 136 <?php
@@ -266,16 +137,10 @@
266 137 }
267 138 parent::display_tablenav( $which );
268 139 }
269 140
270 - /**
271 - * @param string $which
272 - *
273 - * @return void
274 - */
275 141 protected function extra_tablenav( $which ) {
276 142 $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
277 -
278 143 if ( $which === 'top' && ! $form_id ) {
279 144 echo '<div class="alignleft actions">';
280 145
281 146 // Override the referrer to prevent it from being used for the screen options.
@@ -280,10 +145,8 @@
280 145
281 146 // Override the referrer to prevent it from being used for the screen options.
282 147 echo '<input type="hidden" name="_wp_http_referer" value="" />';
283 148
284 - echo '<label for="form" class="screen-reader-text">' . esc_html__( 'Filter by form', 'formidable' ) . '</label>';
285 -
286 149 FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) );
287 150 submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) );
288 151 echo '</div>';
289 152 }
@@ -302,9 +165,9 @@
302 165
303 166 $primary_column = '';
304 167
305 168 foreach ( $columns as $column_key => $column_display_name ) {
306 - if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden ) ) {
169 + if ( 'cb' != $column_key && ! in_array( $column_key, $hidden ) ) {
307 170 $primary_column = $column_key;
308 171 break;
309 172 }
310 173 }
@@ -311,29 +174,8 @@
311 174
312 175 return $primary_column;
313 176 }
314 177
315 - /**
316 - * @since 6.12
317 - *
318 - * @param object $item
319 - *
320 - * @return string
321 - */
322 - private static function get_entry_label( $item ) {
323 - if ( $item->name ) {
324 - return $item->name;
325 - }
326 - /* translators: %d: Entry id */
327 - return sprintf( __( 'Entry %d', 'formidable' ), $item->id );
328 - }
329 -
330 - /**
331 - * @param object $item
332 - * @param string $style
333 - *
334 - * @return string
335 - */
336 178 public function single_row( $item, $style = '' ) {
337 179 // Set up the hover actions for this user
338 180 $actions = array();
339 181 $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id;
@@ -343,10 +185,8 @@
343 185 $action_links = $this->row_actions( $actions );
344 186
345 187 // Set up the checkbox ( because the user is editable, otherwise its empty )
346 188 $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
347 - /* translators: %s: Form name */
348 - $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>';
349 189
350 190 $r = "<tr id='item-action-{$item->id}'$style>";
351 191
352 192 list( $columns, $hidden, , $primary ) = $this->get_column_info();
@@ -372,9 +212,9 @@
372 212
373 213 $form_id = $this->params['form'] ? $this->params['form'] : 0;
374 214 $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
375 215
376 - if ( $this->column_name === 'cb' ) {
216 + if ( $this->column_name == 'cb' ) {
377 217 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
378 218 } else {
379 219 if ( in_array( $column_name, $hidden, true ) ) {
380 220 $val = '';
@@ -382,21 +222,19 @@
382 222 $val = $this->column_value( $item );
383 223 }
384 224
385 225 $r .= "<td $attributes>";
386 -
387 226 if ( $column_name == $action_col ) {
388 - $edit_link = admin_url( 'admin.php?page=formidable-entries&frm_action=edit&id=' . $item->id );
389 - $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
390 - $r .= $action_links;
227 + $edit_link = FrmAppHelper::maybe_full_screen_link( '?page=formidable-entries&frm_action=edit&id=' . $item->id );
228 + $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
229 + $r .= $action_links;
391 230 } else {
392 231 $r .= $val;
393 232 }
394 -
395 233 $r .= '</td>';
396 - }//end if
234 + }
397 235 unset( $val );
398 - }//end foreach
236 + }
399 237 $r .= '</tr>';
400 238
401 239 return $r;
402 240 }
@@ -402,22 +240,15 @@
402 240 }
403 241
404 242 /**
405 243 * Get the column names that the logged in user can action on
406 - *
407 - * @return string[]
408 244 */
409 245 private function get_action_columns() {
410 246 return array( 'cb', 'form_id', 'id', 'post_id' );
411 247 }
412 248
413 - /**
414 - * @param object $item
415 - *
416 - * @return mixed
417 - */
418 249 private function column_value( $item ) {
419 - $col_name = $this->maybe_fix_column_name( $this->column_name );
250 + $col_name = $this->column_name;
420 251
421 252 switch ( $col_name ) {
422 253 case 'ip':
423 254 case 'id':
@@ -424,8 +255,9 @@
424 255 case 'item_key':
425 256 $val = $item->{$col_name};
426 257 break;
427 258 case 'name':
259 + case 'description':
428 260 $val = FrmAppHelper::truncate( strip_tags( $item->{$col_name} ), 100 );
429 261 break;
430 262 case 'created_at':
431 263 case 'updated_at':
@@ -432,19 +264,13 @@
432 264 $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
433 265 $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
434 266 break;
435 267 case 'is_draft':
436 - $entry_status = FrmEntriesHelper::get_entry_status_label( $item->is_draft );
437 - $val = sprintf(
438 - '<span class="frm-meta-tag frm-entry-status frm-entry-status-%s">%s</span>',
439 - sanitize_html_class( $item->is_draft ),
440 - esc_html( $entry_status )
441 - );
268 + $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' );
442 269 break;
443 270 case 'form_id':
444 271 $form_id = $item->form_id;
445 272 $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' );
446 -
447 273 if ( $user_can_edit_forms ) {
448 274 $val = FrmFormsHelper::edit_form_link( $form_id );
449 275 } else {
450 276 $val = FrmFormsHelper::edit_form_link_label( $form_id );
@@ -461,9 +287,8 @@
461 287 $val = $item->parent_item_id;
462 288 break;
463 289 default:
464 290 $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
465 -
466 291 if ( $val === false ) {
467 292 $this->get_column_value( $item, $val );
468 293 }
469 294
@@ -475,53 +300,29 @@
475 300 * @param mixed $val Column value.
476 301 * @param array $args Contains `item` and `col_name`.
477 302 */
478 303 $val = apply_filters( 'frm_entries_column_value', $val, compact( 'item', 'col_name' ) );
479 - }//end switch
304 + }
480 305
481 306 return $val;
482 307 }
483 308
484 309 /**
485 - * When a form has entries with the 0 item meta value, the values do not appear properly in the entries list.
486 - *
487 - * @since 6.11.2
488 - *
489 - * @param string $column_name
490 - *
491 - * @return string
492 - */
493 - private function maybe_fix_column_name( $column_name ) {
494 - if ( 0 === strpos( $column_name, '0_' ) ) {
495 - $column_name = substr( $column_name, 2 );
496 - }
497 - return $column_name;
498 - }
499 -
500 - /**
501 - * @param array $actions
502 - * @param object $item
503 310 * @param string $view_link
504 - *
505 - * @return void
506 311 */
507 312 private function get_actions( &$actions, $item, $view_link ) {
313 + $view_link = FrmAppHelper::maybe_full_screen_link( $view_link );
508 314 $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
509 315
510 316 if ( current_user_can( 'frm_delete_entries' ) ) {
511 317 $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
512 - $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>';
318 + $delete_link = FrmAppHelper::maybe_full_screen_link( $delete_link );
319 + $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" class="submitdelete" data-frmverify="' . esc_attr__( 'Permanently delete this entry?', 'formidable' ) . '">' . __( 'Delete', 'formidable' ) . '</a>';
513 320 }
514 321
515 322 $actions = apply_filters( 'frm_row_actions', $actions, $item );
516 323 }
517 324
518 - /**
519 - * @param object $item
520 - * @param false $val
521 - *
522 - * @return void
523 - */
524 325 private function get_column_value( $item, &$val ) {
525 326 $col_name = $this->column_name;
526 327
527 328 if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
@@ -535,9 +336,8 @@
535 336 list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
536 337 }
537 338
538 339 $field = FrmField::getOne( $col_name );
539 -
540 340 if ( ! $field ) {
541 341 return;
542 342 }
543 343
@@ -564,19 +364,7 @@
564 364 /**
565 365 * @return string
566 366 */
567 367 protected function confirm_bulk_delete() {
568 - return sprintf(
569 - /* translators: %1$s: HTML break line, %2$s: HTML bold text */
570 - esc_html__( 'ALL entries in this form will be permanently deleted.%1$sWant to proceed? Type %2$s below.', 'formidable' ),
571 - '<br/>',
572 - '<b>DELETE ALL</b>'
573 - );
574 - }
575 -
576 - /**
577 - * @return string
578 - */
579 - protected function loaded_from() {
580 - return 'entries-list';
368 + return __( 'ALL selected entries in this form will be permanently deleted. Want to proceed?', 'formidable' );
581 369 }
582 370 }