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

451 lines 12.2 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
236 $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
237
238 list( $columns, $hidden ) = $this->get_column_info();
239
240 $format = 'Y/m/d';
241 if ( 'list' != $mode ) {
242 $format .= ' \<\b\r \/\> g:i:s a';
243 }
244
245 foreach ( $columns as $column_name => $column_display_name ) {
246 $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
247
248 $style = '';
249 if ( in_array( $column_name, $hidden ) ) {
250 $class .= ' frm_hidden';
251 }
252
253 if ( $column_name === 'name' ) {
254 $class .= ' column-primary';
255 }
256
257 $class = 'class="' . esc_attr( $class ) . '"';
258 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
259 $attributes = $class . $style . $data_colname;
260
261 switch ( $column_name ) {
262 case 'cb':
263 $r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
264 break;
265 case 'id':
266 case 'form_key':
267 $val = $item->{$column_name};
268 break;
269 case 'name':
270 $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
271 $val .= $action_links;
272 break;
273 case 'created_at':
274 $date = gmdate( $format, strtotime( $item->created_at ) );
275 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
276 break;
277 case 'entries':
278 if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
279 $val = FrmAppHelper::icon_by_class(
280 'frmfont frm_forbid_icon frm_bstooltip',
281 array(
282 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
283 'echo' => false,
284 )
285 );
286 } else {
287 $text = FrmEntry::getRecordCount( $item->id );
288 $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
289 unset( $text );
290 }
291 break;
292 default:
293 if ( method_exists( $this, 'column_' . $column_name ) ) {
294 $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
295 }
296 break;
297 }//end switch
298
299 if ( isset( $val ) ) {
300 $r .= "<td $attributes>";
301 $r .= $val;
302 $r .= '</td>';
303 }
304 unset( $val );
305 }//end foreach
306 $r .= '</tr>';
307
308 return $r;
309 }
310
311 /**
312 * Get the HTML for the Actions column in the form list.
313 * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
314 *
315 * @since 6.0
316 *
317 * @param stdClass $form
318 * @return string
319 */
320 protected function column_shortcode( $form ) {
321 $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>';
322 $val .= $this->column_style( $form );
323 $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
324 // Remove the space hard coded in Landing pages.
325 $val = str_replace( '&nbsp;', '', $val );
326 $val = '<div>' . $val . '</div>';
327 return $val;
328 }
329
330 /**
331 * Get the HTML for the Style column in the form list.
332 *
333 * @since 6.0
334 *
335 * @param stdClass $form
336 * @return string
337 */
338 protected function column_style( $form ) {
339 $style_setting = isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : '';
340 $frm_settings = FrmAppHelper::get_settings();
341
342 if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
343 // Don't show a link if styling is off.
344 return '';
345 }
346
347 $style = FrmStylesController::get_form_style( $form );
348 if ( ! $style ) {
349 // Do a second pass to avoid null values.
350 $frm_style = new FrmStyle( 'default' );
351 $style = $frm_style->get_one();
352 }
353
354 $href = FrmStylesHelper::get_edit_url( $style, $form->id );
355 return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>';
356 }
357
358 /**
359 * @param array $actions
360 * @param object $item
361 * @param string $edit_link
362 *
363 * @return void
364 */
365 private function get_actions( &$actions, $item, $edit_link ) {
366 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
367 foreach ( $new_actions as $link => $action ) {
368 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
369 }
370
371 if ( 'trash' == $this->status ) {
372 $actions = $new_actions;
373
374 return;
375 }
376
377 if ( current_user_can( 'frm_edit_forms' ) ) {
378 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
379 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
380 }
381
382 $actions = array_merge( $actions, $new_actions );
383 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
384 }
385
386 /**
387 * @param object $item
388 * @param array $actions
389 * @param string $edit_link
390 * @param string $mode
391 *
392 * @return string
393 */
394 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
395 $form_name = $item->name;
396 if ( trim( $form_name ) == '' ) {
397 $form_name = __( '(no title)', 'formidable' );
398 }
399 $form_name = FrmAppHelper::kses( $form_name );
400 if ( 'excerpt' != $mode ) {
401 $form_name = FrmAppHelper::truncate( $form_name, 50 );
402 }
403
404 $val = '<strong>';
405 if ( 'trash' == $this->status ) {
406 $val .= $form_name;
407 } else {
408 $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> ';
409 }
410
411 $this->add_draft_label( $item, $val );
412 $val .= '</strong>';
413
414 $this->add_form_description( $item, $val );
415
416 return $val;
417 }
418
419 /**
420 * @param object $item
421 * @param string $val
422 *
423 * @return void
424 */
425 private function add_draft_label( $item, &$val ) {
426 if ( 'draft' == $item->status && 'draft' != $this->status ) {
427 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
428 }
429 }
430
431 /**
432 * @param object $item
433 * @param string $val
434 *
435 * @return void
436 */
437 private function add_form_description( $item, &$val ) {
438 global $mode;
439 if ( 'excerpt' == $mode ) {
440 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
441 }
442 }
443
444 /**
445 * @return string
446 */
447 protected function confirm_bulk_delete() {
448 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
449 }
450 }
451