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

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