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

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