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

458 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 ( (array) $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 public function get_views() {
163
164 $statuses = array(
165 'published' => __( 'My Forms', 'formidable' ),
166 'draft' => __( 'Drafts', 'formidable' ),
167 'trash' => __( 'Trash', 'formidable' ),
168 );
169
170 $links = array();
171 $counts = FrmForm::get_count();
172 $form_type = FrmAppHelper::simple_get( 'form_type', 'sanitize_title', 'published' );
173
174 if ( isset( $statuses[ $form_type ] ) ) {
175 $counts->$form_type = $this->total_items;
176 }
177
178 $form_type = self::get_param(
179 array(
180 'param' => 'form_type',
181 'default' => 'published',
182 )
183 );
184
185 foreach ( $statuses as $status => $name ) {
186
187 if ( $status == $form_type ) {
188 $class = ' class="current"';
189 } else {
190 $class = '';
191 }
192
193 if ( $counts->{$status} || 'draft' !== $status ) {
194 /* translators: %1$s: Status, %2$s: Number of items */
195 $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>';
196 }
197
198 unset( $status, $name );
199 }
200
201 return $links;
202 }
203
204 /**
205 * @return void
206 */
207 public function pagination( $which ) {
208 global $mode;
209
210 parent::pagination( $which );
211
212 if ( 'top' === $which ) {
213 $this->view_switcher( $mode );
214 }
215 }
216
217 /**
218 * @param stdClass $item
219 * @param string $style
220 * @return string
221 */
222 public function single_row( $item, $style = '' ) {
223 global $frm_vars, $mode;
224
225 // Set up the hover actions for this user
226 $actions = array();
227 $edit_link = FrmForm::get_edit_link( $item->id );
228
229 $this->get_actions( $actions, $item, $edit_link );
230
231 $action_links = $this->row_actions( $actions );
232
233 // Set up the checkbox ( because the user is editable, otherwise its empty )
234 $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
235 $checkbox_label_text = sprintf(
236 // translators: Form title
237 __( 'Select %s', 'formidable' ),
238 ! empty( $item->name ) ? $item->name : __( '(no title)', 'formidable' )
239 );
240
241 $checkbox .= '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . $checkbox_label_text . '</span></label>';
242
243 $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
244
245 list( $columns, $hidden ) = $this->get_column_info();
246
247 $format = 'Y/m/d';
248 if ( 'list' != $mode ) {
249 $format .= ' \<\b\r \/\> g:i:s a';
250 }
251
252 foreach ( $columns as $column_name => $column_display_name ) {
253 $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
254
255 $style = '';
256 if ( in_array( $column_name, $hidden ) ) {
257 $class .= ' frm_hidden';
258 }
259
260 if ( $column_name === 'name' ) {
261 $class .= ' column-primary';
262 }
263
264 $class = 'class="' . esc_attr( $class ) . '"';
265 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
266 $attributes = $class . $style . $data_colname;
267
268 switch ( $column_name ) {
269 case 'cb':
270 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
271 break;
272 case 'id':
273 case 'form_key':
274 $val = $item->{$column_name};
275 break;
276 case 'name':
277 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
278 $val .= $action_links;
279 break;
280 case 'created_at':
281 $date = gmdate( $format, strtotime( $item->created_at ) );
282 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
283 break;
284 case 'entries':
285 if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
286 $val = FrmAppHelper::icon_by_class(
287 'frmfont frm_forbid_icon frm_bstooltip',
288 array(
289 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
290 'echo' => false,
291 )
292 );
293 } else {
294 $text = FrmEntry::getRecordCount( $item->id );
295 $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
296 unset( $text );
297 }
298 break;
299 default:
300 if ( method_exists( $this, 'column_' . $column_name ) ) {
301 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
302 }
303 break;
304 }//end switch
305
306 if ( isset( $val ) ) {
307 $r .= "<td $attributes>";
308 $r .= $val;
309 $r .= '</td>';
310 }
311 unset( $val );
312 }//end foreach
313 $r .= '</tr>';
314
315 return $r;
316 }
317
318 /**
319 * Get the HTML for the Actions column in the form list.
320 * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
321 *
322 * @since 6.0
323 *
324 * @param stdClass $form
325 * @return string
326 */
327 protected function column_shortcode( $form ) {
328 $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>';
329 $val .= $this->column_style( $form );
330 $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
331 // Remove the space hard coded in Landing pages.
332 $val = str_replace( '&nbsp;', '', $val );
333 $val = '<div>' . $val . '</div>';
334 return $val;
335 }
336
337 /**
338 * Get the HTML for the Style column in the form list.
339 *
340 * @since 6.0
341 *
342 * @param stdClass $form
343 * @return string
344 */
345 protected function column_style( $form ) {
346 $style_setting = isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : '';
347 $frm_settings = FrmAppHelper::get_settings();
348
349 if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
350 // Don't show a link if styling is off.
351 return '';
352 }
353
354 $style = FrmStylesController::get_form_style( $form );
355 if ( ! $style ) {
356 // Do a second pass to avoid null values.
357 $frm_style = new FrmStyle( 'default' );
358 $style = $frm_style->get_one();
359 }
360
361 $href = FrmStylesHelper::get_edit_url( $style, $form->id );
362 return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>';
363 }
364
365 /**
366 * @param array $actions
367 * @param object $item
368 * @param string $edit_link
369 *
370 * @return void
371 */
372 private function get_actions( &$actions, $item, $edit_link ) {
373 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
374 foreach ( $new_actions as $link => $action ) {
375 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
376 }
377
378 if ( 'trash' == $this->status ) {
379 $actions = $new_actions;
380
381 return;
382 }
383
384 if ( current_user_can( 'frm_edit_forms' ) ) {
385 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
386 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
387 }
388
389 $actions = array_merge( $actions, $new_actions );
390 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
391 }
392
393 /**
394 * @param object $item
395 * @param array $actions
396 * @param string $edit_link
397 * @param string $mode
398 *
399 * @return string
400 */
401 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
402 $form_name = $item->name;
403 if ( trim( $form_name ) == '' ) {
404 $form_name = __( '(no title)', 'formidable' );
405 }
406 $form_name = FrmAppHelper::kses( $form_name );
407 if ( 'excerpt' != $mode ) {
408 $form_name = FrmAppHelper::truncate( $form_name, 50 );
409 }
410
411 $val = '<strong>';
412 if ( 'trash' == $this->status ) {
413 $val .= $form_name;
414 } else {
415 $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> ';
416 }
417
418 $this->add_draft_label( $item, $val );
419 $val .= '</strong>';
420
421 $this->add_form_description( $item, $val );
422
423 return $val;
424 }
425
426 /**
427 * @param object $item
428 * @param string $val
429 *
430 * @return void
431 */
432 private function add_draft_label( $item, &$val ) {
433 if ( 'draft' == $item->status && 'draft' != $this->status ) {
434 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
435 }
436 }
437
438 /**
439 * @param object $item
440 * @param string $val
441 *
442 * @return void
443 */
444 private function add_form_description( $item, &$val ) {
445 global $mode;
446 if ( 'excerpt' == $mode ) {
447 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
448 }
449 }
450
451 /**
452 * @return string
453 */
454 protected function confirm_bulk_delete() {
455 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
456 }
457 }
458