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
formidable / classes / helpers / FrmEntriesListHelper.php

FrmEntriesListHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.2.1, at classes/helpers/FrmEntriesListHelper.php

401 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmEntriesListHelper extends FrmListHelper {
7 protected $column_name;
8 protected $item;
9 protected $field;
10
11 /**
12 * @since 4.07
13 */
14 public $total_items = 0;
15
16 /**
17 * @return void
18 */
19 public function prepare_items() {
20 global $per_page;
21
22 $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
23 $form_id = $this->params['form'];
24
25 $s_query = array();
26
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 }
38
39 $s = self::get_param(
40 array(
41 'param' => 's',
42 'sanitize' => 'sanitize_text_field',
43 )
44 );
45
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 }
50
51 $s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
52
53 $orderby = self::get_param(
54 array(
55 'param' => 'orderby',
56 'default' => 'id',
57 )
58 );
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(
66 array(
67 'param' => 'order',
68 'default' => 'DESC',
69 )
70 );
71 $order = FrmDb::esc_order( $orderby . ' ' . $order );
72
73 $page = $this->get_pagenum();
74 $start = (int) self::get_param(
75 array(
76 'param' => 'start',
77 'default' => ( $page - 1 ) * $per_page,
78 )
79 );
80
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;
85
86 $this->set_pagination_args(
87 array(
88 'total_items' => $total_items,
89 'per_page' => $per_page,
90 )
91 );
92 }
93
94 /**
95 * @return void
96 */
97 public function no_items() {
98 $s = self::get_param(
99 array(
100 'param' => 's',
101 'sanitize' => 'sanitize_text_field',
102 )
103 );
104 if ( ! empty( $s ) ) {
105 esc_html_e( 'No Entries Found', 'formidable' );
106
107 return;
108 }
109
110 $form_id = $this->params['form'];
111 $form = $this->params['form'];
112
113 if ( $form_id ) {
114 $form = FrmForm::getOne( $form_id );
115 }
116 $has_form = ! empty( $form );
117
118 if ( ! $has_form ) {
119 $has_form = FrmForm::getAll( array(), '', 1 );
120 $has_form = ! empty( $has_form );
121 }
122
123 $colspan = $this->get_column_count();
124
125 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
126 }
127
128 /**
129 * @return void
130 */
131 public function search_box( $text, $input_id ) {
132 // Searching is a pro feature
133 }
134
135 /**
136 * @return void
137 */
138 protected function display_tablenav( $which ) {
139 $is_footer = ( $which !== 'top' );
140 if ( $is_footer && ! empty( $this->items ) ) {
141 ?>
142 <p>
143 <?php esc_html_e( 'Getting spam form submissions?', 'formidable' ); ?>
144 <a href="https://formidableforms.com/knowledgebase/add-spam-protection/" target="_blank">
145 <?php esc_html_e( 'Learn how to prevent them.', 'formidable' ); ?>
146 </a>
147 </p>
148 <?php
149 }
150 parent::display_tablenav( $which );
151 }
152
153 /**
154 * @return void
155 */
156 protected function extra_tablenav( $which ) {
157 $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
158 if ( $which === 'top' && ! $form_id ) {
159 echo '<div class="alignleft actions">';
160
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>';
167 }
168 }
169
170 /**
171 * Gets the name of the primary column in the Entries screen
172 *
173 * @since 2.0.14
174 *
175 * @return string $primary_column
176 */
177 protected function get_primary_column_name() {
178 $columns = get_column_headers( $this->screen );
179 $hidden = get_hidden_columns( $this->screen );
180
181 $primary_column = '';
182
183 foreach ( $columns as $column_key => $column_display_name ) {
184 if ( 'cb' != $column_key && ! in_array( $column_key, $hidden ) ) {
185 $primary_column = $column_key;
186 break;
187 }
188 }
189
190 return $primary_column;
191 }
192
193 /**
194 * @return string
195 */
196 public function single_row( $item, $style = '' ) {
197 // Set up the hover actions for this user
198 $actions = array();
199 $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id;
200
201 $this->get_actions( $actions, $item, $view_link );
202
203 $action_links = $this->row_actions( $actions );
204
205 // Set up the checkbox ( because the user is editable, otherwise its empty )
206 $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
207
208 $r = "<tr id='item-action-{$item->id}'$style>";
209
210 list( $columns, $hidden, , $primary ) = $this->get_column_info();
211 $action_col = false;
212 $action_columns = $this->get_action_columns();
213
214 foreach ( $columns as $column_name => $column_display_name ) {
215 $class = $column_name . ' column-' . $column_name;
216
217 if ( $column_name === $primary ) {
218 $class .= ' column-primary';
219 }
220
221 if ( in_array( $column_name, $hidden, true ) ) {
222 $class .= ' frm_hidden';
223 } elseif ( ! $action_col && ! in_array( $column_name, $action_columns, true ) ) {
224 $action_col = $column_name;
225 }
226
227 $attributes = 'class="' . esc_attr( $class ) . '"';
228 unset( $class );
229 $attributes .= ' data-colname="' . $column_display_name . '"';
230
231 $form_id = $this->params['form'] ? $this->params['form'] : 0;
232 $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
233
234 if ( $this->column_name == 'cb' ) {
235 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
236 } else {
237 if ( in_array( $column_name, $hidden, true ) ) {
238 $val = '';
239 } else {
240 $val = $this->column_value( $item );
241 }
242
243 $r .= "<td $attributes>";
244 if ( $column_name == $action_col ) {
245 $edit_link = admin_url( 'admin.php?page=formidable-entries&frm_action=edit&id=' . $item->id );
246 $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
247 $r .= $action_links;
248 } else {
249 $r .= $val;
250 }
251 $r .= '</td>';
252 }
253 unset( $val );
254 }
255 $r .= '</tr>';
256
257 return $r;
258 }
259
260 /**
261 * Get the column names that the logged in user can action on
262 *
263 * @return string[]
264 */
265 private function get_action_columns() {
266 return array( 'cb', 'form_id', 'id', 'post_id' );
267 }
268
269 /**
270 * @param object $item
271 */
272 private function column_value( $item ) {
273 $col_name = $this->column_name;
274
275 switch ( $col_name ) {
276 case 'ip':
277 case 'id':
278 case 'item_key':
279 $val = $item->{$col_name};
280 break;
281 case 'name':
282 case 'description':
283 $val = FrmAppHelper::truncate( strip_tags( $item->{$col_name} ), 100 );
284 break;
285 case 'created_at':
286 case 'updated_at':
287 $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
288 $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
289 break;
290 case 'is_draft':
291 $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' );
292 break;
293 case 'form_id':
294 $form_id = $item->form_id;
295 $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' );
296 if ( $user_can_edit_forms ) {
297 $val = FrmFormsHelper::edit_form_link( $form_id );
298 } else {
299 $val = FrmFormsHelper::edit_form_link_label( $form_id );
300 }
301 break;
302 case 'post_id':
303 $val = FrmAppHelper::post_edit_link( $item->post_id );
304 break;
305 case 'user_id':
306 $user = get_userdata( $item->user_id );
307 $val = $user ? $user->user_login : '';
308 break;
309 case 'parent_item_id':
310 $val = $item->parent_item_id;
311 break;
312 default:
313 $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
314 if ( $val === false ) {
315 $this->get_column_value( $item, $val );
316 }
317
318 /**
319 * Allows changing entries list column value.
320 *
321 * @since 5.1
322 *
323 * @param mixed $val Column value.
324 * @param array $args Contains `item` and `col_name`.
325 */
326 $val = apply_filters( 'frm_entries_column_value', $val, compact( 'item', 'col_name' ) );
327 }
328
329 return $val;
330 }
331
332 /**
333 * @param string $view_link
334 * @param array $actions
335 * @param object $item
336 *
337 * @return void
338 */
339 private function get_actions( &$actions, $item, $view_link ) {
340 $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
341
342 if ( current_user_can( 'frm_delete_entries' ) ) {
343 $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
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>';
345 }
346
347 $actions = apply_filters( 'frm_row_actions', $actions, $item );
348 }
349
350 /**
351 * @param false $val
352 *
353 * @return void
354 */
355 private function get_column_value( $item, &$val ) {
356 $col_name = $this->column_name;
357
358 if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
359 $sep_val = true;
360 $col_name = str_replace( 'frmsep_', '', $col_name );
361 } else {
362 $sep_val = false;
363 }
364
365 if ( strpos( $col_name, '-_-' ) ) {
366 list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
367 }
368
369 $field = FrmField::getOne( $col_name );
370 if ( ! $field ) {
371 return;
372 }
373
374 $atts = array(
375 'type' => $field->type,
376 'truncate' => true,
377 'post_id' => $item->post_id,
378 'entry_id' => $item->id,
379 'embedded_field_id' => 0,
380 );
381
382 if ( $sep_val ) {
383 $atts['saved_value'] = true;
384 }
385
386 if ( isset( $embedded_field_id ) ) {
387 $atts['embedded_field_id'] = $embedded_field_id;
388 unset( $embedded_field_id );
389 }
390
391 $val = FrmEntriesHelper::prepare_display_value( $item, $field, $atts );
392 }
393
394 /**
395 * @return string
396 */
397 protected function confirm_bulk_delete() {
398 return __( 'ALL selected entries in this form will be permanently deleted. Want to proceed?', 'formidable' );
399 }
400 }
401