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

446 lines 12.1 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 }
298
299 if ( isset( $val ) ) {
300 $r .= "<td $attributes>";
301 $r .= $val;
302 $r .= '</td>';
303 }
304 unset( $val );
305 }
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 $val = str_replace( '&nbsp;', '', $val ); // Remove the space hard coded in Landing pages.
325 $val = '<div>' . $val . '</div>';
326 return $val;
327 }
328
329 /**
330 * Get the HTML for the Style column in the form list.
331 *
332 * @since 6.0
333 *
334 * @param stdClass $form
335 * @return string
336 */
337 protected function column_style( $form ) {
338 $style_setting = isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : '';
339 $frm_settings = FrmAppHelper::get_settings();
340
341 if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
342 // Don't show a link if styling is off.
343 return '';
344 }
345
346 $style = FrmStylesController::get_form_style( $form );
347 if ( ! $style ) {
348 // Do a second pass to avoid null values.
349 $frm_style = new FrmStyle( 'default' );
350 $style = $frm_style->get_one();
351 }
352
353 $href = FrmStylesHelper::get_edit_url( $style, $form->id );
354 return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>';
355 }
356
357 /**
358 * @param string $edit_link
359 * @param array $actions
360 * @param stdClass $item
361 *
362 * @return void
363 */
364 private function get_actions( &$actions, $item, $edit_link ) {
365 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
366 foreach ( $new_actions as $link => $action ) {
367 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
368 }
369
370 if ( 'trash' == $this->status ) {
371 $actions = $new_actions;
372
373 return;
374 }
375
376 if ( current_user_can( 'frm_edit_forms' ) ) {
377 $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
378 $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
379 }
380
381 $actions = array_merge( $actions, $new_actions );
382 $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
383 }
384
385 /**
386 * @param string $edit_link
387 * @param stdClass $item
388 *
389 * @return string
390 */
391 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
392 $form_name = $item->name;
393 if ( trim( $form_name ) == '' ) {
394 $form_name = __( '(no title)', 'formidable' );
395 }
396 $form_name = FrmAppHelper::kses( $form_name );
397 if ( 'excerpt' != $mode ) {
398 $form_name = FrmAppHelper::truncate( $form_name, 50 );
399 }
400
401 $val = '<strong>';
402 if ( 'trash' == $this->status ) {
403 $val .= $form_name;
404 } else {
405 $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> ';
406 }
407
408 $this->add_draft_label( $item, $val );
409 $val .= '</strong>';
410
411 $this->add_form_description( $item, $val );
412
413 return $val;
414 }
415
416 /**
417 * @param string $val
418 *
419 * @return void
420 */
421 private function add_draft_label( $item, &$val ) {
422 if ( 'draft' == $item->status && 'draft' != $this->status ) {
423 $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
424 }
425 }
426
427 /**
428 * @param string $val
429 *
430 * @return void
431 */
432 private function add_form_description( $item, &$val ) {
433 global $mode;
434 if ( 'excerpt' == $mode ) {
435 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
436 }
437 }
438
439 /**
440 * @return string
441 */
442 protected function confirm_bulk_delete() {
443 return __( 'ALL selected forms and their entries will be permanently deleted. Want to proceed?', 'formidable' );
444 }
445 }
446