PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4.4
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 / FrmFormsListHelper.php

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

367 lines 10.2 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 FrmFormsListHelper extends FrmListHelper {
7 public $status = '';
8
9 public $total_items = 0;
10
11 public function __construct( $args ) {
12 $this->status = self::get_param( array( 'param' => 'form_type' ) );
13
14 parent::__construct( $args );
15 }
16
17 public function prepare_items() {
18 global $wpdb, $per_page, $mode;
19
20 $page = $this->get_pagenum();
21 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
22
23 $mode = self::get_param(
24 array(
25 'param' => 'mode',
26 'default' => 'list',
27 )
28 );
29 $orderby = self::get_param(
30 array(
31 'param' => 'orderby',
32 'default' => 'name',
33 )
34 );
35 $order = self::get_param(
36 array(
37 'param' => 'order',
38 'default' => 'ASC',
39 )
40 );
41 $start = self::get_param(
42 array(
43 'param' => 'start',
44 'default' => ( $page - 1 ) * $per_page,
45 )
46 );
47
48 $s_query = array(
49 array(
50 'or' => 1,
51 'parent_form_id' => null,
52 'parent_form_id <' => 1,
53 ),
54 );
55 switch ( $this->status ) {
56 case 'draft':
57 $s_query['is_template'] = 0;
58 $s_query['status'] = 'draft';
59 break;
60 case 'trash':
61 $s_query['status'] = 'trash';
62 break;
63 default:
64 $s_query['is_template'] = 0;
65 $s_query['status !'] = 'trash';
66 break;
67 }
68
69 $s = self::get_param(
70 array(
71 'param' => 's',
72 'sanitize' => 'sanitize_text_field',
73 )
74 );
75 if ( $s != '' ) {
76 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
77 $search_terms = array_map( 'trim', $matches[0] );
78 foreach ( (array) $search_terms as $term ) {
79 $s_query[] = array(
80 'or' => true,
81 'name LIKE' => $term,
82 'description LIKE' => $term,
83 'created_at LIKE' => $term,
84 'form_key LIKE' => $term,
85 'id' => $term,
86 );
87 unset( $term );
88 }
89 }
90
91 $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
92 $total_items = FrmDb::get_count( 'frm_forms', $s_query );
93 $this->total_items = $total_items;
94
95 $this->set_pagination_args(
96 array(
97 'total_items' => $total_items,
98 'per_page' => $per_page,
99 )
100 );
101 }
102
103 public function no_items() {
104 if ( $this->status === 'trash' ) {
105 echo '<p>';
106 esc_html_e( 'No forms found in the trash.', 'formidable' );
107 ?>
108 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
109 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
110 </a>
111 <?php
112 echo '</p>';
113 } else {
114 $title = __( 'No Forms Found', 'formidable' );
115 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
116 }
117 }
118
119 public function get_bulk_actions() {
120 $actions = array();
121
122 if ( 'trash' == $this->status ) {
123 if ( current_user_can( 'frm_edit_forms' ) ) {
124 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
125 }
126
127 if ( current_user_can( 'frm_delete_forms' ) ) {
128 $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
129 }
130 } elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
131 $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
132 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
133 $actions['bulk_delete'] = __( 'Delete', 'formidable' );
134 }
135
136 return $actions;
137 }
138
139 public function extra_tablenav( $which ) {
140 if ( 'top' != $which ) {
141 return;
142 }
143
144 if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
145 ?>
146 <div class="alignleft actions frm_visible_overflow">
147 <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
148 </div>
149 <?php
150 }
151 }
152
153 public function get_views() {
154
155 $statuses = array(
156 'published' => __( 'My Forms', 'formidable' ),
157 'draft' => __( 'Drafts', 'formidable' ),
158 'trash' => __( 'Trash', 'formidable' ),
159 );
160
161 $links = array();
162 $counts = FrmForm::get_count();
163 $form_type = self::get_param(
164 array(
165 'param' => 'form_type',
166 'default' => 'published',
167 )
168 );
169
170 foreach ( $statuses as $status => $name ) {
171
172 if ( $status == $form_type ) {
173 $class = ' class="current"';
174 } else {
175 $class = '';
176 }
177
178 if ( $counts->{$status} || 'draft' !== $status ) {
179 /* translators: %1$s: Status, %2$s: Number of items */
180 $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
181 }
182
183 unset( $status, $name );
184 }
185
186 return $links;
187 }
188
189 public function pagination( $which ) {
190 global $mode;
191
192 parent::pagination( $which );
193
194 if ( 'top' === $which ) {
195 $this->view_switcher( $mode );
196 }
197 }
198
199 public function single_row( $item, $style = '' ) {
200 global $frm_vars, $mode;
201
202 // Set up the hover actions for this user
203 $actions = array();
204 $edit_link = FrmForm::get_edit_link( $item->id );
205
206 $this->get_actions( $actions, $item, $edit_link );
207
208 $action_links = $this->row_actions( $actions );
209
210 // Set up the checkbox ( because the user is editable, otherwise its empty )
211 $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
212
213 $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
214
215 list( $columns, $hidden ) = $this->get_column_info();
216
217 $format = 'Y/m/d';
218 if ( 'list' != $mode ) {
219 $format .= ' \<\b\r \/\> g:i:s a';
220 }
221
222 foreach ( $columns as $column_name => $column_display_name ) {
223 $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
224
225 $style = '';
226 if ( in_array( $column_name, $hidden ) ) {
227 $class .= ' frm_hidden';
228 }
229
230 $class = 'class="' . esc_attr( $class ) . '"';
231 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
232 $attributes = $class . $style . $data_colname;
233
234 switch ( $column_name ) {
235 case 'cb':
236 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
237 break;
238 case 'id':
239 case 'form_key':
240 $val = $item->{$column_name};
241 break;
242 case 'name':
243 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
244 $val .= $action_links;
245
246 break;
247 case 'created_at':
248 $date = gmdate( $format, strtotime( $item->created_at ) );
249 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
250 break;
251 case 'shortcode':
252 $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_html__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>';
253 $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $item ) );
254 break;
255 case 'entries':
256 if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
257 $val = FrmAppHelper::icon_by_class(
258 'frmfont frm_forbid_icon frm_bstooltip',
259 array(
260 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
261 'echo' => false,
262 )
263 );
264 } else {
265 $text = FrmEntry::getRecordCount( $item->id );
266 $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
267 unset( $text );
268 }
269 break;
270 default:
271 if ( method_exists( $this, 'column_' . $column_name ) ) {
272 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
273 }
274 break;
275 }
276
277 if ( isset( $val ) ) {
278 $r .= "<td $attributes>";
279 $r .= $val;
280 $r .= '</td>';
281 }
282 unset( $val );
283 }
284 $r .= '</tr>';
285
286 return $r;
287 }
288
289 /**
290 * @param string $edit_link
291 */
292 private function get_actions( &$actions, $item, $edit_link ) {
293 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
294 foreach ( $new_actions as $link => $action ) {
295 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
296 }
297
298 if ( 'trash' == $this->status ) {
299 $actions = $new_actions;
300
301 return;
302 }
303
304 if ( current_user_can( 'frm_edit_forms' ) ) {
305 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
306 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
307 }
308
309 $actions = array_merge( $actions, $new_actions );
310 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
311 }
312
313 /**
314 * @param string $edit_link
315 */
316 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
317 $form_name = $item->name;
318 if ( trim( $form_name ) == '' ) {
319 $form_name = __( '(no title)', 'formidable' );
320 }
321 $form_name = FrmAppHelper::kses( $form_name );
322 if ( 'excerpt' != $mode ) {
323 $form_name = FrmAppHelper::truncate( $form_name, 50 );
324 }
325
326 $val = '<strong>';
327 if ( 'trash' == $this->status ) {
328 $val .= $form_name;
329 } else {
330 $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
331 }
332
333 $this->add_draft_label( $item, $val );
334 $val .= '</strong>';
335
336 $this->add_form_description( $item, $val );
337
338 return $val;
339 }
340
341 /**
342 * @param string $val
343 */
344 private function add_draft_label( $item, &$val ) {
345 if ( 'draft' == $item->status && 'draft' != $this->status ) {
346 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
347 }
348 }
349
350 /**
351 * @param string $val
352 */
353 private function add_form_description( $item, &$val ) {
354 global $mode;
355 if ( 'excerpt' == $mode ) {
356 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
357 }
358 }
359
360 /**
361 * @return string
362 */
363 protected function confirm_bulk_delete() {
364 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
365 }
366 }
367