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

340 lines 9.4 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 public function prepare_items() {
17 global $per_page;
18
19 $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' );
20 $form_id = $this->params['form'];
21
22 $s_query = array();
23
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 }
35
36 $s = self::get_param(
37 array(
38 'param' => 's',
39 'sanitize' => 'sanitize_text_field',
40 )
41 );
42
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 }
47
48 $s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) );
49
50 $orderby = self::get_param(
51 array(
52 'param' => 'orderby',
53 'default' => 'id',
54 )
55 );
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(
63 array(
64 'param' => 'order',
65 'default' => 'DESC',
66 )
67 );
68 $order = FrmDb::esc_order( $orderby . ' ' . $order );
69
70 $page = $this->get_pagenum();
71 $start = (int) self::get_param(
72 array(
73 'param' => 'start',
74 'default' => ( $page - 1 ) * $per_page,
75 )
76 );
77
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;
82
83 $this->set_pagination_args(
84 array(
85 'total_items' => $total_items,
86 'per_page' => $per_page,
87 )
88 );
89 }
90
91 public function no_items() {
92 $s = self::get_param(
93 array(
94 'param' => 's',
95 'sanitize' => 'sanitize_text_field',
96 )
97 );
98 if ( ! empty( $s ) ) {
99 esc_html_e( 'No Entries Found', 'formidable' );
100
101 return;
102 }
103
104 $form_id = $this->params['form'];
105 $form = $this->params['form'];
106
107 if ( $form_id ) {
108 $form = FrmForm::getOne( $form_id );
109 }
110 $has_form = ! empty( $form );
111
112 if ( ! $has_form ) {
113 $has_form = FrmForm::getAll( array(), '', 1 );
114 $has_form = ! empty( $has_form );
115 }
116
117 $colspan = $this->get_column_count();
118
119 include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.php' );
120 }
121
122 public function search_box( $text, $input_id ) {
123 // Searching is a pro feature
124 }
125
126 protected function display_tablenav( $which ) {
127 $is_footer = ( $which !== 'top' );
128 if ( $is_footer && ! empty( $this->items ) ) {
129 ?>
130 <p>
131 <?php esc_html_e( 'Getting spam form submissions?', 'formidable' ); ?>
132 <a href="https://formidableforms.com/knowledgebase/add-spam-protection/" target="_blank">
133 <?php esc_html_e( 'Learn how to prevent them.', 'formidable' ); ?>
134 </a>
135 </p>
136 <?php
137 }
138 parent::display_tablenav( $which );
139 }
140
141 protected function extra_tablenav( $which ) {
142 $form_id = FrmAppHelper::simple_get( 'form', 'absint' );
143 if ( $which == 'top' && empty( $form_id ) ) {
144 echo '<div class="alignleft actions">';
145
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>';
152 }
153 }
154
155 /**
156 * Gets the name of the primary column in the Entries screen
157 *
158 * @since 2.0.14
159 *
160 * @return string $primary_column
161 */
162 protected function get_primary_column_name() {
163 $columns = get_column_headers( $this->screen );
164 $hidden = get_hidden_columns( $this->screen );
165
166 $primary_column = '';
167
168 foreach ( $columns as $column_key => $column_display_name ) {
169 if ( 'cb' != $column_key && ! in_array( $column_key, $hidden ) ) {
170 $primary_column = $column_key;
171 break;
172 }
173 }
174
175 return $primary_column;
176 }
177
178 public function single_row( $item, $style = '' ) {
179 // Set up the hover actions for this user
180 $actions = array();
181 $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id;
182
183 $this->get_actions( $actions, $item, $view_link );
184
185 $action_links = $this->row_actions( $actions );
186
187 // Set up the checkbox ( because the user is editable, otherwise its empty )
188 $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
189
190 $r = "<tr id='item-action-{$item->id}'$style>";
191
192 list( $columns, $hidden, , $primary ) = $this->get_column_info();
193 $action_col = false;
194
195 foreach ( $columns as $column_name => $column_display_name ) {
196 $class = $column_name . ' column-' . $column_name;
197
198 if ( $column_name === $primary ) {
199 $class .= ' column-primary';
200 }
201
202 if ( in_array( $column_name, $hidden ) ) {
203 $class .= ' frm_hidden';
204 } elseif ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) {
205 $action_col = $column_name;
206 }
207
208 $attributes = 'class="' . esc_attr( $class ) . '"';
209 unset( $class );
210 $attributes .= ' data-colname="' . $column_display_name . '"';
211
212 $form_id = $this->params['form'] ? $this->params['form'] : 0;
213 $this->column_name = preg_replace( '/^(' . $form_id . '_)/', '', $column_name );
214
215 if ( $this->column_name == 'cb' ) {
216 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
217 } else {
218 if ( in_array( $column_name, $hidden ) ) {
219 $val = '';
220 } else {
221 $val = $this->column_value( $item );
222 }
223
224 $r .= "<td $attributes>";
225 if ( $column_name == $action_col ) {
226 $edit_link = FrmAppHelper::maybe_full_screen_link( '?page=formidable-entries&frm_action=edit&id=' . $item->id );
227 $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> ';
228 $r .= $action_links;
229 } else {
230 $r .= $val;
231 }
232 $r .= '</td>';
233 }
234 unset( $val );
235 }
236 $r .= '</tr>';
237
238 return $r;
239 }
240
241 private function column_value( $item ) {
242 $col_name = $this->column_name;
243
244 switch ( $col_name ) {
245 case 'ip':
246 case 'id':
247 case 'item_key':
248 $val = $item->{$col_name};
249 break;
250 case 'name':
251 case 'description':
252 $val = FrmAppHelper::truncate( strip_tags( $item->{$col_name} ), 100 );
253 break;
254 case 'created_at':
255 case 'updated_at':
256 $date = FrmAppHelper::get_formatted_time( $item->{$col_name} );
257 $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>';
258 break;
259 case 'is_draft':
260 $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' );
261 break;
262 case 'form_id':
263 $val = FrmFormsHelper::edit_form_link( $item->form_id );
264 break;
265 case 'post_id':
266 $val = FrmAppHelper::post_edit_link( $item->post_id );
267 break;
268 case 'user_id':
269 $user = get_userdata( $item->user_id );
270 $val = $user ? $user->user_login : '';
271 break;
272 case 'parent_item_id':
273 $val = $item->parent_item_id;
274 break;
275 default:
276 $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) );
277 if ( $val === false ) {
278 $this->get_column_value( $item, $val );
279 }
280 }
281
282 return $val;
283 }
284
285 /**
286 * @param string $view_link
287 */
288 private function get_actions( &$actions, $item, $view_link ) {
289 $view_link = FrmAppHelper::maybe_full_screen_link( $view_link );
290 $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . __( 'View', 'formidable' ) . '</a>';
291
292 if ( current_user_can( 'frm_delete_entries' ) ) {
293 $delete_link = '?page=formidable-entries&frm_action=destroy&id=' . $item->id . '&form=' . $this->params['form'];
294 $delete_link = FrmAppHelper::maybe_full_screen_link( $delete_link );
295 $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>';
296 }
297
298 $actions = apply_filters( 'frm_row_actions', $actions, $item );
299 }
300
301 private function get_column_value( $item, &$val ) {
302 $col_name = $this->column_name;
303
304 if ( strpos( $col_name, 'frmsep_' ) === 0 ) {
305 $sep_val = true;
306 $col_name = str_replace( 'frmsep_', '', $col_name );
307 } else {
308 $sep_val = false;
309 }
310
311 if ( strpos( $col_name, '-_-' ) ) {
312 list( $col_name, $embedded_field_id ) = explode( '-_-', $col_name );
313 }
314
315 $field = FrmField::getOne( $col_name );
316 if ( ! $field ) {
317 return;
318 }
319
320 $atts = array(
321 'type' => $field->type,
322 'truncate' => true,
323 'post_id' => $item->post_id,
324 'entry_id' => $item->id,
325 'embedded_field_id' => 0,
326 );
327
328 if ( $sep_val ) {
329 $atts['saved_value'] = true;
330 }
331
332 if ( isset( $embedded_field_id ) ) {
333 $atts['embedded_field_id'] = $embedded_field_id;
334 unset( $embedded_field_id );
335 }
336
337 $val = FrmEntriesHelper::prepare_display_value( $item, $field, $atts );
338 }
339 }
340