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