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

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