PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.02
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 +54 -228 6.25.1 → 5.2.02 View file →
@@ -3,9 +3,8 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmEntriesListHelper extends FrmListHelper {
7 -
8 7 protected $column_name;
9 8 protected $item;
10 9 protected $field;
11 10
@@ -10,87 +9,45 @@
10 9 protected $field;
11 10
12 11 /**
13 12 * @since 4.07
14 - * @var bool|int
15 13 */
16 14 public $total_items = 0;
17 15
18 - public function __construct( $args ) {
19 - parent::__construct( $args );
20 - $this->screen->set_screen_reader_content(
21 - array(
22 - 'heading_list' => esc_html__( 'Entries list', 'formidable' ),
23 - )
24 - );
25 - }
26 -
27 - /**
28 - * @return void
29 - */
30 16 public function prepare_items() {
31 - $this->set_per_page();
32 - $s_query = array();
17 + global $per_page;
33 18
34 - $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'];
35 21
36 - $this->items = $this->get_entry_items( $s_query, $join_form_in_query );
37 - $this->set_total_items( $s_query );
38 - $this->prepare_pagination();
39 - }
22 + $s_query = array();
40 23
41 - protected function set_total_items( $s_query ) {
42 - $this->total_items = FrmEntry::getRecordCount( $s_query );
43 - }
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 + }
44 35
45 - /**
46 - * Prepares pagination.
47 - *
48 - * @since 6.5.4
49 - */
50 - protected function prepare_pagination() {
51 - global $per_page;
52 -
53 - $this->set_pagination_args(
36 + $s = self::get_param(
54 37 array(
55 - 'total_items' => $this->total_items,
56 - 'per_page' => $per_page,
38 + 'param' => 's',
39 + 'sanitize' => 'sanitize_text_field',
57 40 )
58 41 );
59 - }
60 42
61 - /**
62 - * Sets the global $per_page variable
63 - *
64 - * @since 6.5.4
65 - */
66 - protected function set_per_page() {
67 - global $per_page;
68 - $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
69 - }
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 + }
70 47
71 - /**
72 - * @since 6.5.4
73 - *
74 - * @param array $s_query
75 - * @param bool $join_form_in_query
76 - *
77 - * @return array
78 - */
79 - protected function get_entry_items( &$s_query, &$join_form_in_query ) {
80 - global $per_page;
81 - $s_query = $this->get_search_query( $join_form_in_query );
82 - $order = $this->get_order_by();
83 - $limit = $this->get_limit( $per_page );
48 + $s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
84 49
85 - return FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query );
86 - }
87 -
88 - /**
89 - * @since 6.5.4
90 - * @return string
91 - */
92 - protected function get_order_by() {
93 50 $orderby = self::get_param(
94 51 array(
95 52 'param' => 'orderby',
96 53 'default' => 'id',
@@ -95,35 +52,22 @@
95 52 'param' => 'orderby',
96 53 'default' => 'id',
97 54 )
98 55 );
99 - $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(
100 63 array(
101 64 'param' => 'order',
102 65 'default' => 'DESC',
103 66 )
104 67 );
68 + $order = FrmDb::esc_order( $orderby . ' ' . $order );
105 69
106 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
107 -
108 - if ( strpos( $orderby, 'meta' ) !== false ) {
109 - $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) );
110 -
111 - if ( in_array( $order_field_type, array( 'number', 'scale', 'star' ), true ) ) {
112 - $orderby .= '+0';
113 - }
114 - }
115 -
116 - return FrmDb::esc_order( $orderby . ' ' . $order );
117 - }
118 -
119 - /**
120 - * @since 6.5.4
121 - *
122 - * @param int $per_page
123 - * @return string
124 - */
125 - protected function get_limit( $per_page ) {
126 70 $page = $this->get_pagenum();
127 71 $start = (int) self::get_param(
128 72 array(
129 73 'param' => 'start',
@@ -130,61 +74,21 @@
130 74 'default' => ( $page - 1 ) * $per_page,
131 75 )
132 76 );
133 77
134 - return FrmDb::esc_limit( $start . ',' . $per_page );
135 - }
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;
136 82
137 - /**
138 - * @since 6.5.4
139 - *
140 - * @param bool $join_form_in_query
141 - * @return array
142 - */
143 - protected function get_search_query( &$join_form_in_query ) {
144 - $form_id = $this->params['form'];
145 - $s_query = array();
146 -
147 - if ( $form_id ) {
148 - $form_ids = $this->get_form_ids( $form_id );
149 - $s_query['it.form_id'] = count( $form_ids ) > 1 ? $form_ids : $form_ids[0];
150 - } else {
151 - $s_query[] = array(
152 - 'or' => 1,
153 - 'parent_form_id' => null,
154 - 'parent_form_id <' => 1,
155 - );
156 - $join_form_in_query = true;
157 - }
158 -
159 - $s = self::get_param(
83 + $this->set_pagination_args(
160 84 array(
161 - 'param' => 's',
162 - 'sanitize' => 'sanitize_text_field',
85 + 'total_items' => $total_items,
86 + 'per_page' => $per_page,
163 87 )
164 88 );
165 -
166 - if ( $s != '' && FrmAppHelper::pro_is_installed() ) {
167 - $fid = self::get_param( array( 'param' => 'fid' ) );
168 - $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid );
169 - }
170 -
171 - return apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
172 89 }
173 90
174 - /**
175 - * @since 6.5.4
176 - *
177 - * @param int|string $form_id
178 - * @return array<int>
179 - */
180 - protected function get_form_ids( $form_id ) {
181 - return array( (int) $form_id );
182 - }
183 -
184 - /**
185 - * @return void
186 - */
187 91 public function no_items() {
188 92 $s = self::get_param(
189 93 array(
190 94 'param' => 's',
@@ -211,32 +115,22 @@
211 115 }
212 116
213 117 $colspan = $this->get_column_count();
214 118
215 - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php';
119 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
216 120 }
217 121
218 - /**
219 - * @return void
220 - */
221 122 public function search_box( $text, $input_id ) {
222 123 // Searching is a pro feature
223 124 }
224 125
225 - /**
226 - * @return void
227 - */
228 126 protected function display_tablenav( $which ) {
229 127 $is_footer = ( $which !== 'top' );
230 128 if ( $is_footer && ! empty( $this->items ) ) {
231 - $utm = array(
232 - 'campaign' => 'spam-protection',
233 - 'content' => 'entries-list-spam-protection',
234 - );
235 129 ?>
236 130 <p>
237 131 <?php esc_html_e( 'Getting spam form submissions?', 'formidable' ); ?>
238 - <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">
239 133 <?php esc_html_e( 'Learn how to prevent them.', 'formidable' ); ?>
240 134 </a>
241 135 </p>
242 136 <?php
@@ -243,11 +137,8 @@
243 137 }
244 138 parent::display_tablenav( $which );
245 139 }
246 140
247 - /**
248 - * @return void
249 - */
250 141 protected function extra_tablenav( $which ) {
251 142 $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
252 143 if ( $which === 'top' && ! $form_id ) {
253 144 echo '<div class="alignleft actions">';
@@ -254,10 +145,8 @@
254 145
255 146 // Override the referrer to prevent it from being used for the screen options.
256 147 echo '<input type="hidden" name="_wp_http_referer" value="" />';
257 148
258 - echo '<label for="form" class="screen-reader-text">' . esc_html__( 'Filter by form', 'formidable' ) . '</label>';
259 -
260 149 FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) );
261 150 submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) );
262 151 echo '</div>';
263 152 }
@@ -276,9 +165,9 @@
276 165
277 166 $primary_column = '';
278 167
279 168 foreach ( $columns as $column_key => $column_display_name ) {
280 - if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden ) ) {
169 + if ( 'cb' != $column_key && ! in_array( $column_key, $hidden ) ) {
281 170 $primary_column = $column_key;
282 171 break;
283 172 }
284 173 }
@@ -285,25 +174,8 @@
285 174
286 175 return $primary_column;
287 176 }
288 177
289 - /**
290 - * @since 6.12
291 - *
292 - * @param object $item
293 - * @return string
294 - */
295 - private static function get_entry_label( $item ) {
296 - if ( $item->name ) {
297 - return $item->name;
298 - }
299 - /* translators: %d: Entry id */
300 - return sprintf( __( 'Entry %d', 'formidable' ), $item->id );
301 - }
302 -
303 - /**
304 - * @return string
305 - */
306 178 public function single_row( $item, $style = '' ) {
307 179 // Set up the hover actions for this user
308 180 $actions = array();
309 181 $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id;
@@ -313,10 +185,8 @@
313 185 $action_links = $this->row_actions( $actions );
314 186
315 187 // Set up the checkbox ( because the user is editable, otherwise its empty )
316 188 $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
317 - /* 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>';
319 189
320 190 $r = "<tr id='item-action-{$item->id}'$style>";
321 191
322 192 list( $columns, $hidden, , $primary ) = $this->get_column_info();
@@ -342,9 +212,9 @@
342 212
343 213 $form_id = $this->params['form'] ? $this->params['form'] : 0;
344 214 $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
345 215
346 - if ( $this->column_name === 'cb' ) {
216 + if ( $this->column_name == 'cb' ) {
347 217 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
348 218 } else {
349 219 if ( in_array( $column_name, $hidden, true ) ) {
350 220 $val = '';
@@ -353,11 +223,11 @@
353 223 }
354 224
355 225 $r .= "<td $attributes>";
356 226 if ( $column_name == $action_col ) {
357 - $edit_link = admin_url( 'admin.php?page=formidable-entries&frm_action=edit&id=' . $item->id );
358 - $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
359 - $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;
360 230 } else {
361 231 $r .= $val;
362 232 }
363 233 $r .= '</td>';
@@ -362,9 +232,9 @@
362 232 }
363 233 $r .= '</td>';
364 234 }
365 235 unset( $val );
366 - }//end foreach
236 + }
367 237 $r .= '</tr>';
368 238
369 239 return $r;
370 240 }
@@ -370,20 +240,15 @@
370 240 }
371 241
372 242 /**
373 243 * Get the column names that the logged in user can action on
374 - *
375 - * @return string[]
376 244 */
377 245 private function get_action_columns() {
378 246 return array( 'cb', 'form_id', 'id', 'post_id' );
379 247 }
380 248
381 - /**
382 - * @param object $item
383 - */
384 249 private function column_value( $item ) {
385 - $col_name = $this->maybe_fix_column_name( $this->column_name );
250 + $col_name = $this->column_name;
386 251
387 252 switch ( $col_name ) {
388 253 case 'ip':
389 254 case 'id':
@@ -390,8 +255,9 @@
390 255 case 'item_key':
391 256 $val = $item->{$col_name};
392 257 break;
393 258 case 'name':
259 + case 'description':
394 260 $val = FrmAppHelper::truncate( strip_tags( $item->{$col_name} ), 100 );
395 261 break;
396 262 case 'created_at':
397 263 case 'updated_at':
@@ -398,14 +264,9 @@
398 264 $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
399 265 $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
400 266 break;
401 267 case 'is_draft':
402 - $entry_status = FrmEntriesHelper::get_entry_status_label( $item->is_draft );
403 - $val = sprintf(
404 - '<span class="frm-meta-tag frm-entry-status frm-entry-status-%s">%s</span>',
405 - sanitize_html_class( $item->is_draft ),
406 - esc_html( $entry_status )
407 - );
268 + $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' );
408 269 break;
409 270 case 'form_id':
410 271 $form_id = $item->form_id;
411 272 $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' );
@@ -439,52 +300,29 @@
439 300 * @param mixed $val Column value.
440 301 * @param array $args Contains `item` and `col_name`.
441 302 */
442 303 $val = apply_filters( 'frm_entries_column_value', $val, compact( 'item', 'col_name' ) );
443 - }//end switch
304 + }
444 305
445 306 return $val;
446 307 }
447 308
448 309 /**
449 - * When a form has entries with the 0 item meta value, the values do not appear properly in the entries list.
450 - *
451 - * @since 6.11.2
452 - *
453 - * @param string $column_name
454 - * @return string
455 - */
456 - private function maybe_fix_column_name( $column_name ) {
457 - if ( 0 === strpos( $column_name, '0_' ) ) {
458 - $column_name = substr( $column_name, 2 );
459 - }
460 - return $column_name;
461 - }
462 -
463 - /**
464 - * @param array $actions
465 - * @param object $item
466 310 * @param string $view_link
467 - *
468 - * @return void
469 311 */
470 312 private function get_actions( &$actions, $item, $view_link ) {
313 + $view_link = FrmAppHelper::maybe_full_screen_link( $view_link );
471 314 $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
472 315
473 316 if ( current_user_can( 'frm_delete_entries' ) ) {
474 317 $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>';
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>';
476 320 }
477 321
478 322 $actions = apply_filters( 'frm_row_actions', $actions, $item );
479 323 }
480 324
481 - /**
482 - * @param object $item
483 - * @param false $val
484 - *
485 - * @return void
486 - */
487 325 private function get_column_value( $item, &$val ) {
488 326 $col_name = $this->column_name;
489 327
490 328 if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
@@ -526,19 +364,7 @@
526 364 /**
527 365 * @return string
528 366 */
529 367 protected function confirm_bulk_delete() {
530 - return sprintf(
531 - /* translators: %1$s: HTML break line, %2$s: HTML bold text */
532 - esc_html__( 'ALL entries in this form will be permanently deleted.%1$sWant to proceed? Type %2$s below.', 'formidable' ),
533 - '<br/>',
534 - '<b>DELETE ALL</b>'
535 - );
536 - }
537 -
538 - /**
539 - * @return string
540 - */
541 - protected function loaded_from() {
542 - return 'entries-list';
368 + return __( 'ALL selected entries in this form will be permanently deleted. Want to proceed?', 'formidable' );
543 369 }
544 370 }