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