PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
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
← All changes | classes/helpers/FrmFormsListHelper.php +53 -204 6.315.3 View file →
@@ -3,35 +3,20 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmFormsListHelper extends FrmListHelper {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public $status = '';
12 8
13 9 public $total_items = 0;
14 10
15 - /**
16 - * @param array $args
17 - */
18 11 public function __construct( $args ) {
19 12 $this->status = self::get_param( array( 'param' => 'form_type' ) );
20 13
21 14 parent::__construct( $args );
22 - $this->screen->set_screen_reader_content(
23 - array(
24 - 'heading_list' => esc_html__( 'Forms list', 'formidable' ),
25 - )
26 - );
27 15 }
28 16
29 - /**
30 - * @return void
31 - */
32 17 public function prepare_items() {
33 - global $per_page, $mode;
18 + global $wpdb, $per_page, $mode;
34 19
35 20 $page = $this->get_pagenum();
36 21 $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
37 22
@@ -52,12 +37,9 @@
52 37 'param' => 'order',
53 38 'default' => 'ASC',
54 39 )
55 40 );
56 -
57 - FrmAppController::apply_saved_sort_preference( $orderby, $order );
58 -
59 - $start = self::get_param(
41 + $start = self::get_param(
60 42 array(
61 43 'param' => 'start',
62 44 'default' => ( $page - 1 ) * $per_page,
63 45 )
@@ -89,14 +71,12 @@
89 71 'param' => 's',
90 72 'sanitize' => 'sanitize_text_field',
91 73 )
92 74 );
93 -
94 - if ( $s !== '' ) {
75 + if ( $s != '' ) {
95 76 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
96 77 $search_terms = array_map( 'trim', $matches[0] );
97 -
98 - foreach ( $search_terms as $term ) {
78 + foreach ( (array) $search_terms as $term ) {
99 79 $s_query[] = array(
100 80 'or' => true,
101 81 'name LIKE' => $term,
102 82 'description LIKE' => $term,
@@ -107,10 +87,10 @@
107 87 unset( $term );
108 88 }
109 89 }
110 90
111 - $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
112 - $total_items = FrmDb::get_count( 'frm_forms', $s_query );
91 + $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
92 + $total_items = FrmDb::get_count( 'frm_forms', $s_query );
113 93 $this->total_items = $total_items;
114 94
115 95 $this->set_pagination_args(
116 96 array(
@@ -119,22 +99,17 @@
119 99 )
120 100 );
121 101 }
122 102
123 - /**
124 - * @return void
125 - */
126 103 public function no_items() {
127 104 if ( $this->status === 'trash' ) {
128 105 echo '<p>';
129 106 esc_html_e( 'No forms found in the trash.', 'formidable' );
130 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
131 107 ?>
132 108 <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable' ) ); ?>">
133 109 <?php esc_html_e( 'See all forms.', 'formidable' ); ?>
134 110 </a>
135 111 <?php
136 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
137 112 echo '</p>';
138 113 } else {
139 114 $title = __( 'No Forms Found', 'formidable' );
140 115 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_no_forms.php';
@@ -143,9 +118,9 @@
143 118
144 119 public function get_bulk_actions() {
145 120 $actions = array();
146 121
147 - if ( 'trash' === $this->status ) {
122 + if ( 'trash' == $this->status ) {
148 123 if ( current_user_can( 'frm_edit_forms' ) ) {
149 124 $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
150 125 }
151 126
@@ -160,35 +135,24 @@
160 135
161 136 return $actions;
162 137 }
163 138
164 - /**
165 - * @param string $which
166 - *
167 - * @return void
168 - */
169 139 public function extra_tablenav( $which ) {
170 - if ( 'top' !== $which ) {
140 + if ( 'top' != $which ) {
171 141 return;
172 142 }
173 143
174 - if ( 'trash' !== $this->status || ! current_user_can( 'frm_delete_forms' ) ) {
175 - return;
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
176 150 }
177 -
178 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
179 - ?>
180 - <div class="alignleft actions frm_visible_overflow">
181 - <?php submit_button( __( 'Empty Trash', 'formidable' ), 'apply', 'delete_all', false ); ?>
182 - </div>
183 - <?php
184 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
185 151 }
186 152
187 - /**
188 - * @return array
189 - */
190 153 public function get_views() {
154 +
191 155 $statuses = array(
192 156 'published' => __( 'My Forms', 'formidable' ),
193 157 'draft' => __( 'Drafts', 'formidable' ),
194 158 'trash' => __( 'Trash', 'formidable' ),
@@ -195,14 +159,8 @@
195 159 );
196 160
197 161 $links = array();
198 162 $counts = FrmForm::get_count();
199 - $form_type = FrmAppHelper::simple_get( 'form_type', 'sanitize_title', 'published' );
200 -
201 - if ( isset( $statuses[ $form_type ] ) ) {
202 - $counts->$form_type = $this->total_items;
203 - }
204 -
205 163 $form_type = self::get_param(
206 164 array(
207 165 'param' => 'form_type',
208 166 'default' => 'published',
@@ -209,13 +167,18 @@
209 167 )
210 168 );
211 169
212 170 foreach ( $statuses as $status => $name ) {
213 - $class = $status == $form_type ? ' class="current"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons
214 171
172 + if ( $status == $form_type ) {
173 + $class = ' class="current"';
174 + } else {
175 + $class = '';
176 + }
177 +
215 178 if ( $counts->{$status} || 'draft' !== $status ) {
216 179 /* translators: %1$s: Status, %2$s: Number of items */
217 - $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>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
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>';
218 181 }
219 182
220 183 unset( $status, $name );
221 184 }
@@ -222,13 +185,8 @@
222 185
223 186 return $links;
224 187 }
225 188
226 - /**
227 - * @param string $which
228 - *
229 - * @return void
230 - */
231 189 public function pagination( $which ) {
232 190 global $mode;
233 191
234 192 parent::pagination( $which );
@@ -237,16 +195,10 @@
237 195 $this->view_switcher( $mode );
238 196 }
239 197 }
240 198
241 - /**
242 - * @param stdClass $item
243 - * @param string $style
244 - *
245 - * @return string
246 - */
247 199 public function single_row( $item, $style = '' ) {
248 - global $mode;
200 + global $frm_vars, $mode;
249 201
250 202 // Set up the hover actions for this user
251 203 $actions = array();
252 204 $edit_link = FrmForm::get_edit_link( $item->id );
@@ -255,38 +207,27 @@
255 207
256 208 $action_links = $this->row_actions( $actions );
257 209
258 210 // Set up the checkbox ( because the user is editable, otherwise its empty )
259 - $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
260 - $checkbox_label_text = sprintf(
261 - // translators: Form title
262 - __( 'Select %s', 'formidable' ),
263 - ! empty( $item->name ) ? $item->name : FrmFormsHelper::get_no_title_text()
264 - );
211 + $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
265 212
266 - $checkbox .= '<label for="cb-item-action-' . absint( $item->id ) . '"><span class="screen-reader-text">' . esc_html( $checkbox_label_text ) . '</span></label>';
267 - $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
213 + $r = '<tr id="item-action-' . absint( $item->id ) . '"' . $style . '>';
268 214
269 215 list( $columns, $hidden ) = $this->get_column_info();
270 216
271 217 $format = 'Y/m/d';
272 -
273 - if ( 'list' !== $mode ) {
218 + if ( 'list' != $mode ) {
274 219 $format .= ' \<\b\r \/\> g:i:s a';
275 220 }
276 221
277 222 foreach ( $columns as $column_name => $column_display_name ) {
278 - $class = $column_name . ' column-' . $column_name . ( 'name' === $column_name ? ' post-title page-title column-title' : '' );
223 + $class = $column_name . ' column-' . $column_name . ( 'name' == $column_name ? ' post-title page-title column-title' : '' );
224 +
279 225 $style = '';
280 -
281 - if ( in_array( $column_name, $hidden, true ) ) {
226 + if ( in_array( $column_name, $hidden ) ) {
282 227 $class .= ' frm_hidden';
283 228 }
284 229
285 - if ( $column_name === 'name' ) {
286 - $class .= ' column-primary';
287 - }
288 -
289 230 $class = 'class="' . esc_attr( $class ) . '"';
290 231 $data_colname = ' data-colname="' . esc_attr( $column_display_name ) . '"';
291 232 $attributes = $class . $style . $data_colname;
292 233
@@ -298,17 +239,22 @@
298 239 case 'form_key':
299 240 $val = $item->{$column_name};
300 241 break;
301 242 case 'name':
302 - $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
243 + $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
303 244 $val .= $action_links;
245 +
304 246 break;
305 247 case 'created_at':
306 248 $date = gmdate( $format, strtotime( $item->created_at ) );
307 249 $val = '<abbr title="' . esc_attr( gmdate( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
308 250 break;
251 + case 'shortcode':
252 + $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>';
253 + $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $item ) );
254 + break;
309 255 case 'entries':
310 - if ( ! empty( $item->options['no_save'] ) ) {
256 + if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
311 257 $val = FrmAppHelper::icon_by_class(
312 258 'frmfont frm_forbid_icon frm_bstooltip',
313 259 array(
314 260 'title' => __( 'Saving entries is disabled for this form', 'formidable' ),
@@ -316,18 +262,12 @@
316 262 )
317 263 );
318 264 } else {
319 265 $text = FrmEntry::getRecordCount( $item->id );
320 - $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
266 + $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text;
321 267 unset( $text );
322 268 }
323 - break;
324 - default:
325 - if ( method_exists( $this, 'column_' . $column_name ) ) {
326 - $val = call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
327 - }
328 - break;
329 - }//end switch
269 + }
330 270
331 271 if ( isset( $val ) ) {
332 272 $r .= "<td $attributes>";
333 273 $r .= $val;
@@ -333,140 +273,56 @@
333 273 $r .= $val;
334 274 $r .= '</td>';
335 275 }
336 276 unset( $val );
337 - }//end foreach
338 - return $r . '</tr>';
339 - }
340 -
341 - /**
342 - * Get the HTML for the Actions column in the form list.
343 - * This includes multiple icons for triggering the embed modal, the visual styler, and an active landing page.
344 - *
345 - * @since 6.0
346 - *
347 - * @param stdClass $form
348 - *
349 - * @return string
350 - */
351 - protected function column_shortcode( $form ) {
352 - $val = '<a href="#" class="frm-embed-form" role="button" aria-label="' . esc_attr__( 'Embed Form', 'formidable' ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_code_icon', array( 'echo' => false ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
353 - $val .= $this->column_style( $form );
354 - $val .= $this->column_views( $form );
355 - $val = apply_filters( 'frm_form_list_actions', $val, array( 'form' => $form ) );
356 - // Remove the space hard coded in Landing pages.
357 - $val = str_replace( '&nbsp;', '', $val );
358 - return '<div>' . $val . '</div>';
359 - }
360 -
361 - /**
362 - * Get the HTML for the Style column in the form list.
363 - *
364 - * @since 6.0
365 - *
366 - * @param stdClass $form
367 - *
368 - * @return string
369 - */
370 - protected function column_style( $form ) {
371 - $style_setting = $form->options['custom_style'] ?? '';
372 - $frm_settings = FrmAppHelper::get_settings();
373 -
374 - if ( $style_setting === '0' || 'none' === $frm_settings->load_style ) {
375 - // Don't show a link if styling is off.
376 - return '';
377 277 }
278 + $r .= '</tr>';
378 279
379 - $style = FrmStylesController::get_form_style( $form );
380 -
381 - if ( ! $style ) {
382 - // Do a second pass to avoid null values.
383 - $frm_style = new FrmStyle( 'default' );
384 - $style = $frm_style->get_one();
385 - }
386 -
387 - $href = FrmStylesHelper::get_edit_url( $style, $form->id );
388 - return '<a href="' . esc_url( $href ) . '" title="' . esc_attr( $style->post_title ) . '">' . FrmAppHelper::icon_by_class( 'frmfont frm_pallet_icon', array( 'echo' => false ) ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
280 + return $r;
389 281 }
390 282
391 283 /**
392 - * Generate the HTML for the form Views page.
393 - *
394 - * @since 6.19
395 - *
396 - * @param stdClass $form Form object.
397 - *
398 - * @return string
399 - */
400 - protected function column_views( $form ) {
401 - $attributes = array(
402 - 'href' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $form->id ) . '&show_nav=1' ),
403 - 'title' => __( 'Link to list of all views for this form.', 'formidable' ),
404 - 'target' => '_blank',
405 - );
406 -
407 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
408 - return '<a ' . FrmAppHelper::array_to_html_params( $attributes ) . '>
409 - ' . FrmAppHelper::icon_by_class( 'frmfont frm_eye_icon', array( 'echo' => false ) ) .
410 - '</a>';
411 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
412 - }
413 -
414 - /**
415 - * @param array $actions
416 - * @param object $item
417 284 * @param string $edit_link
418 - *
419 - * @return void
420 285 */
421 286 private function get_actions( &$actions, $item, $edit_link ) {
422 287 $new_actions = FrmFormsHelper::get_action_links( $item->id, $item );
423 -
424 288 foreach ( $new_actions as $link => $action ) {
425 289 $new_actions[ $link ] = FrmFormsHelper::format_link_html( $action, 'short' );
426 290 }
427 291
428 - if ( 'trash' === $this->status ) {
292 + if ( 'trash' == $this->status ) {
429 293 $actions = $new_actions;
294 +
430 295 return;
431 296 }
432 297
433 298 if ( current_user_can( 'frm_edit_forms' ) ) {
434 - $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>';
435 - $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . esc_html__( 'Settings', 'formidable' ) . '</a>';
299 + $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'formidable' ) . '</a>';
300 + $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
436 301 }
437 302
438 303 $actions = array_merge( $actions, $new_actions );
439 - $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . esc_html__( 'Preview', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
304 + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview', 'formidable' ) . '</a>';
440 305 }
441 306
442 307 /**
443 - * @param object $item
444 - * @param array $actions
445 308 * @param string $edit_link
446 - * @param string $mode
447 - *
448 - * @return string
449 309 */
450 310 private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
451 311 $form_name = $item->name;
452 -
453 - if ( is_null( $form_name ) || trim( $form_name ) === '' ) {
454 - $form_name = FrmFormsHelper::get_no_title_text();
312 + if ( trim( $form_name ) == '' ) {
313 + $form_name = __( '(no title)', 'formidable' );
455 314 }
456 -
457 315 $form_name = FrmAppHelper::kses( $form_name );
458 -
459 - if ( 'excerpt' !== $mode ) {
316 + if ( 'excerpt' != $mode ) {
460 317 $form_name = FrmAppHelper::truncate( $form_name, 50 );
461 318 }
462 319
463 320 $val = '<strong>';
464 -
465 - if ( 'trash' === $this->status ) {
321 + if ( 'trash' == $this->status ) {
466 322 $val .= $form_name;
467 323 } else {
468 - $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> '; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
324 + $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> ';
469 325 }
470 326
471 327 $this->add_draft_label( $item, $val );
472 328 $val .= '</strong>';
@@ -476,29 +332,22 @@
476 332 return $val;
477 333 }
478 334
479 335 /**
480 - * @param object $item
481 336 * @param string $val
482 - *
483 - * @return void
484 337 */
485 338 private function add_draft_label( $item, &$val ) {
486 - if ( 'draft' === $item->status && 'draft' !== $this->status ) {
487 - $val .= ' - <span class="post-state">' . esc_html__( 'Draft', 'formidable' ) . '</span>';
339 + if ( 'draft' == $item->status && 'draft' != $this->status ) {
340 + $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
488 341 }
489 342 }
490 343
491 344 /**
492 - * @param object $item
493 345 * @param string $val
494 - *
495 - * @return void
496 346 */
497 347 private function add_form_description( $item, &$val ) {
498 348 global $mode;
499 -
500 - if ( 'excerpt' === $mode && ! is_null( $item->description ) ) {
349 + if ( 'excerpt' == $mode ) {
501 350 $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
502 351 }
503 352 }
504 353