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

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