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

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

511 lines 13.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 FrmFormsListHelper extends FrmListHelper {
7
8 /**
9 * @var string
10 */
11 public $status = '';
12
13 public $total_items = 0;
14
15 public function __construct( $args ) {
16 $this->status = self::get_param( array( 'param' => 'form_type' ) );
17
18 parent::__construct( $args );
19 $this->screen->set_screen_reader_content(
20 array(
21 'heading_list' => esc_html__( 'Forms list', 'formidable' ),
22 )
23 );
24 }
25
26 /**
27 * @return void
28 */
29 public function prepare_items() {
30 global $wpdb, $per_page, $mode;
31
32 $page = $this->get_pagenum();
33 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
34
35 $mode = self::get_param(
36 array(
37 'param' => 'mode',
38 'default' => 'list',
39 )
40 );
41 $orderby = self::get_param(
42 array(
43 'param' => 'orderby',
44 'default' => 'name',
45 )
46 );
47 $order = self::get_param(
48 array(
49 'param' => 'order',
50 'default' => 'ASC',
51 )
52 );
53
54 FrmAppController::apply_saved_sort_preference( $orderby, $order );
55
56 $start = self::get_param(
57 array(
58 'param' => 'start',
59 'default' => ( $page - 1 ) * $per_page,
60 )
61 );
62
63 $s_query = array(
64 array(
65 'or' => 1,
66 'parent_form_id' => null,
67 'parent_form_id <' => 1,
68 ),
69 );
70 switch ( $this->status ) {
71 case 'draft':
72 $s_query['is_template'] = 0;
73 $s_query['status'] = 'draft';
74 break;
75 case 'trash':
76 $s_query['status'] = 'trash';
77 break;
78 default:
79 $s_query['is_template'] = 0;
80 $s_query['status !'] = 'trash';
81 break;
82 }
83
84 $s = self::get_param(
85 array(
86 'param' => 's',
87 'sanitize' => 'sanitize_text_field',
88 )
89 );
90
91 if ( $s != '' ) {
92 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
93 $search_terms = array_map( 'trim', $matches[0] );
94
95 foreach ( $search_terms as $term ) {
96 $s_query[] = array(
97 'or' => true,
98 'name LIKE' => $term,
99 'description LIKE' => $term,
100 'created_at LIKE' => $term,
101 'form_key LIKE' => $term,
102 'id' => $term,
103 );
104 unset( $term );
105 }
106 }
107
108 $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
109 $total_items = FrmDb::get_count( 'frm_forms', $s_query );
110 $this->total_items = $total_items;
111
112 $this->set_pagination_args(
113 array(
114 'total_items' => $total_items,
115 'per_page' => $per_page,
116 )
117 );
118 }
119
120 /**
121 * @return void
122 */
123 public function no_items() {
124 if ( $this->status === 'trash' ) {
125 echo '<p>';
126 esc_html_e( 'No forms found in the trash.', 'formidable' );
127 ?>
128 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
129 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
130 </a>
131 <?php
132 echo '</p>';
133 } else {
134 $title = __( 'No Forms Found', 'formidable' );
135 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
136 }
137 }
138
139 public function get_bulk_actions() {
140 $actions = array();
141
142 if ( 'trash' === $this->status ) {
143 if ( current_user_can( 'frm_edit_forms' ) ) {
144 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
145 }
146
147 if ( current_user_can( 'frm_delete_forms' ) ) {
148 $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
149 }
150 } elseif ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
151 $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
152 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
153 $actions['bulk_delete'] = __( 'Delete', 'formidable' );
154 }
155
156 return $actions;
157 }
158
159 /**
160 * @param string $which
161 *
162 * @return void
163 */
164 public function extra_tablenav( $which ) {
165 if ( 'top' !== $which ) {
166 return;
167 }
168
169 if ( 'trash' === $this->status && current_user_can( 'frm_delete_forms' ) ) {
170 ?>
171 <div class="alignleft actions frm_visible_overflow">
172 <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
173 </div>
174 <?php
175 }
176 }
177
178 /**
179 * @return array
180 */
181 public function get_views() {
182 $statuses = array(
183 'published' => __( 'My Forms', 'formidable' ),
184 'draft' => __( 'Drafts', 'formidable' ),
185 'trash' => __( 'Trash', 'formidable' ),
186 );
187
188 $links = array();
189 $counts = FrmForm::get_count();
190 $form_type = FrmAppHelper::simple_get( 'form_type', 'sanitize_title', 'published' );
191
192 if ( isset( $statuses[ $form_type ] ) ) {
193 $counts->$form_type = $this->total_items;
194 }
195
196 $form_type = self::get_param(
197 array(
198 'param' => 'form_type',
199 'default' => 'published',
200 )
201 );
202
203 foreach ( $statuses as $status => $name ) {
204
205 if ( $status == $form_type ) {
206 $class = ' class="current"';
207 } else {
208 $class = '';
209 }
210
211 if ( $counts->{$status} || 'draft' !== $status ) {
212 /* translators: %1$s: Status, %2$s: Number of items */
213 $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>';
214 }
215
216 unset( $status, $name );
217 }
218
219 return $links;
220 }
221
222 /**
223 * @param string $which
224 *
225 * @return void
226 */
227 public function pagination( $which ) {
228 global $mode;
229
230 parent::pagination( $which );
231
232 if ( 'top' === $which ) {
233 $this->view_switcher( $mode );
234 }
235 }
236
237 /**
238 * @param stdClass $item
239 * @param string $style
240 *
241 * @return string
242 */
243 public function single_row( $item, $style = '' ) {
244 global $frm_vars, $mode;
245
246 // Set up the hover actions for this user
247 $actions = array();
248 $edit_link = FrmForm::get_edit_link( $item->id );
249
250 $this->get_actions( $actions, $item, $edit_link );
251
252 $action_links = $this->row_actions( $actions );
253
254 // Set up the checkbox ( because the user is editable, otherwise its empty )
255 $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
256 $checkbox_label_text = sprintf(
257 // translators: Form title
258 __( 'Select %s', 'formidable' ),
259 ! empty( $item->name ) ? $item->name : FrmFormsHelper::get_no_title_text()
260 );
261
262 $checkbox .= '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . esc_html( $checkbox_label_text ) . '</span></label>';
263
264 $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
265
266 list( $columns, $hidden ) = $this->get_column_info();
267
268 $format = 'Y/m/d';
269
270 if ( 'list' !== $mode ) {
271 $format .= ' \<\b\r \/\> g:i:s a';
272 }
273
274 foreach ( $columns as $column_name => $column_display_name ) {
275 $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' );
276
277 $style = '';
278
279 if ( in_array( $column_name, $hidden, true ) ) {
280 $class .= ' frm_hidden';
281 }
282
283 if ( $column_name === 'name' ) {
284 $class .= ' column-primary';
285 }
286
287 $class = 'class="' . esc_attr( $class ) . '"';
288 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
289 $attributes = $class . $style . $data_colname;
290
291 switch ( $column_name ) {
292 case 'cb':
293 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
294 break;
295 case 'id':
296 case 'form_key':
297 $val = $item->{$column_name};
298 break;
299 case 'name':
300 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
301 $val .= $action_links;
302 break;
303 case 'created_at':
304 $date = gmdate( $format, strtotime( $item->created_at ) );
305 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
306 break;
307 case 'entries':
308 if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
309 $val = FrmAppHelper::icon_by_class(
310 'frmfont frm_forbid_icon frm_bstooltip',
311 array(
312 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
313 'echo' => false,
314 )
315 );
316 } else {
317 $text = FrmEntry::getRecordCount( $item->id );
318 $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
319 unset( $text );
320 }
321 break;
322 default:
323 if ( method_exists( $this, 'column_' . $column_name ) ) {
324 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
325 }
326 break;
327 }//end switch
328
329 if ( isset( $val ) ) {
330 $r .= "<td $attributes>";
331 $r .= $val;
332 $r .= '</td>';
333 }
334 unset( $val );
335 }//end foreach
336 $r .= '</tr>';
337
338 return $r;
339 }
340
341 /**
342 * Get the HTML for the Actions column in the form list.
343 * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
344 *
345 * @since 6.0
346 *
347 * @param stdClass $form
348 *
349 * @return string
350 */
351 protected function column_shortcode( $form ) {
352 $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_attr__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>';
353 $val .= $this->column_style( $form );
354 $val .= $this->column_views( $form );
355 $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
356 // Remove the space hard coded in Landing pages.
357 $val = str_replace( '&nbsp;', '', $val );
358 $val = '<div>' . $val . '</div>';
359 return $val;
360 }
361
362 /**
363 * Get the HTML for the Style column in the form list.
364 *
365 * @since 6.0
366 *
367 * @param stdClass $form
368 *
369 * @return string
370 */
371 protected function column_style( $form ) {
372 $style_setting = $form->options['custom_style'] ?? '';
373 $frm_settings = FrmAppHelper::get_settings();
374
375 if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
376 // Don't show a link if styling is off.
377 return '';
378 }
379
380 $style = FrmStylesController::get_form_style( $form );
381
382 if ( ! $style ) {
383 // Do a second pass to avoid null values.
384 $frm_style = new FrmStyle( 'default' );
385 $style = $frm_style->get_one();
386 }
387
388 $href = FrmStylesHelper::get_edit_url( $style, $form->id );
389 return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>';
390 }
391
392 /**
393 * Generate the HTML for the form Views page.
394 *
395 * @since 6.19
396 *
397 * @param stdClass $form Form object.
398 *
399 * @return string
400 */
401 protected function column_views( $form ) {
402 $attributes = array(
403 'href' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $form->id ) . '&show_nav=1' ),
404 'title' => __( 'Link to list of all views for this form.', 'formidable' ),
405 'target' => '_blank',
406 );
407
408 return '<a ' . FrmAppHelper::array_to_html_params( $attributes ) . '>
409 ' . FrmAppHelper::icon_by_class( 'frmfont frm_eye_icon', array( 'echo' => false ) ) .
410 '</a>';
411 }
412
413 /**
414 * @param array $actions
415 * @param object $item
416 * @param string $edit_link
417 *
418 * @return void
419 */
420 private function get_actions( &$actions, $item, $edit_link ) {
421 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
422
423 foreach ( $new_actions as $link => $action ) {
424 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
425 }
426
427 if ( 'trash' === $this->status ) {
428 $actions = $new_actions;
429 return;
430 }
431
432 if ( current_user_can( 'frm_edit_forms' ) ) {
433 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
434 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
435 }
436
437 $actions = array_merge( $actions, $new_actions );
438 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
439 }
440
441 /**
442 * @param object $item
443 * @param array $actions
444 * @param string $edit_link
445 * @param string $mode
446 *
447 * @return string
448 */
449 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
450 $form_name = $item->name;
451
452 if ( is_null( $form_name ) || trim( $form_name ) === '' ) {
453 $form_name = FrmFormsHelper::get_no_title_text();
454 }
455
456 $form_name = FrmAppHelper::kses( $form_name );
457
458 if ( 'excerpt' != $mode ) {
459 $form_name = FrmAppHelper::truncate( $form_name, 50 );
460 }
461
462 $val = '<strong>';
463
464 if ( 'trash' === $this->status ) {
465 $val .= $form_name;
466 } else {
467 $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> ';
468 }
469
470 $this->add_draft_label( $item, $val );
471 $val .= '</strong>';
472
473 $this->add_form_description( $item, $val );
474
475 return $val;
476 }
477
478 /**
479 * @param object $item
480 * @param string $val
481 *
482 * @return void
483 */
484 private function add_draft_label( $item, &$val ) {
485 if ( 'draft' === $item->status && 'draft' != $this->status ) {
486 $val .= ' - <span class="post-state">' . esc_html__( 'Draft', 'formidable' ) . '</span>';
487 }
488 }
489
490 /**
491 * @param object $item
492 * @param string $val
493 *
494 * @return void
495 */
496 private function add_form_description( $item, &$val ) {
497 global $mode;
498
499 if ( 'excerpt' === $mode && ! is_null( $item->description ) ) {
500 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
501 }
502 }
503
504 /**
505 * @return string
506 */
507 protected function confirm_bulk_delete() {
508 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
509 }
510 }
511