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

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