PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.4.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.4.2
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.4.2, at classes/helpers/FrmEntriesListHelper.php

405 lines 10.7 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 $val = FrmAppHelper::truncate( strip_tags( $item->{$col_name} ), 100 );
283 break;
284 case 'created_at':
285 case 'updated_at':
286 $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
287 $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
288 break;
289 case 'is_draft':
290 $entry_status = FrmEntriesHelper::get_entry_status_label( $item->is_draft );
291 $val = sprintf(
292 '<span class="frm-entry-status frm-entry-status-%s">%s</span>',
293 sanitize_html_class( $item->is_draft ),
294 esc_html( $entry_status )
295 );
296 break;
297 case 'form_id':
298 $form_id = $item->form_id;
299 $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' );
300 if ( $user_can_edit_forms ) {
301 $val = FrmFormsHelper::edit_form_link( $form_id );
302 } else {
303 $val = FrmFormsHelper::edit_form_link_label( $form_id );
304 }
305 break;
306 case 'post_id':
307 $val = FrmAppHelper::post_edit_link( $item->post_id );
308 break;
309 case 'user_id':
310 $user = get_userdata( $item->user_id );
311 $val = $user ? $user->user_login : '';
312 break;
313 case 'parent_item_id':
314 $val = $item->parent_item_id;
315 break;
316 default:
317 $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
318 if ( $val === false ) {
319 $this->get_column_value( $item, $val );
320 }
321
322 /**
323 * Allows changing entries list column value.
324 *
325 * @since 5.1
326 *
327 * @param mixed $val Column value.
328 * @param array $args Contains `item` and `col_name`.
329 */
330 $val = apply_filters( 'frm_entries_column_value', $val, compact( 'item', 'col_name' ) );
331 }
332
333 return $val;
334 }
335
336 /**
337 * @param string $view_link
338 * @param array $actions
339 * @param object $item
340 *
341 * @return void
342 */
343 private function get_actions( &$actions, $item, $view_link ) {
344 $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
345
346 if ( current_user_can( 'frm_delete_entries' ) ) {
347 $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
348 $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>';
349 }
350
351 $actions = apply_filters( 'frm_row_actions', $actions, $item );
352 }
353
354 /**
355 * @param false $val
356 *
357 * @return void
358 */
359 private function get_column_value( $item, &$val ) {
360 $col_name = $this->column_name;
361
362 if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
363 $sep_val = true;
364 $col_name = str_replace( 'frmsep_', '', $col_name );
365 } else {
366 $sep_val = false;
367 }
368
369 if ( strpos( $col_name, '-_-' ) ) {
370 list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
371 }
372
373 $field = FrmField::getOne( $col_name );
374 if ( ! $field ) {
375 return;
376 }
377
378 $atts = array(
379 'type' => $field->type,
380 'truncate' => true,
381 'post_id' => $item->post_id,
382 'entry_id' => $item->id,
383 'embedded_field_id' => 0,
384 );
385
386 if ( $sep_val ) {
387 $atts['saved_value'] = true;
388 }
389
390 if ( isset( $embedded_field_id ) ) {
391 $atts['embedded_field_id'] = $embedded_field_id;
392 unset( $embedded_field_id );
393 }
394
395 $val = FrmEntriesHelper::prepare_display_value( $item, $field, $atts );
396 }
397
398 /**
399 * @return string
400 */
401 protected function confirm_bulk_delete() {
402 return __( 'ALL selected entries in this form will be permanently deleted. Want to proceed?', 'formidable' );
403 }
404 }
405